diff --git a/examples/pingpong.nim b/examples/pingpong.nim index bfdb67c..f2e17f5 100644 --- a/examples/pingpong.nim +++ b/examples/pingpong.nim @@ -22,8 +22,8 @@ proc main() {.async.} = var cfg_raya = DefaultConfig() # Cross pollinate Peers - No Waku discovery is used in this example - cfg_saro.staticPeers.add(cfg_raya.getMultiAddr()) - cfg_raya.staticPeers.add(cfg_saro.getMultiAddr()) + # cfg_saro.staticPeers.add(cfg_raya.getMultiAddr()) + # cfg_raya.staticPeers.add(cfg_saro.getMultiAddr()) 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() 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.} = let raya_bundle = raya.createIntroBundle() discard await saro.newPrivateConversation(raya_bundle) - await sleepAsync(20.seconds) # Run for some time + await sleepAsync(200.seconds) # Run for some time saro.stop() raya.stop() diff --git a/examples/tui/tui.nim b/examples/tui/tui.nim index f49c608..914897f 100644 --- a/examples/tui/tui.nim +++ b/examples/tui/tui.nim @@ -106,9 +106,9 @@ proc getSelectedConvo(app: ChatApp): ptr ConvoInfo = proc createChatClient(name: string): Future[Client] {.async.} = var cfg = await getCfg(name) - for key, val in fetchRegistrations(): - if key != name: - cfg.waku.staticPeers.add(val) + # for key, val in fetchRegistrations(): + # if key != name: + # cfg.waku.staticPeers.add(val) result = newClient(cfg.waku, cfg.ident) @@ -124,7 +124,7 @@ proc sendMessage(app: ChatApp, convoInfo: ptr ConvoInfo, msg: string) {.async.} var msgId = "" if convoInfo.convo != nil: - msgId = await convoInfo.convo.sendMessage(app.client.ds, initTextFrame(msg).toContentFrame()) + msgId = await convoInfo.convo.sendMessage(initTextFrame(msg).toContentFrame()) convoInfo[].addMessage(msgId, "You", app.inputBuffer) @@ -490,7 +490,7 @@ proc appLoop(app: ChatApp, panes: seq[Pane]) : Future[void] {.async.} = illwillInit(fullscreen = false) # Clear buffer while true: - await sleepAsync(5.milliseconds) + await sleepAsync(chronos.milliseconds(5)) app.tb.clear() drawStatusBar(app, panes[0], fgBlack, getIdColor(app.client.getId())) @@ -527,7 +527,7 @@ proc appLoop(app: ChatApp, panes: seq[Pane]) : Future[void] {.async.} = proc peerWatch(app: ChatApp): Future[void] {.async.} = while true: - await sleepAsync(1.seconds) + await sleepAsync(chronos.seconds(1)) app.peerCount = app.client.ds.getConnectedPeerCount() diff --git a/src/chat/client.nim b/src/chat/client.nim index ee52046..5f1901b 100644 --- a/src/chat/client.nim +++ b/src/chat/client.nim @@ -15,6 +15,12 @@ import # Foreign tables, types +import + waku/[ + waku_node, + discovery/waku_dnsdisc + ] + import #local conversations, conversations/convo_impl, @@ -44,7 +50,7 @@ type type KeyEntry* = object keyType: string - privateKey: PrivateKey + privateKey: crypto.PrivateKey timestamp: int64 type Client* = ref object @@ -287,6 +293,17 @@ proc start*(client: Client) {.async.} = client.isRunning = true + let dnsDiscoveryUrl = "enrtree://AIRVQ5DDA4FFWLRBCHJWUWOO6X6S4ZTZ5B667LQ6AJU6PEYDLRD5O@sandbox.waku.nodes.status.im" + let nameServer = parseIpAddress("1.1.1.1") + let discoveredPeers = await retrieveDynamicBootstrapNodes(dnsDiscoveryUrl, @[nameServer]) + if discoveredPeers.isOk: + info "Connecting to discovered peers" + let remotePeers = discoveredPeers.get() + info "Discovered and connecting to peers", peerCount = remotePeers.len + asyncSpawn client.ds.node.connectToNodes(remotePeers) + else: + warn "Failed to find peers via DNS discovery", error = discoveredPeers.error + asyncSpawn client.messageQueueConsumer() notice "Client start complete", client = client.getId()