Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added simple change to allow user detection of services *leaving* via… #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ func (c *client) mainloop(ctx context.Context, params *LookupParams) {
}

// Iterate through channels from listeners goroutines
var entries, sentEntries map[string]*ServiceEntry
sentEntries = make(map[string]*ServiceEntry)
var entries map[string]*ServiceEntry
sentEntries := make(map[string]uint32)
for {
select {
case <-ctx.Done():
Expand Down Expand Up @@ -273,12 +273,7 @@ func (c *client) mainloop(ctx context.Context, params *LookupParams) {

if len(entries) > 0 {
for k, e := range entries {
if e.TTL == 0 {
delete(entries, k)
delete(sentEntries, k)
continue
}
if _, ok := sentEntries[k]; ok {
if oldTTL, ok := sentEntries[k]; ok && (e.TTL==oldTTL) {
continue
}

Expand All @@ -295,7 +290,7 @@ func (c *client) mainloop(ctx context.Context, params *LookupParams) {
// This is also a point to possibly stop probing actively for a
// service entry.
params.Entries <- e
sentEntries[k] = e
sentEntries[k] = e.TTL
params.disableProbing()
}
// reset entries
Expand Down
6 changes: 5 additions & 1 deletion examples/resolv/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ func main() {
entries := make(chan *zeroconf.ServiceEntry)
go func(results <-chan *zeroconf.ServiceEntry) {
for entry := range results {
log.Println(entry)
if entry.TTL>0 {
log.Println("[+]", entry)
} else {
log.Println("[-]", entry)
}
}
log.Println("No more entries.")
}(entries)
Expand Down