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);