@@ -25,6 +25,13 @@ module.exports = (swarm, options, connHandler) => {
25
25
listener . stopHandler = new Stop ( swarm )
26
26
listener . hopHandler = new Hop ( swarm , options . hop )
27
27
28
+ /**
29
+ * Add swarm handler and listen for incoming connections
30
+ *
31
+ * @param {Multiaddr } ma
32
+ * @param {Function } callback
33
+ * @return {void }
34
+ */
28
35
listener . listen = ( ma , callback ) => {
29
36
callback = callback || ( ( ) => { } )
30
37
@@ -65,12 +72,33 @@ module.exports = (swarm, options, connHandler) => {
65
72
callback ( )
66
73
}
67
74
75
+ /**
76
+ * Remove swarm listener
77
+ *
78
+ * @param {Function } cb
79
+ * @return {void }
80
+ */
68
81
listener . close = ( cb ) => {
69
82
swarm . unhandle ( multicodec . stop )
70
83
setImmediate ( ( ) => listener . emit ( 'close' ) )
71
84
cb ( )
72
85
}
73
86
87
+ /**
88
+ * Get fixed up multiaddrs
89
+ *
90
+ * NOTE: This method will grab the peers multiaddrs and expand them such that:
91
+ *
92
+ * a) If it's an existing /p2p-circuit address for a specific relay i.e.
93
+ * `/ip4/0.0.0.0/tcp/0/ipfs/QmRelay/p2p-circuit` this method will expand the
94
+ * address to `/ip4/0.0.0.0/tcp/0/ipfs/QmRelay/p2p-circuit/ipfs/QmPeer` where
95
+ * `QmPeer` is this peers id
96
+ * b) If it's not a /p2p-circuit address, it will encapsulate the address as a /p2p-circuit
97
+ * addr such that dials a relay uses that address to dial this peer
98
+ *
99
+ * @param {Function } callback
100
+ * @return {void }
101
+ */
74
102
listener . getAddrs = ( callback ) => {
75
103
let addrs = swarm . _peerInfo . multiaddrs . toArray ( )
76
104
@@ -94,7 +122,7 @@ module.exports = (swarm, options, connHandler) => {
94
122
}
95
123
96
124
if ( ! mafmt . Circuit . matches ( addr ) ) {
97
- if ( addr . getPeerId ( ) !== null ) {
125
+ if ( addr . getPeerId ( ) ) {
98
126
// by default we're reachable over any relay
99
127
listenAddrs . push ( multiaddr ( `/p2p-circuit` ) . encapsulate ( addr ) )
100
128
} else {
0 commit comments