@@ -40,16 +40,20 @@ type RendezvousClient interface {
4040 DiscoverSubscribe (ctx context.Context , ns string ) (<- chan peer.AddrInfo , error )
4141}
4242
43- func NewRendezvousPoint (host host.Host , p peer.ID ) RendezvousPoint {
43+ func NewRendezvousPoint (host host.Host , p peer.ID , opts ... RendezvousPointOption ) RendezvousPoint {
44+ cfg := defaultRendezvousPointConfig
45+ cfg .apply (opts ... )
4446 return & rendezvousPoint {
45- host : host ,
46- p : p ,
47+ addrFactory : cfg .AddrsFactory ,
48+ host : host ,
49+ p : p ,
4750 }
4851}
4952
5053type rendezvousPoint struct {
51- host host.Host
52- p peer.ID
54+ addrFactory AddrsFactory
55+ host host.Host
56+ p peer.ID
5357}
5458
5559func NewRendezvousClient (host host.Host , rp peer.ID , sync ... RendezvousSyncClient ) RendezvousClient {
@@ -75,7 +79,13 @@ func (rp *rendezvousPoint) Register(ctx context.Context, ns string, ttl int) (ti
7579 r := ggio .NewDelimitedReader (s , inet .MessageSizeMax )
7680 w := ggio .NewDelimitedWriter (s )
7781
78- req := newRegisterMessage (ns , peer.AddrInfo {ID : rp .host .ID (), Addrs : rp .host .Addrs ()}, ttl )
82+ addrs := rp .addrFactory (rp .host .Addrs ())
83+ if len (addrs ) == 0 {
84+ return 0 , fmt .Errorf ("no addrs available to advertise: %s" , ns )
85+ }
86+
87+ log .Debugf ("advertising on `%s` with: %v" , ns , addrs )
88+ req := newRegisterMessage (ns , peer.AddrInfo {ID : rp .host .ID (), Addrs : addrs }, ttl )
7989 err = w .WriteMsg (req )
8090 if err != nil {
8191 return 0 , err
@@ -88,7 +98,7 @@ func (rp *rendezvousPoint) Register(ctx context.Context, ns string, ttl int) (ti
8898 }
8999
90100 if res .GetType () != pb .Message_REGISTER_RESPONSE {
91- return 0 , fmt .Errorf ("Unexpected response: %s" , res .GetType ().String ())
101+ return 0 , fmt .Errorf ("unexpected response: %s" , res .GetType ().String ())
92102 }
93103
94104 response := res .GetRegisterResponse ()
0 commit comments