diff --git a/association.go b/association.go index 47c0d94e..b4056a86 100644 --- a/association.go +++ b/association.go @@ -19,6 +19,12 @@ import ( "github.com/pion/randutil" ) +// Port 5000 shows up in examples for SDPs used by WebRTC. Since this implementation +// assumes it will be used by DTLS over UDP, the port is only meaningful for de-multiplexing +// but more-so verification. +// Example usage: https://www.rfc-editor.org/rfc/rfc8841.html#section-13.1-2 +const defaultSCTPSrcDstPort = 5000 + // Use global random generator to properly seed by crypto grade random. var globalMathRandomGenerator = randutil.NewMathRandomGenerator() // nolint:gochecknoglobals @@ -393,8 +399,8 @@ func (a *Association) sendInit() error { outbound := &packet{} outbound.verificationTag = a.peerVerificationTag - a.sourcePort = 5000 // Spec?? - a.destinationPort = 5000 // Spec?? + a.sourcePort = defaultSCTPSrcDstPort + a.destinationPort = defaultSCTPSrcDstPort outbound.sourcePort = a.sourcePort outbound.destinationPort = a.destinationPort diff --git a/packet_test.go b/packet_test.go index 1a270e53..40557f3d 100644 --- a/packet_test.go +++ b/packet_test.go @@ -20,10 +20,10 @@ func TestPacketUnmarshal(t *testing.T) { switch { case err != nil: t.Errorf("Unmarshal failed for SCTP packet with no chunks: %v", err) - case pkt.sourcePort != 5000: - t.Errorf("Unmarshal passed for SCTP packet, but got incorrect source port exp: %d act: %d", 5000, pkt.sourcePort) - case pkt.destinationPort != 5000: - t.Errorf("Unmarshal passed for SCTP packet, but got incorrect destination port exp: %d act: %d", 5000, pkt.destinationPort) + case pkt.sourcePort != defaultSCTPSrcDstPort: + t.Errorf("Unmarshal passed for SCTP packet, but got incorrect source port exp: %d act: %d", defaultSCTPSrcDstPort, pkt.sourcePort) + case pkt.destinationPort != defaultSCTPSrcDstPort: + t.Errorf("Unmarshal passed for SCTP packet, but got incorrect destination port exp: %d act: %d", defaultSCTPSrcDstPort, pkt.destinationPort) case pkt.verificationTag != 0: t.Errorf("Unmarshal passed for SCTP packet, but got incorrect verification tag exp: %d act: %d", 0, pkt.verificationTag) } diff --git a/vnet_test.go b/vnet_test.go index 6f225bbd..90152171 100644 --- a/vnet_test.go +++ b/vnet_test.go @@ -202,8 +202,8 @@ func testRwndFull(t *testing.T, unordered bool) { defer close(serverShutDown) // connected UDP conn for server conn, err := venv.net0.DialUDP("udp4", - &net.UDPAddr{IP: net.ParseIP("1.1.1.1"), Port: 5000}, - &net.UDPAddr{IP: net.ParseIP("2.2.2.2"), Port: 5000}, + &net.UDPAddr{IP: net.ParseIP("1.1.1.1"), Port: defaultSCTPSrcDstPort}, + &net.UDPAddr{IP: net.ParseIP("2.2.2.2"), Port: defaultSCTPSrcDstPort}, ) if !assert.NoError(t, err, "should succeed") { return @@ -277,8 +277,8 @@ func testRwndFull(t *testing.T, unordered bool) { defer close(clientShutDown) // connected UDP conn for client conn, err := venv.net1.DialUDP("udp4", - &net.UDPAddr{IP: net.ParseIP("2.2.2.2"), Port: 5000}, - &net.UDPAddr{IP: net.ParseIP("1.1.1.1"), Port: 5000}, + &net.UDPAddr{IP: net.ParseIP("2.2.2.2"), Port: defaultSCTPSrcDstPort}, + &net.UDPAddr{IP: net.ParseIP("1.1.1.1"), Port: defaultSCTPSrcDstPort}, ) if !assert.NoError(t, err, "should succeed") { return @@ -435,8 +435,8 @@ func TestStreamClose(t *testing.T) { defer close(serverShutDown) // connected UDP conn for server conn, innerErr := venv.net0.DialUDP("udp4", - &net.UDPAddr{IP: net.ParseIP("1.1.1.1"), Port: 5000}, - &net.UDPAddr{IP: net.ParseIP("2.2.2.2"), Port: 5000}, + &net.UDPAddr{IP: net.ParseIP("1.1.1.1"), Port: defaultSCTPSrcDstPort}, + &net.UDPAddr{IP: net.ParseIP("2.2.2.2"), Port: defaultSCTPSrcDstPort}, ) if !assert.NoError(t, innerErr, "should succeed") { return @@ -485,8 +485,8 @@ func TestStreamClose(t *testing.T) { // connected UDP conn for client conn, err := venv.net1.DialUDP("udp4", - &net.UDPAddr{IP: net.ParseIP("2.2.2.2"), Port: 5000}, - &net.UDPAddr{IP: net.ParseIP("1.1.1.1"), Port: 5000}, + &net.UDPAddr{IP: net.ParseIP("2.2.2.2"), Port: defaultSCTPSrcDstPort}, + &net.UDPAddr{IP: net.ParseIP("1.1.1.1"), Port: defaultSCTPSrcDstPort}, ) if !assert.NoError(t, err, "should succeed") { return @@ -620,8 +620,8 @@ func TestCookieEchoRetransmission(t *testing.T) { defer close(serverShutDown) // connected UDP conn for server conn, err := venv.net0.DialUDP("udp4", - &net.UDPAddr{IP: net.ParseIP("1.1.1.1"), Port: 5000}, - &net.UDPAddr{IP: net.ParseIP("2.2.2.2"), Port: 5000}, + &net.UDPAddr{IP: net.ParseIP("1.1.1.1"), Port: defaultSCTPSrcDstPort}, + &net.UDPAddr{IP: net.ParseIP("2.2.2.2"), Port: defaultSCTPSrcDstPort}, ) if !assert.NoError(t, err, "should succeed") { return @@ -650,8 +650,8 @@ func TestCookieEchoRetransmission(t *testing.T) { defer close(clientShutDown) // connected UDP conn for client conn, err := venv.net1.DialUDP("udp4", - &net.UDPAddr{IP: net.ParseIP("2.2.2.2"), Port: 5000}, - &net.UDPAddr{IP: net.ParseIP("1.1.1.1"), Port: 5000}, + &net.UDPAddr{IP: net.ParseIP("2.2.2.2"), Port: defaultSCTPSrcDstPort}, + &net.UDPAddr{IP: net.ParseIP("1.1.1.1"), Port: defaultSCTPSrcDstPort}, ) if !assert.NoError(t, err, "should succeed") { return