Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
feat: skip p2p-circuit addresses
  • Loading branch information
dryajov committed Sep 14, 2017
commit 23a7cbe723f5adc7e8ef40e66c6c7482f98d91ba
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@
"Richard Littauer <[email protected]>",
"Stephen Whitmore <[email protected]>"
]
}
}
10 changes: 10 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const net = require('net')
const toPull = require('stream-to-pull-stream')
const mafmt = require('mafmt')
const includes = require('lodash.includes')
const isFunction = require('lodash.isfunction')
const Connection = require('interface-connection').Connection
const once = require('once')
Expand Down Expand Up @@ -66,7 +67,16 @@ class TCP {
if (!Array.isArray(multiaddrs)) {
multiaddrs = [multiaddrs]
}

return multiaddrs.filter((ma) => {
if (includes(ma.protoNames(), 'p2p-circuit')) {
return false
}

if (includes(ma.protoNames(), 'ipfs')) {
ma = ma.decapsulate('ipfs')
}

return mafmt.TCP.matches(ma)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notes from the call today:

It should continue to be valid to pass an ipfs multiaddr, it just needs to check things differently.

    1. check if it is relay, if it is, skip it
    1. if not relay, check if it is ipfs, if it is, decapsulate
    1. check if it is TCP, if it is, include it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diasdavid ii and iii already happen in master, so it should be adding a check for circuit and skipping it if its present (i).

})
}
Expand Down
6 changes: 5 additions & 1 deletion test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,10 @@ describe('filter addrs', () => {
const mh3 = multiaddr('/ip4/127.0.0.1/tcp/9090/http')
const mh4 = multiaddr('/ip4/127.0.0.1/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
const mh5 = multiaddr('/ip4/127.0.0.1/tcp/9090/http/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
const mh6 = multiaddr('/ip4/127.0.0.1/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw' +
'/p2p-circuit/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')

const valid = tcp.filter([mh1, mh2, mh3, mh4, mh5])
const valid = tcp.filter([mh1, mh2, mh3, mh4, mh5, mh6])
expect(valid.length).to.equal(2)
expect(valid[0]).to.deep.equal(mh1)
expect(valid[1]).to.deep.equal(mh4)
Expand Down Expand Up @@ -350,6 +352,7 @@ describe('valid Connection', () => {
const conn = tcp.dial(ma)

pull(conn, pull.onEnd(endHandler))

function endHandler () {
conn.getPeerInfo((err, peerInfo) => {
expect(err).to.exist()
Expand All @@ -376,6 +379,7 @@ describe('valid Connection', () => {
const conn = tcp.dial(ma)

pull(conn, pull.onEnd(endHandler))

function endHandler () {
conn.setPeerInfo('arroz')
conn.getPeerInfo((err, peerInfo) => {
Expand Down