From b2bd098474621c46bd51382cdba2a3a4eec1941c Mon Sep 17 00:00:00 2001 From: Jazz Turner-Baggs <473256+jazzz@users.noreply.github.com> Date: Thu, 20 Nov 2025 16:06:18 -0800 Subject: [PATCH] remove dead files --- src/dev.nim | 191 --------------------------------------------------- src/tui2.nim | 185 ------------------------------------------------- 2 files changed, 376 deletions(-) delete mode 100644 src/dev.nim delete mode 100644 src/tui2.nim diff --git a/src/dev.nim b/src/dev.nim deleted file mode 100644 index 8db0a06..0000000 --- a/src/dev.nim +++ /dev/null @@ -1,191 +0,0 @@ -import chronos -import chronicles -import strformat -import tables - -import sds - -import std/typetraits -import sequtils - -logScope: - topics = "dev" - -type A = ref object - asg: string - -proc dir*[T](obj: T) = - echo "Object of type: ", T - for name, value in fieldPairs(obj): - if type(value) is string: - echo " ", name, ": ", value - if type(value) is Table: - echo "hmmmm" - -proc `$`(rm: ReliabilityManager): string = - result = "RM" - - - -type Msg = object - id*: string - shouldDrop: bool - data*: seq[byte] - - - - -proc send(rm: ReliabilityManager, channel: string, id: string, msg: seq[ - byte]): seq[byte] = - result = rm.wrapOutgoingMessage(msg, id, channel).valueOr: - raise newException(ValueError, "Bad outgoing message") - -proc recv(rm: ReliabilityManager, bytes: seq[byte]) = - let (unwrapped, missingDeps, channelId) = rm.unwrapReceivedMessage(bytes).valueOr: - raise newException(ValueError, "Bad unwrap") - info "RECV", channel = channelId, data = unwrapped, mdeps = missingDeps - - - -proc main() {.async.} = - - var messageSentCount = 0 - let CHANNEL = "CHANNEL" - let msg = @[byte(1), 2, 3] - let msgId = "test-msg-1" - - var rm = newReliabilityManager().valueOr: - raise newException(ValueError, fmt"SDS InitializationError") - - rm.setCallbacks( - proc(messageId: SdsMessageID, channelId: SdsChannelID) {.gcsafe.} = - echo "OnMsgReady" - discard, - proc(messageId: SdsMessageID, channelId: SdsChannelID) {.gcsafe.} = - echo "OnMsgSent" - messageSentCount += 1, - proc(messageId: SdsMessageID, missingDeps: seq[SdsMessageID], - channelId: SdsChannelID) {.gcsafe.} = - echo "OnMissing" - discard, - ) - - - let sourceMsgs = @[Msg(id: "1", shouldDrop: false, data: @[byte(1), 2, 3]), - Msg(id: "2", shouldDrop: true, data: @[byte(0), 5, 6]), - Msg(id: "3", shouldDrop: false, data: @[byte(7), 8, 9]), - ] - rm.ensureChannel(CHANNEL).isOkOr: - raise newException(ValueError, "Bad channel") - - - let encodedMessage = sourceMsgs.map(proc(m: Msg): seq[byte] = - rm.wrapOutgoingMessage(m.data, m.id, CHANNEL).valueOr: - raise newException(ValueError, "Bad outgoing message")) - - var i = 0 - var droppedMessages: seq[seq[byte]] = @[] - for x in encodedMessage: - if i mod 2 == 0: - droppedMessages.add(x) - inc(i) - - - - # let droppedMessages = encodedMessage.keepIf(proc(item: seq[ - # byte]): bool = - # items.find(item) mod 2 == 0 - # ) - # let droppedMessages = enumerate(encodedMessage).filter(proc(x: seq[ - # byte]): bool = x[0] mod 2 == 0) - - for s in droppedMessages: - info "DROPPED", len = len(s) - - for m in droppedMessages: - let (unwrapped, missingDeps, channelId) = rm.unwrapReceivedMessage(m).valueOr: - raise newException(ValueError, "Bad unwrap") - - info "RECV", channel = channelId, data = unwrapped, mdeps = missingDeps - - -proc messageSequence(){.async.} = - var messageSentCount = 0 - let CHANNEL = "CHANNEL" - - - var raya = newReliabilityManager().valueOr: - raise newException(ValueError, fmt"SDS InitializationError") - - var saro = newReliabilityManager().valueOr: - raise newException(ValueError, fmt"SDS InitializationError") - - raya.setCallbacks( - proc(messageId: SdsMessageID, channelId: SdsChannelID) {.gcsafe.} = - debug "OnMsgReady", client = "raya", id = messageId - discard, - proc(messageId: SdsMessageID, channelId: SdsChannelID) {.gcsafe.} = - debug "OnMsgSent", client = "raya", id = messageId - messageSentCount += 1, - proc(messageId: SdsMessageID, missingDeps: seq[SdsMessageID], - channelId: SdsChannelID) {.gcsafe.} = - info "OnMissing", client = "raya", id = messageId - discard, - ) - - saro.setCallbacks( - proc(messageId: SdsMessageID, channelId: SdsChannelID) {.gcsafe.} = - debug "OnMsgReady", client = "saro", id = messageId - discard, - proc(messageId: SdsMessageID, channelId: SdsChannelID) {.gcsafe.} = - debug "OnMsgSent", client = "saro", id = messageId - messageSentCount += 1, - proc(messageId: SdsMessageID, missingDeps: seq[SdsMessageID], - channelId: SdsChannelID) {.gcsafe.} = - info "OnMissing", client = "saro", id = messageId - discard, - ) - - raya.ensureChannel(CHANNEL).isOkOr: - raise newException(ValueError, "Bad channel") - - saro.ensureChannel(CHANNEL).isOkOr: - raise newException(ValueError, "Bad channel") - - - let s1 = saro.send(CHANNEL, "s1", @[byte(1), 1, 1]) - raya.recv(s1) - - let r1 = raya.send(CHANNEL, "r1", @[byte(2), 1, 2]) - saro.recv(r1) - - let r2 = raya.send(CHANNEL, "r2", @[byte(2), 2, 2]) - # saro.recv(r2) - - let r3 = raya.send(CHANNEL, "r3", @[byte(2), 3, 2]) - saro.recv(r3) - - let s2 = saro.send(CHANNEL, "s2", @[byte(1), 2, 1]) - raya.recv(s2) - - let s3 = saro.send(CHANNEL, "s3", @[byte(1), 3, 1]) - raya.recv(s3) - - - let r4 = raya.send(CHANNEL, "r4", @[byte(2), 4, 2]) - saro.recv(r4) - saro.recv(r2) - - let r5 = raya.send(CHANNEL, "r5", @[byte(2), 5, 2]) - saro.recv(r5) - - let r6 = raya.send(CHANNEL, "r6", @[byte(2), 6, 2]) - saro.recv(r6) - - saro.recv(r4) - saro.recv(r3) - - saro.recv(r4) -when isMainModule: - waitFor messageSequence() - echo ">>>" diff --git a/src/tui2.nim b/src/tui2.nim deleted file mode 100644 index 6fa112f..0000000 --- a/src/tui2.nim +++ /dev/null @@ -1,185 +0,0 @@ -import chronos -import chronicles -import strformat - -import chat_sdk/client -import chat_sdk/identity -import chat_sdk/conversations -import chat_sdk/delivery/waku_client -import chat_sdk/utils -import chat_sdk/proto_types - -import content_types/all -import libp2p/crypto/crypto -# import libp2p/crypto/secp256k1 -import os -import std/sequtils -import strutils -import tables -import std/parseopt - -import std/json -import std/jsonutils except distinctBase -import std/marshal -import std/streams - -import std/base64 - - - -import tui/persistence - - -const SELF_DEFINED = 99 - - -################################################# -# Command Line Args -################################################# - -type CmdArgs = object - username*: string - invite*: string - -proc getCmdArgs(): CmdArgs = - var username = "" - var invite = "" - for kind, key, val in getopt(): - case kind - of cmdArgument: - discard - of cmdLongOption, cmdShortOption: - case key - of "name", "n": - username = val - of "invite", "i": - invite = val - of cmdEnd: - break - if username == "": - username = "" - - result = CmdArgs(username: username, invite: invite) - - - -################################################# -# Link Generation -################################################# - -proc toBundle*(link: string): Result[IntroBundle, string] = - # Check scheme - if not link.startsWith("wap://"): - return err("InvalidScheme") - - # Remove scheme - let path = link[6..^1] # Remove "waku://" - - # Split by '/' - let parts = path.split('/') - - # Expected format: ident/{ident}/ephemeral/{ephemeral}/eid/{eid} - if parts.len != 6: - return err("InvalidFormat") - - # Validate structure - if parts[0] != "ident" or parts[2] != "ephemeral" or parts[4] != "eid": - return err("InvalidFormat") - - # Extract values - let ident = decode(parts[1]).toBytes() - let ephemeral = decode(parts[3]).toBytes() - let eid = int32(parseInt(parts[5])) # TODO: catch parse error - - # Validate non-empty - if ident.len == 0: - return err("MissingIdent") - if ephemeral.len == 0: - return err("MissingEphemeral") - - return ok(IntroBundle( - ident: ident, - ephemeral: ephemeral, - ephemeral_id: eid - )) - - -proc toLink(intro: IntroBundle): string = - let ident = encode(intro.ident, safe = true) - let ephemeral = intro.ephemeral.toHex() - result = fmt"wap://ident/{ident}/ephemeral/{ephemeral}/eid/{intro.ephemeral_id}" - - -proc createChatClient(name: string): Future[Client] {.async.} = - try: - var cfg = await getCfg(name) - for key, val in fetchRegistrations(): - if key != name: - cfg.waku.staticPeers.add(val) - - result = newClient(name, cfg.waku, cfg.ident) - except Exception as e: - echo "Failed to create client: ", e.msg - -proc main() {.async.} = - - let args = getCmdArgs() - var client = await createChatClient(args.username) - - echo "Identity: ", client.getId() - echo "Key: ", client.identity.getAddr() - echo "NodeAaddr:", client.ds.cfg.getMultiAddr() - - client.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} = - echo " ------> Raya :: " - await sleepAsync(10000) - await convo.sendMessage(client.ds, initTextFrame("Pong").toContentFrame()) - ) - - client.onNewConversation(proc(convo: Conversation) {.async.} = - echo " ------> Raya :: New Conversation: " & convo.id() - await convo.sendMessage(client.ds, initTextFrame("Hello").toContentFrame()) - ) - - client.onDeliveryAck(proc(convo: Conversation, msgId: string) {.async.} = - echo " raya -- Read Receipt for " & msgId - ) - - await client.start() - - - - - # Perform OOB Introduction: Raya -> Saro - let x = proc() {.async.} = - while true: - await sleepAsync(5000) - notice "Heartbeat - PeerCount: ", peerCount = client.ds.getConnectedPeerCount() - asyncSpawn x() - - - warn "==== arg Invite ", arg= args.invite, peers = client.ds.getConnectedPeerCount() - if args.invite != "": - let invite = toBundle(args.invite).get() - await sleepAsync(20000) - discard await client.newPrivateConversation(invite) - else: - let bundle = client.createIntroBundle() - echo "Link: ", toLink(bundle) -# - - - # let link = toLink(raya_bundle) - # echo "Raya Intro Link: ", link - - # let parsed = toBundle(link).get() - # echo repr(parsed) - - await sleepAsync(400000) - - client.stop() - -when isMainModule: - setLogLevel(LogLevel.Debug) - waitFor main() - notice "Shutdown"