Add enable loopback candidate option (#1185)

This commit is contained in:
cnderrauber
2022-11-23 16:01:36 +08:00
committed by GitHub
parent 491a15e49e
commit 6711060cdb
7 changed files with 37 additions and 74 deletions
+13 -12
View File
@@ -58,18 +58,19 @@ type Config struct {
}
type RTCConfig struct {
UDPPort uint32 `yaml:"udp_port,omitempty"`
TCPPort uint32 `yaml:"tcp_port,omitempty"`
ICEPortRangeStart uint32 `yaml:"port_range_start,omitempty"`
ICEPortRangeEnd uint32 `yaml:"port_range_end,omitempty"`
NodeIP string `yaml:"node_ip,omitempty"`
NodeIPAutoGenerated bool `yaml:"-"`
STUNServers []string `yaml:"stun_servers,omitempty"`
TURNServers []TURNServer `yaml:"turn_servers,omitempty"`
UseExternalIP bool `yaml:"use_external_ip"`
UseICELite bool `yaml:"use_ice_lite,omitempty"`
Interfaces InterfacesConfig `yaml:"interfaces"`
IPs IPsConfig `yaml:"ips"`
UDPPort uint32 `yaml:"udp_port,omitempty"`
TCPPort uint32 `yaml:"tcp_port,omitempty"`
ICEPortRangeStart uint32 `yaml:"port_range_start,omitempty"`
ICEPortRangeEnd uint32 `yaml:"port_range_end,omitempty"`
NodeIP string `yaml:"node_ip,omitempty"`
NodeIPAutoGenerated bool `yaml:"-"`
STUNServers []string `yaml:"stun_servers,omitempty"`
TURNServers []TURNServer `yaml:"turn_servers,omitempty"`
UseExternalIP bool `yaml:"use_external_ip"`
UseICELite bool `yaml:"use_ice_lite,omitempty"`
Interfaces InterfacesConfig `yaml:"interfaces"`
IPs IPsConfig `yaml:"ips"`
EnableLoopbackCandidate bool `yaml:"enable_loopback_candidate"`
// Number of packets to buffer for NACK
PacketBufferSize int `yaml:"packet_buffer_size,omitempty"`
+6 -2
View File
@@ -30,14 +30,14 @@ func (conf *Config) determineIP() (string, error) {
}
// use local ip instead
addresses, err := GetLocalIPAddresses()
addresses, err := GetLocalIPAddresses(false)
if len(addresses) > 0 {
return addresses[0], err
}
return "", err
}
func GetLocalIPAddresses() ([]string, error) {
func GetLocalIPAddresses(includeLoopback bool) ([]string, error) {
ifaces, err := net.Interfaces()
if err != nil {
return nil, err
@@ -70,6 +70,10 @@ func GetLocalIPAddresses() ([]string, error) {
}
}
if includeLoopback {
addresses = append(addresses, loopBacks...)
}
if len(addresses) > 0 {
return addresses, nil
}
+11 -4
View File
@@ -114,12 +114,15 @@ func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, err
return nil, err
}
} else if rtcConf.UDPPort != 0 {
udpMux, err := ice.NewMultiUDPMuxFromPort(
int(rtcConf.UDPPort),
opts := []ice.UDPMuxFromPortOption{
ice.UDPMuxFromPortWithReadBufferSize(defaultUDPBufferSize),
ice.UDPMuxFromPortWithWriteBufferSize(defaultUDPBufferSize),
ice.UDPMuxFromPortWithLogger(s.LoggerFactory.NewLogger("udp_mux")),
)
}
if rtcConf.EnableLoopbackCandidate {
opts = append(opts, ice.UDPMuxFromPortWithLoopback())
}
udpMux, err := ice.NewMultiUDPMuxFromPort(int(rtcConf.UDPPort), opts...)
if err != nil {
return nil, err
}
@@ -159,6 +162,10 @@ func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, err
}
s.SetNetworkTypes(networkTypes)
if rtcConf.EnableLoopbackCandidate {
s.SetIncludeLoopbackCandidate(true)
}
// publisher configuration
publisherConfig := DirectionConfig{
RTPHeaderExtension: RTPHeaderExtensionConfig{
@@ -251,7 +258,7 @@ func getNAT1to1IPsForConf(conf *config.Config, ipFilter func(net.IP) bool) ([]st
if len(stunServers) == 0 {
stunServers = config.DefaultStunServers
}
localIPs, err := config.GetLocalIPAddresses()
localIPs, err := config.GetLocalIPAddresses(conf.RTC.EnableLoopbackCandidate)
if err != nil {
return nil, err
}
+2 -50
View File
@@ -7,8 +7,6 @@
package service
import (
"context"
"crypto/tls"
"fmt"
"github.com/go-redis/redis/v8"
"github.com/livekit/livekit-server/pkg/clientconfiguration"
@@ -19,7 +17,7 @@ import (
"github.com/livekit/protocol/egress"
"github.com/livekit/protocol/ingress"
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
redis2 "github.com/livekit/protocol/redis"
"github.com/livekit/protocol/webhook"
"github.com/pion/turn/v2"
"github.com/pkg/errors"
@@ -144,53 +142,7 @@ func createWebhookNotifier(conf *config.Config, provider auth.KeyProvider) (webh
}
func createRedisClient(conf *config.Config) (redis.UniversalClient, error) {
if !conf.HasRedis() {
return nil, nil
}
var rc redis.UniversalClient
var tlsConfig *tls.Config
if conf.Redis.UseTLS {
tlsConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
}
}
values := make([]interface{}, 0)
values = append(values, "sentinel", conf.UseSentinel())
if conf.UseSentinel() {
values = append(values, "addr", conf.Redis.SentinelAddresses, "masterName", conf.Redis.MasterName)
rcOptions := &redis.FailoverOptions{
SentinelAddrs: conf.Redis.SentinelAddresses,
SentinelUsername: conf.Redis.SentinelUsername,
SentinelPassword: conf.Redis.SentinelPassword,
MasterName: conf.Redis.MasterName,
Username: conf.Redis.Username,
Password: conf.Redis.Password,
DB: conf.Redis.DB,
TLSConfig: tlsConfig,
}
rc = redis.NewFailoverClient(rcOptions)
} else {
values = append(values, "addr", conf.Redis.Address)
rcOptions := &redis.Options{
Addr: conf.Redis.Address,
Username: conf.Redis.Username,
Password: conf.Redis.Password,
DB: conf.Redis.DB,
TLSConfig: tlsConfig,
}
rc = redis.NewClient(rcOptions)
}
logger.Infow("using multi-node routing via redis", values...)
if err := rc.Ping(context.Background()).Err(); err != nil {
err = errors.Wrap(err, "unable to connect to redis")
return nil, err
}
return rc, nil
return redis2.GetRedisClient(&conf.Redis)
}
func createStore(rc redis.UniversalClient) ObjectStore {