snapshot of https://github.com/pion/webrtc.git (main, 2026-09-15; blobs > 131072B omitted)
Some checks failed
REUSE Compliance Check / lint (push) Failing after 0s
Browser E2E / Test (push) Failing after 3s
Test / test (1.24) (push) Failing after 0s
Test / test-i386 (1.25) (push) Failing after 0s
Test / test-i386 (1.24) (push) Failing after 0s
Test / test-windows (1.25) (push) Failing after 0s
Test / test-windows (1.24) (push) Failing after 0s
Test / test (1.25) (push) Failing after 0s
Examples Tests / Test (push) Failing after 3s
Test / test-macos (1.25) (push) Failing after 0s
Test / test-macos (1.24) (push) Failing after 0s
Go mod tidy / tidy (push) Failing after 0s
Test / test-wasm (push) Failing after 0s
CodeQL / analyze (push) Failing after 1s
Fuzz / fuzz (push) Failing after 0s
Some checks failed
REUSE Compliance Check / lint (push) Failing after 0s
Browser E2E / Test (push) Failing after 3s
Test / test (1.24) (push) Failing after 0s
Test / test-i386 (1.25) (push) Failing after 0s
Test / test-i386 (1.24) (push) Failing after 0s
Test / test-windows (1.25) (push) Failing after 0s
Test / test-windows (1.24) (push) Failing after 0s
Test / test (1.25) (push) Failing after 0s
Examples Tests / Test (push) Failing after 3s
Test / test-macos (1.25) (push) Failing after 0s
Test / test-macos (1.24) (push) Failing after 0s
Go mod tidy / tidy (push) Failing after 0s
Test / test-wasm (push) Failing after 0s
CodeQL / analyze (push) Failing after 1s
Fuzz / fuzz (push) Failing after 0s
This commit is contained in:
67
internal/mux/muxfunc.go
Normal file
67
internal/mux/muxfunc.go
Normal file
@@ -0,0 +1,67 @@
|
||||
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package mux
|
||||
|
||||
// MatchFunc allows custom logic for mapping packets to an Endpoint.
|
||||
type MatchFunc func([]byte) bool
|
||||
|
||||
// MatchAll always returns true.
|
||||
func MatchAll([]byte) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// MatchRange returns true if the first byte of buf is in [lower..upper].
|
||||
func MatchRange(lower, upper byte, buf []byte) bool {
|
||||
if len(buf) < 1 {
|
||||
return false
|
||||
}
|
||||
b := buf[0]
|
||||
|
||||
return b >= lower && b <= upper
|
||||
}
|
||||
|
||||
// MatchFuncs as described in RFC7983
|
||||
// https://tools.ietf.org/html/rfc7983
|
||||
// +----------------+
|
||||
// | [0..3] -+--> forward to STUN
|
||||
// | |
|
||||
// | [16..19] -+--> forward to ZRTP
|
||||
// | |
|
||||
// packet --> | [20..63] -+--> forward to DTLS
|
||||
// | |
|
||||
// | [64..79] -+--> forward to TURN Channel
|
||||
// | |
|
||||
// | [128..191] -+--> forward to RTP/RTCP
|
||||
// +----------------+
|
||||
|
||||
// MatchDTLS is a MatchFunc that accepts packets with the first byte in [20..63]
|
||||
// as defied in RFC7983.
|
||||
func MatchDTLS(b []byte) bool {
|
||||
return MatchRange(20, 63, b)
|
||||
}
|
||||
|
||||
// MatchSRTPOrSRTCP is a MatchFunc that accepts packets with the first byte in [128..191]
|
||||
// as defied in RFC7983.
|
||||
func MatchSRTPOrSRTCP(b []byte) bool {
|
||||
return MatchRange(128, 191, b)
|
||||
}
|
||||
|
||||
func isRTCP(buf []byte) bool {
|
||||
// Not long enough to determine RTP/RTCP
|
||||
if len(buf) < 4 {
|
||||
return false
|
||||
}
|
||||
|
||||
return buf[1] >= 192 && buf[1] <= 223
|
||||
}
|
||||
|
||||
// MatchSRTP is a MatchFunc that only matches SRTP and not SRTCP.
|
||||
func MatchSRTP(buf []byte) bool {
|
||||
return MatchSRTPOrSRTCP(buf) && !isRTCP(buf)
|
||||
}
|
||||
|
||||
// MatchSRTCP is a MatchFunc that only matches SRTCP and not SRTP.
|
||||
func MatchSRTCP(buf []byte) bool {
|
||||
return MatchSRTPOrSRTCP(buf) && isRTCP(buf)
|
||||
}
|
||||
Reference in New Issue
Block a user