mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-01-02 14:13:10 +00:00
Add Client origin logging
This commit is contained in:
parent
776b726249
commit
b4b2472c2a
@ -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()
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user