Skip to content

Commit

Permalink
continue sending queries when browsing
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Jun 8, 2021
1 parent 4a4f94f commit 2c53f0f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
11 changes: 5 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2c53f0f

Please sign in to comment.