Allow any port range

This commit is contained in:
Joe Turki
2025-12-12 18:55:37 +02:00
parent 58ab74b167
commit f808e10d45
2 changed files with 7 additions and 7 deletions

View File

@@ -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

View File

@@ -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) {