refactor: can't inherit from HandshakeOpen without a import cycle

This commit is contained in:
Derrick Hammer 2024-01-07 05:13:09 -05:00
parent 54f0a53f77
commit 6597a78e51
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 24 additions and 5 deletions

View File

@ -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 {