feat: add EncodeMsgpack, HandleMessage, and NewHandshakeDoneRequest toHandshakeDone

This commit is contained in:
Derrick Hammer 2024-01-07 09:09:17 -05:00
parent cc2885f2b4
commit a6389eb738
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 37 additions and 1 deletions

View File

@ -6,10 +6,13 @@ import (
"git.lumeweb.com/LumeWeb/libs5-go/interfaces" "git.lumeweb.com/LumeWeb/libs5-go/interfaces"
"git.lumeweb.com/LumeWeb/libs5-go/net" "git.lumeweb.com/LumeWeb/libs5-go/net"
"git.lumeweb.com/LumeWeb/libs5-go/protocol/base" "git.lumeweb.com/LumeWeb/libs5-go/protocol/base"
"git.lumeweb.com/LumeWeb/libs5-go/types"
"github.com/vmihailenco/msgpack/v5" "github.com/vmihailenco/msgpack/v5"
"net/url"
) )
var _ base.IncomingMessageTyped = (*HandshakeDone)(nil) var _ base.IncomingMessageTyped = (*HandshakeDone)(nil)
var _ base.EncodeableMessage = (*HandshakeDone)(nil)
type HandshakeDone struct { type HandshakeDone struct {
challenge []byte challenge []byte
@ -17,6 +20,40 @@ type HandshakeDone struct {
base.IncomingMessageTypedImpl base.IncomingMessageTypedImpl
base.IncomingMessageHandler base.IncomingMessageHandler
supportedFeatures int supportedFeatures int
connectionUris []*url.URL
handshake []byte
}
func NewHandshakeDoneRequest(handshake []byte, supportedFeatures int, connectionUris []*url.URL) *HandshakeDone {
return &HandshakeDone{
handshake: handshake,
supportedFeatures: supportedFeatures,
connectionUris: connectionUris,
}
}
func (m HandshakeDone) EncodeMsgpack(enc *msgpack.Encoder) error {
err := enc.EncodeUint(uint64(types.ProtocolMethodHandshakeDone))
if err != nil {
return err
}
err = enc.EncodeBytes(m.Original())
if err != nil {
return err
}
err = enc.EncodeString(m.networkId)
if err != nil {
return err
}
err = enc.EncodeInt(int64(m.supportedFeatures))
if err != nil {
return err
}
return nil
} }
func (m *HandshakeDone) SetChallenge(challenge []byte) { func (m *HandshakeDone) SetChallenge(challenge []byte) {
@ -86,7 +123,6 @@ func (h HandshakeDone) HandleMessage(node interfaces.Node, peer net.Peer, verify
} }
func (h HandshakeDone) DecodeMessage(dec *msgpack.Decoder) error { func (h HandshakeDone) DecodeMessage(dec *msgpack.Decoder) error {
challenge, err := dec.DecodeBytes() challenge, err := dec.DecodeBytes()
if err != nil { if err != nil {
return err return err