From b4b2472c2a852f136c3524f8344d613915536229 Mon Sep 17 00:00:00 2001 From: Jazz Turner-Baggs <473256+jazzz@users.noreply.github.com> Date: Wed, 20 Aug 2025 11:34:02 -0700 Subject: [PATCH] Add Client origin logging --- src/client.nim | 15 ++++++++------- src/conversations/private_v1.nim | 1 + src/inbox.nim | 10 +++++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/client.nim b/src/client.nim index f15cc28..0a6a568 100644 --- a/src/client.nim +++ b/src/client.nim @@ -77,7 +77,7 @@ proc newClient*(name: string, cfg: WakuConfig): Client {.raises: [IOError, # Parameter Access ################################################# -proc getId(client: Client): string = +proc getId*(client: Client): string = result = client.ident.getId() proc identity*(client: Client): Identity = @@ -128,11 +128,11 @@ proc createIntroBundle*(self: var Client): IntroBundle = ################################################# proc addConversation*(client: Client, convo: Conversation) = - notice "Creating conversation", topic = convo.id() + notice "Creating conversation", client = client.getId(), topic = convo.id() client.conversations[convo.id()] = convo proc getConversation*(client: Client, convoId: string): Conversation = - notice "Get conversation", convoId = convoId + notice "Get conversation", client = client.getId(), convoId = convoId result = client.conversations[convoId] proc newPrivateConversation*(client: Client, @@ -140,7 +140,7 @@ proc newPrivateConversation*(client: Client, ## Creates a private conversation with the given `IntroBundle`. ## `IntroBundles` are provided out-of-band. - notice "New PRIVATE Convo ", clientId = client.getId(), + notice "New PRIVATE Convo ", client = client.getId(), fromm = introBundle.ident.mapIt(it.toHex(2)).join("") let destPubkey = loadPublicKeyFromBytes(introBundle.ident).valueOr: @@ -243,7 +243,8 @@ proc simulateMessages(client: Client){.async.} = for conversation in client.conversations.values(): if conversation of PrivateV1: - await client.addMessage(PrivateV1(conversation), fmt"message: {a}") + await client.addMessage(PrivateV1(conversation), + fmt"message: {a} from:{client.getId()}") ################################################# # Control Functions @@ -259,9 +260,9 @@ proc start*(client: Client) {.async.} = asyncSpawn client.messageQueueConsumer() asyncSpawn client.simulateMessages() - notice "Client start complete" + notice "Client start complete", client = client.getId() proc stop*(client: Client) = ## Stop the client. client.isRunning = false - notice "Client stopped" + notice "Client stopped", client = client.getId() diff --git a/src/conversations/private_v1.nim b/src/conversations/private_v1.nim index bfe11ab..437226d 100644 --- a/src/conversations/private_v1.nim +++ b/src/conversations/private_v1.nim @@ -88,6 +88,7 @@ proc handleFrame*[T: ConversationStore](convo: PrivateV1, client: T, case frame.getKind(): of typeContentFrame: + # TODO: Using client.getId() results in an error in this context notice "Got Mail", text = frame.content.bytes.toUtfString() of typePlaceholder: notice "Got Placeholder", text = frame.placeholder.counter diff --git a/src/inbox.nim b/src/inbox.nim index 273caa2..916ebff 100644 --- a/src/inbox.nim +++ b/src/inbox.nim @@ -12,6 +12,9 @@ import proto_types, utils +logScope: + topics = "chat inbox" + type Inbox* = ref object of Conversation pubkey: PublicKey @@ -70,7 +73,8 @@ proc createPrivateV1FromInvite*[T: ConversationStore](client: T, let convo = initPrivateV1(client.identity(), destPubkey, "default") - notice "Creating PrivateV1 conversation", topic = convo.getConvoId() + notice "Creating PrivateV1 conversation", client = client.getId(), + topic = convo.getConvoId() client.addConversation(convo) proc handleFrame*[T: ConversationStore](convo: Inbox, client: T, bytes: seq[byte]) = @@ -81,7 +85,7 @@ proc handleFrame*[T: ConversationStore](convo: Inbox, client: T, bytes: seq[byte raise newException(ValueError, "Failed to decode payload") let frame = convo.decrypt(enc).valueOr: - error "Decrypt failed", error = error + error "Decrypt failed", client = client.getId(), error = error raise newException(ValueError, "Failed to Decrypt MEssage: " & error) @@ -90,4 +94,4 @@ proc handleFrame*[T: ConversationStore](convo: Inbox, client: T, bytes: seq[byte createPrivateV1FromInvite(client, frame.invitePrivateV1) of typeNote: - notice "Receive Note", text = frame.note.text + notice "Receive Note", client = client.getId(), text = frame.note.text