Skip to content

Commit ca9de18

Browse files
committed
Move URL type to pion/stun.URI
1 parent 6c82312 commit ca9de18

16 files changed

+153
-377
lines changed

agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ type Agent struct {
105105

106106
selectedPair atomic.Value // *CandidatePair
107107

108-
urls []*URL
108+
urls []*stun.URI
109109
networkTypes []NetworkType
110110

111111
buf *packetio.Buffer

agent_config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/pion/logging"
11+
"github.com/pion/stun"
1112
"github.com/pion/transport/v2"
1213
"golang.org/x/net/proxy"
1314
)
@@ -54,7 +55,7 @@ func defaultCandidateTypes() []CandidateType {
5455
// AgentConfig collects the arguments to ice.Agent construction into
5556
// a single structure, for future-proofness of the interface
5657
type AgentConfig struct {
57-
Urls []*URL
58+
Urls []*stun.URI
5859

5960
// PortMin and PortMax are optional. Leave them 0 for the default UDP port allocation strategy.
6061
PortMin uint16

agent_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,11 @@ func TestConnectivityLite(t *testing.T) {
301301
lim := test.TimeOut(time.Second * 30)
302302
defer lim.Stop()
303303

304-
stunServerURL := &URL{
304+
stunServerURL := &stun.URI{
305305
Scheme: SchemeTypeSTUN,
306306
Host: "1.2.3.4",
307307
Port: 3478,
308-
Proto: ProtoTypeUDP,
308+
Proto: stun.ProtoTypeUDP,
309309
}
310310

311311
natType := &vnet.NATType{
@@ -320,7 +320,7 @@ func TestConnectivityLite(t *testing.T) {
320320
bNotifier, bConnected := onConnected()
321321

322322
cfg0 := &AgentConfig{
323-
Urls: []*URL{stunServerURL},
323+
Urls: []*stun.URI{stunServerURL},
324324
NetworkTypes: supportedNetworkTypes(),
325325
MulticastDNSMode: MulticastDNSModeDisabled,
326326
Net: v.net0,
@@ -331,7 +331,7 @@ func TestConnectivityLite(t *testing.T) {
331331
require.NoError(t, aAgent.OnConnectionStateChange(aNotifier))
332332

333333
cfg1 := &AgentConfig{
334-
Urls: []*URL{},
334+
Urls: []*stun.URI{},
335335
Lite: true,
336336
CandidateTypes: []CandidateType{CandidateTypeHost},
337337
NetworkTypes: supportedNetworkTypes(),
@@ -548,7 +548,7 @@ func TestConnectionStateCallback(t *testing.T) {
548548
KeepaliveInterval := time.Duration(0)
549549

550550
cfg := &AgentConfig{
551-
Urls: []*URL{},
551+
Urls: []*stun.URI{},
552552
NetworkTypes: supportedNetworkTypes(),
553553
DisconnectedTimeout: &disconnectedDuration,
554554
FailedTimeout: &failedDuration,
@@ -1330,7 +1330,7 @@ func TestCloseInConnectionStateCallback(t *testing.T) {
13301330
CheckInterval := 500 * time.Millisecond
13311331

13321332
cfg := &AgentConfig{
1333-
Urls: []*URL{},
1333+
Urls: []*stun.URI{},
13341334
NetworkTypes: supportedNetworkTypes(),
13351335
DisconnectedTimeout: &disconnectedDuration,
13361336
FailedTimeout: &failedDuration,
@@ -1382,7 +1382,7 @@ func TestRunTaskInConnectionStateCallback(t *testing.T) {
13821382
CheckInterval := 50 * time.Millisecond
13831383

13841384
cfg := &AgentConfig{
1385-
Urls: []*URL{},
1385+
Urls: []*stun.URI{},
13861386
NetworkTypes: supportedNetworkTypes(),
13871387
DisconnectedTimeout: &oneSecond,
13881388
FailedTimeout: &oneSecond,
@@ -1427,7 +1427,7 @@ func TestRunTaskInSelectedCandidatePairChangeCallback(t *testing.T) {
14271427
CheckInterval := 50 * time.Millisecond
14281428

14291429
cfg := &AgentConfig{
1430-
Urls: []*URL{},
1430+
Urls: []*stun.URI{},
14311431
NetworkTypes: supportedNetworkTypes(),
14321432
DisconnectedTimeout: &oneSecond,
14331433
FailedTimeout: &oneSecond,

candidate_relay_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"testing"
1313
"time"
1414

15+
"github.com/pion/stun"
1516
"github.com/pion/transport/v2/test"
1617
"github.com/pion/turn/v2"
1718
"github.com/stretchr/testify/assert"
@@ -47,14 +48,14 @@ func TestRelayOnlyConnection(t *testing.T) {
4748

4849
cfg := &AgentConfig{
4950
NetworkTypes: supportedNetworkTypes(),
50-
Urls: []*URL{
51+
Urls: []*stun.URI{
5152
{
52-
Scheme: SchemeTypeTURN,
53+
Scheme: stun.SchemeTypeTURN,
5354
Host: "127.0.0.1",
5455
Username: "username",
5556
Password: "password",
5657
Port: serverPort,
57-
Proto: ProtoTypeUDP,
58+
Proto: stun.ProtoTypeUDP,
5859
},
5960
},
6061
CandidateTypes: []CandidateType{CandidateTypeRelay},

candidate_server_reflexive_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"testing"
1313
"time"
1414

15+
"github.com/pion/stun"
1516
"github.com/pion/transport/v2/test"
1617
"github.com/pion/turn/v2"
1718
"github.com/stretchr/testify/assert"
@@ -43,7 +44,7 @@ func TestServerReflexiveOnlyConnection(t *testing.T) {
4344

4445
cfg := &AgentConfig{
4546
NetworkTypes: []NetworkType{NetworkTypeUDP4},
46-
Urls: []*URL{
47+
Urls: []*stun.URI{
4748
{
4849
Scheme: SchemeTypeSTUN,
4950
Host: "127.0.0.1",

connectivity_vnet_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func connectWithVNet(aAgent, bAgent *Agent) (*Conn, *Conn) {
226226
}
227227

228228
type agentTestConfig struct {
229-
urls []*URL
229+
urls []*stun.URI
230230
nat1To1IPCandidateType CandidateType
231231
}
232232

@@ -305,20 +305,20 @@ func TestConnectivityVNet(t *testing.T) {
305305
report := test.CheckRoutines(t)
306306
defer report()
307307

308-
stunServerURL := &URL{
309-
Scheme: SchemeTypeSTUN,
308+
stunServerURL := &stun.URI{
309+
Scheme: stun.SchemeTypeSTUN,
310310
Host: vnetSTUNServerIP,
311311
Port: vnetSTUNServerPort,
312-
Proto: ProtoTypeUDP,
312+
Proto: stun.ProtoTypeUDP,
313313
}
314314

315-
turnServerURL := &URL{
316-
Scheme: SchemeTypeTURN,
315+
turnServerURL := &stun.URI{
316+
Scheme: stun.SchemeTypeTURN,
317317
Host: vnetSTUNServerIP,
318318
Port: vnetSTUNServerPort,
319319
Username: "user",
320320
Password: "pass",
321-
Proto: ProtoTypeUDP,
321+
Proto: stun.ProtoTypeUDP,
322322
}
323323

324324
t.Run("Full-cone NATs on both ends", func(t *testing.T) {
@@ -339,12 +339,12 @@ func TestConnectivityVNet(t *testing.T) {
339339

340340
log.Debug("Connecting...")
341341
a0TestConfig := &agentTestConfig{
342-
urls: []*URL{
342+
urls: []*stun.URI{
343343
stunServerURL,
344344
},
345345
}
346346
a1TestConfig := &agentTestConfig{
347-
urls: []*URL{
347+
urls: []*stun.URI{
348348
stunServerURL,
349349
},
350350
}
@@ -376,13 +376,13 @@ func TestConnectivityVNet(t *testing.T) {
376376

377377
log.Debug("Connecting...")
378378
a0TestConfig := &agentTestConfig{
379-
urls: []*URL{
379+
urls: []*stun.URI{
380380
stunServerURL,
381381
turnServerURL,
382382
},
383383
}
384384
a1TestConfig := &agentTestConfig{
385-
urls: []*URL{
385+
urls: []*stun.URI{
386386
stunServerURL,
387387
},
388388
}
@@ -416,11 +416,11 @@ func TestConnectivityVNet(t *testing.T) {
416416

417417
log.Debug("Connecting...")
418418
a0TestConfig := &agentTestConfig{
419-
urls: []*URL{},
419+
urls: []*stun.URI{},
420420
nat1To1IPCandidateType: CandidateTypeHost, // Use 1:1 NAT IP as a host candidate
421421
}
422422
a1TestConfig := &agentTestConfig{
423-
urls: []*URL{},
423+
urls: []*stun.URI{},
424424
}
425425
ca, cb := pipeWithVNet(v, a0TestConfig, a1TestConfig)
426426

@@ -452,11 +452,11 @@ func TestConnectivityVNet(t *testing.T) {
452452

453453
log.Debug("Connecting...")
454454
a0TestConfig := &agentTestConfig{
455-
urls: []*URL{},
455+
urls: []*stun.URI{},
456456
nat1To1IPCandidateType: CandidateTypeServerReflexive, // Use 1:1 NAT IP as a srflx candidate
457457
}
458458
a1TestConfig := &agentTestConfig{
459-
urls: []*URL{},
459+
urls: []*stun.URI{},
460460
}
461461
ca, cb := pipeWithVNet(v, a0TestConfig, a1TestConfig)
462462

errors.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ var (
124124
errReadingStreamingPacket = errors.New("error reading streaming packet")
125125
errWriting = errors.New("error writing to")
126126
errClosingConnection = errors.New("error closing connection")
127-
errMissingProtocolScheme = errors.New("missing protocol scheme")
128-
errTooManyColonsAddr = errors.New("too many colons in address")
129127
errRead = errors.New("unexpected error trying to read")
130128
errUnknownRole = errors.New("unknown role")
131129
errICEWriteSTUNMessage = errors.New("the ICE conn can't write STUN messages")

gather.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/pion/ice/v2/internal/fakenet"
1818
stunx "github.com/pion/ice/v2/internal/stun"
1919
"github.com/pion/logging"
20+
"github.com/pion/stun"
2021
"github.com/pion/turn/v2"
2122
)
2223

@@ -376,7 +377,7 @@ func (a *Agent) gatherCandidatesSrflxMapped(ctx context.Context, networkTypes []
376377
}
377378
}
378379

379-
func (a *Agent) gatherCandidatesSrflxUDPMux(ctx context.Context, urls []*URL, networkTypes []NetworkType) { //nolint:gocognit
380+
func (a *Agent) gatherCandidatesSrflxUDPMux(ctx context.Context, urls []*stun.URI, networkTypes []NetworkType) { //nolint:gocognit
380381
var wg sync.WaitGroup
381382
defer wg.Wait()
382383

@@ -393,7 +394,7 @@ func (a *Agent) gatherCandidatesSrflxUDPMux(ctx context.Context, urls []*URL, ne
393394
continue
394395
}
395396
wg.Add(1)
396-
go func(url URL, network string, localAddr *net.UDPAddr) {
397+
go func(url stun.URI, network string, localAddr *net.UDPAddr) {
397398
defer wg.Done()
398399

399400
hostPort := fmt.Sprintf("%s:%d", url.Host, url.Port)
@@ -444,7 +445,7 @@ func (a *Agent) gatherCandidatesSrflxUDPMux(ctx context.Context, urls []*URL, ne
444445
}
445446
}
446447

447-
func (a *Agent) gatherCandidatesSrflx(ctx context.Context, urls []*URL, networkTypes []NetworkType) { //nolint:gocognit
448+
func (a *Agent) gatherCandidatesSrflx(ctx context.Context, urls []*stun.URI, networkTypes []NetworkType) { //nolint:gocognit
448449
var wg sync.WaitGroup
449450
defer wg.Wait()
450451

@@ -455,7 +456,7 @@ func (a *Agent) gatherCandidatesSrflx(ctx context.Context, urls []*URL, networkT
455456

456457
for i := range urls {
457458
wg.Add(1)
458-
go func(url URL, network string) {
459+
go func(url stun.URI, network string) {
459460
defer wg.Done()
460461

461462
hostPort := fmt.Sprintf("%s:%d", url.Host, url.Port)
@@ -518,14 +519,14 @@ func (a *Agent) gatherCandidatesSrflx(ctx context.Context, urls []*URL, networkT
518519
}
519520
}
520521

521-
func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //nolint:gocognit
522+
func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*stun.URI) { //nolint:gocognit
522523
var wg sync.WaitGroup
523524
defer wg.Wait()
524525

525526
network := NetworkTypeUDP4.String()
526527
for i := range urls {
527528
switch {
528-
case urls[i].Scheme != SchemeTypeTURN && urls[i].Scheme != SchemeTypeTURNS:
529+
case urls[i].Scheme != stun.SchemeTypeTURN && urls[i].Scheme != stun.SchemeTypeTURNS:
529530
continue
530531
case urls[i].Username == "":
531532
a.log.Errorf("Failed to gather relay candidates: %v", ErrUsernameEmpty)
@@ -536,7 +537,7 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
536537
}
537538

538539
wg.Add(1)
539-
go func(url URL) {
540+
go func(url stun.URI) {
540541
defer wg.Done()
541542
turnServerAddr := fmt.Sprintf("%s:%d", url.Host, url.Port)
542543
var (
@@ -548,7 +549,7 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
548549
)
549550

550551
switch {
551-
case url.Proto == ProtoTypeUDP && url.Scheme == SchemeTypeTURN:
552+
case url.Proto == stun.ProtoTypeUDP && url.Scheme == stun.SchemeTypeTURN:
552553
if locConn, err = a.net.ListenPacket(network, "0.0.0.0:0"); err != nil {
553554
a.log.Warnf("Failed to listen %s: %v", network, err)
554555
return
@@ -557,8 +558,8 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
557558
relAddr = locConn.LocalAddr().(*net.UDPAddr).IP.String() //nolint:forcetypeassert
558559
relPort = locConn.LocalAddr().(*net.UDPAddr).Port //nolint:forcetypeassert
559560
relayProtocol = udp
560-
case a.proxyDialer != nil && url.Proto == ProtoTypeTCP &&
561-
(url.Scheme == SchemeTypeTURN || url.Scheme == SchemeTypeTURNS):
561+
case a.proxyDialer != nil && url.Proto == stun.ProtoTypeTCP &&
562+
(url.Scheme == stun.SchemeTypeTURN || url.Scheme == stun.SchemeTypeTURNS):
562563
conn, connectErr := a.proxyDialer.Dial(NetworkTypeTCP4.String(), turnServerAddr)
563564
if connectErr != nil {
564565
a.log.Warnf("Failed to dial TCP address %s via proxy dialer: %v", turnServerAddr, connectErr)
@@ -567,14 +568,14 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
567568

568569
relAddr = conn.LocalAddr().(*net.TCPAddr).IP.String() //nolint:forcetypeassert
569570
relPort = conn.LocalAddr().(*net.TCPAddr).Port //nolint:forcetypeassert
570-
if url.Scheme == SchemeTypeTURN {
571+
if url.Scheme == stun.SchemeTypeTURN {
571572
relayProtocol = tcp
572-
} else if url.Scheme == SchemeTypeTURNS {
573+
} else if url.Scheme == stun.SchemeTypeTURNS {
573574
relayProtocol = "tls"
574575
}
575576
locConn = turn.NewSTUNConn(conn)
576577

577-
case url.Proto == ProtoTypeTCP && url.Scheme == SchemeTypeTURN:
578+
case url.Proto == stun.ProtoTypeTCP && url.Scheme == stun.SchemeTypeTURN:
578579
tcpAddr, connectErr := a.net.ResolveTCPAddr(NetworkTypeTCP4.String(), turnServerAddr)
579580
if connectErr != nil {
580581
a.log.Warnf("Failed to resolve TCP address %s: %v", turnServerAddr, connectErr)
@@ -591,7 +592,7 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
591592
relPort = conn.LocalAddr().(*net.TCPAddr).Port //nolint:forcetypeassert
592593
relayProtocol = tcp
593594
locConn = turn.NewSTUNConn(conn)
594-
case url.Proto == ProtoTypeUDP && url.Scheme == SchemeTypeTURNS:
595+
case url.Proto == stun.ProtoTypeUDP && url.Scheme == stun.SchemeTypeTURNS:
595596
udpAddr, connectErr := a.net.ResolveUDPAddr(network, turnServerAddr)
596597
if connectErr != nil {
597598
a.log.Warnf("Failed to resolve UDP address %s: %v", turnServerAddr, connectErr)
@@ -617,7 +618,7 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
617618
relPort = conn.LocalAddr().(*net.UDPAddr).Port //nolint:forcetypeassert
618619
relayProtocol = "dtls"
619620
locConn = &fakenet.PacketConn{Conn: conn}
620-
case url.Proto == ProtoTypeTCP && url.Scheme == SchemeTypeTURNS:
621+
case url.Proto == stun.ProtoTypeTCP && url.Scheme == stun.SchemeTypeTURNS:
621622
tcpAddr, resolvErr := a.net.ResolveTCPAddr(NetworkTypeTCP4.String(), turnServerAddr)
622623
if resolvErr != nil {
623624
a.log.Warnf("Failed to resolve relay address %s: %v", turnServerAddr, resolvErr)

0 commit comments

Comments
 (0)