@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
@@ -98,6 +99,16 @@ func getRTPMaxPayloadSize(udpMaxPayloadSize int, rtspEncryption conf.Encryption)
|
||||
return v
|
||||
}
|
||||
|
||||
func supportsIPv6() bool {
|
||||
ln, err := net.ListenUDP("udp6", &net.UDPAddr{IP: net.IPv6unspecified, Port: 0})
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer ln.Close() //nolint:errcheck
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
var cli struct {
|
||||
Confpath string `arg:"" default:""`
|
||||
Version bool `help:"print version"`
|
||||
@@ -111,6 +122,7 @@ type Core struct {
|
||||
ctxCancel func()
|
||||
confPath string
|
||||
conf *conf.Conf
|
||||
supportsIPv6 bool
|
||||
logger *logger.Logger
|
||||
externalCmdPool *externalcmd.Pool
|
||||
authManager *auth.Manager
|
||||
@@ -345,6 +357,8 @@ func (p *Core) createResources(initial bool) error {
|
||||
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
|
||||
p.supportsIPv6 = supportsIPv6()
|
||||
|
||||
p.externalCmdPool = &externalcmd.Pool{}
|
||||
p.externalCmdPool.Initialize()
|
||||
}
|
||||
@@ -456,6 +470,7 @@ func (p *Core) createResources(initial bool) error {
|
||||
udpReadBufferSize: p.conf.UDPReadBufferSize,
|
||||
udpMaxPayloadSize: p.conf.UDPMaxPayloadSize,
|
||||
rtpMaxPayloadSize: rtpMaxPayloadSize,
|
||||
supportsIPv6: p.supportsIPv6,
|
||||
pathConfs: p.conf.Paths,
|
||||
authManager: p.authManager,
|
||||
externalCmdPool: p.externalCmdPool,
|
||||
@@ -659,6 +674,7 @@ func (p *Core) createResources(initial bool) error {
|
||||
UDPReadBufferSize: p.conf.UDPReadBufferSize,
|
||||
LocalUDPAddress: p.conf.WebRTCLocalUDPAddress,
|
||||
LocalTCPAddress: p.conf.WebRTCLocalTCPAddress,
|
||||
SupportsIPv6: p.supportsIPv6,
|
||||
IPsFromInterfaces: p.conf.WebRTCIPsFromInterfaces,
|
||||
IPsFromInterfacesList: p.conf.WebRTCIPsFromInterfacesList,
|
||||
AdditionalHosts: p.conf.WebRTCAdditionalHosts,
|
||||
|
||||
@@ -101,6 +101,7 @@ type path struct {
|
||||
udpReadBufferSize uint
|
||||
udpMaxPayloadSize int
|
||||
rtpMaxPayloadSize int
|
||||
supportsIPv6 bool
|
||||
conf *conf.Path
|
||||
name string
|
||||
matches []string
|
||||
@@ -237,6 +238,7 @@ func (pa *path) run() {
|
||||
WriteQueueSize: pa.writeQueueSize,
|
||||
UDPReadBufferSize: pa.udpReadBufferSize,
|
||||
RTPMaxPayloadSize: pa.rtpMaxPayloadSize,
|
||||
SupportsIPv6: pa.supportsIPv6,
|
||||
Matches: pa.matches,
|
||||
PathManager: pa.parent,
|
||||
Parent: pa,
|
||||
|
||||
@@ -83,6 +83,7 @@ type pathManager struct {
|
||||
udpReadBufferSize uint
|
||||
udpMaxPayloadSize int
|
||||
rtpMaxPayloadSize int
|
||||
supportsIPv6 bool
|
||||
pathConfs map[string]*conf.Path
|
||||
authManager pathManagerAuthManager
|
||||
externalCmdPool *externalcmd.Pool
|
||||
@@ -504,6 +505,7 @@ func (pm *pathManager) createPath(
|
||||
udpReadBufferSize: pm.udpReadBufferSize,
|
||||
udpMaxPayloadSize: pm.udpMaxPayloadSize,
|
||||
rtpMaxPayloadSize: pm.rtpMaxPayloadSize,
|
||||
supportsIPv6: pm.supportsIPv6,
|
||||
conf: pathConf,
|
||||
name: name,
|
||||
matches: matches,
|
||||
|
||||
@@ -180,6 +180,7 @@ type PeerConnection struct {
|
||||
IPsFromInterfacesList []string
|
||||
AdditionalHosts []string
|
||||
STUNGatherTimeout time.Duration
|
||||
SupportsIPv6 bool
|
||||
Publish bool
|
||||
OutboundTracks []*OutboundTrack
|
||||
OutboundDataChannels []*OutboundDataChannel
|
||||
@@ -217,13 +218,16 @@ func (co *PeerConnection) Start() error {
|
||||
settingsEngine.SetIncludeLoopbackCandidate(true)
|
||||
|
||||
// always enable TCP since we might be the client of a remote TCP listener
|
||||
networkTypes := []webrtc.NetworkType{
|
||||
webrtc.NetworkTypeTCP4,
|
||||
webrtc.NetworkTypeTCP6,
|
||||
networkTypes := []webrtc.NetworkType{webrtc.NetworkTypeTCP4}
|
||||
if co.SupportsIPv6 {
|
||||
networkTypes = append(networkTypes, webrtc.NetworkTypeTCP6)
|
||||
}
|
||||
|
||||
if co.LocalRandomUDP || co.ICEUDPMux != nil || len(co.ICEServers) != 0 {
|
||||
networkTypes = append(networkTypes, webrtc.NetworkTypeUDP4, webrtc.NetworkTypeUDP6)
|
||||
networkTypes = append(networkTypes, webrtc.NetworkTypeUDP4)
|
||||
if co.SupportsIPv6 {
|
||||
networkTypes = append(networkTypes, webrtc.NetworkTypeUDP6)
|
||||
}
|
||||
}
|
||||
|
||||
settingsEngine.SetNetworkTypes(networkTypes)
|
||||
|
||||
@@ -161,6 +161,7 @@ func TestPeerConnectionCandidates(t *testing.T) {
|
||||
LocalRandomUDP: (ca == "udp random" || ca == "udp random+stun"),
|
||||
ICEUDPMux: udpMux,
|
||||
ICETCPMux: tcpMux,
|
||||
SupportsIPv6: true,
|
||||
IPsFromInterfaces: true,
|
||||
IPsFromInterfacesList: []string{"lo"},
|
||||
Log: test.NilLogger,
|
||||
@@ -203,6 +204,45 @@ func TestPeerConnectionCandidates(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPeerConnectionCandidatesIPv6Disabled(t *testing.T) {
|
||||
pc2, err := webrtc.NewPeerConnection(webrtc.Configuration{})
|
||||
require.NoError(t, err)
|
||||
defer pc2.Close() //nolint:errcheck
|
||||
|
||||
track, err := webrtc.NewTrackLocalStaticRTP(
|
||||
webrtc.RTPCodecCapability{
|
||||
MimeType: webrtc.MimeTypeVP8,
|
||||
ClockRate: 90000,
|
||||
},
|
||||
"video",
|
||||
"publisher",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = pc2.AddTrack(track)
|
||||
require.NoError(t, err)
|
||||
|
||||
offer, err := pc2.CreateOffer(nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
pc := &PeerConnection{
|
||||
SupportsIPv6: false,
|
||||
IPsFromInterfaces: true,
|
||||
IPsFromInterfacesList: []string{"lo"},
|
||||
Log: test.NilLogger,
|
||||
}
|
||||
|
||||
err = pc.Start()
|
||||
require.NoError(t, err)
|
||||
defer pc.Close()
|
||||
|
||||
answer, err := pc.CreateFullAnswer(&offer, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NotContains(t, answer.SDP, " udp6 ")
|
||||
require.NotContains(t, answer.SDP, " tcp6 ")
|
||||
}
|
||||
|
||||
func TestPeerConnectionConnectivity(t *testing.T) {
|
||||
for _, mode := range []string{
|
||||
"passive udp",
|
||||
|
||||
@@ -81,6 +81,7 @@ type Client struct {
|
||||
HTTPClient *http.Client
|
||||
BearerToken string
|
||||
UDPReadBufferSize uint
|
||||
SupportsIPv6 bool
|
||||
STUNGatherTimeout time.Duration
|
||||
HandshakeTimeout time.Duration
|
||||
TrackGatherTimeout time.Duration
|
||||
@@ -110,6 +111,7 @@ func (c *Client) Initialize(ctx context.Context) error {
|
||||
c.pc = &webrtc.PeerConnection{
|
||||
Net: &webrtc.Net{UDPReadBufferSize: int(c.UDPReadBufferSize)},
|
||||
LocalRandomUDP: true,
|
||||
SupportsIPv6: c.SupportsIPv6,
|
||||
ICEServers: iceServers,
|
||||
IPsFromInterfaces: true,
|
||||
Publish: c.Publish,
|
||||
|
||||
@@ -197,6 +197,7 @@ type Server struct {
|
||||
UDPReadBufferSize uint
|
||||
LocalUDPAddress string
|
||||
LocalTCPAddress string
|
||||
SupportsIPv6 bool
|
||||
IPsFromInterfaces bool
|
||||
IPsFromInterfacesList []string
|
||||
AdditionalHosts []string
|
||||
@@ -370,6 +371,7 @@ outer:
|
||||
additionalHosts: s.AdditionalHosts,
|
||||
iceUDPMux: s.iceUDPMux,
|
||||
iceTCPMux: s.iceTCPMux,
|
||||
supportsIPv6: s.SupportsIPv6,
|
||||
stunGatherTimeout: s.STUNGatherTimeout,
|
||||
handshakeTimeout: s.HandshakeTimeout,
|
||||
trackGatherTimeout: s.TrackGatherTimeout,
|
||||
|
||||
@@ -243,6 +243,7 @@ type session struct {
|
||||
additionalHosts []string
|
||||
iceUDPMux ice.UDPMux
|
||||
iceTCPMux *webrtc.TCPMuxWrapper
|
||||
supportsIPv6 bool
|
||||
stunGatherTimeout conf.Duration
|
||||
handshakeTimeout conf.Duration
|
||||
trackGatherTimeout conf.Duration
|
||||
@@ -368,6 +369,7 @@ func (s *session) runPublish(req *initialRequestReq) (int, error) {
|
||||
Net: s.net,
|
||||
ICEUDPMux: s.iceUDPMux,
|
||||
ICETCPMux: s.iceTCPMux,
|
||||
SupportsIPv6: s.supportsIPv6,
|
||||
ICEServers: iceServers,
|
||||
IPsFromInterfaces: s.ipsFromInterfaces,
|
||||
IPsFromInterfacesList: s.ipsFromInterfacesList,
|
||||
@@ -518,6 +520,7 @@ func (s *session) runRead(req *initialRequestReq) (int, error) {
|
||||
Net: s.net,
|
||||
ICEUDPMux: s.iceUDPMux,
|
||||
ICETCPMux: s.iceTCPMux,
|
||||
SupportsIPv6: s.supportsIPv6,
|
||||
ICEServers: iceServers,
|
||||
IPsFromInterfaces: s.ipsFromInterfaces,
|
||||
IPsFromInterfacesList: s.ipsFromInterfacesList,
|
||||
|
||||
@@ -67,6 +67,7 @@ type Handler struct {
|
||||
WriteQueueSize int
|
||||
UDPReadBufferSize uint
|
||||
RTPMaxPayloadSize int
|
||||
SupportsIPv6 bool
|
||||
Matches []string
|
||||
PathManager handlerPathManager
|
||||
Parent handlerParent
|
||||
@@ -147,6 +148,7 @@ func (s *Handler) Initialize() {
|
||||
DumpPackets: s.DumpPackets,
|
||||
ReadTimeout: s.ReadTimeout,
|
||||
UDPReadBufferSize: s.UDPReadBufferSize,
|
||||
SupportsIPv6: s.SupportsIPv6,
|
||||
Parent: s,
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ type Source struct {
|
||||
DumpPackets bool
|
||||
ReadTimeout conf.Duration
|
||||
UDPReadBufferSize uint
|
||||
SupportsIPv6 bool
|
||||
Parent parent
|
||||
}
|
||||
|
||||
@@ -76,6 +77,7 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error {
|
||||
},
|
||||
BearerToken: params.Conf.WHEPBearerToken,
|
||||
UDPReadBufferSize: s.UDPReadBufferSize,
|
||||
SupportsIPv6: s.SupportsIPv6,
|
||||
STUNGatherTimeout: time.Duration(params.Conf.WHEPSTUNGatherTimeout),
|
||||
HandshakeTimeout: time.Duration(params.Conf.WHEPHandshakeTimeout),
|
||||
TrackGatherTimeout: time.Duration(params.Conf.WHEPTrackGatherTimeout),
|
||||
|
||||
Reference in New Issue
Block a user