2023-06-30 11:05:33 +00:00
|
|
|
package libgm
|
2023-06-30 09:54:08 +00:00
|
|
|
|
|
|
|
import (
|
2023-07-15 22:45:57 +00:00
|
|
|
"encoding/base64"
|
2023-06-30 09:54:08 +00:00
|
|
|
)
|
|
|
|
|
2023-07-17 23:01:06 +00:00
|
|
|
func (s *SessionHandler) waitResponse(requestID string) chan *IncomingRPCMessage {
|
|
|
|
ch := make(chan *IncomingRPCMessage, 1)
|
2023-07-15 22:45:57 +00:00
|
|
|
s.responseWaitersLock.Lock()
|
|
|
|
s.responseWaiters[requestID] = ch
|
|
|
|
s.responseWaitersLock.Unlock()
|
|
|
|
return ch
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
|
|
|
|
2023-07-17 23:01:06 +00:00
|
|
|
func (s *SessionHandler) cancelResponse(requestID string, ch chan *IncomingRPCMessage) {
|
2023-07-15 22:45:57 +00:00
|
|
|
s.responseWaitersLock.Lock()
|
|
|
|
close(ch)
|
|
|
|
delete(s.responseWaiters, requestID)
|
|
|
|
s.responseWaitersLock.Unlock()
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
|
|
|
|
2023-07-17 23:01:06 +00:00
|
|
|
func (s *SessionHandler) receiveResponse(msg *IncomingRPCMessage) bool {
|
2023-07-18 12:13:53 +00:00
|
|
|
if msg.Message == nil {
|
|
|
|
return false
|
|
|
|
}
|
2023-07-17 23:01:06 +00:00
|
|
|
requestID := msg.Message.SessionID
|
2023-07-15 22:45:57 +00:00
|
|
|
s.responseWaitersLock.Lock()
|
2023-07-17 23:01:06 +00:00
|
|
|
ch, ok := s.responseWaiters[requestID]
|
2023-06-30 09:54:08 +00:00
|
|
|
if !ok {
|
2023-07-15 22:45:57 +00:00
|
|
|
s.responseWaitersLock.Unlock()
|
|
|
|
return false
|
|
|
|
}
|
2023-07-17 23:01:06 +00:00
|
|
|
delete(s.responseWaiters, requestID)
|
2023-07-15 22:45:57 +00:00
|
|
|
s.responseWaitersLock.Unlock()
|
|
|
|
evt := s.client.Logger.Trace().
|
2023-07-17 23:01:06 +00:00
|
|
|
Str("request_id", requestID)
|
|
|
|
if evt.Enabled() {
|
|
|
|
if msg.DecryptedData != nil {
|
|
|
|
evt.Str("data", base64.StdEncoding.EncodeToString(msg.DecryptedData))
|
|
|
|
}
|
|
|
|
if msg.DecryptedMessage != nil {
|
|
|
|
evt.Str("proto_name", string(msg.DecryptedMessage.ProtoReflect().Descriptor().FullName()))
|
|
|
|
}
|
2023-07-15 22:45:57 +00:00
|
|
|
}
|
|
|
|
evt.Msg("Received response")
|
2023-07-17 23:01:06 +00:00
|
|
|
ch <- msg
|
2023-07-15 22:45:57 +00:00
|
|
|
return true
|
2023-06-30 09:55:49 +00:00
|
|
|
}
|