This commit is contained in:
aler9
2021-06-03 23:41:39 +02:00
parent d07e93f245
commit 363871d658
4 changed files with 13 additions and 22 deletions

View File

@@ -487,6 +487,7 @@ func TestClientReadNoContentBase(t *testing.T) {
func TestClientReadAnyPort(t *testing.T) {
for _, ca := range []string{
"zero",
"zero_one",
"no",
} {
t.Run(ca, func(t *testing.T) {
@@ -556,8 +557,12 @@ func TestClientReadAnyPort(t *testing.T) {
}(),
ClientPorts: th.ClientPorts,
ServerPorts: func() *[2]int {
if ca == "zero" {
switch ca {
case "zero":
return &[2]int{0, 0}
case "zero_one":
return &[2]int{0, 1}
}
return nil
}(),

View File

@@ -37,6 +37,10 @@ func isErrNOUDPPacketsReceivedRecently(err error) bool {
return ok
}
func isAnyPort(p int) bool {
return p == 0 || p == 1
}
type clientConnState int
const (
@@ -1304,23 +1308,13 @@ func (cc *ClientConn) doSetup(
}
if proto == StreamProtocolUDP {
if thRes.ServerPorts != nil {
if (thRes.ServerPorts[0] == 0 && thRes.ServerPorts[1] != 0) ||
(thRes.ServerPorts[0] != 0 && thRes.ServerPorts[1] == 0) {
rtpListener.close()
rtcpListener.close()
return nil, liberrors.ErrClientServerPortsZero{}
}
}
if !cc.c.AnyPortEnable {
if thRes.ServerPorts == nil || (thRes.ServerPorts[0] == 0 && thRes.ServerPorts[1] == 0) {
if thRes.ServerPorts == nil || isAnyPort(thRes.ServerPorts[0]) || isAnyPort(thRes.ServerPorts[1]) {
rtpListener.close()
rtcpListener.close()
return nil, liberrors.ErrClientServerPortsNotProvided{}
}
}
} else {
if thRes.InterleavedIDs == nil {
return nil, liberrors.ErrClientTransportHeaderNoInterleavedIDs{}

View File

@@ -85,7 +85,7 @@ func (l *clientConnUDPListener) run() {
uaddr := addr.(*net.UDPAddr)
if !l.remoteIP.Equal(uaddr.IP) || (l.remotePort != 0 && l.remotePort != uaddr.Port) {
if !l.remoteIP.Equal(uaddr.IP) || (!isAnyPort(l.remotePort) && l.remotePort != uaddr.Port) {
continue
}
@@ -104,7 +104,7 @@ func (l *clientConnUDPListener) run() {
uaddr := addr.(*net.UDPAddr)
if !l.remoteIP.Equal(uaddr.IP) || (l.remotePort != 0 && l.remotePort != uaddr.Port) {
if !l.remoteIP.Equal(uaddr.IP) || (!isAnyPort(l.remotePort) && l.remotePort != uaddr.Port) {
continue
}

View File

@@ -97,14 +97,6 @@ func (e ErrClientUDPPortsNotConsecutive) Error() string {
return "rtcpPort must be rtpPort + 1"
}
// ErrClientServerPortsZero is an error that can be returned by a client.
type ErrClientServerPortsZero struct{}
// Error implements the error interface.
func (e ErrClientServerPortsZero) Error() string {
return "server ports must be both zero or both not zero"
}
// ErrClientServerPortsNotProvided is an error that can be returned by a client.
type ErrClientServerPortsNotProvided struct{}