Skip to content
This repository has been archived by the owner on Jun 21, 2020. It is now read-only.

scrtlabs/enigma-p2p

Repository files navigation

enigma-p2p

The Enigma Worker P2P package written in Node.js based on libp2p-js

The P2P implementation of the Enigma Worker. This implementation is part of the Node stack running as a process on the OS communicating both with Core and the outside world.

Branch Build Code Coverage
Master Build Status codecov
Develop Build Status codecov

Table of Contents

Getting Started

Prerequisites

Installing

For using the released version (corresponding to the main branch of this repository) download it from npm:

npm i enigma-p2p

For installing a different branch of the repository:

git clone this repository

If running with Docker

cd into the project directory and type:

docker build .

To run later, save the final build hash or give it a name.

To run the node inside a container from the project directory type:

 docker run -v "$PWD":/usr/src/app -ti --net="host" <image-build-id> /bin/bash

Installing globally with nvm

  1. install nvm
  2. install some node version : $nvm install 10.16
  3. type npm install -g enigma-p2p
  4. to run global type : enigma-p2p-test <flags>

Incase of missing modules such as connect and tempdir install them in the same way.

npm install -g <missing module name>

Running the Node

Currently the node is started based on a command line interface (CLI). The node can be started from a single configuration file or with default configuration and CLI flags.

For usage example of a single configuration file see unit-test.

To launch the node using the CLI:

First enter the relevant directory:

cd ./src/cli

For help type:

$node cli_app.js -h

For interactive options help type help while running.

Example:

  1. launch a Bootstrap node:
node cli_app.js -i B1 -p B1 --core 127.0.0.1:1543 --proxy 3346 --random-db --mock-core
  1. launch a regular worker node that will connect to the bootstrap:
node cli_app.js -b B1 --core 127.0.0.1:6000 --random-db --mock-core
  1. launch ANOTHER regular worker node that will connect to the bootstrap:
node cli_app.js -b B1 --core 127.0.0.1:6001 --random-db --mock-core

In this example:

--core <ip>:<port> enigma-core uri. In this example we will be using a core simulation.

--mock-core launch a core simulation.

--proxy <port> will start up the JSON-RPC server as well.

--random-db is a must to generate a temporary database for the task management during testing.

-b flag for the bootstrap node, B1 is hard-coded for testing.

-i load specific node id from a hardcoded path.

-p run on a specific port since the bootstrap node is the first node everyone will connect to.

Running the tests

Tests are based on Mocha and can invoked by typing:

$npm test

Interacting with the node

JSON RPC API

The API for interacting with a proxy node.

Usage example:

  1. Start a bootstrap node which is also a Proxy
node cli_app.js -i B1 -p B1 --core 127.0.0.1:1543 --mock-core --proxy 3346 --random-db
  1. Start a regular worker that is NOT a proxy
node cli_app.js -b B1 --core 127.0.0.1:6000 --mock-core --random-db
  1. IMPORTANT: assuming the worker from #2 is the selected one, type selfSubscribe in the CLI so that the worker will subscribe to its own sign key. The key will be printed to std, copy it:
   [Wed Mar 27 2019 17:41:06 GMT+0200 (Israel Standard Time)] DEBUG subscribed to [0xd71c1bccb4b238cea332201bab1cd0fa70bec080] self signKey
  1. User wanting to call getWorkerEncryptionKey with curl see example and use the key from step 3 as the workerAddress parameter.

streams flow

Node health check

The node health check currently consists of the following checks:

  • The ability to interact with core
  • The ability to interact with Ethereum

To enable the health check, start the node with --health parameter. For example:

node cli_app.js -i B1 -p B1 --core 127.0.0.1:1543 --mock-core --health 12345

To query node status, curl can be used:

curl http://localhost:12345/healthcheck

Built With

Developers

If you wish to learn more about the project and contribute make sure to checkout:

  1. On boarding guide
  2. In depth design

Authors

License

The Enigma Worker P2P is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.