diff options
author | 2020-12-01 13:57:29 +0100 | |
---|---|---|
committer | 2020-12-03 10:14:12 +0100 | |
commit | bcf3fbd21aa22d1546bc85ffb887ae5ba557808e (patch) | |
tree | 60668ecb3d0721bf33cfa1b37736a494f675ec4b /core/request_handler.go | |
parent | 2b743eede78b6fed115421716888f80088edefdb (diff) |
Fixed incorrect message error in the stream API
The message package is passed to the stream object and
used to evaluate correct reply message type
Change-Id: I2c9844d6447d024af1693205efd5721e2f89f22d
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
Diffstat (limited to 'core/request_handler.go')
-rw-r--r-- | core/request_handler.go | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/core/request_handler.go b/core/request_handler.go index fc704cb..f9d972a 100644 --- a/core/request_handler.go +++ b/core/request_handler.go @@ -210,9 +210,9 @@ func (c *Connection) msgCallback(msgID uint16, data []byte) { return } - msg, ok := c.msgMap[msgID] - if !ok { - log.Warnf("Unknown message received, ID: %d", msgID) + msg, err := c.getMessageByID(msgID) + if err != nil { + log.Warnln(err) return } @@ -419,3 +419,19 @@ func compareSeqNumbers(seqNum1, seqNum2 uint16) int { } return 1 } + +// Returns first message from any package where the message ID matches +// Note: the msg is further used only for its MessageType which is not +// affected by the message's package +func (c *Connection) getMessageByID(msgID uint16) (msg api.Message, err error) { + var ok bool + for _, msgs := range c.msgMapByPath { + if msg, ok = msgs[msgID]; ok { + break + } + } + if !ok { + return nil, fmt.Errorf("unknown message received, ID: %d", msgID) + } + return msg, nil +} |