refactor: remove useless log

This commit is contained in:
kaichaosun 2025-12-04 11:51:34 +08:00
parent 567db393ac
commit 70bd36785c
No known key found for this signature in database
GPG Key ID: 223E0F992F4F03BF
4 changed files with 39 additions and 4 deletions

View File

@ -229,14 +229,14 @@ proc newPrivateConversation*(client: Client,
#################################################
# Payload Handling
# Receives a incoming payload, decodes it, and processes it.
#################################################
proc parseMessage(client: Client, msg: ChatPayload) {.raises: [ValueError,
SerializationError].} =
## Receives a incoming payload, decodes it, and processes it.
let envelopeRes = decode(msg.bytes, WapEnvelopeV1)
if envelopeRes.isErr:
debug "Failed to decode WapEnvelopeV1", err = envelopeRes.error
debug "Failed to decode WapEnvelopeV1", client = client.getId(), err = envelopeRes.error
return
let envelope = envelopeRes.get()
@ -268,6 +268,11 @@ proc messageQueueConsumer(client: Client) {.async.} =
while client.isRunning:
let message = await client.inboundQueue.queue.get()
let topicRes = inbox.parseTopic(message.contentTopic).or(private_v1.parseTopic(message.contentTopic))
if topicRes.isErr:
debug "Invalid content topic", client = client.getId(), err = topicRes.error, contentTopic = message.contentTopic
continue
notice "Inbound Message Received", client = client.getId(),
contentTopic = message.contentTopic, len = message.bytes.len()
try:

View File

@ -42,6 +42,9 @@ type
discriminator: string
doubleratchet: naxolotl.Doubleratchet
const
TopicPrefixPrivateV1 = "/convo/private/"
proc getTopic*(self: PrivateV1): string =
## Returns the topic for the PrivateV1 conversation.
return self.topic
@ -63,7 +66,18 @@ proc getConvoId*(self: PrivateV1): string =
proc derive_topic(participants: seq[PublicKey], discriminator: string): string =
## Derives a topic from the participants' public keys.
return "/convo/private/" & getConvoIdRaw(participants, discriminator)
return TopicPrefixPrivateV1 & getConvoIdRaw(participants, discriminator)
## Parses the topic to extract the conversation ID.
proc parseTopic*(topic: string): Result[string, ChatError] =
if not topic.startsWith(TopicPrefixPrivateV1):
return err(ChatError(code: errTopic, context: "Invalid topic prefix"))
let id = topic.split('/')[^1]
if id == "":
return err(ChatError(code: errTopic, context: "Empty conversation ID"))
return ok(id)
proc calcMsgId(self: PrivateV1, msgBytes: seq[byte]): string =
let s = fmt"{self.getConvoId()}|{msgBytes}"

View File

@ -8,6 +8,7 @@ type
ErrorCode* = enum
errTypeError
errWrapped
errTopic
proc `$`*(x: ChatError): string =
fmt"ChatError(code={$x.code}, context: {x.context})"

View File

@ -1,3 +1,5 @@
import std/[strutils]
import
chronicles,
chronos,
@ -10,6 +12,7 @@ import
conversation_store,
crypto,
delivery/waku_client,
errors,
proto_types,
types
@ -21,6 +24,8 @@ type
pubkey: PublicKey
inbox_addr: string
const
TopicPrefixInbox = "/inbox/"
proc `$`*(conv: Inbox): string =
fmt"Inbox: addr->{conv.inbox_addr}"
@ -56,7 +61,17 @@ proc conversation_id_for*(pubkey: PublicKey): string =
# TODO derive this from instance of Inbox
proc topic_inbox*(client_addr: string): string =
return "/inbox/" & client_addr
return TopicPrefixInbox & client_addr
proc parseTopic*(topic: string): Result[string, ChatError] =
if not topic.startsWith(TopicPrefixInbox):
return err(ChatError(code: errTopic, context: "Invalid inbox topic prefix"))
let id = topic.split('/')[^1]
if id == "":
return err(ChatError(code: errTopic, context: "Empty inbox id"))
return ok(id)
method id*(convo: Inbox): string =
return conversation_id_for(convo.pubkey)