blockhub-node-operator

1.4.0 • Public • Published

logo


Gitter chat license

Node Operator for BlockHub


BlockHub Node Operator assists BlockHub clients with the following:

  • Brokering p2p connections between clients. Data is not proxied/passed through the operator.
  • Distributing IPFS downloads.
  • Serving data for clients to hydrate screen information (such as a product page).

Quick Links

Install

Install Node Package Manager (NVM):

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

Install Node 8.11.1:

nvm install 8.11.1

If you get nvm: command not found, simply close your current terminal, open a new terminal, and try again. Please see the NVM readme if you have any issues.

Run Server

Install the library:

$> yarn add blockhub-node-operator

Run the server:

$> blockhub-node-operator --port 9000 --key nodeOperator

Or, create a custom server:

let BlockHubServer = require('blockhub-node-operator').BlockHubServer
let server = BlockHubServer({ port: 9000, path: '/myapp' })

Connecting to the server from frontend:

<script>
    let peer = new Peer('someid', { host: 'localhost', port: 9000, path: '/myapp' })
</script>

Using HTTPS: Simply pass in PEM-encoded certificate and key.

let fs = require('fs')
let BlockHubServer = require('peer').BlockHubServer

let server = BlockHubServer({
  port: 9000,
  ssl: {
    key: fs.readFileSync('/path/to/your/ssl/key/here.key'),
    cert: fs.readFileSync('/path/to/your/ssl/certificate/here.crt')
  }
})

Running BlockHubServer behind a reverse proxy

Make sure to set the proxied option, otherwise IP based limiting will fail. The option is passed verbatim to the expressjs trust proxy setting if it is truthy.

let BlockHubServer = require('blockhub-node-operator').BlockHubServer
let server = BlockHubServer({ port: 9000, path: '/myapp', proxied: true })

Combining with existing express app

let express = require('express')
let app = express()
let ExpressServer = require('blockhub-node-operator').ExpressServer

app.get('/', function(req, res, next) { res.send('Hello world!') })

// =======

let server = app.listen(9000)

let options = {
    debug: true
}

let expressServer = ExpressServer(server, options)

app.use('/api', expressServer)

// == OR ==

let server = require('http').createServer(app)
let expressServer = ExpressServer(server, options)

app.use('/nodeOperator', expressServer)

server.listen(9000)

// ========

Events

The 'connection' event is emitted when a peer connects to the server.

expressServer.on('connection', function(id) { ... })

The 'disconnect' event is emitted when a peer disconnects from the server or when the peer can no longer be reached.

expressServer.on('disconnect', function(id) { ... })

Problems?

Discuss Node Operator on our Gitter: https://gitter.im/Hyperbridge/Lobby

Please post any bugs as a Github issue.

Readme

Keywords

none

Package Sidebar

Install

npm i blockhub-node-operator

Weekly Downloads

4

Version

1.4.0

License

SEE LICENSE IN LICENSE

Unpacked Size

53.5 kB

Total Files

30

Last publish

Collaborators

  • ericmuyser