@@ -11,7 +11,6 @@ const Ping = require('libp2p-ping')
11
11
const Swarm = require ( 'libp2p-swarm' )
12
12
const PeerId = require ( 'peer-id' )
13
13
const PeerInfo = require ( 'peer-info' )
14
- const mafmt = require ( 'mafmt' )
15
14
const PeerBook = require ( 'peer-book' )
16
15
const mafmt = require ( 'mafmt' )
17
16
const multiaddr = require ( 'multiaddr' )
@@ -44,23 +43,13 @@ class Node extends EventEmitter {
44
43
// If muxer exists, we can use Identify
45
44
this . swarm . connection . reuse ( )
46
45
47
- // enable circuit relaying
48
- // TODO: move defaults elsewhere
49
- _options . Relay = Object . assign ( {
50
- Circuit : {
51
- Enabled : false ,
52
- Active : false
53
- } ,
54
- DialMode : 'onion'
55
- } , _options . Relay )
56
-
57
- if ( _options . Relay . Circuit . Enabled ) {
58
- this . relayCircuit = new Circuit . Relay ( _options . Relay . Circuit )
46
+ if ( _options . relay && _options . relay . circuit ) {
47
+ this . relayCircuit = new Circuit . Hop ( _options . relay . circuit )
59
48
this . relayCircuit . mount ( this . swarm )
60
49
}
61
50
62
51
// If muxer exists, we can use Relay for listening/dialing
63
- this . swarm . connection . relay ( _options . Relay )
52
+ this . swarm . connection . enableRelayDialing ( _options . relay )
64
53
65
54
// Received incommind dial and muxer upgrade happened,
66
55
// reuse this muxed connection
@@ -267,7 +256,6 @@ class Node extends EventEmitter {
267
256
268
257
dial ( peer , protocol , callback ) {
269
258
assert ( this . isStarted ( ) , NOT_STARTED_ERROR_MESSAGE )
270
- const peerInfo = this . _getPeerInfo ( peer )
271
259
272
260
if ( typeof protocol === 'function' ) {
273
261
callback = protocol
@@ -317,16 +305,24 @@ class Node extends EventEmitter {
317
305
// PeerInfo
318
306
if ( PeerInfo . isPeerInfo ( peer ) ) {
319
307
p = peer
320
- // Multiaddr instance (not string)
308
+ // Multiaddr instance (not string)
321
309
} else if ( multiaddr . isMultiaddr ( peer ) ) {
322
- const peerIdB58Str = peer . getPeerId ( )
310
+ let peerId
311
+ if ( peer . toString ( ) . includes ( 'p2p-circuit' ) ) {
312
+ // last segment is always the peer ipfs segment
313
+ peerId = multiaddr ( peer . toString ( ) . split ( 'p2p-circuit' ) . pop ( ) )
314
+ } else {
315
+ peerId = peer
316
+ }
317
+
318
+ const peerIdB58Str = peerId . getPeerId ( )
323
319
try {
324
320
p = this . peerBook . get ( peerIdB58Str )
325
321
} catch ( err ) {
326
322
p = new PeerInfo ( PeerId . createFromB58String ( peerIdB58Str ) )
327
323
}
328
324
p . multiaddrs . add ( peer )
329
- // PeerId
325
+ // PeerId
330
326
} else if ( PeerId . isPeerId ( peer ) ) {
331
327
const peerIdB58Str = peer . toB58String ( )
332
328
try {
0 commit comments