Skip to content

Commit

Permalink
don't store the context
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Aug 18, 2021
1 parent a2627b9 commit 62ad319
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions p2p/mdns/mdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ type mdnsService struct {
host host.Host
serviceName string

// This ctx is passed to the resolver.
// It is closed when Close() is called.
ctx context.Context
// The context is canceled when Close() is called.
ctxCancel context.CancelFunc

resolverRunning chan struct{}
Expand All @@ -57,14 +55,13 @@ func NewMdnsService(host host.Host, serviceName string) *mdnsService {
serviceName = ServiceName
}
s := &mdnsService{
ctx: ctx,
ctxCancel: cancel,
resolverRunning: make(chan struct{}),
host: host,
serviceName: serviceName,
}
s.startServer()
s.startResolver()
s.startResolver(ctx)
return s
}

Expand Down Expand Up @@ -154,7 +151,7 @@ func (s *mdnsService) startServer() error {
return nil
}

func (s *mdnsService) startResolver() {
func (s *mdnsService) startResolver(ctx context.Context) {
entryChan := make(chan *zeroconf.ServiceEntry, 1000)
go func() {
for entry := range entryChan {
Expand Down Expand Up @@ -189,7 +186,7 @@ func (s *mdnsService) startResolver() {
}()
go func() {
defer close(s.resolverRunning)
if err := zeroconf.Browse(s.ctx, s.serviceName, mdnsDomain, entryChan); err != nil {
if err := zeroconf.Browse(ctx, s.serviceName, mdnsDomain, entryChan); err != nil {
log.Debugf("zeroconf browsing failed: %s", err)
}
}()
Expand Down

0 comments on commit 62ad319

Please sign in to comment.