Log all pblite response contents

This commit is contained in:
Tulir Asokan 2023-07-15 16:17:02 +03:00
parent 08cbe12181
commit cb7e12290b
3 changed files with 14 additions and 7 deletions

View file

@ -21,6 +21,15 @@ func (r *RPC) deduplicateHash(hash [32]byte) bool {
return false
}
func (r *RPC) logContent(res *pblite.Response) {
if r.client.Logger.Trace().Enabled() && res.Data.Decrypted != nil {
r.client.Logger.Trace().
Str("proto_name", string(res.Data.Decrypted.ProtoReflect().Descriptor().FullName())).
Str("data", base64.StdEncoding.EncodeToString(res.Data.RawDecrypted)).
Msg("Got event")
}
}
func (r *RPC) deduplicateUpdate(response *pblite.Response) bool {
if response.Data.RawDecrypted != nil {
contentHash := sha256.Sum256(response.Data.RawDecrypted)
@ -28,13 +37,7 @@ func (r *RPC) deduplicateUpdate(response *pblite.Response) bool {
r.client.Logger.Trace().Hex("data_hash", contentHash[:]).Msg("Ignoring duplicate update")
return true
}
if r.client.Logger.Trace().Enabled() {
r.client.Logger.Trace().
Str("proto_name", string(response.Data.Decrypted.ProtoReflect().Descriptor().FullName())).
Str("data", base64.StdEncoding.EncodeToString(response.Data.RawDecrypted)).
Hex("data_hash", contentHash[:]).
Msg("Got event")
}
r.logContent(response)
}
return false
}

View file

@ -63,6 +63,7 @@ func (s *SessionHandler) respondToRequestChannel(res *pblite.Response) {
return
}
s.client.Logger.Debug().Any("actionType", actionType).Any("requestId", requestId).Msg("responding to request")
s.client.rpc.logContent(res)
actionResponseChan.response = res
actionResponseChan.wg.Done()

View file

@ -17,9 +17,11 @@ func (c *Client) handleUpdatesEvent(res *pblite.Response) {
switch evt := data.Event.(type) {
case *binary.UpdateEvents_UserAlertEvent:
c.rpc.logContent(res)
c.handleUserAlertEvent(res, evt.UserAlertEvent)
case *binary.UpdateEvents_SettingsEvent:
c.rpc.logContent(res)
c.handleSettingsEvent(res, evt.SettingsEvent)
case *binary.UpdateEvents_ConversationEvent:
@ -35,6 +37,7 @@ func (c *Client) handleUpdatesEvent(res *pblite.Response) {
c.triggerEvent(evt.MessageEvent.GetData())
case *binary.UpdateEvents_TypingEvent:
c.rpc.logContent(res)
c.handleTypingEvent(res, evt.TypingEvent.GetData())
default:
c.Logger.Debug().Any("evt", evt).Any("res", res).Msg("Got unknown event type")