11import chronicles
22import chronos
3+ import strformat
34
45import chat_sdk
56import content_types
67
8+ # TEsting
9+ import ../ src/ chat_sdk/ crypto
10+
711
812proc getContent (content: ContentFrame ): string =
913 # Skip type checks and assume its a TextFrame
1014 let m = decode (content.bytes, TextFrame ).valueOr:
11- raise newException (ValueError , fmt" Badly formed Content " )
12- return fmt" { m} "
15+ raise newException (ValueError , fmt" Badly formed Content " )
16+ return fmt" { m} "
1317
1418proc main () {.async .} =
1519
@@ -21,15 +25,22 @@ proc main() {.async.} =
2125 cfg_saro.staticPeers.add (cfg_raya.getMultiAddr ())
2226 cfg_raya.staticPeers.add (cfg_saro.getMultiAddr ())
2327
28+ let sKey = loadPrivateKeyFromBytes (@ [45 u8 , 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 ()
29+ let rKey = loadPrivateKeyFromBytes (@ [43 u8 , 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 ()
30+
31+ let sIdent = Identity (name: " saro" , privateKey: sKey)
32+
2433 # Create Clients
25- var saro = newClient (cfg_saro, createIdentity ( " Saro " ) )
26- var raya = newClient (cfg_raya, createIdentity ( " Raya " ))
34+ var saro = newClient (cfg_saro, sIdent )
35+ var raya = newClient (cfg_raya, Identity (name: " raya " , privateKey: rKey ))
2736
37+ var ri = 0
2838 # Wire Callbacks
2939 saro.onNewMessage (proc (convo: Conversation , msg: ContentFrame ) {.async .} =
3040 echo " Saro <------ :: " & getContent (msg)
31- await sleepAsync (10000 )
41+ await sleepAsync (5000 )
3242 discard await convo.sendMessage (saro.ds, initTextFrame (" Ping" ).toContentFrame ())
43+
3344 )
3445
3546 saro.onDeliveryAck (proc (convo: Conversation , msgId: string ) {.async .} =
@@ -41,8 +52,13 @@ proc main() {.async.} =
4152
4253 raya.onNewMessage (proc (convo: Conversation , msg: ContentFrame ) {.async .} =
4354 echo " ------> Raya :: " & getContent (msg)
44- await sleepAsync (10000 )
45- sdiscard await convo.sendMessage (raya.ds, initTextFrame (" Pong" ).toContentFrame ())
55+ await sleepAsync (500 )
56+ discard await convo.sendMessage (raya.ds, initTextFrame (" Pong" & $ ri).toContentFrame ())
57+ await sleepAsync (800 )
58+ discard await convo.sendMessage (raya.ds, initTextFrame (" Pong" & $ ri).toContentFrame ())
59+ await sleepAsync (500 )
60+ discard await convo.sendMessage (raya.ds, initTextFrame (" Pong" & $ ri).toContentFrame ())
61+ inc ri
4662 )
4763
4864 raya.onNewConversation (proc (convo: Conversation ) {.async .} =
@@ -63,7 +79,12 @@ proc main() {.async.} =
6379 let raya_bundle = raya.createIntroBundle ()
6480 discard await saro.newPrivateConversation (raya_bundle)
6581
66- await sleepAsync (10000 ) # Run for some time
82+ await sleepAsync (20000 ) # Run for some time
6783
6884 saro.stop ()
69- raya.stop ()
85+ raya.stop ()
86+
87+
88+ when isMainModule :
89+ waitFor main ()
90+ notice " Shutdown"
0 commit comments