From 6597a78e51a11f4bd6c04307be9eec717b20b913 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 7 Jan 2024 05:13:09 -0500 Subject: [PATCH] refactor: can't inherit from HandshakeOpen without a import cycle --- protocol/signed/handshake_done.go | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/protocol/signed/handshake_done.go b/protocol/signed/handshake_done.go index c98c420..317d662 100644 --- a/protocol/signed/handshake_done.go +++ b/protocol/signed/handshake_done.go @@ -5,19 +5,30 @@ import ( "errors" "git.lumeweb.com/LumeWeb/libs5-go/interfaces" "git.lumeweb.com/LumeWeb/libs5-go/net" - "git.lumeweb.com/LumeWeb/libs5-go/protocol" + "git.lumeweb.com/LumeWeb/libs5-go/protocol/base" "github.com/vmihailenco/msgpack/v5" ) -var _ protocol.IncomingMessageTyped = (*HandshakeDone)(nil) +var _ base.IncomingMessageTyped = (*HandshakeDone)(nil) type HandshakeDone struct { - protocol.HandshakeOpen + challenge []byte + networkId string + base.IncomingMessageTypedImpl + base.IncomingMessageHandler supportedFeatures int } +func (m *HandshakeDone) SetChallenge(challenge []byte) { + m.challenge = challenge +} + +func (m *HandshakeDone) SetNetworkId(networkId string) { + m.networkId = networkId +} + func NewHandshakeDone() *HandshakeDone { - return &HandshakeDone{HandshakeOpen: *protocol.NewHandshakeOpen(nil, ""), supportedFeatures: -1} + return &HandshakeDone{challenge: nil, networkId: "", supportedFeatures: -1} } func (h HandshakeDone) HandleMessage(node interfaces.Node, peer *net.Peer, verifyId bool) error { @@ -29,7 +40,7 @@ func (h HandshakeDone) HandleMessage(node interfaces.Node, peer *net.Peer, verif return nil } - if !bytes.Equal((*peer).GetChallenge(), h.HandshakeOpen.Challenge()) { + if !bytes.Equal((*peer).GetChallenge(), h.challenge) { return errors.New("Invalid challenge") } /* @@ -75,6 +86,14 @@ func (h HandshakeDone) HandleMessage(node interfaces.Node, peer *net.Peer, verif } func (h HandshakeDone) DecodeMessage(dec *msgpack.Decoder) error { + + challenge, err := dec.DecodeBytes() + if err != nil { + return err + } + + h.challenge = challenge + supportedFeatures, err := dec.DecodeInt() if err != nil {