From 5652eccd1b58433628a7416422f145fbac7715a7 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 14 Aug 2022 06:49:24 -0400 Subject: [PATCH] *Add method to get current relays in a DHT instance --- src/index.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/index.ts b/src/index.ts index 7594b24..fd7a9f2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -32,6 +32,7 @@ addHandler("write", handleWriteSocketEvent); addHandler("addRelay", handleAddRelay); addHandler("removeRelay", handleRemoveRelay); addHandler("clearRelays", handleClearRelays); +addHandler("getRelays", handleGetRelays); addHandler("ready", handleReady); async function handlePresentSeed(aq: ActiveQuery) { @@ -258,6 +259,16 @@ function handleClearRelays(aq: ActiveQuery) { aq.respond(); } +function handleGetRelays(aq: ActiveQuery) { + const dht = validateDht(aq); + + if (!dht) { + return; + } + + aq.respond(dht.relays); +} + async function handleReady(aq: ActiveQuery) { const dht = validateDht(aq);