@@ -121,19 +121,19 @@ export class RelayConnection implements IConnection {
121121 } ,
122122 connectionGater : {
123123 // By default, this function forbids connections to private peers. For example multiaddr with ip 127.0.0.1 isn't allowed
124- denyDialMultiaddr : ( ) => Promise . resolve ( false )
124+ denyDialMultiaddr : ( ) => Promise . resolve ( false ) ,
125125 } ,
126126 services : {
127127 identify : identifyService ( ) ,
128- ping : pingService ( )
129- }
128+ ping : pingService ( ) ,
129+ } ,
130130 } ) ;
131131
132132 const supportedProtocols = ( await this . lib2p2Peer . peerStore . get ( this . lib2p2Peer . peerId ) ) . protocols ;
133133 await this . lib2p2Peer . peerStore . patch ( this . lib2p2Peer . peerId , {
134- protocols : [ ...supportedProtocols , PROTOCOL_NAME ]
134+ protocols : [ ...supportedProtocols , PROTOCOL_NAME ] ,
135135 } ) ;
136-
136+
137137 await this . connect ( ) ;
138138 }
139139
@@ -166,14 +166,10 @@ export class RelayConnection implements IConnection {
166166 log . trace ( 'created stream with id ' , stream . id ) ;
167167 const sink = stream . sink ;
168168
169- await pipe (
170- [ fromString ( serializeToString ( particle ) ) ] ,
171- encode ( ) ,
172- sink ,
173- ) ;
169+ await pipe ( [ fromString ( serializeToString ( particle ) ) ] , encode ( ) , sink ) ;
174170 log . trace ( 'data written to sink' ) ;
175171 }
176-
172+
177173 private async processIncomingMessage ( msg : string , stream : Stream ) {
178174 let particle : Particle | undefined ;
179175 try {
@@ -182,13 +178,19 @@ export class RelayConnection implements IConnection {
182178 const initPeerId = peerIdFromString ( particle . initPeerId ) ;
183179
184180 if ( initPeerId . publicKey === undefined ) {
185- log . error ( 'cannot retrieve public key from init_peer_id. particle id: %s. init_peer_id: %s' , particle . id , particle . initPeerId ) ;
181+ log . error (
182+ 'cannot retrieve public key from init_peer_id. particle id: %s. init_peer_id: %s' ,
183+ particle . id ,
184+ particle . initPeerId ,
185+ ) ;
186186 return ;
187187 }
188-
189- // TODO: uncomment this after nox rolls out signature verification
190- // const isVerified = await KeyPair.verifyWithPublicKey(initPeerId.publicKey, buildParticleMessage(particle), particle.signature);
191- const isVerified = true ;
188+
189+ const isVerified = await KeyPair . verifyWithPublicKey (
190+ initPeerId . publicKey ,
191+ buildParticleMessage ( particle ) ,
192+ particle . signature ,
193+ ) ;
192194 if ( isVerified ) {
193195 this . particleSource . next ( particle ) ;
194196 } else {
@@ -208,20 +210,21 @@ export class RelayConnection implements IConnection {
208210
209211 await this . lib2p2Peer . handle (
210212 [ PROTOCOL_NAME ] ,
211- async ( { connection, stream } ) => pipe (
212- stream . source ,
213- decode ( ) ,
214- ( source ) => map ( source , ( buf ) => toString ( buf . subarray ( ) ) ) ,
215- async ( source ) => {
216- try {
217- for await ( const msg of source ) {
218- await this . processIncomingMessage ( msg , stream ) ;
213+ async ( { connection, stream } ) =>
214+ pipe (
215+ stream . source ,
216+ decode ( ) ,
217+ ( source ) => map ( source , ( buf ) => toString ( buf . subarray ( ) ) ) ,
218+ async ( source ) => {
219+ try {
220+ for await ( const msg of source ) {
221+ await this . processIncomingMessage ( msg , stream ) ;
222+ }
223+ } catch ( e ) {
224+ log . error ( 'connection closed: %j' , e ) ;
219225 }
220- } catch ( e ) {
221- log . error ( 'connection closed: %j' , e ) ;
222- }
223- } ,
224- ) ,
226+ } ,
227+ ) ,
225228 {
226229 maxInboundStreams : this . config . maxInboundStreams ,
227230 maxOutboundStreams : this . config . maxOutboundStreams ,
0 commit comments