You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please, check for existing issues to avoid duplicates.
No similar issues found.
What happened?
I am implementing a peer-locking mechanism, aiming to prevent a third peer (p3) from communicating with peers p1 and p2 if they are already paired. However, when p3 attempts to connect to p1, who is already locked with p2, p1 is unexpectedly disconnected, and the connection behavior does not align with the intended functionality.
Code -
import{Injectable,Logger}from'@nestjs/common';import{NestExpressApplication}from'@nestjs/platform-express';import{ExpressPeerServer,PeerServerEvents,IClient,IMessage}from'peer';
@Injectable()exportclassChannelService{privatereadonlylogger=newLogger(ChannelService.name);privatereadonlylockedPeers=newMap<string,string>();publicenablePeerServer(app: NestExpressApplication){constpeerServer=ExpressPeerServer(app.getHttpServer(),{path: '/channel',allow_discovery: true,});(peerServerasPeerServerEvents).on('connection',(client: IClient)=>{constpeerId=client.getId();this.logger.log(`Client connected: ${peerId}`);}).on('message',(client: IClient,message: IMessage)=>{constsourcePeerId=message.src;consttargetPeerId=message.dst;if(sourcePeerId&&targetPeerId){if(this.isPeerLocked(sourcePeerId)||this.isPeerLocked(targetPeerId)){this.logger.log(`Message from ${sourcePeerId} to ${targetPeerId} denied. One of the peers is already in a pair: ${message.type}`,);returnclient.send({type: 'ERROR',payload: 'One of the peers is locked in a pair.',});}else{if(message.type==='ANSWER'){this.lockedPeers.set(sourcePeerId,targetPeerId);this.lockedPeers.set(targetPeerId,sourcePeerId);this.logger.log(`Pair ${sourcePeerId} and ${targetPeerId} locked after ANSWER.`,);}}}else{this.logger.log(`Message from ${sourcePeerId}: ${message.type}`);}if(message.type==='LEAVE'){if(this.lockedPeers.delete(sourcePeerId)){this.lockedPeers.delete(this.lockedPeers.get(sourcePeerId)!);this.logger.log(`Pair containing ${sourcePeerId} released after LEAVE.`,);}}}).on('disconnect',(client: IClient)=>{constpeerId=client.getId();this.lockedPeers.forEach((value,key)=>{if(key===peerId||value===peerId){this.lockedPeers.delete(key);this.logger.log(`Pair involving ${peerId} released on disconnect.`);}});this.logger.log(`Client disconnected: ${peerId}`);}).on('error',(error: Error)=>{this.logger.error('PeerServer error:',error);});app.use(peerServer);}privateisPeerLocked(peerId: string): boolean{return(Array.from(this.lockedPeers.keys()).includes(peerId)||Array.from(this.lockedPeers.values()).includes(peerId));}}
Additional Context:
The disconnect event is being triggered when p3 attempts to connect to a peer already in an established pair, leading to p1’s disconnection. This issue might stem from the message with type error being returned. But I need it to throw an error when an individual peer tries to connect to paired peers.
How can we reproduce the issue?
Start the peer server with the provided code, where the peer-locking mechanism is implemented.
Connect three peer clients: p1, p2, and p3.
Establish a connection between p1 and p2 (pair lock) and exchange a message (ANSWER).
While p1 and p2 are connected, attempt to establish a connection from p3 to either p1 or p2.
Observe p1 client as it loses connection and the logs, which show p1 being disconnected when p3 tries to connect.
What do you expected to happen?
Expected Behavior:
When p3 attempts to connect to either p1 or p2, p1 and p2 should remain connected, and p3 should not be able to establish a connection with either of them.
Actual Behavior:
When p3 attempts to connect to p1, the logs indicate that p1 is disconnected, despite the intention being to prevent communication between p3 and the locked peers, without disconnecting anyone.
Environment setup
OS: Zorin OS 12
Platform: Nodejs 20
Browser: Microsoft Edge v131.0.2903
Is this a regression?
No response
Anything else?
Logs:
3296 6/12/2024, 7:30:29 pm LOG [NestFactory] Starting Nest application... +0ms
3296 6/12/2024, 7:30:29 pm LOG [InstanceLoader] ChannelModule dependencies initialized +12ms
3296 6/12/2024, 7:30:29 pm LOG [InstanceLoader] AppModule dependencies initialized +1ms
3296 6/12/2024, 7:30:29 pm LOG [RoutesResolver] AppController {/communication/api}: +9ms
3296 6/12/2024, 7:30:29 pm LOG [RouterExplorer] Mapped {/communication/api/status, GET} route +2ms
3296 6/12/2024, 7:30:29 pm LOG [NestApplication] Nest application successfully started +3ms
3296 6/12/2024, 7:31:14 pm LOG [ChannelService] Client connected: one_s864go37r8c +44s
3296 6/12/2024, 7:31:14 pm LOG [ChannelService] Client connected: two_h4ox542979a +600ms
3296 6/12/2024, 7:31:16 pm LOG [ChannelService] Client connected: two_v4flzxtxh7a +1s
3296 6/12/2024, 7:31:19 pm LOG [ChannelService] Message from one_s864go37r8c: HEARTBEAT +3s
3296 6/12/2024, 7:31:19 pm LOG [ChannelService] Message from two_h4ox542979a: HEARTBEAT +600ms
3296 6/12/2024, 7:31:21 pm LOG [ChannelService] Message from two_v4flzxtxh7a: HEARTBEAT +1s
3296 6/12/2024, 7:31:24 pm LOG [ChannelService] Pair one_s864go37r8c and two_h4ox542979a locked after ANSWER. +150ms
3296 6/12/2024, 7:31:24 pm LOG [ChannelService] Message from one_s864go37r8c to two_h4ox542979a denied. One of the peers is already in a pair: CANDIDATE +3ms
3296 6/12/2024, 7:31:24 pm LOG [ChannelService] Message from one_s864go37r8c to two_h4ox542979a denied. One of the peers is already in a pair: CANDIDATE +1ms
3296 6/12/2024, 7:31:24 pm LOG [ChannelService] Pair involving one_s864go37r8c released on disconnect. +4ms
3296 6/12/2024, 7:31:24 pm LOG [ChannelService] Client disconnected: one_s864go37r8c +0ms
The text was updated successfully, but these errors were encountered:
Please, check for existing issues to avoid duplicates.
What happened?
I am implementing a peer-locking mechanism, aiming to prevent a third peer (p3) from communicating with peers p1 and p2 if they are already paired. However, when p3 attempts to connect to p1, who is already locked with p2, p1 is unexpectedly disconnected, and the connection behavior does not align with the intended functionality.
Code -
Additional Context:
The disconnect event is being triggered when p3 attempts to connect to a peer already in an established pair, leading to p1’s disconnection. This issue might stem from the message with type error being returned. But I need it to throw an error when an individual peer tries to connect to paired peers.
How can we reproduce the issue?
What do you expected to happen?
Expected Behavior:
When p3 attempts to connect to either p1 or p2, p1 and p2 should remain connected, and p3 should not be able to establish a connection with either of them.
Actual Behavior:
When p3 attempts to connect to p1, the logs indicate that p1 is disconnected, despite the intention being to prevent communication between p3 and the locked peers, without disconnecting anyone.
Environment setup
Is this a regression?
No response
Anything else?
Logs:
The text was updated successfully, but these errors were encountered: