Skip to content

Commit 0fa14c9

Browse files
feat: handle ipfs multiaddrs
Closes libp2p#38
1 parent ac7c8a1 commit 0fa14c9

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

package.json

+11-10
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,26 @@
4040
"bl": "^1.1.2",
4141
"buffer-loader": "0.0.1",
4242
"chai": "^3.5.0",
43-
"aegir": "^2.1.0",
43+
"aegir": "^2.1.1",
4444
"gulp": "^3.9.1",
45-
"istanbul": "^0.4.2",
45+
"istanbul": "^0.4.3",
4646
"libp2p-multiplex": "^0.2.1",
47-
"libp2p-spdy": "^0.2.3",
47+
"libp2p-spdy": "^0.3.1",
4848
"libp2p-tcp": "^0.4.0",
49-
"libp2p-websockets": "^0.3.1",
50-
"multiaddr": "^1.3.0",
51-
"peer-id": "^0.6.0",
52-
"peer-info": "^0.6.0",
49+
"libp2p-websockets": "^0.3.2",
50+
"multiaddr": "^1.4.0",
51+
"peer-id": "^0.6.6",
52+
"peer-info": "^0.6.2",
5353
"pre-commit": "^1.1.2",
5454
"stream-pair": "^1.0.3"
5555
},
5656
"dependencies": {
5757
"babel-runtime": "^6.6.1",
5858
"duplex-passthrough": "github:diasdavid/duplex-passthrough",
59-
"ip-address": "^5.0.2",
60-
"multistream-select": "^0.6.1",
61-
"protocol-buffers-stream": "^1.2.0"
59+
"ip-address": "^5.8.0",
60+
"lodash.contains": "^2.4.3",
61+
"multistream-select": "^0.6.5",
62+
"protocol-buffers-stream": "^1.3.1"
6263
},
6364
"aegir": {
6465
"webpack": {

src/index.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const multistream = require('multistream-select')
44
const identify = require('./identify')
55
const DuplexPassThrough = require('duplex-passthrough')
6+
const contains = require('lodash.contains')
67

78
exports = module.exports = Swarm
89

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

90-
const multiaddrs = this.transports[key].filter(peerInfo.multiaddrs)
91+
const multiaddrs = this.transports[key].filter(
92+
peerInfo.multiaddrs.map((addr) => {
93+
// ipfs multiaddrs are not dialable so we drop them here
94+
if (contains(addr.protoNames(), 'ipfs')) {
95+
return addr.decapsulate('ipfs')
96+
}
97+
98+
return addr
99+
})
100+
)
91101

92102
this.transports[key].createListener(multiaddrs, handler, (err, maUpdate) => {
93103
if (err) {

test/08-swarm-without-muxing.node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('high level API - 1st without stream multiplexing (on TCP)', function (
2121
peerB = new Peer()
2222

2323
peerA.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9001'))
24-
peerB.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9002'))
24+
peerB.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9002/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'))
2525

2626
swarmA = new Swarm(peerA)
2727
swarmB = new Swarm(peerB)

0 commit comments

Comments
 (0)