2024-01-10 11:21:03 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.lumeweb.com/LumeWeb/libs5-go/protocol/base"
|
|
|
|
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
|
|
|
"github.com/vmihailenco/msgpack/v5"
|
|
|
|
)
|
|
|
|
|
2024-01-29 04:39:40 +00:00
|
|
|
var _ base.IncomingMessage = (*RegistryEntryRequest)(nil)
|
2024-01-10 11:21:03 +00:00
|
|
|
var _ base.EncodeableMessage = (*RegistryEntryRequest)(nil)
|
|
|
|
|
|
|
|
type RegistryEntryRequest struct {
|
2024-01-29 04:59:43 +00:00
|
|
|
sre SignedRegistryEntry
|
2024-01-29 04:39:40 +00:00
|
|
|
base.HandshakeRequirement
|
2024-01-10 11:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewEmptyRegistryEntryRequest() *RegistryEntryRequest {
|
2024-01-13 16:22:01 +00:00
|
|
|
rer := &RegistryEntryRequest{}
|
|
|
|
|
|
|
|
rer.SetRequiresHandshake(true)
|
|
|
|
|
|
|
|
return rer
|
2024-01-10 11:21:03 +00:00
|
|
|
}
|
2024-01-29 04:59:43 +00:00
|
|
|
func NewRegistryEntryRequest(sre SignedRegistryEntry) *RegistryEntryRequest {
|
2024-01-10 11:21:03 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-01-29 04:39:40 +00:00
|
|
|
func (s *RegistryEntryRequest) DecodeMessage(dec *msgpack.Decoder, message base.IncomingMessageData) error {
|
|
|
|
sre, err := UnmarshalSignedRegistryEntry(message.Data)
|
2024-01-10 11:21:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s.sre = sre
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-29 04:39:40 +00:00
|
|
|
func (s *RegistryEntryRequest) HandleMessage(message base.IncomingMessageData) error {
|
|
|
|
peer := message.Peer
|
2024-01-29 06:55:36 +00:00
|
|
|
services := message.Services
|
|
|
|
return services.Registry().Set(s.sre, false, peer)
|
2024-01-10 11:21:03 +00:00
|
|
|
}
|