From b34b7a3a0172adf0b0ce1476f6c68912dcd05576 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 1 Sep 2023 19:49:42 -0400 Subject: [PATCH] feat: add eventemitter support on p2p service and have the handshakedone message emit peerConnected --- src/messages/signedMessages/handshakeDone.ts | 1 + src/service/p2p.ts | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/messages/signedMessages/handshakeDone.ts b/src/messages/signedMessages/handshakeDone.ts index ae7f122..7830bcf 100644 --- a/src/messages/signedMessages/handshakeDone.ts +++ b/src/messages/signedMessages/handshakeDone.ts @@ -60,4 +60,5 @@ export default async function ( p2p.sendPublicPeersToPeer(p, [peer]); } } + p2p.emit("peerConnected", peer); } diff --git a/src/service/p2p.ts b/src/service/p2p.ts index 37b9699..73fe25c 100644 --- a/src/service/p2p.ts +++ b/src/service/p2p.ts @@ -26,8 +26,9 @@ import { createTransportSocket, } from "#transports/index.js"; import messages from "#messages/index.js"; +import { EventEmitter } from "events"; -export class P2PService { +export class P2PService extends EventEmitter { private logger: Logger; private nodeKeyPair: KeyPairEd25519; private localNodeId?: NodeId; @@ -39,6 +40,7 @@ export class P2PService { >; constructor(node: S5Node) { + super(); this._node = node; this._networkId = node.config.p2p?.network; this.nodeKeyPair = node.config.keyPair;