fix: need to use NewDecoder and manually call DecodeMessage and HandleMessage

This commit is contained in:
Derrick Hammer 2024-01-30 17:26:06 -05:00
parent 881e19d569
commit 5079db4f03
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 11 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package protocol
import (
"bytes"
"crypto/ed25519"
"errors"
"git.lumeweb.com/LumeWeb/libs5-go/config"
@ -96,18 +97,22 @@ func (s *SignedMessage) HandleMessage(message IncomingMessageData) error {
logger.Debug("Peer is not handshake done, ignoring message", zap.Any("type", types.ProtocolMethodMap[types.ProtocolMethod(payload.kind)]))
return nil
}
err := msgpack.Unmarshal(payload.message, &msgHandler)
if err != nil {
return err
}
data := IncomingMessageDataSigned{
signedDec := msgpack.NewDecoder(bytes.NewReader(payload.message))
signedMsg := IncomingMessageDataSigned{
IncomingMessageData: message,
NodeId: s.nodeId,
}
err = msgHandler.HandleMessage(data)
err = msgHandler.DecodeMessage(signedDec, signedMsg)
if err != nil {
logger.Error("Error decoding signed message", zap.Error(err))
return err
}
if err = msgHandler.HandleMessage(signedMsg); err != nil {
logger.Error("Error handling signed message", zap.Error(err))
return err
}
}