refactor: can't inherit from HandshakeOpen without a import cycle
This commit is contained in:
parent
54f0a53f77
commit
6597a78e51
|
@ -5,19 +5,30 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"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"
|
"git.lumeweb.com/LumeWeb/libs5-go/protocol/base"
|
||||||
"github.com/vmihailenco/msgpack/v5"
|
"github.com/vmihailenco/msgpack/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ protocol.IncomingMessageTyped = (*HandshakeDone)(nil)
|
var _ base.IncomingMessageTyped = (*HandshakeDone)(nil)
|
||||||
|
|
||||||
type HandshakeDone struct {
|
type HandshakeDone struct {
|
||||||
protocol.HandshakeOpen
|
challenge []byte
|
||||||
|
networkId string
|
||||||
|
base.IncomingMessageTypedImpl
|
||||||
|
base.IncomingMessageHandler
|
||||||
supportedFeatures int
|
supportedFeatures int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *HandshakeDone) SetChallenge(challenge []byte) {
|
||||||
|
m.challenge = challenge
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *HandshakeDone) SetNetworkId(networkId string) {
|
||||||
|
m.networkId = networkId
|
||||||
|
}
|
||||||
|
|
||||||
func NewHandshakeDone() *HandshakeDone {
|
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 {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal((*peer).GetChallenge(), h.HandshakeOpen.Challenge()) {
|
if !bytes.Equal((*peer).GetChallenge(), h.challenge) {
|
||||||
return errors.New("Invalid 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 {
|
func (h HandshakeDone) DecodeMessage(dec *msgpack.Decoder) error {
|
||||||
|
|
||||||
|
challenge, err := dec.DecodeBytes()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
h.challenge = challenge
|
||||||
|
|
||||||
supportedFeatures, err := dec.DecodeInt()
|
supportedFeatures, err := dec.DecodeInt()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue