11package mux
22
3- import (
4- "bytes"
5- "encoding/binary"
6- )
7-
83// MatchFunc allows custom logic for mapping packets to an Endpoint
94type MatchFunc func ([]byte ) bool
105
@@ -13,15 +8,13 @@ func MatchAll(b []byte) bool {
138 return true
149}
1510
16- // MatchRange is a MatchFunc that accepts packets with the first byte in [lower..upper]
17- func MatchRange (lower , upper byte ) MatchFunc {
18- return func (buf []byte ) bool {
19- if len (buf ) < 1 {
20- return false
21- }
22- b := buf [0 ]
23- return b >= lower && b <= upper
11+ // MatchRange returns true if the first byte of buf is in [lower..upper]
12+ func MatchRange (lower , upper byte , buf []byte ) bool {
13+ if len (buf ) < 1 {
14+ return false
2415 }
16+ b := buf [0 ]
17+ return b >= lower && b <= upper
2518}
2619
2720// MatchFuncs as described in RFC7983
@@ -41,30 +34,21 @@ func MatchRange(lower, upper byte) MatchFunc {
4134// MatchDTLS is a MatchFunc that accepts packets with the first byte in [20..63]
4235// as defied in RFC7983
4336func MatchDTLS (b []byte ) bool {
44- return MatchRange (20 , 63 )( b )
37+ return MatchRange (20 , 63 , b )
4538}
4639
4740// MatchSRTPOrSRTCP is a MatchFunc that accepts packets with the first byte in [128..191]
4841// as defied in RFC7983
4942func MatchSRTPOrSRTCP (b []byte ) bool {
50- return MatchRange (128 , 191 )( b )
43+ return MatchRange (128 , 191 , b )
5144}
5245
5346func isRTCP (buf []byte ) bool {
5447 // Not long enough to determine RTP/RTCP
5548 if len (buf ) < 4 {
5649 return false
5750 }
58-
59- var rtcpPacketType uint8
60- r := bytes .NewReader ([]byte {buf [1 ]})
61- if err := binary .Read (r , binary .BigEndian , & rtcpPacketType ); err != nil {
62- return false
63- } else if rtcpPacketType >= 192 && rtcpPacketType <= 223 {
64- return true
65- }
66-
67- return false
51+ return buf [1 ] >= 192 && buf [1 ] <= 223
6852}
6953
7054// MatchSRTP is a MatchFunc that only matches SRTP and not SRTCP
0 commit comments