Skip to content

feature: Circuit Relay #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@
"pull-serializer": "^0.3.2",
"pull-stream": "^3.6.0",
"safe-buffer": "^5.1.1",
"sinon": "^2.3.6",
"wrtc": "0.0.62"
},
"dependencies": {
"async": "^2.5.0",
"libp2p-ping": "~0.4.0",
"libp2p-swarm": "~0.29.1",
"libp2p-circuit": "~0.0.1",
"mafmt": "^2.1.8",
"multiaddr": "^2.3.0",
"peer-book": "~0.4.0",
Expand Down
17 changes: 14 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class Node extends EventEmitter {
// If muxer exists, we can use Identify
this.swarm.connection.reuse()

// If muxer exists, we can use Relay for listening/dialing
this.swarm.connection.enableRelayDialing(_options.relay)

// Received incommind dial and muxer upgrade happened,
// reuse this muxed connection
this.swarm.on('peer-mux-established', (peerInfo) => {
Expand Down Expand Up @@ -293,16 +296,24 @@ class Node extends EventEmitter {
// PeerInfo
if (PeerInfo.isPeerInfo(peer)) {
p = peer
// Multiaddr instance (not string)
// Multiaddr instance (not string)
} else if (multiaddr.isMultiaddr(peer)) {
const peerIdB58Str = peer.getPeerId()
let peerId
if (peer.toString().includes('p2p-circuit')) {
// last segment is always the peer ipfs segment
peerId = multiaddr(peer.toString().split('p2p-circuit').pop())
} else {
peerId = peer
}

const peerIdB58Str = peerId.getPeerId()
try {
p = this.peerBook.get(peerIdB58Str)
} catch (err) {
p = new PeerInfo(PeerId.createFromB58String(peerIdB58Str))
}
p.multiaddrs.add(peer)
// PeerId
// PeerId
} else if (PeerId.isPeerId(peer)) {
const peerIdB58Str = peer.toB58String()
try {
Expand Down
1 change: 1 addition & 0 deletions test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ require('./nodejs-bundle/stream-muxing')
require('./nodejs-bundle/discovery')
require('./nodejs-bundle/peer-routing')
require('./nodejs-bundle/content-routing')
require('./nodejs-bundle/circuit/circuit')
Loading