2024-01-06 11:33:46 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2024-01-07 08:58:22 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/libs5-go/interfaces"
|
2024-01-06 11:33:46 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/libs5-go/net"
|
2024-01-07 10:12:43 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/libs5-go/protocol/base"
|
2024-01-06 11:33:46 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
|
|
|
"github.com/vmihailenco/msgpack/v5"
|
|
|
|
)
|
|
|
|
|
|
|
|
type HandshakeOpen struct {
|
|
|
|
challenge []byte
|
|
|
|
networkId string
|
2024-01-07 10:12:43 +00:00
|
|
|
base.IncomingMessageTypedImpl
|
|
|
|
base.IncomingMessageHandler
|
2024-01-06 11:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m HandshakeOpen) Challenge() []byte {
|
|
|
|
return m.challenge
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m HandshakeOpen) NetworkId() string {
|
|
|
|
return m.networkId
|
|
|
|
}
|
|
|
|
|
2024-01-07 10:12:43 +00:00
|
|
|
var _ base.EncodeableMessage = (*HandshakeOpen)(nil)
|
2024-01-06 11:33:46 +00:00
|
|
|
var (
|
|
|
|
errInvalidChallenge = errors.New("Invalid challenge")
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewHandshakeOpen(challenge []byte, networkId string) *HandshakeOpen {
|
|
|
|
return &HandshakeOpen{
|
|
|
|
challenge: challenge,
|
|
|
|
networkId: networkId,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (m HandshakeOpen) EncodeMsgpack(enc *msgpack.Encoder) error {
|
|
|
|
err := enc.EncodeUint(uint64(types.ProtocolMethodHandshakeOpen))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = enc.EncodeBytes(m.challenge)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.networkId != "" {
|
|
|
|
err = enc.EncodeString(m.networkId)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-07 11:35:41 +00:00
|
|
|
func (m *HandshakeOpen) HandleMessage(node interfaces.Node, peer net.Peer, verifyId bool) error {
|
2024-01-06 11:33:46 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|