@@ -121,19 +121,19 @@ export class RelayConnection implements IConnection {
121
121
} ,
122
122
connectionGater : {
123
123
// 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 ) ,
125
125
} ,
126
126
services : {
127
127
identify : identifyService ( ) ,
128
- ping : pingService ( )
129
- }
128
+ ping : pingService ( ) ,
129
+ } ,
130
130
} ) ;
131
131
132
132
const supportedProtocols = ( await this . lib2p2Peer . peerStore . get ( this . lib2p2Peer . peerId ) ) . protocols ;
133
133
await this . lib2p2Peer . peerStore . patch ( this . lib2p2Peer . peerId , {
134
- protocols : [ ...supportedProtocols , PROTOCOL_NAME ]
134
+ protocols : [ ...supportedProtocols , PROTOCOL_NAME ] ,
135
135
} ) ;
136
-
136
+
137
137
await this . connect ( ) ;
138
138
}
139
139
@@ -166,14 +166,10 @@ export class RelayConnection implements IConnection {
166
166
log . trace ( 'created stream with id ' , stream . id ) ;
167
167
const sink = stream . sink ;
168
168
169
- await pipe (
170
- [ fromString ( serializeToString ( particle ) ) ] ,
171
- encode ( ) ,
172
- sink ,
173
- ) ;
169
+ await pipe ( [ fromString ( serializeToString ( particle ) ) ] , encode ( ) , sink ) ;
174
170
log . trace ( 'data written to sink' ) ;
175
171
}
176
-
172
+
177
173
private async processIncomingMessage ( msg : string , stream : Stream ) {
178
174
let particle : Particle | undefined ;
179
175
try {
@@ -182,13 +178,19 @@ export class RelayConnection implements IConnection {
182
178
const initPeerId = peerIdFromString ( particle . initPeerId ) ;
183
179
184
180
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
+ ) ;
186
186
return ;
187
187
}
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
+ ) ;
192
194
if ( isVerified ) {
193
195
this . particleSource . next ( particle ) ;
194
196
} else {
@@ -208,20 +210,21 @@ export class RelayConnection implements IConnection {
208
210
209
211
await this . lib2p2Peer . handle (
210
212
[ 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 ) ;
219
225
}
220
- } catch ( e ) {
221
- log . error ( 'connection closed: %j' , e ) ;
222
- }
223
- } ,
224
- ) ,
226
+ } ,
227
+ ) ,
225
228
{
226
229
maxInboundStreams : this . config . maxInboundStreams ,
227
230
maxOutboundStreams : this . config . maxOutboundStreams ,
0 commit comments