diff --git a/examples/peerB.js b/examples/peerB.js index c480983a..95ca3ff6 100644 --- a/examples/peerB.js +++ b/examples/peerB.js @@ -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') }) diff --git a/package.json b/package.json index f59408d5..4f5129bf 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/src/swarm.js b/src/swarm.js index 4d792999..6c38ec09 100644 --- a/src/swarm.js +++ b/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 } }