This repository has been archived by the owner on Aug 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
fix: dial self #329
Merged
Merged
fix: dial self #329
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
const dirtyChai = require('dirty-chai') | ||
const expect = chai.expect | ||
chai.use(dirtyChai) | ||
const Multiaddr = require('multiaddr') | ||
const PeerInfo = require('peer-info') | ||
|
||
const TransportManager = require('../src/transport') | ||
|
||
describe('Transport Manager', () => { | ||
describe('dialables', () => { | ||
let peerInfo | ||
const dialAllTransport = { filter: addrs => addrs } | ||
|
||
beforeEach(done => { | ||
PeerInfo.create((err, info) => { | ||
if (err) return done(err) | ||
peerInfo = info | ||
done() | ||
}) | ||
}) | ||
|
||
it('should return all transport addresses when peer info has 0 addrs', () => { | ||
const queryAddrs = [ | ||
'/ip4/127.0.0.1/tcp/4002', | ||
'/ip4/192.168.0.3/tcp/4002', | ||
'/ip6/::1/tcp/4001' | ||
].map(a => Multiaddr(a)) | ||
|
||
const dialableAddrs = TransportManager.dialables(dialAllTransport, queryAddrs, peerInfo) | ||
|
||
expect(dialableAddrs).to.have.length(queryAddrs.length) | ||
|
||
queryAddrs.forEach(qa => { | ||
expect(dialableAddrs.some(da => da.equals(qa))).to.be.true() | ||
}) | ||
}) | ||
|
||
it('should return all transport addresses when we pass no peer info', () => { | ||
const queryAddrs = [ | ||
'/ip4/127.0.0.1/tcp/4002', | ||
'/ip4/192.168.0.3/tcp/4002', | ||
'/ip6/::1/tcp/4001' | ||
].map(a => Multiaddr(a)) | ||
|
||
const dialableAddrs = TransportManager.dialables(dialAllTransport, queryAddrs) | ||
|
||
expect(dialableAddrs).to.have.length(queryAddrs.length) | ||
|
||
queryAddrs.forEach(qa => { | ||
expect(dialableAddrs.some(da => da.equals(qa))).to.be.true() | ||
}) | ||
}) | ||
|
||
it('should filter our addresses', () => { | ||
const queryAddrs = [ | ||
'/ip4/127.0.0.1/tcp/4002', | ||
'/ip4/192.168.0.3/tcp/4002', | ||
'/ip6/::1/tcp/4001' | ||
].map(a => Multiaddr(a)) | ||
|
||
const ourAddrs = [ | ||
'/ip4/127.0.0.1/tcp/4002', | ||
'/ip4/192.168.0.3/tcp/4002' | ||
] | ||
|
||
ourAddrs.forEach(a => peerInfo.multiaddrs.add(a)) | ||
|
||
const dialableAddrs = TransportManager.dialables(dialAllTransport, queryAddrs, peerInfo) | ||
|
||
expect(dialableAddrs).to.have.length(1) | ||
expect(dialableAddrs[0].toString()).to.equal('/ip6/::1/tcp/4001') | ||
}) | ||
|
||
it('should filter our addresses with peer ID suffix', () => { | ||
const queryAddrs = [ | ||
'/ip4/127.0.0.1/tcp/4002/ipfs/QmebzNV1kSzLfaYpSZdShuiABNUxoKT1vJmCdxM2iWsM2j', | ||
'/ip4/192.168.0.3/tcp/4002', | ||
'/ip6/::1/tcp/4001' | ||
].map(a => Multiaddr(a)) | ||
|
||
const ourAddrs = [ | ||
`/ip4/127.0.0.1/tcp/4002`, | ||
`/ip4/192.168.0.3/tcp/4002/ipfs/${peerInfo.id.toB58String()}` | ||
] | ||
|
||
ourAddrs.forEach(a => peerInfo.multiaddrs.add(a)) | ||
|
||
const dialableAddrs = TransportManager.dialables(dialAllTransport, queryAddrs, peerInfo) | ||
|
||
expect(dialableAddrs).to.have.length(1) | ||
expect(dialableAddrs[0].toString()).to.equal('/ip6/::1/tcp/4001') | ||
}) | ||
|
||
it('should filter our addresses over relay/rendezvous', () => { | ||
const peerId = peerInfo.id.toB58String() | ||
const queryAddrs = [ | ||
`/p2p-circuit/ipfs/${peerId}`, | ||
`/p2p-circuit/ip4/127.0.0.1/tcp/4002`, | ||
`/p2p-circuit/ip4/192.168.0.3/tcp/4002`, | ||
`/p2p-circuit/ip4/127.0.0.1/tcp/4002/ipfs/${peerId}`, | ||
`/p2p-circuit/ip4/192.168.0.3/tcp/4002/ipfs/${peerId}`, | ||
`/p2p-circuit/ip4/127.0.0.1/tcp/4002/ipfs/QmebzNV1kSzLfaYpSZdShuiABNUxoKT1vJmCdxM2iWsM2j`, | ||
`/p2p-circuit/ip4/192.168.0.3/tcp/4002/ipfs/QmebzNV1kSzLfaYpSZdShuiABNUxoKT1vJmCdxM2iWsM2j`, | ||
`/p2p-webrtc-star/ipfs/${peerId}`, | ||
`/p2p-websocket-star/ipfs/${peerId}`, | ||
`/p2p-stardust/ipfs/${peerId}`, | ||
'/ip6/::1/tcp/4001' | ||
].map(a => Multiaddr(a)) | ||
|
||
const ourAddrs = [ | ||
`/ip4/127.0.0.1/tcp/4002`, | ||
`/ip4/192.168.0.3/tcp/4002/ipfs/${peerInfo.id.toB58String()}` | ||
] | ||
|
||
ourAddrs.forEach(a => peerInfo.multiaddrs.add(a)) | ||
|
||
const dialableAddrs = TransportManager.dialables(dialAllTransport, queryAddrs, peerInfo) | ||
|
||
expect(dialableAddrs).to.have.length(1) | ||
expect(dialableAddrs[0].toString()).to.equal('/ip6/::1/tcp/4001') | ||
}) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should create and store this after listening is done, instead of running it before every dial. Our addresses shouldn't change, at the moment, after listening is done. It might save us quite a bit of processing when there are a lot of dials being done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could. It sounds like it would add a bunch of complexity that might easily cause confusion/bugs in the in the future if/when our addresses can change. Can we do it in a separate PR if it's a bottleneck?
Really, a lot of this should go away when addrs don't automatically carry a peer ID.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am ok with addressing this in a new PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, and since it's on my list of things to get to this quarter I think we can move forward with this. The queuing should mitigate the performance impact anyway.