@@ -104,7 +104,7 @@ export class RelayConnection implements IConnection {
104104 return ;
105105 }
106106
107- const lib2p2Peer = await createLibp2p ( {
107+ this . lib2p2Peer = await createLibp2p ( {
108108 peerId : this . config . peerId ,
109109 transports : [
110110 webSockets ( {
@@ -121,15 +121,16 @@ export class RelayConnection implements IConnection {
121121 denyDialMultiaddr : ( ) => Promise . resolve ( false )
122122 } ,
123123 services : {
124- identify : identifyService ( {
125- runOnConnectionOpen : false ,
126- } ) ,
124+ identify : identifyService ( ) ,
127125 ping : pingService ( )
128126 }
129127 } ) ;
130128
131- this . lib2p2Peer = lib2p2Peer ;
132- this . lib2p2Peer . start ( ) ;
129+ const supportedProtocols = ( await this . lib2p2Peer . peerStore . get ( this . lib2p2Peer . peerId ) ) . protocols ;
130+ await this . lib2p2Peer . peerStore . patch ( this . lib2p2Peer . peerId , {
131+ protocols : [ ...supportedProtocols , PROTOCOL_NAME ]
132+ } ) ;
133+
133134 await this . connect ( ) ;
134135 }
135136
@@ -156,16 +157,8 @@ export class RelayConnection implements IConnection {
156157 ) ;
157158 }
158159
159- /*
160- TODO:: find out why this doesn't work and a new connection has to be established each time
161- if (this._connection.streams.length !== 1) {
162- throw new Error('Incorrect number of streams in FluenceConnection');
163- }
164-
165- const sink = this._connection.streams[0].sink;
166- */
167-
168160 log . trace ( 'sending particle...' ) ;
161+ // Reusing active connection here
169162 const stream = await this . lib2p2Peer . dialProtocol ( this . relayAddress , PROTOCOL_NAME ) ;
170163 log . trace ( 'created stream with id ' , stream . id ) ;
171164 const sink = stream . sink ;
0 commit comments