mirror of
https://github.com/pion/ice.git
synced 2025-12-24 13:38:03 +08:00
Allow any port range
This commit is contained in:
@@ -358,10 +358,6 @@ func WithUrls(urls []*stun.URI) AgentOption {
|
||||
// WithPortRange sets the UDP port range for host candidates.
|
||||
func WithPortRange(portMin, portMax uint16) AgentOption {
|
||||
return func(a *Agent) error {
|
||||
if portMax < portMin {
|
||||
return ErrPort
|
||||
}
|
||||
|
||||
a.portMin = portMin
|
||||
a.portMax = portMax
|
||||
|
||||
|
||||
@@ -141,13 +141,17 @@ func TestWithUrls(t *testing.T) {
|
||||
func TestWithPortRange(t *testing.T) {
|
||||
agent, err := NewAgentWithOptions(WithPortRange(1000, 2000))
|
||||
require.NoError(t, err)
|
||||
defer agent.Close() //nolint:errcheck
|
||||
|
||||
assert.Equal(t, uint16(1000), agent.portMin)
|
||||
assert.Equal(t, uint16(2000), agent.portMax)
|
||||
|
||||
_, err = NewAgentWithOptions(WithPortRange(2000, 1000))
|
||||
assert.ErrorIs(t, err, ErrPort)
|
||||
agent.Close() //nolint:gosec,errcheck
|
||||
agent, err = NewAgentWithOptions(WithPortRange(2000, 0))
|
||||
assert.NoError(t, err)
|
||||
defer agent.Close() //nolint:gosec,errcheck
|
||||
|
||||
assert.Equal(t, uint16(2000), agent.portMin)
|
||||
assert.Equal(t, uint16(0), agent.portMax)
|
||||
}
|
||||
|
||||
func TestWithTimeoutOptions(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user