Created
September 2, 2018 18:01
-
-
Save Sean-Der/dd91ade2d6083d0f09022f81fd00b0d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/pkg/ice/agent.go b/pkg/ice/agent.go | |
| index 6c0d0ce..c61a877 100644 | |
| --- a/pkg/ice/agent.go | |
| +++ b/pkg/ice/agent.go | |
| @@ -113,8 +113,11 @@ func (a *Agent) Start(isControlling bool, remoteUfrag, remotePwd string) error { | |
| } | |
| func (a *Agent) pingCandidate(local, remote Candidate) { | |
| + var msg *stun.Message | |
| + var err error | |
| + | |
| if a.isControlling { | |
| - msg, err := stun.Build(stun.ClassRequest, stun.MethodBinding, stun.GenerateTransactionId(), | |
| + msg, err = stun.Build(stun.ClassRequest, stun.MethodBinding, stun.GenerateTransactionId(), | |
| &stun.Username{Username: a.remoteUfrag + ":" + a.LocalUfrag}, | |
| &stun.UseCandidate{}, | |
| &stun.IceControlling{TieBreaker: a.tieBreaker}, | |
| @@ -124,20 +127,8 @@ func (a *Agent) pingCandidate(local, remote Candidate) { | |
| }, | |
| &stun.Fingerprint{}, | |
| ) | |
| - if err != nil { | |
| - fmt.Println(err) | |
| - return | |
| - } | |
| - | |
| - a.outboundCallback(msg.Pack(), &stun.TransportAddr{ | |
| - IP: net.ParseIP(local.GetBase().Address), | |
| - Port: local.GetBase().Port, | |
| - }, &net.UDPAddr{ | |
| - IP: net.ParseIP(remote.GetBase().Address), | |
| - Port: remote.GetBase().Port, | |
| - }) | |
| } else { | |
| - msg, err := stun.Build(stun.ClassRequest, stun.MethodBinding, stun.GenerateTransactionId(), | |
| + msg, err = stun.Build(stun.ClassRequest, stun.MethodBinding, stun.GenerateTransactionId(), | |
| &stun.Username{Username: a.remoteUfrag + ":" + a.LocalUfrag}, | |
| &stun.UseCandidate{}, | |
| &stun.IceControlled{TieBreaker: a.tieBreaker}, | |
| @@ -147,19 +138,19 @@ func (a *Agent) pingCandidate(local, remote Candidate) { | |
| }, | |
| &stun.Fingerprint{}, | |
| ) | |
| - if err != nil { | |
| - fmt.Println(err) | |
| - return | |
| - } | |
| + } | |
| - a.outboundCallback(msg.Pack(), &stun.TransportAddr{ | |
| - IP: net.ParseIP(local.GetBase().Address), | |
| - Port: local.GetBase().Port, | |
| - }, &net.UDPAddr{ | |
| - IP: net.ParseIP(remote.GetBase().Address), | |
| - Port: remote.GetBase().Port, | |
| - }) | |
| + if err != nil { | |
| + fmt.Println(err) | |
| + return | |
| } | |
| + a.outboundCallback(msg.Pack(), &stun.TransportAddr{ | |
| + IP: net.ParseIP(local.GetBase().Address), | |
| + Port: local.GetBase().Port, | |
| + }, &net.UDPAddr{ | |
| + IP: net.ParseIP(remote.GetBase().Address), | |
| + Port: remote.GetBase().Port, | |
| + }) | |
| } | |
| func (a *Agent) updateConnectionState(newState ConnectionState) { | |
| @@ -207,27 +198,14 @@ func (a *Agent) agentTaskLoop() { | |
| select { | |
| case <-t.C: | |
| a.Lock() | |
| - if a.isControlling { | |
| - if assertSelectedPairValid() { | |
| - a.Unlock() | |
| - continue | |
| - } | |
| - | |
| - for _, localCandidate := range a.LocalCandidates { | |
| - for _, remoteCandidate := range a.remoteCandidates { | |
| - a.pingCandidate(localCandidate, remoteCandidate) | |
| - } | |
| - } | |
| - } else { | |
| - if assertSelectedPairValid() { | |
| - a.Unlock() | |
| - continue | |
| - } | |
| + if assertSelectedPairValid() { | |
| + a.Unlock() | |
| + continue | |
| + } | |
| - for _, localCandidate := range a.LocalCandidates { | |
| - for _, remoteCandidate := range a.remoteCandidates { | |
| - a.pingCandidate(localCandidate, remoteCandidate) | |
| - } | |
| + for _, localCandidate := range a.LocalCandidates { | |
| + for _, remoteCandidate := range a.remoteCandidates { | |
| + a.pingCandidate(localCandidate, remoteCandidate) | |
| } | |
| } | |
| a.Unlock() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment