mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-01-02 14:13:10 +00:00
feat: dns discovery bootstrap
This commit is contained in:
parent
a6b24f780b
commit
cc01e954ef
@ -22,8 +22,8 @@ proc main() {.async.} =
|
|||||||
var cfg_raya = DefaultConfig()
|
var cfg_raya = DefaultConfig()
|
||||||
|
|
||||||
# Cross pollinate Peers - No Waku discovery is used in this example
|
# Cross pollinate Peers - No Waku discovery is used in this example
|
||||||
cfg_saro.staticPeers.add(cfg_raya.getMultiAddr())
|
# cfg_saro.staticPeers.add(cfg_raya.getMultiAddr())
|
||||||
cfg_raya.staticPeers.add(cfg_saro.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 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()
|
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()
|
let raya_bundle = raya.createIntroBundle()
|
||||||
discard await saro.newPrivateConversation(raya_bundle)
|
discard await saro.newPrivateConversation(raya_bundle)
|
||||||
|
|
||||||
await sleepAsync(20.seconds) # Run for some time
|
await sleepAsync(200.seconds) # Run for some time
|
||||||
|
|
||||||
saro.stop()
|
saro.stop()
|
||||||
raya.stop()
|
raya.stop()
|
||||||
|
|||||||
@ -106,9 +106,9 @@ proc getSelectedConvo(app: ChatApp): ptr ConvoInfo =
|
|||||||
|
|
||||||
proc createChatClient(name: string): Future[Client] {.async.} =
|
proc createChatClient(name: string): Future[Client] {.async.} =
|
||||||
var cfg = await getCfg(name)
|
var cfg = await getCfg(name)
|
||||||
for key, val in fetchRegistrations():
|
# for key, val in fetchRegistrations():
|
||||||
if key != name:
|
# if key != name:
|
||||||
cfg.waku.staticPeers.add(val)
|
# cfg.waku.staticPeers.add(val)
|
||||||
|
|
||||||
result = newClient(cfg.waku, cfg.ident)
|
result = newClient(cfg.waku, cfg.ident)
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ proc sendMessage(app: ChatApp, convoInfo: ptr ConvoInfo, msg: string) {.async.}
|
|||||||
|
|
||||||
var msgId = ""
|
var msgId = ""
|
||||||
if convoInfo.convo != nil:
|
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)
|
convoInfo[].addMessage(msgId, "You", app.inputBuffer)
|
||||||
|
|
||||||
@ -490,7 +490,7 @@ proc appLoop(app: ChatApp, panes: seq[Pane]) : Future[void] {.async.} =
|
|||||||
illwillInit(fullscreen = false)
|
illwillInit(fullscreen = false)
|
||||||
# Clear buffer
|
# Clear buffer
|
||||||
while true:
|
while true:
|
||||||
await sleepAsync(5.milliseconds)
|
await sleepAsync(chronos.milliseconds(5))
|
||||||
app.tb.clear()
|
app.tb.clear()
|
||||||
|
|
||||||
drawStatusBar(app, panes[0], fgBlack, getIdColor(app.client.getId()))
|
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.} =
|
proc peerWatch(app: ChatApp): Future[void] {.async.} =
|
||||||
while true:
|
while true:
|
||||||
await sleepAsync(1.seconds)
|
await sleepAsync(chronos.seconds(1))
|
||||||
app.peerCount = app.client.ds.getConnectedPeerCount()
|
app.peerCount = app.client.ds.getConnectedPeerCount()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,12 @@ import # Foreign
|
|||||||
tables,
|
tables,
|
||||||
types
|
types
|
||||||
|
|
||||||
|
import
|
||||||
|
waku/[
|
||||||
|
waku_node,
|
||||||
|
discovery/waku_dnsdisc
|
||||||
|
]
|
||||||
|
|
||||||
import #local
|
import #local
|
||||||
conversations,
|
conversations,
|
||||||
conversations/convo_impl,
|
conversations/convo_impl,
|
||||||
@ -44,7 +50,7 @@ type
|
|||||||
|
|
||||||
type KeyEntry* = object
|
type KeyEntry* = object
|
||||||
keyType: string
|
keyType: string
|
||||||
privateKey: PrivateKey
|
privateKey: crypto.PrivateKey
|
||||||
timestamp: int64
|
timestamp: int64
|
||||||
|
|
||||||
type Client* = ref object
|
type Client* = ref object
|
||||||
@ -287,6 +293,17 @@ proc start*(client: Client) {.async.} =
|
|||||||
|
|
||||||
client.isRunning = true
|
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()
|
asyncSpawn client.messageQueueConsumer()
|
||||||
|
|
||||||
notice "Client start complete", client = client.getId()
|
notice "Client start complete", client = client.getId()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user