mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-01-05 23:53:09 +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
|
# Parameter Access
|
||||||
#################################################
|
#################################################
|
||||||
|
|
||||||
proc getId(client: Client): string =
|
proc getId*(client: Client): string =
|
||||||
result = client.ident.getId()
|
result = client.ident.getId()
|
||||||
|
|
||||||
proc identity*(client: Client): Identity =
|
proc identity*(client: Client): Identity =
|
||||||
@ -128,11 +128,11 @@ proc createIntroBundle*(self: var Client): IntroBundle =
|
|||||||
#################################################
|
#################################################
|
||||||
|
|
||||||
proc addConversation*(client: Client, convo: Conversation) =
|
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
|
client.conversations[convo.id()] = convo
|
||||||
|
|
||||||
proc getConversation*(client: Client, convoId: string): Conversation =
|
proc getConversation*(client: Client, convoId: string): Conversation =
|
||||||
notice "Get conversation", convoId = convoId
|
notice "Get conversation", client = client.getId(), convoId = convoId
|
||||||
result = client.conversations[convoId]
|
result = client.conversations[convoId]
|
||||||
|
|
||||||
proc newPrivateConversation*(client: Client,
|
proc newPrivateConversation*(client: Client,
|
||||||
@ -140,7 +140,7 @@ proc newPrivateConversation*(client: Client,
|
|||||||
## Creates a private conversation with the given `IntroBundle`.
|
## Creates a private conversation with the given `IntroBundle`.
|
||||||
## `IntroBundles` are provided out-of-band.
|
## `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("")
|
fromm = introBundle.ident.mapIt(it.toHex(2)).join("")
|
||||||
|
|
||||||
let destPubkey = loadPublicKeyFromBytes(introBundle.ident).valueOr:
|
let destPubkey = loadPublicKeyFromBytes(introBundle.ident).valueOr:
|
||||||
@ -243,7 +243,8 @@ proc simulateMessages(client: Client){.async.} =
|
|||||||
|
|
||||||
for conversation in client.conversations.values():
|
for conversation in client.conversations.values():
|
||||||
if conversation of PrivateV1:
|
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
|
# Control Functions
|
||||||
@ -259,9 +260,9 @@ proc start*(client: Client) {.async.} =
|
|||||||
asyncSpawn client.messageQueueConsumer()
|
asyncSpawn client.messageQueueConsumer()
|
||||||
asyncSpawn client.simulateMessages()
|
asyncSpawn client.simulateMessages()
|
||||||
|
|
||||||
notice "Client start complete"
|
notice "Client start complete", client = client.getId()
|
||||||
|
|
||||||
proc stop*(client: Client) =
|
proc stop*(client: Client) =
|
||||||
## Stop the client.
|
## Stop the client.
|
||||||
client.isRunning = false
|
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():
|
case frame.getKind():
|
||||||
of typeContentFrame:
|
of typeContentFrame:
|
||||||
|
# TODO: Using client.getId() results in an error in this context
|
||||||
notice "Got Mail", text = frame.content.bytes.toUtfString()
|
notice "Got Mail", text = frame.content.bytes.toUtfString()
|
||||||
of typePlaceholder:
|
of typePlaceholder:
|
||||||
notice "Got Placeholder", text = frame.placeholder.counter
|
notice "Got Placeholder", text = frame.placeholder.counter
|
||||||
|
|||||||
@ -12,6 +12,9 @@ import
|
|||||||
proto_types,
|
proto_types,
|
||||||
utils
|
utils
|
||||||
|
|
||||||
|
logScope:
|
||||||
|
topics = "chat inbox"
|
||||||
|
|
||||||
type
|
type
|
||||||
Inbox* = ref object of Conversation
|
Inbox* = ref object of Conversation
|
||||||
pubkey: PublicKey
|
pubkey: PublicKey
|
||||||
@ -70,7 +73,8 @@ proc createPrivateV1FromInvite*[T: ConversationStore](client: T,
|
|||||||
|
|
||||||
let convo = initPrivateV1(client.identity(), destPubkey, "default")
|
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)
|
client.addConversation(convo)
|
||||||
|
|
||||||
proc handleFrame*[T: ConversationStore](convo: Inbox, client: T, bytes: seq[byte]) =
|
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")
|
raise newException(ValueError, "Failed to decode payload")
|
||||||
|
|
||||||
let frame = convo.decrypt(enc).valueOr:
|
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: " &
|
raise newException(ValueError, "Failed to Decrypt MEssage: " &
|
||||||
error)
|
error)
|
||||||
|
|
||||||
@ -90,4 +94,4 @@ proc handleFrame*[T: ConversationStore](convo: Inbox, client: T, bytes: seq[byte
|
|||||||
createPrivateV1FromInvite(client, frame.invitePrivateV1)
|
createPrivateV1FromInvite(client, frame.invitePrivateV1)
|
||||||
|
|
||||||
of typeNote:
|
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