1
Fork 0

Implement option -udp-range.

This commit is contained in:
Juliusz Chroboczek 2021-04-29 22:02:36 +02:00
parent cd6920d7e2
commit 99026c0e48
2 changed files with 25 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package main
import ( import (
"flag" "flag"
"fmt"
"log" "log"
"os" "os"
"os/signal" "os/signal"
@ -20,6 +21,7 @@ import (
func main() { func main() {
var cpuprofile, memprofile, mutexprofile, httpAddr, dataDir string var cpuprofile, memprofile, mutexprofile, httpAddr, dataDir string
var udpRange string
flag.StringVar(&httpAddr, "http", ":8443", "web server `address`") flag.StringVar(&httpAddr, "http", ":8443", "web server `address`")
flag.StringVar(&webserver.StaticRoot, "static", "./static/", flag.StringVar(&webserver.StaticRoot, "static", "./static/",
@ -40,6 +42,8 @@ func main() {
"store memory profile in `file`") "store memory profile in `file`")
flag.StringVar(&mutexprofile, "mutexprofile", "", flag.StringVar(&mutexprofile, "mutexprofile", "",
"store mutex profile in `file`") "store mutex profile in `file`")
flag.StringVar(&udpRange, "udp-range", "",
"UDP port `range`")
flag.BoolVar(&group.UseMDNS, "mdns", false, "gather mDNS addresses") flag.BoolVar(&group.UseMDNS, "mdns", false, "gather mDNS addresses")
flag.BoolVar(&ice.ICERelayOnly, "relay-only", false, flag.BoolVar(&ice.ICERelayOnly, "relay-only", false,
"require use of TURN relays for all media traffic") "require use of TURN relays for all media traffic")
@ -47,6 +51,21 @@ func main() {
"built-in TURN server `address` (\"\" to disable)") "built-in TURN server `address` (\"\" to disable)")
flag.Parse() flag.Parse()
if udpRange != "" {
var min, max uint16
n, err := fmt.Sscanf(udpRange, "%v-%v", &min, &max)
if err != nil {
log.Printf("UDP range: %v", err)
os.Exit(1)
}
if n != 2 || min <= 0 || max <= 0 || min > max {
log.Printf("UDP range: bad range")
os.Exit(1)
}
group.UDPMin = min
group.UDPMax = max
}
if cpuprofile != "" { if cpuprofile != "" {
f, err := os.Create(cpuprofile) f, err := os.Create(cpuprofile)
if err != nil { if err != nil {

View File

@ -18,6 +18,7 @@ import (
var Directory string var Directory string
var UseMDNS bool var UseMDNS bool
var UDPMin, UDPMax uint16
var ErrNotAuthorised = errors.New("not authorised") var ErrNotAuthorised = errors.New("not authorised")
@ -247,6 +248,11 @@ func APIFromCodecs(codecs []webrtc.RTPCodecCapability) (*webrtc.API, error) {
continue continue
} }
} }
if UDPMin > 0 && UDPMax > 0 {
s.SetEphemeralUDPPortRange(UDPMin, UDPMax)
}
return webrtc.NewAPI( return webrtc.NewAPI(
webrtc.WithSettingEngine(s), webrtc.WithSettingEngine(s),
webrtc.WithMediaEngine(&m), webrtc.WithMediaEngine(&m),