libs5-go/protocol/handshake_open.go

65 lines
1.3 KiB
Go
Raw Normal View History

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"
"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"
)
2024-01-07 12:59:14 +00:00
var _ base.IncomingMessageTyped = (*HandshakeOpen)(nil)
2024-01-06 11:33:46 +00:00
type HandshakeOpen struct {
challenge []byte
networkId string
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
}
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
}
func (m *HandshakeOpen) HandleMessage(node interfaces.Node, peer net.Peer, verifyId bool) error {
2024-01-06 11:33:46 +00:00
return nil
}