From 2c53f0f5b1a0c9d1a0c8cc81a97f3b243955bef7 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sat, 5 Jun 2021 18:13:40 -0700 Subject: [PATCH] continue sending queries when browsing --- client.go | 11 +++++------ service.go | 12 ++++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/client.go b/client.go index 84399a1a..1ebed508 100644 --- a/client.go +++ b/client.go @@ -86,6 +86,7 @@ func (r *Resolver) Browse(ctx context.Context, service, domain string, entries c params.Domain = domain } params.Entries = entries + params.isBrowsing = true ctx, cancel := context.WithCancel(ctx) go r.c.mainloop(ctx, params) @@ -134,7 +135,7 @@ func (r *Resolver) Lookup(ctx context.Context, instance, service, domain string, // defaultParams returns a default set of QueryParams. func defaultParams(service string) *lookupParams { - return newLookupParams("", service, "local", make(chan *ServiceEntry)) + return newLookupParams("", service, "local", false, make(chan *ServiceEntry)) } // Client structure encapsulates both IPv4/IPv6 UDP connections. @@ -293,7 +294,9 @@ func (c *client) mainloop(ctx context.Context, params *lookupParams) { // service entry. params.Entries <- e sentEntries[k] = e - params.disableProbing() + if !params.isBrowsing { + params.disableProbing() + } } // reset entries entries = make(map[string]*ServiceEntry) @@ -368,10 +371,6 @@ func (c *client) recv(ctx context.Context, l interface{}, msgCh chan *dns.Msg) { // TODO: move error reporting to shutdown function as periodicQuery is called from // go routine context. func (c *client) periodicQuery(ctx context.Context, params *lookupParams) error { - if params.stopProbing == nil { - return nil - } - bo := backoff.NewExponentialBackOff() bo.InitialInterval = 4 * time.Second bo.MaxInterval = 60 * time.Second diff --git a/service.go b/service.go index 0dffe337..6253c543 100644 --- a/service.go +++ b/service.go @@ -70,18 +70,22 @@ type lookupParams struct { ServiceRecord Entries chan<- *ServiceEntry // Entries Channel + isBrowsing bool stopProbing chan struct{} once sync.Once } // newLookupParams constructs a lookupParams. -func newLookupParams(instance, service, domain string, entries chan<- *ServiceEntry) *lookupParams { - return &lookupParams{ +func newLookupParams(instance, service, domain string, isBrowsing bool, entries chan<- *ServiceEntry) *lookupParams { + p := &lookupParams{ ServiceRecord: *NewServiceRecord(instance, service, domain), Entries: entries, - - stopProbing: make(chan struct{}), + isBrowsing: isBrowsing, + } + if !isBrowsing { + p.stopProbing = make(chan struct{}) } + return p } // Notify subscriber that no more entries will arrive. Mostly caused