Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

feat: handle ipfs multiaddrs #41

Merged
merged 1 commit into from
Apr 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,26 @@
"bl": "^1.1.2",
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"aegir": "^2.1.0",
"aegir": "^2.1.1",
"gulp": "^3.9.1",
"istanbul": "^0.4.2",
"istanbul": "^0.4.3",
"libp2p-multiplex": "^0.2.1",
"libp2p-spdy": "^0.2.3",
"libp2p-spdy": "^0.3.1",
"libp2p-tcp": "^0.4.0",
"libp2p-websockets": "^0.3.1",
"multiaddr": "^1.3.0",
"peer-id": "^0.6.0",
"peer-info": "^0.6.0",
"libp2p-websockets": "^0.3.2",
"multiaddr": "^1.4.0",
"peer-id": "^0.6.6",
"peer-info": "^0.6.2",
"pre-commit": "^1.1.2",
"stream-pair": "^1.0.3"
},
"dependencies": {
"babel-runtime": "^6.6.1",
"duplex-passthrough": "github:diasdavid/duplex-passthrough",
"ip-address": "^5.0.2",
"multistream-select": "^0.6.1",
"protocol-buffers-stream": "^1.2.0"
"ip-address": "^5.8.0",
"lodash.contains": "^2.4.3",
"multistream-select": "^0.6.5",
"protocol-buffers-stream": "^1.3.1"
},
"aegir": {
"webpack": {
Expand Down
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const multistream = require('multistream-select')
const identify = require('./identify')
const DuplexPassThrough = require('duplex-passthrough')
const contains = require('lodash.contains')

exports = module.exports = Swarm

Expand Down Expand Up @@ -87,7 +88,16 @@ function Swarm (peerInfo) {
// if no callback is passed, we pass conns to connHandler
if (!handler) { handler = connHandler }

const multiaddrs = this.transports[key].filter(peerInfo.multiaddrs)
const multiaddrs = this.transports[key].filter(
peerInfo.multiaddrs.map((addr) => {
// ipfs multiaddrs are not dialable so we drop them here
if (contains(addr.protoNames(), 'ipfs')) {
return addr.decapsulate('ipfs')
}

return addr
})
)

this.transports[key].createListener(multiaddrs, handler, (err, maUpdate) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion test/08-swarm-without-muxing.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('high level API - 1st without stream multiplexing (on TCP)', function (
peerB = new Peer()

peerA.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9001'))
peerB.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9002'))
peerB.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9002/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'))

swarmA = new Swarm(peerA)
swarmB = new Swarm(peerB)
Expand Down