mirror of
https://github.com/netbirdio/ice.git
synced 2026-05-22 17:10:58 -07:00
Gather srflx candidates from turn: urls
allow gathering srflx candidates from turn: urls
This commit is contained in:
committed by
Lander Noterman
parent
bc8f00d8e0
commit
d8d3ef3aac
@@ -51,6 +51,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu
|
||||
* [adwpc](https://github.com/adwpc)
|
||||
* [Ori Bernstein](https://eigenstate.org)
|
||||
* [Sam Lancia](https://github.com/nerd2)
|
||||
* [Lander Noterman](https://github.com/LanderN)
|
||||
|
||||
### License
|
||||
MIT License - see [LICENSE](LICENSE) for full text
|
||||
|
||||
@@ -252,10 +252,6 @@ func (a *Agent) gatherCandidatesSrflxMapped(networkTypes []NetworkType, wg *sync
|
||||
func (a *Agent) gatherCandidatesSrflx(urls []*URL, networkTypes []NetworkType, wg *sync.WaitGroup) {
|
||||
for _, networkType := range networkTypes {
|
||||
for i := range urls {
|
||||
if urls[i].Scheme != SchemeTypeSTUN {
|
||||
continue
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go func(url URL, network string) {
|
||||
defer wg.Done()
|
||||
|
||||
@@ -322,6 +322,66 @@ func TestSTUNTURNConcurrency(t *testing.T) {
|
||||
assert.NoError(t, server.Close())
|
||||
}
|
||||
|
||||
// Assert that srflx candidates can be gathered from TURN servers
|
||||
//
|
||||
// When TURN servers are utilized, both types of candidates
|
||||
// (i.e. srflx and relay) are obtained from the TURN server.
|
||||
//
|
||||
// https://tools.ietf.org/html/rfc5245#section-2.1
|
||||
func TestTURNSrflx(t *testing.T) {
|
||||
report := test.CheckRoutines(t)
|
||||
defer report()
|
||||
|
||||
lim := test.TimeOut(time.Second * 30)
|
||||
defer lim.Stop()
|
||||
|
||||
serverPort := randomPort(t)
|
||||
serverListener, err := net.ListenPacket("udp4", "127.0.0.1:"+strconv.Itoa(serverPort))
|
||||
assert.NoError(t, err)
|
||||
|
||||
server, err := turn.NewServer(turn.ServerConfig{
|
||||
Realm: "pion.ly",
|
||||
AuthHandler: optimisticAuthHandler,
|
||||
PacketConnConfigs: []turn.PacketConnConfig{
|
||||
{
|
||||
PacketConn: serverListener,
|
||||
RelayAddressGenerator: &turn.RelayAddressGeneratorNone{Address: "127.0.0.1"},
|
||||
},
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
urls := []*URL{{
|
||||
Scheme: SchemeTypeTURN,
|
||||
Proto: ProtoTypeUDP,
|
||||
Host: "127.0.0.1",
|
||||
Port: serverPort,
|
||||
Username: "username",
|
||||
Password: "password",
|
||||
}}
|
||||
|
||||
a, err := NewAgent(&AgentConfig{
|
||||
NetworkTypes: supportedNetworkTypes,
|
||||
Urls: urls,
|
||||
CandidateTypes: []CandidateType{CandidateTypeServerReflexive, CandidateTypeRelay},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
candidateGathered, candidateGatheredFunc := context.WithCancel(context.Background())
|
||||
assert.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
if c != nil && c.Type() == CandidateTypeServerReflexive {
|
||||
candidateGatheredFunc()
|
||||
}
|
||||
}))
|
||||
|
||||
assert.NoError(t, a.GatherCandidates())
|
||||
|
||||
<-candidateGathered.Done()
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
assert.NoError(t, server.Close())
|
||||
}
|
||||
|
||||
func TestCloseConnLog(t *testing.T) {
|
||||
a, err := NewAgent(&AgentConfig{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user