@@ -14,6 +14,7 @@ const PeerInfo = require('peer-info')
14
14
const PeerBook = require ( 'peer-book' )
15
15
const mafmt = require ( 'mafmt' )
16
16
const multiaddr = require ( 'multiaddr' )
17
+ const Circuit = require ( 'libp2p-circuit' )
17
18
18
19
exports = module . exports
19
20
@@ -29,6 +30,7 @@ class Node extends EventEmitter {
29
30
this . peerInfo = _peerInfo
30
31
this . peerBook = _peerBook || new PeerBook ( )
31
32
this . isOnline = false
33
+ this . relayCircuit = null
32
34
33
35
this . swarm = new Swarm ( this . peerInfo , this . peerBook )
34
36
@@ -41,6 +43,24 @@ class Node extends EventEmitter {
41
43
// If muxer exists, we can use Identify
42
44
this . swarm . connection . reuse ( )
43
45
46
+ // enable circuit relaying
47
+ // TODO: move defaults elsewhere
48
+ _options . Relay = Object . assign ( {
49
+ Circuit : {
50
+ Enabled : false ,
51
+ Active : false
52
+ } ,
53
+ DialMode : 'onion'
54
+ } , _options . Relay )
55
+
56
+ if ( _options . Relay . Circuit . Enabled ) {
57
+ this . relayCircuit = new Circuit . Relay ( _options . Relay . Circuit )
58
+ this . relayCircuit . mount ( this . swarm )
59
+ }
60
+
61
+ // If muxer exists, we can use Relay for listening/dialing
62
+ this . swarm . connection . relay ( _options . Relay )
63
+
44
64
// Received incommind dial and muxer upgrade happened,
45
65
// reuse this muxed connection
46
66
this . swarm . on ( 'peer-mux-established' , ( peerInfo ) => {
0 commit comments