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