mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-06 05:51:20 +00:00
adding transports works
This commit is contained in:
parent
1833ded0f7
commit
73a6a4fd45
@ -1,29 +1,14 @@
|
|||||||
var Swarm = require('./../src')
|
var Swarm = require('./../src')
|
||||||
|
|
||||||
|
var Peer = require('peer-info')
|
||||||
|
var Id = require('peer-id')
|
||||||
|
var multiaddr = require('multiaddr')
|
||||||
|
var tcp = require('libp2p-tcp')
|
||||||
|
|
||||||
var Peer = require('ipfs-peer')
|
var mh = multiaddr('/ip4/127.0.0.1/tcp/8010')
|
||||||
// var Id = require('ipfs-peer-id')
|
var p = new Peer(Id.create(), [])
|
||||||
// var multiaddr = require('multiaddr')
|
var sw = new Swarm(p)
|
||||||
|
|
||||||
var b = new Swarm()
|
sw.addTransport('tcp', tcp, { multiaddr: mh }, {}, {port: 8010}, function () {
|
||||||
b.port = 4001
|
console.log('transport added')
|
||||||
// var peerB = new Peer(Id.create(), [multiaddr('/ip4/127.0.0.1/tcp/' + b.port)])
|
|
||||||
|
|
||||||
// var i = new Identify(b, peerB)
|
|
||||||
// i.on('thenews', function (news) {
|
|
||||||
// console.log('such news')
|
|
||||||
// })
|
|
||||||
|
|
||||||
b.on('error', function (err) {
|
|
||||||
console.log(err)
|
|
||||||
})
|
|
||||||
|
|
||||||
b.listen()
|
|
||||||
|
|
||||||
b.registerHandler('/ipfs/sparkles/1.2.3', function (stream) {
|
|
||||||
// if (err) {
|
|
||||||
// return console.log(err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
console.log('woop got a stream')
|
|
||||||
})
|
})
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"code": "^1.4.1",
|
"code": "^1.4.1",
|
||||||
"lab": "^5.13.0",
|
"lab": "^5.13.0",
|
||||||
|
"libp2p-tcp": "^0.1.1",
|
||||||
"precommit-hook": "^3.0.0",
|
"precommit-hook": "^3.0.0",
|
||||||
"sinon": "^1.15.4",
|
"sinon": "^1.15.4",
|
||||||
"standard": "^4.5.2",
|
"standard": "^4.5.2",
|
||||||
@ -42,11 +43,11 @@
|
|||||||
"async": "^1.3.0",
|
"async": "^1.3.0",
|
||||||
"ip-address": "^4.0.0",
|
"ip-address": "^4.0.0",
|
||||||
"ipfs-logger": "^0.1.0",
|
"ipfs-logger": "^0.1.0",
|
||||||
"ipfs-peer": "^0.3.0",
|
|
||||||
"ipfs-peer-id": "^0.3.0",
|
|
||||||
"multiaddr": "^1.0.0",
|
"multiaddr": "^1.0.0",
|
||||||
"multiplex-stream-muxer": "^0.2.0",
|
"multiplex-stream-muxer": "^0.2.0",
|
||||||
"multistream-select": "^0.6.1",
|
"multistream-select": "^0.6.1",
|
||||||
|
"peer-id": "^0.3.3",
|
||||||
|
"peer-info": "^0.3.2",
|
||||||
"protocol-buffers-stream": "^1.2.0",
|
"protocol-buffers-stream": "^1.2.0",
|
||||||
"spdy-stream-muxer": "^0.6.0"
|
"spdy-stream-muxer": "^0.6.0"
|
||||||
}
|
}
|
||||||
|
21
src/swarm.js
21
src/swarm.js
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
exports = module.exports = Swarm
|
exports = module.exports = Swarm
|
||||||
|
|
||||||
function Swarm (peerInfo) {
|
function Swarm (peerInfo) {
|
||||||
@ -26,14 +25,14 @@ function Swarm (peerInfo) {
|
|||||||
|
|
||||||
// public interface
|
// public interface
|
||||||
|
|
||||||
self.addTransport = function (transport, options, dialOptions, listenOptions, callback) {
|
self.addTransport = function (name, transport, options, dialOptions, listenOptions, callback) {
|
||||||
// set up the transport and add the list of incoming streams
|
// set up the transport and add the list of incoming streams
|
||||||
// add transport to the list of transports
|
// add transport to the list of transports
|
||||||
|
|
||||||
var listener = transport.createListener(options, listen)
|
var listener = transport.createListener(options, listen)
|
||||||
|
|
||||||
listener.listen(listenOptions, function ready () {
|
listener.listen(listenOptions, function ready () {
|
||||||
self.transports[options.name] = {
|
self.transports[name] = {
|
||||||
transport: transport,
|
transport: transport,
|
||||||
dialOptions: dialOptions,
|
dialOptions: dialOptions,
|
||||||
listenOptions: listenOptions,
|
listenOptions: listenOptions,
|
||||||
@ -49,13 +48,9 @@ function Swarm (peerInfo) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
self.addUpgrade = function (ConnUpgrade, options) {
|
self.addUpgrade = function (ConnUpgrade, options) {}
|
||||||
|
|
||||||
}
|
self.addStreamMuxer = function (StreamMuxer, options) {}
|
||||||
|
|
||||||
self.addStreamMuxer = function (StreamMuxer, options) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
self.dial = function (peerInfo, options, protocol, callback) {
|
self.dial = function (peerInfo, options, protocol, callback) {
|
||||||
// 1. check if we have transports we support
|
// 1. check if we have transports we support
|
||||||
@ -70,15 +65,13 @@ function Swarm (peerInfo) {
|
|||||||
// close everything
|
// close everything
|
||||||
}
|
}
|
||||||
|
|
||||||
self.handleProtocol = function (protocol, handlerFunction) {
|
self.handleProtocol = function (protocol, handlerFunction) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// internals
|
// internals
|
||||||
|
|
||||||
function listen (conn) {
|
function listen (conn) {
|
||||||
console.log('Received new connection')
|
console.log('Received new connection')
|
||||||
// apply upgrades
|
// apply upgrades
|
||||||
// then add it to the multistreamHandler
|
// then add it to the multistreamHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user