fix: remove unregister

This commit is contained in:
Richard Ramos 2021-09-28 15:34:52 -04:00
parent 7b54d608d8
commit c10d69ddf2
No known key found for this signature in database
GPG Key ID: 80D4B01265FDFE8F
3 changed files with 2 additions and 57 deletions

View File

@ -21,7 +21,6 @@ var (
type RendezvousPoint interface {
Register(ctx context.Context, ns string, ttl int) (time.Duration, error)
Unregister(ctx context.Context, ns string) error
Discover(ctx context.Context, ns string, limit int, cookie []byte) ([]Registration, []byte, error)
DiscoverAsync(ctx context.Context, ns string) (<-chan Registration, error)
}
@ -34,7 +33,6 @@ type Registration struct {
type RendezvousClient interface {
Register(ctx context.Context, ns string, ttl int) (time.Duration, error)
Unregister(ctx context.Context, ns string) error
Discover(ctx context.Context, ns string, limit int, cookie []byte) ([]peer.AddrInfo, []byte, error)
DiscoverAsync(ctx context.Context, ns string) (<-chan peer.AddrInfo, error)
}
@ -144,22 +142,6 @@ func registerRefresh(ctx context.Context, rz RendezvousPoint, ns string, ttl int
}
}
func (rp *rendezvousPoint) Unregister(ctx context.Context, ns string) error {
s, err := rp.host.NewStream(ctx, rp.p, RendezvousProto)
if err != nil {
return err
}
defer s.Close()
w := ggio.NewDelimitedWriter(s)
req := newUnregisterMessage(ns, rp.host.ID())
return w.WriteMsg(req)
}
func (rc *rendezvousClient) Unregister(ctx context.Context, ns string) error {
return rc.rp.Unregister(ctx, ns)
}
func (rp *rendezvousPoint) Discover(ctx context.Context, ns string, limit int, cookie []byte) ([]Registration, []byte, error) {
s, err := rp.host.NewStream(ctx, rp.p, RendezvousProto)
if err != nil {

2
go.mod
View File

@ -1,4 +1,4 @@
module github.com/libp2p/go-libp2p-rendezvous
module github.com/status-im/go-libp2p-rendezvous
go 1.15

39
svc.go
View File

@ -1,8 +1,6 @@
package rendezvous
import (
"fmt"
db "github.com/libp2p/go-libp2p-rendezvous/db"
pb "github.com/libp2p/go-libp2p-rendezvous/pb"
@ -14,7 +12,7 @@ import (
)
const (
MaxTTL = 72 * 3600 // 72hr
MaxTTL = 20 // 20sec
MaxNamespaceLength = 256
MaxPeerAddressLength = 2048
MaxRegistrations = 1000
@ -67,12 +65,6 @@ func (rz *RendezvousService) handleStream(s inet.Stream) {
return
}
case pb.Message_UNREGISTER:
err := rz.handleUnregister(pid, req.GetUnregister())
if err != nil {
log.Debugf("Error unregistering peer: %s", err.Error())
}
case pb.Message_DISCOVER:
r := rz.handleDiscover(pid, req.GetDiscover())
res.Type = pb.Message_DISCOVER_RESPONSE.Enum()
@ -174,35 +166,6 @@ func (rz *RendezvousService) handleRegister(p peer.ID, m *pb.Message_Register) *
return newRegisterResponse(ttl)
}
func (rz *RendezvousService) handleUnregister(p peer.ID, m *pb.Message_Unregister) error {
ns := m.GetNs()
mpid := m.GetId()
if mpid != nil {
mp, err := peer.IDFromBytes(mpid)
if err != nil {
return err
}
if mp != p {
return fmt.Errorf("peer id mismatch: %s asked to unregister %s", p.Pretty(), mp.Pretty())
}
}
err := rz.DB.Unregister(p, ns)
if err != nil {
return err
}
log.Infof("unregistered peer %s %s", p, ns)
for _, rzs := range rz.rzs {
rzs.Unregister(p, ns)
}
return nil
}
func (rz *RendezvousService) handleDiscover(p peer.ID, m *pb.Message_Discover) *pb.Message_DiscoverResponse {
ns := m.GetNs()