GithubHelp home page GithubHelp logo

pinghe / bitboot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tintfoundation/bitboot

0.0 0.0 0.0 14 KB

Bootstrap a distributed p2p network

Home Page: http://findingscience.com/bitboot/p2p/tint-foundation/dht/2016/08/05/bitboot-p2p-network-bootstrapping.html

License: MIT License

JavaScript 100.00%

bitboot's Introduction

bitboot travis npm

P2P Network Bootstrapping

Bitboot allows a new node in a peer-to-peer network to find other nodes in the same network, even if the network being joined is as small as a single node. It has no local dependencies and doesn't require that any other local services be running.

Install

npm install -g bitboot

Command Line Usage

bitboot <magic name>

The magic name should be a unique string (make sure to use quotation marks if it's more than one word) for your network. If at least one other instance of bitboot is running somewhere else with the same magic name, then the program will print out other node's locations as they are found (one per line, in host:port format). If you're just starting a new network, this may take a minute or two before other nodes are found.

Library Example

var Bitboot = require('bitboot')

// The rally point name can be any string and should be unique
// to your peer network
var bb = new Bitboot('bitboot test network')

// this is called whenever the node selects a new ID and rejoins
// the BitTorrent mainline DHT network
bb.on('rejoin', function (nodeId) {
  console.log('I have a new node id:', nodeId.toString('hex'))
})

// this is called whenever a search is made for peers
// peers will be the result of that search (and may be empty)
bb.on('peers', function (peers) {
  console.log('I found peers:', peers)
})

bb.on('error', function (err) {
  console.error(err)
})

Background

Many peer-to-peer networks clients are initially bootstrapped by connecting to a handful of hard-coded, centralized nodes (yes, even Bitcoin and BitTorrent). Every new peer-to-peer network must solve this same challenge, usually by hardcoding centralized bootstrap servers. Bitboot allows you to avoid this step of having to run/maintain a new centralized server if you're creating a new p2p network. Bitboot can also be used more generally to find a single peer (for instance, if you just want to be able to find your home computer and the IP is changing frequently).

When you run bitboot, you give it a magic name to uniquely identify the network you'd like to join. Bitboot then joins the existing BitTorrent DHT (perhaps the largest and most reliable/stable DHT on the planet) and finds other nodes with the same magic name. It does this by selecting a rally point to hang out near based on the magic name where it will meet other nodes with the same magic name value. Also, the ID it uses is carefully selected so other nodes can pick it out as a bitboot peer based on the value of the magic name (in case other non-member nodes are hanging out around the rally point).

Note that while bitboot uses the BitTorrent DHT, it does not harm the existing network in any way (and, in fact, strengthens it by adding additional, fully functional nodes).

bitboot's People

Contributors

bmuller 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.