2024-01-10 11:21:03 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.lumeweb.com/LumeWeb/libs5-go/interfaces"
|
|
|
|
"git.lumeweb.com/LumeWeb/libs5-go/net"
|
|
|
|
"git.lumeweb.com/LumeWeb/libs5-go/protocol/base"
|
|
|
|
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
|
|
|
"github.com/vmihailenco/msgpack/v5"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ base.IncomingMessageTyped = (*RegistryEntryRequest)(nil)
|
|
|
|
var _ base.EncodeableMessage = (*RegistryEntryRequest)(nil)
|
|
|
|
|
|
|
|
type RegistryEntryRequest struct {
|
|
|
|
sre interfaces.SignedRegistryEntry
|
|
|
|
base.IncomingMessageTypedImpl
|
|
|
|
base.IncomingMessageHandler
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewEmptyRegistryEntryRequest() *RegistryEntryRequest {
|
|
|
|
return &RegistryEntryRequest{}
|
|
|
|
}
|
|
|
|
func NewRegistryEntryRequest(sre interfaces.SignedRegistryEntry) *RegistryEntryRequest {
|
|
|
|
return &RegistryEntryRequest{sre: sre}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RegistryEntryRequest) EncodeMsgpack(enc *msgpack.Encoder) error {
|
|
|
|
err := enc.EncodeInt(int64(types.RecordTypeRegistryEntry))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = enc.EncodeBytes(MarshalSignedRegistryEntry(s.sre))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RegistryEntryRequest) DecodeMessage(dec *msgpack.Decoder) error {
|
2024-01-10 12:20:33 +00:00
|
|
|
data := s.IncomingMessage().Original()
|
2024-01-10 11:21:03 +00:00
|
|
|
|
2024-01-10 12:20:33 +00:00
|
|
|
sre, err := UnmarshalSignedRegistryEntry(data)
|
2024-01-10 11:21:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s.sre = sre
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RegistryEntryRequest) HandleMessage(node interfaces.Node, peer net.Peer, verifyId bool) error {
|
|
|
|
return node.Services().Registry().Set(s.sre, false, peer)
|
|
|
|
}
|