diff --git a/client/internal/peer/conn.go b/client/internal/peer/conn.go index 7c99ae15a..9627831c0 100644 --- a/client/internal/peer/conn.go +++ b/client/internal/peer/conn.go @@ -334,6 +334,7 @@ func (conn *Conn) iCEConnectionIsReady(priority ConnPriority, iceConnInfo ICECon conn.wgProxyICE = wgProxy } else { conn.log.Infof("direct iceConnInfo: %v", iceConnInfo.RemoteConn) + agentCheck(conn.log, iceConnInfo.Agent) nilCheck(conn.log, iceConnInfo.RemoteConn) directEp, err := net.ResolveUDPAddr("udp", iceConnInfo.RemoteConn.RemoteAddr().String()) if err != nil { diff --git a/client/internal/peer/nilcheck.go b/client/internal/peer/nilcheck.go index 5d2018ac4..4a1f463f5 100644 --- a/client/internal/peer/nilcheck.go +++ b/client/internal/peer/nilcheck.go @@ -4,6 +4,7 @@ import ( "net" "reflect" + "github.com/pion/ice/v3" log "github.com/sirupsen/logrus" ) @@ -15,9 +16,38 @@ func nilCheck(log *log.Entry, conn net.Conn) { if conn.RemoteAddr() == nil { log.Infof("conn.RemoteAddr() is nil") + return } if reflect.ValueOf(conn.RemoteAddr()).IsNil() { log.Infof("value of conn.RemoteAddr() is nil") + return + } +} + +func agentCheck(log *log.Entry, agent *ice.Agent) { + if agent == nil { + log.Errorf("agent is nil") + } + + pair, err := agent.GetSelectedCandidatePair() + if err != nil { + log.Errorf("error getting selected candidate pair: %v", err) + return + } + + if pair == nil { + log.Errorf("pair is nil") + return + } + + if pair.Remote == nil { + log.Errorf("pair.Remote is nil") + return + } + + if pair.Remote.Address() == "" { + log.Errorf("address is empty") + return } } diff --git a/client/internal/peer/worker_ice.go b/client/internal/peer/worker_ice.go index eebcdfd31..8d222a592 100644 --- a/client/internal/peer/worker_ice.go +++ b/client/internal/peer/worker_ice.go @@ -29,6 +29,7 @@ type ICEConnInfo struct { LocalIceCandidateEndpoint string Relayed bool RelayedOnLocal bool + Agent *ice.Agent } type WorkerICECallbacks struct { @@ -157,6 +158,7 @@ func (w *WorkerICE) OnNewOffer(remoteOfferAnswer *OfferAnswer) { RemoteIceCandidateEndpoint: fmt.Sprintf("%s:%d", pair.Remote.Address(), pair.Remote.Port()), Relayed: isRelayed(pair), RelayedOnLocal: isRelayCandidate(pair.Local), + Agent: agent, } w.log.Debugf("on ICE conn read to use ready") go w.conn.OnConnReady(w.selectedPriority, ci)