Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions examples/pingpong.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ proc main() {.async.} =
var cfg_saro = DefaultConfig()
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())

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

Expand Down Expand Up @@ -73,16 +69,16 @@ proc main() {.async.} =
await saro.start()
await raya.start()

await sleepAsync(5.seconds)
await sleepAsync(10.seconds)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the TUI example, you changed all durations to chronos.seconds(10). Which is the preferable form? That way I can make my future code consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In TUI example, the times library is conflict with chronos, so the prefix is needed, 5.seconds seems preferable if no conflict happens.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


# Perform OOB Introduction: Raya -> Saro
let raya_bundle = raya.createIntroBundle()
discard await saro.newPrivateConversation(raya_bundle)

await sleepAsync(20.seconds) # Run for some time

saro.stop()
raya.stop()
await saro.stop()
await raya.stop()


when isMainModule:
Expand Down
10 changes: 3 additions & 7 deletions examples/tui/tui.nim
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ 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)

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


Expand All @@ -124,7 +120,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)

Expand Down Expand Up @@ -490,7 +486,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()))
Expand Down Expand Up @@ -527,7 +523,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()


Expand Down
3 changes: 2 additions & 1 deletion src/chat/client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ proc start*(client: Client) {.async.} =

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

proc stop*(client: Client) =
proc stop*(client: Client) {.async.} =
## Stop the client.
await client.ds.stop()
client.isRunning = false
notice "Client stopped", client = client.getId()
19 changes: 17 additions & 2 deletions src/chat/delivery/waku_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import
waku_node,
waku_enr,
discovery/waku_discv5,
discovery/waku_dnsdisc,
factory/builder,
waku_filter_v2/client,
]
Expand Down Expand Up @@ -71,8 +72,8 @@ type

proc DefaultConfig*(): WakuConfig =
let nodeKey = crypto.PrivateKey.random(Secp256k1, crypto.newRng()[])[]
let clusterId = 19'u16
let shardId = 0'u16
let clusterId = 16'u16
let shardId = 32'u16
var port: uint16 = 50000'u16 + uint16(rand(200))

result = WakuConfig(nodeKey: nodeKey, port: port, clusterId: clusterId,
Expand Down Expand Up @@ -161,6 +162,17 @@ proc start*(client: WakuClient) {.async.} =

client.node.peerManager.start()

let dnsDiscoveryUrl = "enrtree://AI4W5N5IFEUIHF5LESUAOSMV6TKWF2MB6GU2YK7PU4TYUGUNOCEPW@boot.staging.status.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.node.connectToNodes(remotePeers)
else:
warn "Failed to find peers via DNS discovery", error = discoveredPeers.error

let subscription: SubscriptionEvent = (kind: PubsubSub, topic:
client.cfg.pubsubTopic)

Expand Down Expand Up @@ -194,3 +206,6 @@ proc getConnectedPeerCount*(client: WakuClient): int =
if peerInfo.connectedness == Connected:
inc count
return count

proc stop*(client: WakuClient) {.async.} =
await client.node.stop()