headers: change Transport.Destination type to net.IP

This commit is contained in:
aler9
2021-06-19 18:58:31 +02:00
parent 84f174f10f
commit ff8c485b11
6 changed files with 24 additions and 13 deletions

View File

@@ -272,7 +272,7 @@ func TestClientRead(t *testing.T) {
v := base.StreamDeliveryMulticast v := base.StreamDeliveryMulticast
th.Delivery = &v th.Delivery = &v
th.Protocol = base.StreamProtocolUDP th.Protocol = base.StreamProtocolUDP
v2 := "224.1.0.1" v2 := net.ParseIP("224.1.0.1")
th.Destination = &v2 th.Destination = &v2
th.Ports = &[2]int{25000, 25001} th.Ports = &[2]int{25000, 25001}

View File

@@ -1317,12 +1317,12 @@ func (cc *ClientConn) doSetup(
return nil, liberrors.ErrClientTransportHeaderNoDestination{} return nil, liberrors.ErrClientTransportHeaderNoDestination{}
} }
rtpListener, err = newClientConnUDPListener(cc, true, *thRes.Destination+":"+strconv.FormatInt(int64(thRes.Ports[0]), 10)) rtpListener, err = newClientConnUDPListener(cc, true, thRes.Destination.String()+":"+strconv.FormatInt(int64(thRes.Ports[0]), 10))
if err != nil { if err != nil {
return nil, err return nil, err
} }
rtcpListener, err = newClientConnUDPListener(cc, true, *thRes.Destination+":"+strconv.FormatInt(int64(thRes.Ports[1]), 10)) rtcpListener, err = newClientConnUDPListener(cc, true, thRes.Destination.String()+":"+strconv.FormatInt(int64(thRes.Ports[1]), 10))
if err != nil { if err != nil {
rtpListener.close() rtpListener.close()
return nil, err return nil, err

View File

@@ -4,6 +4,7 @@ import (
"encoding/binary" "encoding/binary"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"net"
"strconv" "strconv"
"strings" "strings"
@@ -29,8 +30,8 @@ type Transport struct {
// (optional) delivery method of the stream // (optional) delivery method of the stream
Delivery *base.StreamDelivery Delivery *base.StreamDelivery
// (optional) destination // (optional) destination IP
Destination *string Destination *net.IP
// (optional) interleaved frame ids // (optional) interleaved frame ids
InterleavedIDs *[2]int InterleavedIDs *[2]int
@@ -122,7 +123,11 @@ func (h *Transport) Read(v base.HeaderValue) error {
h.Delivery = &v h.Delivery = &v
case "destination": case "destination":
h.Destination = &v ip := net.ParseIP(v)
if ip == nil {
return fmt.Errorf("invalid destination (%v)", v)
}
h.Destination = &ip
case "interleaved": case "interleaved":
ports, err := parsePorts(v) ports, err := parsePorts(v)
@@ -231,7 +236,7 @@ func (h Transport) Write() base.HeaderValue {
} }
if h.Destination != nil { if h.Destination != nil {
rets = append(rets, "destination="+*h.Destination) rets = append(rets, "destination="+h.Destination.String())
} }
if h.InterleavedIDs != nil { if h.InterleavedIDs != nil {

View File

@@ -1,6 +1,7 @@
package headers package headers
import ( import (
"net"
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@@ -55,8 +56,8 @@ var casesTransport = []struct {
v := base.StreamDeliveryMulticast v := base.StreamDeliveryMulticast
return &v return &v
}(), }(),
Destination: func() *string { Destination: func() *net.IP {
v := "225.219.201.15" v := net.ParseIP("225.219.201.15")
return &v return &v
}(), }(),
TTL: func() *uint { TTL: func() *uint {
@@ -212,6 +213,11 @@ func TestTransportReadErrors(t *testing.T) {
base.HeaderValue{`RTP/AVP;unicast;ttl=aa`}, base.HeaderValue{`RTP/AVP;unicast;ttl=aa`},
"strconv.ParseUint: parsing \"aa\": invalid syntax", "strconv.ParseUint: parsing \"aa\": invalid syntax",
}, },
{
"invalid destination",
base.HeaderValue{`RTP/AVP;unicast;destination=aa`},
"invalid destination (aa)",
},
{ {
"invalid ports 1", "invalid ports 1",
base.HeaderValue{`RTP/AVP;unicast;port=aa`}, base.HeaderValue{`RTP/AVP;unicast;port=aa`},

View File

@@ -456,7 +456,7 @@ func TestServerRead(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
for _, intf := range intfs { for _, intf := range intfs {
err := p.JoinGroup(&intf, &net.UDPAddr{IP: net.ParseIP(*th.Destination)}) err := p.JoinGroup(&intf, &net.UDPAddr{IP: *th.Destination})
require.NoError(t, err) require.NoError(t, err)
} }
@@ -470,7 +470,7 @@ func TestServerRead(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
for _, intf := range intfs { for _, intf := range intfs {
err := p.JoinGroup(&intf, &net.UDPAddr{IP: net.ParseIP(*th.Destination)}) err := p.JoinGroup(&intf, &net.UDPAddr{IP: *th.Destination})
require.NoError(t, err) require.NoError(t, err)
} }
} }
@@ -532,7 +532,7 @@ func TestServerRead(t *testing.T) {
case "multicast": case "multicast":
l2.WriteTo([]byte{0x01, 0x02, 0x03, 0x04}, &net.UDPAddr{ l2.WriteTo([]byte{0x01, 0x02, 0x03, 0x04}, &net.UDPAddr{
IP: net.ParseIP(*th.Destination), IP: *th.Destination,
Port: th.Ports[1], Port: th.Ports[1],
}) })
<-framesReceived <-framesReceived

View File

@@ -675,7 +675,7 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
th.Delivery = &de th.Delivery = &de
v := uint(127) v := uint(127)
th.TTL = &v th.TTL = &v
d := stream.multicastListeners[trackID].rtpListener.ip().String() d := stream.multicastListeners[trackID].rtpListener.ip()
th.Destination = &d th.Destination = &d
th.Ports = &[2]int{ th.Ports = &[2]int{
stream.multicastListeners[trackID].rtpListener.port(), stream.multicastListeners[trackID].rtpListener.port(),