feat: sign peer records

This commit is contained in:
Richard Ramos 2021-10-01 13:39:50 -04:00
parent 020ef08b26
commit 39d264435e
No known key found for this signature in database
GPG Key ID: 80D4B01265FDFE8F
8 changed files with 135 additions and 653 deletions

View File

@ -95,7 +95,12 @@ func (rp *rendezvousPoint) Register(ctx context.Context, ns string, ttl int) (ti
r := ggio.NewDelimitedReader(s, inet.MessageSizeMax)
w := ggio.NewDelimitedWriter(s)
req := newRegisterMessage(ns, peer.AddrInfo{ID: rp.host.ID(), Addrs: rp.host.Addrs()}, ttl)
privKey := rp.host.Peerstore().PrivKey(rp.host.ID())
req, err := newRegisterMessage(privKey, ns, peer.AddrInfo{ID: rp.host.ID(), Addrs: rp.host.Addrs()}, ttl)
if err != nil {
return 0, err
}
err = w.WriteMsg(req)
if err != nil {
return 0, err
@ -118,6 +123,7 @@ func (rp *rendezvousPoint) Register(ctx context.Context, ns string, ttl int) (ti
}
return time.Duration(response.Ttl) * time.Second, nil
return time.Duration(1) * time.Second, nil
}
func (rc *rendezvousClient) Register(ctx context.Context, ns string, ttl int) (time.Duration, error) {
@ -209,7 +215,7 @@ func discoverQuery(ns string, limit int, r ggio.Reader, w ggio.Writer) ([]Regist
regs := res.GetDiscoverResponse().GetRegistrations()
result := make([]Registration, 0, len(regs))
for _, reg := range regs {
pi, err := pbToPeerInfo(reg.GetPeer())
pi, err := pbToPeerRecord(reg.GetPeer())
if err != nil {
log.Errorf("Invalid peer info: %s", err.Error())
continue

View File

@ -21,12 +21,12 @@ type rendezvousDiscovery struct {
}
type discoveryCache struct {
recs map[peer.ID]*record
recs map[peer.ID]*peerRecord
cookie []byte
mux sync.Mutex
}
type record struct {
type peerRecord struct {
peer peer.AddrInfo
expire int64
}
@ -84,7 +84,7 @@ func (c *rendezvousDiscovery) FindPeers(ctx context.Context, ns string, opts ...
c.peerCacheMux.Lock()
cache, ok = c.peerCache[ns]
if !ok {
cache = &discoveryCache{recs: make(map[peer.ID]*record)}
cache = &discoveryCache{recs: make(map[peer.ID]*peerRecord)}
c.peerCache[ns] = cache
}
c.peerCacheMux.Unlock()
@ -111,7 +111,7 @@ func (c *rendezvousDiscovery) FindPeers(ctx context.Context, ns string, opts ...
var regs []Registration
if regs, err = c.rp.Discover(ctx, ns, limit); err == nil {
for _, reg := range regs {
rec := &record{peer: reg.Peer, expire: int64(reg.Ttl) + currentTime}
rec := &peerRecord{peer: reg.Peer, expire: int64(reg.Ttl) + currentTime}
cache.recs[rec.peer.ID] = rec
}
}

2
pb/generate.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
protoc --gofast_out=. --proto_path=$(go list -f '{{ .Dir }}' -m github.com/libp2p/go-libp2p-core) --proto_path=. rendezvous.proto

View File

@ -9,6 +9,7 @@ import (
io "io"
math "math"
math_bits "math/bits"
pb "record/pb"
)
// Reference imports to suppress errors if they are not otherwise used.
@ -100,9 +101,8 @@ type Message struct {
Type Message_MessageType `protobuf:"varint,1,opt,name=type,proto3,enum=rendezvous.pb.Message_MessageType" json:"type,omitempty"`
Register *Message_Register `protobuf:"bytes,2,opt,name=register,proto3" json:"register,omitempty"`
RegisterResponse *Message_RegisterResponse `protobuf:"bytes,3,opt,name=registerResponse,proto3" json:"registerResponse,omitempty"`
Unregister *Message_Unregister `protobuf:"bytes,4,opt,name=unregister,proto3" json:"unregister,omitempty"`
Discover *Message_Discover `protobuf:"bytes,5,opt,name=discover,proto3" json:"discover,omitempty"`
DiscoverResponse *Message_DiscoverResponse `protobuf:"bytes,6,opt,name=discoverResponse,proto3" json:"discoverResponse,omitempty"`
Discover *Message_Discover `protobuf:"bytes,4,opt,name=discover,proto3" json:"discover,omitempty"`
DiscoverResponse *Message_DiscoverResponse `protobuf:"bytes,5,opt,name=discoverResponse,proto3" json:"discoverResponse,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -162,13 +162,6 @@ func (m *Message) GetRegisterResponse() *Message_RegisterResponse {
return nil
}
func (m *Message) GetUnregister() *Message_Unregister {
if m != nil {
return m.Unregister
}
return nil
}
func (m *Message) GetDiscover() *Message_Discover {
if m != nil {
return m.Discover
@ -183,75 +176,20 @@ func (m *Message) GetDiscoverResponse() *Message_DiscoverResponse {
return nil
}
type Message_PeerInfo struct {
Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Addrs [][]byte `protobuf:"bytes,2,rep,name=addrs,proto3" json:"addrs,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Message_PeerInfo) Reset() { *m = Message_PeerInfo{} }
func (m *Message_PeerInfo) String() string { return proto.CompactTextString(m) }
func (*Message_PeerInfo) ProtoMessage() {}
func (*Message_PeerInfo) Descriptor() ([]byte, []int) {
return fileDescriptor_ef0a1d5737df1c36, []int{0, 0}
}
func (m *Message_PeerInfo) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *Message_PeerInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_Message_PeerInfo.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *Message_PeerInfo) XXX_Merge(src proto.Message) {
xxx_messageInfo_Message_PeerInfo.Merge(m, src)
}
func (m *Message_PeerInfo) XXX_Size() int {
return m.Size()
}
func (m *Message_PeerInfo) XXX_DiscardUnknown() {
xxx_messageInfo_Message_PeerInfo.DiscardUnknown(m)
}
var xxx_messageInfo_Message_PeerInfo proto.InternalMessageInfo
func (m *Message_PeerInfo) GetId() []byte {
if m != nil {
return m.Id
}
return nil
}
func (m *Message_PeerInfo) GetAddrs() [][]byte {
if m != nil {
return m.Addrs
}
return nil
}
type Message_Register struct {
Ns string `protobuf:"bytes,1,opt,name=ns,proto3" json:"ns,omitempty"`
Peer *Message_PeerInfo `protobuf:"bytes,2,opt,name=peer,proto3" json:"peer,omitempty"`
Ttl int64 `protobuf:"varint,3,opt,name=ttl,proto3" json:"ttl,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
Ns string `protobuf:"bytes,1,opt,name=ns,proto3" json:"ns,omitempty"`
Peer *pb.Envelope `protobuf:"bytes,2,opt,name=peer,proto3" json:"peer,omitempty"`
Ttl int64 `protobuf:"varint,3,opt,name=ttl,proto3" json:"ttl,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Message_Register) Reset() { *m = Message_Register{} }
func (m *Message_Register) String() string { return proto.CompactTextString(m) }
func (*Message_Register) ProtoMessage() {}
func (*Message_Register) Descriptor() ([]byte, []int) {
return fileDescriptor_ef0a1d5737df1c36, []int{0, 1}
return fileDescriptor_ef0a1d5737df1c36, []int{0, 0}
}
func (m *Message_Register) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@ -287,7 +225,7 @@ func (m *Message_Register) GetNs() string {
return ""
}
func (m *Message_Register) GetPeer() *Message_PeerInfo {
func (m *Message_Register) GetPeer() *pb.Envelope {
if m != nil {
return m.Peer
}
@ -314,7 +252,7 @@ func (m *Message_RegisterResponse) Reset() { *m = Message_RegisterRespon
func (m *Message_RegisterResponse) String() string { return proto.CompactTextString(m) }
func (*Message_RegisterResponse) ProtoMessage() {}
func (*Message_RegisterResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_ef0a1d5737df1c36, []int{0, 2}
return fileDescriptor_ef0a1d5737df1c36, []int{0, 1}
}
func (m *Message_RegisterResponse) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@ -364,61 +302,6 @@ func (m *Message_RegisterResponse) GetTtl() int64 {
return 0
}
type Message_Unregister struct {
Ns string `protobuf:"bytes,1,opt,name=ns,proto3" json:"ns,omitempty"`
Id []byte `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Message_Unregister) Reset() { *m = Message_Unregister{} }
func (m *Message_Unregister) String() string { return proto.CompactTextString(m) }
func (*Message_Unregister) ProtoMessage() {}
func (*Message_Unregister) Descriptor() ([]byte, []int) {
return fileDescriptor_ef0a1d5737df1c36, []int{0, 3}
}
func (m *Message_Unregister) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *Message_Unregister) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_Message_Unregister.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *Message_Unregister) XXX_Merge(src proto.Message) {
xxx_messageInfo_Message_Unregister.Merge(m, src)
}
func (m *Message_Unregister) XXX_Size() int {
return m.Size()
}
func (m *Message_Unregister) XXX_DiscardUnknown() {
xxx_messageInfo_Message_Unregister.DiscardUnknown(m)
}
var xxx_messageInfo_Message_Unregister proto.InternalMessageInfo
func (m *Message_Unregister) GetNs() string {
if m != nil {
return m.Ns
}
return ""
}
func (m *Message_Unregister) GetId() []byte {
if m != nil {
return m.Id
}
return nil
}
type Message_Discover struct {
Ns string `protobuf:"bytes,1,opt,name=ns,proto3" json:"ns,omitempty"`
Limit int64 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"`
@ -431,7 +314,7 @@ func (m *Message_Discover) Reset() { *m = Message_Discover{} }
func (m *Message_Discover) String() string { return proto.CompactTextString(m) }
func (*Message_Discover) ProtoMessage() {}
func (*Message_Discover) Descriptor() ([]byte, []int) {
return fileDescriptor_ef0a1d5737df1c36, []int{0, 4}
return fileDescriptor_ef0a1d5737df1c36, []int{0, 2}
}
func (m *Message_Discover) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@ -487,7 +370,7 @@ func (m *Message_DiscoverResponse) Reset() { *m = Message_DiscoverRespon
func (m *Message_DiscoverResponse) String() string { return proto.CompactTextString(m) }
func (*Message_DiscoverResponse) ProtoMessage() {}
func (*Message_DiscoverResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_ef0a1d5737df1c36, []int{0, 5}
return fileDescriptor_ef0a1d5737df1c36, []int{0, 3}
}
func (m *Message_DiscoverResponse) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@ -541,10 +424,8 @@ func init() {
proto.RegisterEnum("rendezvous.pb.Message_MessageType", Message_MessageType_name, Message_MessageType_value)
proto.RegisterEnum("rendezvous.pb.Message_ResponseStatus", Message_ResponseStatus_name, Message_ResponseStatus_value)
proto.RegisterType((*Message)(nil), "rendezvous.pb.Message")
proto.RegisterType((*Message_PeerInfo)(nil), "rendezvous.pb.Message.PeerInfo")
proto.RegisterType((*Message_Register)(nil), "rendezvous.pb.Message.Register")
proto.RegisterType((*Message_RegisterResponse)(nil), "rendezvous.pb.Message.RegisterResponse")
proto.RegisterType((*Message_Unregister)(nil), "rendezvous.pb.Message.Unregister")
proto.RegisterType((*Message_Discover)(nil), "rendezvous.pb.Message.Discover")
proto.RegisterType((*Message_DiscoverResponse)(nil), "rendezvous.pb.Message.DiscoverResponse")
}
@ -552,44 +433,42 @@ func init() {
func init() { proto.RegisterFile("rendezvous.proto", fileDescriptor_ef0a1d5737df1c36) }
var fileDescriptor_ef0a1d5737df1c36 = []byte{
// 589 bytes of a gzipped FileDescriptorProto
// 551 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xcd, 0x6e, 0xd3, 0x4c,
0x14, 0xad, 0xed, 0x34, 0x5f, 0x72, 0x9b, 0x44, 0xd3, 0xf9, 0x5a, 0x11, 0x65, 0x11, 0x42, 0x24,
0x44, 0x16, 0x28, 0x42, 0xad, 0x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, 0x09,
0xd1, 0x52, 0xd9, 0x39, 0x5f, 0xaa, 0x78, 0xeb, 0x52, 0xbd, 0x35, 0x38, 0x6e, 0x08, 0x34, 0x9e,
0x40, 0x69, 0xc0, 0x79, 0xa0, 0x79, 0x17, 0x3e, 0xad, 0x81, 0xec, 0x3a, 0x71, 0x50, 0x15, 0x94,
0x5d, 0x87, 0x1e, 0xc0, 0xee, 0xd8, 0x71, 0x02, 0x51, 0x97, 0x5b, 0x4a, 0xa7, 0x82, 0x49, 0xd1,
0x18, 0x43, 0x29, 0x33, 0x2b, 0x62, 0x78, 0x22, 0x66, 0x94, 0x51, 0xf6, 0x04, 0x3d, 0x86, 0xc2,
0x94, 0xdf, 0x19, 0x58, 0x76, 0x21, 0xc6, 0x60, 0x4a, 0x40, 0x09, 0xc3, 0xcb, 0x38, 0x1f, 0x05,
0xa3, 0x63, 0xe3, 0xa3, 0x04, 0x64, 0x3d, 0x10, 0xfa, 0x1c, 0x8a, 0x22, 0x1c, 0x87, 0x33, 0x91,
0xbe, 0x4a, 0x0f, 0xb7, 0x26, 0x99, 0x10, 0xcc, 0x18, 0x8c, 0x29, 0x89, 0x36, 0x01, 0x92, 0x93,
0xc5, 0xdf, 0x87, 0xf1, 0x80, 0x65, 0x5c, 0xea, 0xfc, 0x61, 0x8a, 0xc7, 0x00, 0x8b, 0x18, 0x37,
0x56, 0x4d, 0xcc, 0x92, 0x33, 0xb3, 0x22, 0x23, 0x33, 0xbb, 0x37, 0xb0, 0x07, 0xb0, 0x7b, 0xe9,
0xbe, 0x73, 0x93, 0x6b, 0x15, 0x4c, 0x8a, 0xc6, 0x37, 0x09, 0xc8, 0x7a, 0x42, 0x94, 0x41, 0x35,
0xb9, 0x32, 0x18, 0x87, 0xae, 0x1f, 0xab, 0x28, 0x7f, 0xf3, 0xee, 0xaf, 0xb2, 0x96, 0xcc, 0x52,
0xfe, 0xdd, 0xac, 0xc2, 0xba, 0x59, 0xed, 0x09, 0xec, 0x2d, 0xfd, 0x63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, 0xe2, 0x94, 0xb0, 0x3a, 0xc0,
0xc0, 0x28, 0x60, 0x4a, 0x4c, 0xea, 0xea, 0xd6, 0x99, 0x39, 0xe4, 0x48, 0xd5, 0x98, 0x94, 0x57,
0x37, 0xa4, 0x72, 0xfb, 0x33, 0x81, 0xfa, 0xaa, 0x47, 0x56, 0x01, 0xc5, 0x7c, 0x45, 0x4b, 0xec,
0x3e, 0xec, 0x71, 0x47, 0x37, 0x86, 0x5a, 0x4f, 0xef, 0x3a, 0x86, 0x76, 0xce, 0xad, 0xbe, 0x76,
0xc6, 0xe9, 0x64, 0xf5, 0xa2, 0xcf, 0x39, 0x3a, 0xba, 0xf1, 0xdc, 0xa4, 0x82, 0xed, 0x42, 0xed,
0xe6, 0xc2, 0xb6, 0x7b, 0xf4, 0x0d, 0xdb, 0x07, 0xca, 0x1d, 0xc3, 0xb4, 0x1d, 0x6d, 0x60, 0xbf,
0x34, 0x51, 0x7f, 0xcd, 0xbb, 0xf4, 0x9a, 0xa4, 0x6d, 0xdd, 0xb0, 0x39, 0x1a, 0x5a, 0xcf, 0xe1,
0x88, 0x26, 0xd2, 0x2f, 0x0a, 0x63, 0xb1, 0xc0, 0xc0, 0xd0, 0x86, 0x9a, 0xde, 0xd3, 0x4e, 0x7b,
0x9c, 0x7e, 0x54, 0x4f, 0xe9, 0xf5, 0xa2, 0x45, 0xbe, 0x2f, 0x5a, 0xe4, 0xc7, 0xa2, 0x45, 0x3e,
0xfd, 0x6c, 0x95, 0xc6, 0x95, 0xe4, 0xab, 0xf2, 0xf8, 0x57, 0x00, 0x00, 0x00, 0xff, 0xff, 0x08,
0x62, 0x6b, 0xbb, 0x92, 0x04, 0x00, 0x00,
}
func (m *Message) Marshal() (dAtA []byte, err error) {
@ -626,7 +505,7 @@ func (m *Message) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i = encodeVarintRendezvous(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x32
dAtA[i] = 0x2a
}
if m.Discover != nil {
{
@ -638,18 +517,6 @@ func (m *Message) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i = encodeVarintRendezvous(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x2a
}
if m.Unregister != nil {
{
size, err := m.Unregister.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintRendezvous(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x22
}
if m.RegisterResponse != nil {
@ -684,49 +551,6 @@ func (m *Message) MarshalToSizedBuffer(dAtA []byte) (int, error) {
return len(dAtA) - i, nil
}
func (m *Message_PeerInfo) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *Message_PeerInfo) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *Message_PeerInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.XXX_unrecognized != nil {
i -= len(m.XXX_unrecognized)
copy(dAtA[i:], m.XXX_unrecognized)
}
if len(m.Addrs) > 0 {
for iNdEx := len(m.Addrs) - 1; iNdEx >= 0; iNdEx-- {
i -= len(m.Addrs[iNdEx])
copy(dAtA[i:], m.Addrs[iNdEx])
i = encodeVarintRendezvous(dAtA, i, uint64(len(m.Addrs[iNdEx])))
i--
dAtA[i] = 0x12
}
}
if len(m.Id) > 0 {
i -= len(m.Id)
copy(dAtA[i:], m.Id)
i = encodeVarintRendezvous(dAtA, i, uint64(len(m.Id)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func (m *Message_Register) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
@ -822,47 +646,6 @@ func (m *Message_RegisterResponse) MarshalToSizedBuffer(dAtA []byte) (int, error
return len(dAtA) - i, nil
}
func (m *Message_Unregister) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *Message_Unregister) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *Message_Unregister) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.XXX_unrecognized != nil {
i -= len(m.XXX_unrecognized)
copy(dAtA[i:], m.XXX_unrecognized)
}
if len(m.Id) > 0 {
i -= len(m.Id)
copy(dAtA[i:], m.Id)
i = encodeVarintRendezvous(dAtA, i, uint64(len(m.Id)))
i--
dAtA[i] = 0x12
}
if len(m.Ns) > 0 {
i -= len(m.Ns)
copy(dAtA[i:], m.Ns)
i = encodeVarintRendezvous(dAtA, i, uint64(len(m.Ns)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func (m *Message_Discover) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
@ -983,10 +766,6 @@ func (m *Message) Size() (n int) {
l = m.RegisterResponse.Size()
n += 1 + l + sovRendezvous(uint64(l))
}
if m.Unregister != nil {
l = m.Unregister.Size()
n += 1 + l + sovRendezvous(uint64(l))
}
if m.Discover != nil {
l = m.Discover.Size()
n += 1 + l + sovRendezvous(uint64(l))
@ -1001,28 +780,6 @@ func (m *Message) Size() (n int) {
return n
}
func (m *Message_PeerInfo) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.Id)
if l > 0 {
n += 1 + l + sovRendezvous(uint64(l))
}
if len(m.Addrs) > 0 {
for _, b := range m.Addrs {
l = len(b)
n += 1 + l + sovRendezvous(uint64(l))
}
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
return n
}
func (m *Message_Register) Size() (n int) {
if m == nil {
return 0
@ -1068,26 +825,6 @@ func (m *Message_RegisterResponse) Size() (n int) {
return n
}
func (m *Message_Unregister) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.Ns)
if l > 0 {
n += 1 + l + sovRendezvous(uint64(l))
}
l = len(m.Id)
if l > 0 {
n += 1 + l + sovRendezvous(uint64(l))
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
return n
}
func (m *Message_Discover) Size() (n int) {
if m == nil {
return 0
@ -1259,42 +996,6 @@ func (m *Message) Unmarshal(dAtA []byte) error {
}
iNdEx = postIndex
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Unregister", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRendezvous
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthRendezvous
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthRendezvous
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.Unregister == nil {
m.Unregister = &Message_Unregister{}
}
if err := m.Unregister.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 5:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Discover", wireType)
}
@ -1330,7 +1031,7 @@ func (m *Message) Unmarshal(dAtA []byte) error {
return err
}
iNdEx = postIndex
case 6:
case 5:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field DiscoverResponse", wireType)
}
@ -1388,123 +1089,6 @@ func (m *Message) Unmarshal(dAtA []byte) error {
}
return nil
}
func (m *Message_PeerInfo) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRendezvous
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: PeerInfo: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: PeerInfo: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType)
}
var byteLen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRendezvous
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
return ErrInvalidLengthRendezvous
}
postIndex := iNdEx + byteLen
if postIndex < 0 {
return ErrInvalidLengthRendezvous
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Id = append(m.Id[:0], dAtA[iNdEx:postIndex]...)
if m.Id == nil {
m.Id = []byte{}
}
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Addrs", wireType)
}
var byteLen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRendezvous
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
return ErrInvalidLengthRendezvous
}
postIndex := iNdEx + byteLen
if postIndex < 0 {
return ErrInvalidLengthRendezvous
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Addrs = append(m.Addrs, make([]byte, postIndex-iNdEx))
copy(m.Addrs[len(m.Addrs)-1], dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipRendezvous(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthRendezvous
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *Message_Register) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
@ -1596,7 +1180,7 @@ func (m *Message_Register) Unmarshal(dAtA []byte) error {
return io.ErrUnexpectedEOF
}
if m.Peer == nil {
m.Peer = &Message_PeerInfo{}
m.Peer = &pb.Envelope{}
}
if err := m.Peer.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
@ -1764,123 +1348,6 @@ func (m *Message_RegisterResponse) Unmarshal(dAtA []byte) error {
}
return nil
}
func (m *Message_Unregister) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRendezvous
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: Unregister: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: Unregister: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Ns", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRendezvous
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthRendezvous
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthRendezvous
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Ns = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType)
}
var byteLen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRendezvous
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
return ErrInvalidLengthRendezvous
}
postIndex := iNdEx + byteLen
if postIndex < 0 {
return ErrInvalidLengthRendezvous
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Id = append(m.Id[:0], dAtA[iNdEx:postIndex]...)
if m.Id == nil {
m.Id = []byte{}
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipRendezvous(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthRendezvous
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *Message_Discover) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0

View File

@ -2,6 +2,8 @@ syntax = "proto3";
package rendezvous.pb;
import "record/pb/envelope.proto";
message Message {
enum MessageType {
REGISTER = 0;
@ -21,14 +23,9 @@ message Message {
E_UNAVAILABLE = 400;
}
message PeerInfo {
bytes id = 1;
repeated bytes addrs = 2;
}
message Register {
string ns = 1;
PeerInfo peer = 2;
record.pb.Envelope peer = 2;
int64 ttl = 3; // in seconds
}
@ -38,11 +35,6 @@ message Message {
int64 ttl = 3;
}
message Unregister {
string ns = 1;
bytes id = 2;
}
message Discover {
string ns = 1;
int64 limit = 2;
@ -57,7 +49,6 @@ message Message {
MessageType type = 1;
Register register = 2;
RegisterResponse registerResponse = 3;
Unregister unregister = 4;
Discover discover = 5;
DiscoverResponse discoverResponse = 6;
Discover discover = 4;
DiscoverResponse discoverResponse = 5;
}

View File

@ -3,13 +3,18 @@ package rendezvous
import (
"errors"
"fmt"
"time"
"github.com/golang/protobuf/proto"
libp2pCrypto "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/record"
record_pb "github.com/libp2p/go-libp2p-core/record/pb"
pb "github.com/status-im/go-libp2p-rendezvous/pb"
logging "github.com/ipfs/go-log/v2"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/protocol"
ma "github.com/multiformats/go-multiaddr"
)
var log = logging.Logger("rendezvous")
@ -28,7 +33,7 @@ func (e RendezvousError) Error() string {
return fmt.Sprintf("Rendezvous error: %s (%s)", e.Text, pb.Message_ResponseStatus(e.Status).String())
}
func newRegisterMessage(ns string, pi peer.AddrInfo, ttl int) *pb.Message {
func newRegisterMessage(privKey libp2pCrypto.PrivKey, ns string, pi peer.AddrInfo, ttl int) (*pb.Message, error) {
msg := new(pb.Message)
msg.Type = pb.Message_REGISTER
msg.Register = new(pb.Message_Register)
@ -39,24 +44,26 @@ func newRegisterMessage(ns string, pi peer.AddrInfo, ttl int) *pb.Message {
ttl64 := int64(ttl)
msg.Register.Ttl = ttl64
}
msg.Register.Peer = new(pb.Message_PeerInfo)
msg.Register.Peer.Id = []byte(pi.ID)
msg.Register.Peer.Addrs = make([][]byte, len(pi.Addrs))
for i, addr := range pi.Addrs {
msg.Register.Peer.Addrs[i] = addr.Bytes()
}
return msg
}
func newUnregisterMessage(ns string, pid peer.ID) *pb.Message {
msg := new(pb.Message)
msg.Type = pb.Message_UNREGISTER
msg.Unregister = new(pb.Message_Unregister)
if ns != "" {
msg.Unregister.Ns = ns
peerInfo := &peer.PeerRecord{
PeerID: pi.ID,
Addrs: pi.Addrs,
Seq: uint64(time.Now().Unix()),
}
msg.Unregister.Id = []byte(pid)
return msg
envelope, err := record.Seal(peerInfo, privKey)
if err != nil {
return nil, err
}
envPayload, err := envelope.Marshal()
if err != nil {
return nil, err
}
msg.Register.Peer = envPayload
return msg, nil
}
func newDiscoverMessage(ns string, limit int) *pb.Message {
@ -73,26 +80,27 @@ func newDiscoverMessage(ns string, limit int) *pb.Message {
return msg
}
func pbToPeerInfo(p *pb.Message_PeerInfo) (peer.AddrInfo, error) {
if p == nil {
return peer.AddrInfo{}, errors.New("missing peer info")
func pbToPeerRecord(pbEnvelope *record_pb.Envelope) (peer.AddrInfo, error) {
if pbEnvelope == nil {
return peer.AddrInfo{}, errors.New("missing envelope information")
}
id, err := peer.IDFromBytes(p.Id)
envelopeBytes, err := proto.Marshal(pbEnvelope)
if err != nil {
return peer.AddrInfo{}, err
}
addrs := make([]ma.Multiaddr, 0, len(p.Addrs))
for _, bs := range p.Addrs {
addr, err := ma.NewMultiaddrBytes(bs)
if err != nil {
log.Errorf("Error parsing multiaddr: %s", err.Error())
continue
}
addrs = append(addrs, addr)
_, rec, err := record.ConsumeEnvelope(envelopeBytes, peer.PeerRecordEnvelopeDomain)
if err != nil {
return peer.AddrInfo{}, err
}
return peer.AddrInfo{ID: id, Addrs: addrs}, nil
peerRec, ok := rec.(*peer.PeerRecord)
if !ok {
return peer.AddrInfo{}, errors.New("invalid peer record")
}
return peer.AddrInfo{ID: peerRec.PeerID, Addrs: peerRec.Addrs}, nil
}
func newRegisterResponse(ttl int) *pb.Message_RegisterResponse {
@ -110,18 +118,22 @@ func newRegisterResponseError(status pb.Message_ResponseStatus, text string) *pb
return r
}
func newDiscoverResponse(regs []RegistrationRecord) *pb.Message_DiscoverResponse {
func newDiscoverResponse(regs []RegistrationRecord) (*pb.Message_DiscoverResponse, error) {
r := new(pb.Message_DiscoverResponse)
r.Status = pb.Message_OK
rregs := make([]*pb.Message_Register, len(regs))
for i, reg := range regs {
var env = &record_pb.Envelope{}
if err := env.Unmarshal(reg.PeerEnvelope); err != nil {
return nil, err
}
rreg := new(pb.Message_Register)
rns := reg.Ns
rreg.Ns = rns
rreg.Peer = new(pb.Message_PeerInfo)
rreg.Peer.Id = []byte(reg.Id)
rreg.Peer.Addrs = reg.Addrs
rreg.Peer = env
rttl := int64(reg.Ttl)
rreg.Ttl = rttl
rregs[i] = rreg
@ -129,7 +141,7 @@ func newDiscoverResponse(regs []RegistrationRecord) *pb.Message_DiscoverResponse
r.Registrations = rregs
return r
return r, nil
}
func newDiscoverResponseError(status pb.Message_ResponseStatus, text string) *pb.Message_DiscoverResponse {

View File

@ -18,11 +18,10 @@ const (
)
type RegistrationRecord struct {
Id peer.ID
Addrs [][]byte
Ns string
Ttl int
Deadline time.Time
PeerEnvelope []byte
Ns string
Ttl int
Deadline time.Time
}
// TopicPart looks for TopicBodyDelimiter and returns topic prefix from the same key.
@ -67,14 +66,13 @@ type Storage struct {
}
// Add stores record using specified topic.
func (s Storage) Add(ns string, id peer.ID, addrs [][]byte, ttl int, deadline time.Time) (string, error) {
func (s Storage) Add(ns string, id peer.ID, envelope []byte, ttl int, deadline time.Time) (string, error) {
key := NewRecordsKey(ns, id)
stored := RegistrationRecord{
Id: id,
Addrs: addrs,
Ttl: ttl,
Ns: ns,
Deadline: deadline,
PeerEnvelope: envelope,
Ttl: ttl,
Ns: ns,
Deadline: deadline,
}
var data bytes.Buffer

8
svc.go
View File

@ -254,5 +254,11 @@ func (rz *RendezvousService) handleDiscover(p peer.ID, m *pb.Message_Discover) *
log.Infof("discover query: %s %s -> %d", p, ns, len(records))
return newDiscoverResponse(records)
response, err := newDiscoverResponse(records)
if err != nil {
log.Errorf("Error in response: %s", err.Error())
return newDiscoverResponseError(pb.Message_E_INTERNAL_ERROR, "error building response")
}
return response
}