Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Jul 20, 2017
1 parent 76ef5fd commit 16cf0c4
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 15 deletions.
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,6 @@ class Node extends libp2p {
- `key`: Buffer
- `nVals`: Number

---------------------

`SOON™`

#### `libp2p.findPeers`

#### `libp2p.findProviders`

#### `libp2p.record.put`

#### `libp2p.record.get`

[PeerInfo]: https://github.com/libp2p/js-peer-info
[PeerId]: https://github.com/libp2p/js-peer-id
[PeerBook]: https://github.com/libp2p/js-peer-book
Expand Down
1 change: 0 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ Let us know if you find any issue or if you want to contribute and add a new tut
- Running libp2p in the Electron (future)
- [The standard echo net example with libp2p](./echo)
- [A simple chat app with](./chat)
- [See other nodes in the network using WebRTC Star discovery mechanism](./see-nodes)
64 changes: 64 additions & 0 deletions examples/peer-and-content-routing/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict'

const libp2p = require('libp2p')
const TCP = require('libp2p-tcp')
const Multiplex = require('libp2p-multiplex')
const SECIO = require('libp2p-secio')
const PeerInfo = require('peer-info')
const KadDHT = require('libp2p-kad-dht')

const waterfall = require('async/waterfall')
const parallel = require('async/parallel')

class MyBundle extends libp2p {
constructor (peerInfo) {
const modules = {
transport: [new TCP()],
connection: {
muxer: [Multiplex],
crypto: [SECIO]
},
// we add the DHT module that will enable Peer and Content Routing
DHT: KadDHT
}
super(modules, peerInfo)
}
}

function createNode (callback) {
let node

waterfall([
(cb) => PeerInfo.create(cb),
(peerInfo, cb) => {
peerInfo.multiaddrs.add('/ip4/0.0.0.0/tcp/0')
node = new MyBundle(peerInfo)
node.start(cb)
}
], (err) => callback(err, node))
}

parallel([
(cb) => createNode(cb),
(cb) => createNode(cb),
(cb) => createNode(cb)
], (err, nodes) => {
if (err) { throw err }

const node1 = nodes[0]
const node2 = nodes[1]
const node3 = nodes[2]

parallel([
(cb) => node1.dial(node2.peerInfo, cb),
(cb) => node2.dial(node3.peerInfo, cb)
], (err) => {
if (err) { throw err }

node1.peerRouting.findPeer(node3.peerInfo.id, (err, peer) => {
if (err) { throw err }

console.log(peer.id.toB58String())
})
})
})
26 changes: 26 additions & 0 deletions examples/peer-and-content-routing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Peer and Content Routing

DHTs (Distributed Hash Tables) are one of the most common building blocks used when creating P2P networks. However, the name doesn't make justice to all the benefits it brings and putting the whole set of features in one box has proven to be limiting when we want to integrate multiple pieces together. With this in mind, we've come up with a new definition for what a DHT offers: Peer Routing and Content Routing.

Peer Routing is the category of modules that offer a way to find other peers in the network by intentionally issuing queries, iterative or recursive, until a Peer is found or the closest Peers, given the Peer Routing algorithm strategy are found.

Content Routing is the category of modules that offer a way to find where content lives in the network, it works in two steps: 1) Peers provide (announce) to the network that they are holders of specific content (multihashes) and 2) Peers issue queries to find where that content lives. A Content Routing mechanism could be as complex as a Kademlia DHT or a simple registry somewhere in the network.

# 1. Using Peer Routing to find other peers

This example builds on top of the Protocol and Stream Muxing. We need to install `libp2p-kad-dht`, go ahead and `npm install libp2p-kad-dht`.

`TODO`

# 2. Using Content Routing to find providers of content

`TODO`

# 3. Future Work

Currently, the only mechanisms for Peer and Content Routing come from the DHT, however we do have the intention to support:

- Multiple Peer Routing Mechanisms, including ones that do recursive searches (i.e webrtc-explorer like packet switching)
- Content Routing via PubSub
- Content Routing via centralized index (i.e a tracker)

2 changes: 0 additions & 2 deletions examples/peer-routing/README.md

This file was deleted.

2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Node extends EventEmitter {
this.modules = _modules
this.peerInfo = _peerInfo
this.peerBook = _peerBook || new PeerBook()
_options = _options || {}

this._isStarted = false

this.swarm = new Swarm(this.peerInfo, this.peerBook)
Expand Down

0 comments on commit 16cf0c4

Please sign in to comment.