From 935aca0809b925a973ac8072e4c536d792fc5269 Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Fri, 21 Jun 2019 01:10:21 -0700 Subject: [PATCH] Shutdown mDNS Connection once connected Close the connection when we have connected. There is no benefit to leaving it open, but some risk. This allows us to avoid fingerprinting and port exhaustion that might come up when running lots of peers Relates to pion/webrtc#699 --- agent.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/agent.go b/agent.go index 94f92e1..a434e3c 100644 --- a/agent.go +++ b/agent.go @@ -459,6 +459,10 @@ func (a *Agent) setSelectedPair(p *candidatePair) { a.selectedPair = p a.updateConnectionState(ConnectionStateConnected) + // Close mDNS Conn. We don't need to do anymore querying + // and no reason to respond to others traffic + a.closeMulticastConn() + // Signal connected a.onConnectedOnce.Do(func() { close(a.onConnected) }) } @@ -757,12 +761,7 @@ func (a *Agent) Close() error { a.log.Warnf("failed to close buffer: %v", err) } - if a.mDNSConn != nil { - if err := a.mDNSConn.Close(); err != nil { - a.log.Warnf("failed to close mDNS Conn: %v", err) - } - } - + a.closeMulticastConn() }) if err != nil { return err @@ -963,6 +962,14 @@ func (a *Agent) getSelectedPair() (*candidatePair, error) { return out, nil } +func (a *Agent) closeMulticastConn() { + if a.mDNSConn != nil { + if err := a.mDNSConn.Close(); err != nil { + a.log.Warnf("failed to close mDNS Conn: %v", err) + } + } +} + // Role represents ICE agent role, which can be controlling or controlled. type Role byte