2024-01-10 11:21:03 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
|
|
|
"github.com/vmihailenco/msgpack/v5"
|
|
|
|
)
|
|
|
|
|
2024-01-30 03:25:21 +00:00
|
|
|
var _ IncomingMessage = (*RegistryQuery)(nil)
|
|
|
|
var _ EncodeableMessage = (*RegistryQuery)(nil)
|
2024-01-10 11:21:03 +00:00
|
|
|
|
|
|
|
type RegistryQuery struct {
|
|
|
|
pk []byte
|
2024-01-30 03:25:21 +00:00
|
|
|
HandshakeRequirement
|
2024-01-10 11:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewEmptyRegistryQuery() *RegistryQuery {
|
2024-01-13 16:22:01 +00:00
|
|
|
rq := &RegistryQuery{}
|
|
|
|
|
|
|
|
rq.SetRequiresHandshake(true)
|
|
|
|
|
|
|
|
return rq
|
2024-01-10 11:21:03 +00:00
|
|
|
}
|
|
|
|
func NewRegistryQuery(pk []byte) *RegistryQuery {
|
|
|
|
return &RegistryQuery{pk: pk}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RegistryQuery) EncodeMsgpack(enc *msgpack.Encoder) error {
|
|
|
|
err := enc.EncodeInt(int64(types.ProtocolMethodRegistryQuery))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = enc.EncodeBytes(s.pk)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-30 03:25:21 +00:00
|
|
|
func (s *RegistryQuery) DecodeMessage(dec *msgpack.Decoder, message IncomingMessageData) error {
|
2024-01-10 11:21:03 +00:00
|
|
|
pk, err := dec.DecodeBytes()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s.pk = pk
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-30 03:25:21 +00:00
|
|
|
func (s *RegistryQuery) HandleMessage(message IncomingMessageData) error {
|
2024-01-30 05:31:31 +00:00
|
|
|
mediator := message.Mediator
|
2024-01-29 04:39:40 +00:00
|
|
|
peer := message.Peer
|
2024-01-30 05:31:31 +00:00
|
|
|
sre, err := mediator.RegistryGet(s.pk)
|
2024-01-10 11:21:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if sre != nil {
|
|
|
|
err := peer.SendMessage(MarshalSignedRegistryEntry(sre))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|