diff --git a/discovery.go b/discovery.go index 1413a6a..55415be 100644 --- a/discovery.go +++ b/discovery.go @@ -102,35 +102,25 @@ func (dc *DiscoveryService) Shutdown() { type DiscoveryBrowser struct { // Network Web Socket DNS-SD records currently unresolved by this proxy instance cachedDNSRecords map[string]*DNSRecord - inprogress bool closed bool } func NewDiscoveryBrowser() *DiscoveryBrowser { discoveryBrowser := &DiscoveryBrowser{ cachedDNSRecords: make(map[string]*DNSRecord, 255), - inprogress: false, closed: false, } return discoveryBrowser } -func (ds *DiscoveryBrowser) Browse(service *Service, intervalSeconds, timeoutSeconds int) { - - // Don't run two browse processes at the same time - if ds.inprogress { - return - } - - ds.inprogress = true +func (ds *DiscoveryBrowser) Browse(service *Service, timeoutSeconds int) { entries := make(chan *mdns.ServiceEntry, 255) recordsCache := make(map[string]*DNSRecord, 255) timeout := time.Duration(timeoutSeconds) * time.Second - interval := time.Duration(intervalSeconds) * time.Second var targetIPv4 *net.UDPAddr var targetIPv6 *net.UDPAddr @@ -151,7 +141,6 @@ func (ds *DiscoveryBrowser) Browse(service *Service, intervalSeconds, timeoutSec go func() { complete := false timeoutFinish := time.After(timeout) - intervalFinish := time.After(interval) // Wait for responses until timeout for !complete { @@ -203,8 +192,6 @@ func (ds *DiscoveryBrowser) Browse(service *Service, intervalSeconds, timeoutSec // Replace unresolved DNS records cache ds.cachedDNSRecords = recordsCache - ds.inprogress = false - case <-intervalFinish: complete = true } } @@ -213,8 +200,6 @@ func (ds *DiscoveryBrowser) Browse(service *Service, intervalSeconds, timeoutSec // Run the mDNS/DNS-SD query err := mdns.Query(params) - time.Sleep(interval) // sleep until next loop is scheduled - if err != nil { log.Printf("Could not perform mDNS/DNS-SD query. %v", err) return diff --git a/service.go b/service.go index 180db90..d6a86dd 100644 --- a/service.go +++ b/service.go @@ -88,7 +88,7 @@ func (service *Service) Start() <-chan int { service.StartProxyServer() // Start mDNS/DNS-SD Network Web Socket discovery service - service.StartDiscoveryBrowser(10, 2) + service.StartDiscoveryBrowser(10) return service.StopNotify() } @@ -155,14 +155,14 @@ func (service *Service) StartProxyServer() { go http.Serve(tlsSrpListener, serveMux) } -func (service *Service) StartDiscoveryBrowser(intervalSeconds, timeoutSeconds int) { +func (service *Service) StartDiscoveryBrowser(timeoutSeconds int) { log.Printf("Listening for Network Web Socket services on the local network...") go func() { defer service.discoveryBrowser.Shutdown() for !service.discoveryBrowser.closed { - service.discoveryBrowser.Browse(service, intervalSeconds, timeoutSeconds) + service.discoveryBrowser.Browse(service, timeoutSeconds) } }() } @@ -216,9 +216,6 @@ func (service *Service) serveWSCreatorRequest(w http.ResponseWriter, r *http.Req channel := service.GetChannelByName(serviceName) if channel == nil { channel = NewChannel(service, serviceName) - - // Trigger network service detection to speed up pairing (1) - go service.discoveryBrowser.Browse(service, 2, 2) } // Serve network web socket channel peer @@ -247,9 +244,6 @@ func (service *Service) serveWSProxyRequest(w http.ResponseWriter, r *http.Reque if channel.proxyPath == r.URL.Path { channel.ServeProxy(w, r) - // Trigger network service detection to speed up pairing (2) - go service.discoveryBrowser.Browse(service, 2, 2) - return } }