From dfe9e3f0829823a3398cd926f4b623f0a6a3b8fa Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 1 Sep 2023 20:55:21 -0400 Subject: [PATCH] fest: add stop method --- src/node.ts | 4 ++++ src/service/p2p.ts | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/node.ts b/src/node.ts index 2a58c04..0419b68 100644 --- a/src/node.ts +++ b/src/node.ts @@ -69,6 +69,10 @@ export class S5Node { await p2p.start(); } + public async stop() { + await this.services.p2p.stop(); + } + async readStorageLocationsFromDB( hash: Multihash, ): Promise>>> { diff --git a/src/service/p2p.ts b/src/service/p2p.ts index b768856..4c716e4 100644 --- a/src/service/p2p.ts +++ b/src/service/p2p.ts @@ -97,6 +97,9 @@ export class P2PService extends EventEmitter { this.connectToNode([new URL(p)]); } } + async stop() { + [...this.node.services.p2p.peers.values()].forEach((peer) => peer.end()); + } async onNewPeer(peer: Peer, verifyId: boolean): Promise { peer.challenge = crypto.randomBytes(32);