Git Product home page Git Product logo

baseswim's Introduction

baseswim

A base swim node

Install

npm i baseswim -g

or

docker pull matteocollina/baseswim

Usage

baseswim [--http 3000] [--port PORT] [peers...]

Each peer is in the form of IP:PORT, like 127.0.0.1:7799

with Docker

On Linux:

docker run -p 3000:3000 -p 7799:7799/udp -d matteocollina/baseswim --host `ip addr show wlan0 | grep -Po 'inet \K[\d.]+'` --http 3000

adjut the host configuration to your own interface/ip address

On Mac:

docker run -p 3000:3000 -p 7799:7799/udp -d matteocollina/baseswim --host `ipconfig getifaddr en0` --http 3000

adjut the host configuration to your own interface/ip address

On docker-machine:

docker run -p 3000:3000 -p 7799:7799/udp -d matteocollina/baseswim --host `docker-machine ip default` --http 3000

If you need to connect it to other peers pass any peer id at the end, like for the normal usage.

as a module

'use strict'

const baseswim = require('baseswim')
const id = '127.0.0.1:7799' // replace your ip address

const swim = baseswim(id, {
  http: 3000 // to enable the HTTP endpoints
})

swim.on('peerUp', (peer) => console.log(peer))
swim.on('peerDown', (peer) => console.log(peer))

The swim instance is the same of swim-js. See its README for the API.

constructor options

If you do not pass any options, baseswim will bound to a network interface (not localhost) and pick a free udp port.

You can also pass the host and port as parameters:

const swim = baseswim({
  host: '127.0.0.1',
  port: 7799
})

HTTP endpoints

If enabled by the --http flag, baseswim provides two HTTP endpoint to control the base node.

GET /members

Provides a list of the current members, output:

$ curl `docker-machine ip default`:3000/members
{
  "members": [
    {
      "host": "192.168.99.100:7799",
      "state": 0,
      "incarnation": 0
    }
  ]
}

POST /join

Provides a list of the current members, output:

curl -X POST -d 'PEER' `docker-machine ip default`:3000/members

where PEER is an IP:PORT combination.

Acknowledgements

baseswim is sponsored by nearForm.

License

MIT

baseswim's People

Contributors

mcollina avatar trygve-lie avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.