diff --git a/galene.go b/galene.go index bb9c8bf..25fd812 100644 --- a/galene.go +++ b/galene.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "log" + "net" "os" "os/signal" "path/filepath" @@ -23,6 +24,7 @@ import ( func main() { var cpuprofile, memprofile, mutexprofile, httpAddr string var udpRange string + var tcpPort int flag.StringVar(&httpAddr, "http", ":8443", "web server `address`") flag.StringVar(&webserver.StaticRoot, "static", "./static/", @@ -43,6 +45,9 @@ func main() { "store mutex profile in `file`") flag.StringVar(&udpRange, "udp-range", "", "UDP port `range`") + flag.IntVar(&tcpPort, "tcp-port", -1, + "TCP listener `port`. If 0, an ephemeral port is used.\n"+ + "If -1, the TCP listerer is disabled") flag.BoolVar(&group.UseMDNS, "mdns", false, "gather mDNS addresses") flag.BoolVar(&ice.ICERelayOnly, "relay-only", false, "require use of TURN relays for all media traffic") @@ -115,6 +120,15 @@ func main() { // make sure the list of public groups is updated early go group.Update() + if tcpPort >= 0 { + err := group.StartTCPListener(&net.TCPAddr{ + Port: tcpPort, + }) + if err != nil { + log.Fatalf("Couldn't start ICE TCP: %v", err) + } + } + // causes the built-in server to start if required ice.Update() defer turnserver.Stop() diff --git a/go.mod b/go.mod index e3abebf..1f4692d 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/jech/cert v0.0.0-20210819231831-aca735647728 github.com/jech/samplebuilder v0.0.0-20220125212352-4553ed6f9a6c - github.com/pion/ice/v2 v2.1.20 + github.com/pion/ice/v2 v2.2.1-0.20220221210118-fca128a058ec github.com/pion/rtcp v1.2.9 github.com/pion/rtp v1.7.4 github.com/pion/sdp/v3 v3.0.4 diff --git a/go.sum b/go.sum index c4d984d..0ae886a 100644 --- a/go.sum +++ b/go.sum @@ -55,8 +55,9 @@ github.com/pion/dtls/v2 v2.1.1/go.mod h1:qG3gA7ZPZemBqpEFqRKyURYdKEwFZQCGb7gv9T3 github.com/pion/dtls/v2 v2.1.2 h1:22Q1Jk9L++Yo7BIf9130MonNPfPVb+YgdYLeyQotuAA= github.com/pion/dtls/v2 v2.1.2/go.mod h1:o6+WvyLDAlXF7YiPB/RlskRoeK+/JtuaZa5emwQcWus= github.com/pion/ice/v2 v2.1.12/go.mod h1:ovgYHUmwYLlRvcCLI67PnQ5YGe+upXZbGgllBDG/ktU= -github.com/pion/ice/v2 v2.1.20 h1:xpxXyX5b4WjCh/D905gzBeW/hbJxMEPx2ptVfrhVE6M= github.com/pion/ice/v2 v2.1.20/go.mod h1:hEAldRzBhTtAfvlU1V/2/nLCMvveQWFKPNCop+63/Iw= +github.com/pion/ice/v2 v2.2.1-0.20220221210118-fca128a058ec h1:dN7oetSQnnfGeJaBWZyLpnM825etYPasGKCIY88QBpU= +github.com/pion/ice/v2 v2.2.1-0.20220221210118-fca128a058ec/go.mod h1:Op8jlPtjeiycsXh93Cs4jK82C9j/kh7vef6ztIOvtIQ= github.com/pion/interceptor v0.1.0/go.mod h1:j5NIl3tJJPB3u8+Z2Xz8MZs/VV6rc+If9mXEKNuFmEM= github.com/pion/interceptor v0.1.7 h1:HThW0tIIKT9RRoDWGURe8rlZVOx0fJHxBHpA0ej0+bo= github.com/pion/interceptor v0.1.7/go.mod h1:Lh3JSl/cbJ2wP8I3ccrjh1K/deRGRn3UlSPuOTiHb6U= diff --git a/group/group.go b/group/group.go index 37d75dc..891ee7e 100644 --- a/group/group.go +++ b/group/group.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "log" + "net" "net/url" "os" "path" @@ -171,6 +172,18 @@ func (g *Group) API() (*webrtc.API, error) { return APIFromNames(codecs) } +var tcpListener net.Listener + +func StartTCPListener(addr *net.TCPAddr) error { + if tcpListener != nil { + tcpListener.Close() + tcpListener = nil + } + var err error + tcpListener, err = net.ListenTCP("tcp", addr) + return err +} + func fmtpValue(fmtp, key string) string { fields := strings.Split(fmtp, ";") for _, f := range fields { @@ -338,6 +351,17 @@ func APIFromCodecs(codecs []webrtc.RTPCodecParameters) (*webrtc.API, error) { if !UseMDNS { s.SetICEMulticastDNSMode(ice.MulticastDNSModeDisabled) } + if tcpListener != nil { + mux := webrtc.NewICETCPMux(nil, tcpListener, 8) + s.SetICETCPMux(mux) + s.SetNetworkTypes([]webrtc.NetworkType{ + webrtc.NetworkTypeUDP4, + webrtc.NetworkTypeUDP6, + webrtc.NetworkTypeTCP4, + webrtc.NetworkTypeTCP6, + }) + } + m := webrtc.MediaEngine{} for _, codec := range codecs {