Skip to content

Commit cc01e95

Browse files
committed
feat: dns discovery bootstrap
1 parent a6b24f7 commit cc01e95

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

examples/pingpong.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ proc main() {.async.} =
2222
var cfg_raya = DefaultConfig()
2323

2424
# Cross pollinate Peers - No Waku discovery is used in this example
25-
cfg_saro.staticPeers.add(cfg_raya.getMultiAddr())
26-
cfg_raya.staticPeers.add(cfg_saro.getMultiAddr())
25+
# cfg_saro.staticPeers.add(cfg_raya.getMultiAddr())
26+
# cfg_raya.staticPeers.add(cfg_saro.getMultiAddr())
2727

2828
let sKey = loadPrivateKeyFromBytes(@[45u8, 216, 160, 24, 19, 207, 193, 214, 98, 92, 153, 145, 222, 247, 101, 99, 96, 131, 149, 185, 33, 187, 229, 251, 100, 158, 20, 131, 111, 97, 181, 210]).get()
2929
let rKey = loadPrivateKeyFromBytes(@[43u8, 12, 160, 51, 212, 90, 199, 160, 154, 164, 129, 229, 147, 69, 151, 17, 239, 51, 190, 33, 86, 164, 50, 105, 39, 250, 182, 116, 138, 132, 114, 234]).get()
@@ -79,7 +79,7 @@ proc main() {.async.} =
7979
let raya_bundle = raya.createIntroBundle()
8080
discard await saro.newPrivateConversation(raya_bundle)
8181

82-
await sleepAsync(20.seconds) # Run for some time
82+
await sleepAsync(200.seconds) # Run for some time
8383

8484
saro.stop()
8585
raya.stop()

examples/tui/tui.nim

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ proc getSelectedConvo(app: ChatApp): ptr ConvoInfo =
106106

107107
proc createChatClient(name: string): Future[Client] {.async.} =
108108
var cfg = await getCfg(name)
109-
for key, val in fetchRegistrations():
110-
if key != name:
111-
cfg.waku.staticPeers.add(val)
109+
# for key, val in fetchRegistrations():
110+
# if key != name:
111+
# cfg.waku.staticPeers.add(val)
112112

113113
result = newClient(cfg.waku, cfg.ident)
114114

@@ -124,7 +124,7 @@ proc sendMessage(app: ChatApp, convoInfo: ptr ConvoInfo, msg: string) {.async.}
124124

125125
var msgId = ""
126126
if convoInfo.convo != nil:
127-
msgId = await convoInfo.convo.sendMessage(app.client.ds, initTextFrame(msg).toContentFrame())
127+
msgId = await convoInfo.convo.sendMessage(initTextFrame(msg).toContentFrame())
128128

129129
convoInfo[].addMessage(msgId, "You", app.inputBuffer)
130130

@@ -490,7 +490,7 @@ proc appLoop(app: ChatApp, panes: seq[Pane]) : Future[void] {.async.} =
490490
illwillInit(fullscreen = false)
491491
# Clear buffer
492492
while true:
493-
await sleepAsync(5.milliseconds)
493+
await sleepAsync(chronos.milliseconds(5))
494494
app.tb.clear()
495495

496496
drawStatusBar(app, panes[0], fgBlack, getIdColor(app.client.getId()))
@@ -527,7 +527,7 @@ proc appLoop(app: ChatApp, panes: seq[Pane]) : Future[void] {.async.} =
527527

528528
proc peerWatch(app: ChatApp): Future[void] {.async.} =
529529
while true:
530-
await sleepAsync(1.seconds)
530+
await sleepAsync(chronos.seconds(1))
531531
app.peerCount = app.client.ds.getConnectedPeerCount()
532532

533533

src/chat/client.nim

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import # Foreign
1515
tables,
1616
types
1717

18+
import
19+
waku/[
20+
waku_node,
21+
discovery/waku_dnsdisc
22+
]
23+
1824
import #local
1925
conversations,
2026
conversations/convo_impl,
@@ -44,7 +50,7 @@ type
4450

4551
type KeyEntry* = object
4652
keyType: string
47-
privateKey: PrivateKey
53+
privateKey: crypto.PrivateKey
4854
timestamp: int64
4955

5056
type Client* = ref object
@@ -287,6 +293,17 @@ proc start*(client: Client) {.async.} =
287293

288294
client.isRunning = true
289295

296+
let dnsDiscoveryUrl = "enrtree://AIRVQ5DDA4FFWLRBCHJWUWOO6X6S4ZTZ5B667LQ6AJU6PEYDLRD5O@sandbox.waku.nodes.status.im"
297+
let nameServer = parseIpAddress("1.1.1.1")
298+
let discoveredPeers = await retrieveDynamicBootstrapNodes(dnsDiscoveryUrl, @[nameServer])
299+
if discoveredPeers.isOk:
300+
info "Connecting to discovered peers"
301+
let remotePeers = discoveredPeers.get()
302+
info "Discovered and connecting to peers", peerCount = remotePeers.len
303+
asyncSpawn client.ds.node.connectToNodes(remotePeers)
304+
else:
305+
warn "Failed to find peers via DNS discovery", error = discoveredPeers.error
306+
290307
asyncSpawn client.messageQueueConsumer()
291308

292309
notice "Client start complete", client = client.getId()

0 commit comments

Comments
 (0)