Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Awesome DHT #86

Merged
merged 8 commits into from
Apr 6, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
'use strict'

const EventEmitter = require('events').EventEmitter
const assert = require('assert')

const setImmediate = require('async/setImmediate')
const each = require('async/each')
const series = require('async/series')

const Ping = require('libp2p-ping')
const DHT = require('libp2p-dht')
const Swarm = require('libp2p-swarm')
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const mafmt = require('mafmt')
const PeerBook = require('peer-book')
const mafmt = require('mafmt')
const multiaddr = require('multiaddr')
const EventEmitter = require('events').EventEmitter
const assert = require('assert')
const Ping = require('libp2p-ping')
const setImmediate = require('async/setImmediate')

exports = module.exports

Expand Down Expand Up @@ -73,9 +78,10 @@ class Node extends EventEmitter {
// Mount default protocols
Ping.mount(this.swarm)

this.dht = new DHT(this)

// Not fully implemented in js-libp2p yet
this.routing = undefined
this.records = undefined
}

/*
Expand Down Expand Up @@ -117,22 +123,29 @@ class Node extends EventEmitter {
}
})

this.swarm.listen((err) => {
series([
(cb) => this.swarm.listen(cb),
(cb) => {
if (this.modules.discovery) {
each(this.modules.discovery, (d, cb) => {
d.start(cb)
}, cb)
}
cb()
},
(cb) => this.dht.start(cb)
], (err) => {
if (err) {
return callback(err)
}

if (ws) {
this.swarm.transport.add(ws.tag || ws.constructor.name, ws)
this.swarm.transport.add(
ws.tag || ws.constructor.name, ws
)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transports (swarm) prep needs to happen first than discovery as discovery will trigger dials that use swarm.


this.isOnline = true

if (this.modules.discovery) {
this.modules.discovery.forEach((discovery) => {
setImmediate(() => discovery.start(() => {}))
})
}

callback()
})
}
Expand Down