Move confiuration helpers to config module.

This commit is contained in:
Joachim Bauch 2025-12-11 19:53:03 +01:00
commit 98764f2782
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
15 changed files with 111 additions and 97 deletions

View file

@ -30,6 +30,10 @@ component_management:
name: client
paths:
- client/**
- component_id: module_config
name: config
paths:
- config/**
- component_id: module_container
name: container
paths:

View file

@ -50,6 +50,7 @@ import (
"github.com/strukturag/nextcloud-spreed-signaling/api"
"github.com/strukturag/nextcloud-spreed-signaling/async"
"github.com/strukturag/nextcloud-spreed-signaling/config"
"github.com/strukturag/nextcloud-spreed-signaling/container"
"github.com/strukturag/nextcloud-spreed-signaling/internal"
"github.com/strukturag/nextcloud-spreed-signaling/log"
@ -87,11 +88,11 @@ type BackendServer struct {
buffers pool.BufferPool
}
func NewBackendServer(ctx context.Context, config *goconf.ConfigFile, hub *Hub, version string) (*BackendServer, error) {
func NewBackendServer(ctx context.Context, cfg *goconf.ConfigFile, hub *Hub, version string) (*BackendServer, error) {
logger := log.LoggerFromContext(ctx)
turnapikey, _ := GetStringOptionWithEnv(config, "turn", "apikey")
turnsecret, _ := GetStringOptionWithEnv(config, "turn", "secret")
turnservers, _ := config.GetString("turn", "servers")
turnapikey, _ := config.GetStringOptionWithEnv(cfg, "turn", "apikey")
turnsecret, _ := config.GetStringOptionWithEnv(cfg, "turn", "secret")
turnservers, _ := cfg.GetString("turn", "servers")
// TODO(jojo): Make the validity for TURN credentials configurable.
turnvalid := 24 * time.Hour
@ -111,7 +112,7 @@ func NewBackendServer(ctx context.Context, config *goconf.ConfigFile, hub *Hub,
}
}
statsAllowed, _ := config.GetString("stats", "allowed_ips")
statsAllowed, _ := cfg.GetString("stats", "allowed_ips")
statsAllowedIps, err := container.ParseIPList(statsAllowed)
if err != nil {
return nil, err
@ -129,7 +130,7 @@ func NewBackendServer(ctx context.Context, config *goconf.ConfigFile, hub *Hub,
return nil, err
}
debug, _ := config.GetBool("app", "debug")
debug, _ := cfg.GetBool("app", "debug")
result := &BackendServer{
logger: logger,

View file

@ -29,6 +29,7 @@ import (
"github.com/dlintw/goconf"
"github.com/strukturag/nextcloud-spreed-signaling/api"
"github.com/strukturag/nextcloud-spreed-signaling/config"
"github.com/strukturag/nextcloud-spreed-signaling/internal"
"github.com/strukturag/nextcloud-spreed-signaling/log"
)
@ -45,11 +46,11 @@ type backendStorageStatic struct {
compatBackend *Backend
}
func NewBackendStorageStatic(logger log.Logger, config *goconf.ConfigFile, stats BackendStorageStats) (BackendStorage, error) {
allowAll, _ := config.GetBool("backend", "allowall")
allowHttp, _ := config.GetBool("backend", "allowhttp")
commonSecret, _ := GetStringOptionWithEnv(config, "backend", "secret")
sessionLimit, err := config.GetInt("backend", "sessionlimit")
func NewBackendStorageStatic(logger log.Logger, cfg *goconf.ConfigFile, stats BackendStorageStats) (BackendStorage, error) {
allowAll, _ := cfg.GetBool("backend", "allowall")
allowHttp, _ := cfg.GetBool("backend", "allowhttp")
commonSecret, _ := config.GetStringOptionWithEnv(cfg, "backend", "secret")
sessionLimit, err := cfg.GetInt("backend", "sessionlimit")
if err != nil || sessionLimit < 0 {
sessionLimit = 0
}
@ -59,11 +60,11 @@ func NewBackendStorageStatic(logger log.Logger, config *goconf.ConfigFile, stats
numBackends := 0
if allowAll {
logger.Println("WARNING: All backend hostnames are allowed, only use for development!")
maxStreamBitrate, err := config.GetInt("backend", "maxstreambitrate")
maxStreamBitrate, err := cfg.GetInt("backend", "maxstreambitrate")
if err != nil || maxStreamBitrate < 0 {
maxStreamBitrate = 0
}
maxScreenBitrate, err := config.GetInt("backend", "maxscreenbitrate")
maxScreenBitrate, err := cfg.GetInt("backend", "maxscreenbitrate")
if err != nil || maxScreenBitrate < 0 {
maxScreenBitrate = 0
}
@ -85,9 +86,9 @@ func NewBackendStorageStatic(logger log.Logger, config *goconf.ConfigFile, stats
updateBackendStats(compatBackend)
backendsById[compatBackend.id] = compatBackend
numBackends++
} else if backendIds, _ := config.GetString("backend", "backends"); backendIds != "" {
} else if backendIds, _ := cfg.GetString("backend", "backends"); backendIds != "" {
added := make(map[string]*Backend)
for host, configuredBackends := range getConfiguredHosts(logger, backendIds, config, commonSecret) {
for host, configuredBackends := range getConfiguredHosts(logger, backendIds, cfg, commonSecret) {
backends[host] = append(backends[host], configuredBackends...)
for _, be := range configuredBackends {
added[be.id] = be
@ -100,7 +101,7 @@ func NewBackendStorageStatic(logger log.Logger, config *goconf.ConfigFile, stats
be.counted = true
}
numBackends += len(added)
} else if allowedUrls, _ := config.GetString("backend", "allowed"); allowedUrls != "" {
} else if allowedUrls, _ := cfg.GetString("backend", "allowed"); allowedUrls != "" {
// Old-style configuration, only hosts are configured and are using a common secret.
allowMap := make(map[string]bool)
for u := range internal.SplitEntries(allowedUrls, ",") {
@ -117,11 +118,11 @@ func NewBackendStorageStatic(logger log.Logger, config *goconf.ConfigFile, stats
if len(allowMap) == 0 {
logger.Println("WARNING: No backend hostnames are allowed, check your configuration!")
} else {
maxStreamBitrate, err := config.GetInt("backend", "maxstreambitrate")
maxStreamBitrate, err := cfg.GetInt("backend", "maxstreambitrate")
if err != nil || maxStreamBitrate < 0 {
maxStreamBitrate = 0
}
maxScreenBitrate, err := config.GetInt("backend", "maxscreenbitrate")
maxScreenBitrate, err := cfg.GetInt("backend", "maxscreenbitrate")
if err != nil || maxScreenBitrate < 0 {
maxScreenBitrate = 0
}
@ -297,11 +298,11 @@ func getConfiguredBackendIDs(backendIds string) (ids []string) {
return ids
}
func getConfiguredHosts(logger log.Logger, backendIds string, config *goconf.ConfigFile, commonSecret string) (hosts map[string][]*Backend) {
func getConfiguredHosts(logger log.Logger, backendIds string, cfg *goconf.ConfigFile, commonSecret string) (hosts map[string][]*Backend) {
hosts = make(map[string][]*Backend)
seenUrls := make(map[string]string)
for _, id := range getConfiguredBackendIDs(backendIds) {
secret, _ := GetStringOptionWithEnv(config, id, "secret")
secret, _ := config.GetStringOptionWithEnv(cfg, id, "secret")
if secret == "" && commonSecret != "" {
logger.Printf("Backend %s has no own shared secret set, using common shared secret", id)
secret = commonSecret
@ -311,7 +312,7 @@ func getConfiguredHosts(logger log.Logger, backendIds string, config *goconf.Con
continue
}
sessionLimit, err := config.GetInt(id, "sessionlimit")
sessionLimit, err := cfg.GetInt(id, "sessionlimit")
if err != nil || sessionLimit < 0 {
sessionLimit = 0
}
@ -319,20 +320,20 @@ func getConfiguredHosts(logger log.Logger, backendIds string, config *goconf.Con
logger.Printf("Backend %s allows a maximum of %d sessions", id, sessionLimit)
}
maxStreamBitrate, err := config.GetInt(id, "maxstreambitrate")
maxStreamBitrate, err := cfg.GetInt(id, "maxstreambitrate")
if err != nil || maxStreamBitrate < 0 {
maxStreamBitrate = 0
}
maxScreenBitrate, err := config.GetInt(id, "maxscreenbitrate")
maxScreenBitrate, err := cfg.GetInt(id, "maxscreenbitrate")
if err != nil || maxScreenBitrate < 0 {
maxScreenBitrate = 0
}
var urls []string
if u, _ := GetStringOptionWithEnv(config, id, "urls"); u != "" {
if u, _ := config.GetStringOptionWithEnv(cfg, id, "urls"); u != "" {
urls = slices.Sorted(internal.SplitEntries(u, ","))
urls = slices.Compact(urls)
} else if u, _ := GetStringOptionWithEnv(config, id, "url"); u != "" {
} else if u, _ := config.GetStringOptionWithEnv(cfg, id, "url"); u != "" {
if u = strings.TrimSpace(u); u != "" {
urls = []string{u}
}
@ -391,7 +392,7 @@ func getConfiguredHosts(logger log.Logger, backendIds string, config *goconf.Con
return hosts
}
func (s *backendStorageStatic) Reload(config *goconf.ConfigFile) {
func (s *backendStorageStatic) Reload(cfg *goconf.ConfigFile) {
s.mu.Lock()
defer s.mu.Unlock()
@ -400,10 +401,10 @@ func (s *backendStorageStatic) Reload(config *goconf.ConfigFile) {
return
}
commonSecret, _ := GetStringOptionWithEnv(config, "backend", "secret")
commonSecret, _ := config.GetStringOptionWithEnv(cfg, "backend", "secret")
if backendIds, _ := config.GetString("backend", "backends"); backendIds != "" {
configuredHosts := getConfiguredHosts(s.logger, backendIds, config, commonSecret)
if backendIds, _ := cfg.GetString("backend", "backends"); backendIds != "" {
configuredHosts := getConfiguredHosts(s.logger, backendIds, cfg, commonSecret)
// remove backends that are no longer configured
seen := make(map[string]seenState)

View file

@ -49,6 +49,7 @@ import (
signaling "github.com/strukturag/nextcloud-spreed-signaling"
"github.com/strukturag/nextcloud-spreed-signaling/api"
"github.com/strukturag/nextcloud-spreed-signaling/config"
"github.com/strukturag/nextcloud-spreed-signaling/internal"
"github.com/strukturag/nextcloud-spreed-signaling/talk"
)
@ -60,7 +61,7 @@ var (
addr = flag.String("addr", "localhost:28080", "http service address")
config = flag.String("config", "server.conf", "config file to use")
configFlag = flag.String("config", "server.conf", "config file to use")
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
@ -508,12 +509,12 @@ func main() {
os.Exit(0)
}
config, err := goconf.ReadConfigFile(*config)
cfg, err := goconf.ReadConfigFile(*configFlag)
if err != nil {
log.Fatal("Could not read configuration: ", err)
}
secret, _ := signaling.GetStringOptionWithEnv(config, "backend", "secret")
secret, _ := config.GetStringOptionWithEnv(cfg, "backend", "secret")
backendSecret = []byte(secret)
log.Printf("Using a maximum of %d CPUs", runtime.GOMAXPROCS(0))

View file

@ -19,7 +19,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package signaling
package config
import (
"errors"

View file

@ -19,7 +19,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package signaling
package config
import (
"testing"

View file

@ -39,6 +39,7 @@ import (
"github.com/dlintw/goconf"
"github.com/oschwald/maxminddb-golang"
"github.com/strukturag/nextcloud-spreed-signaling/config"
"github.com/strukturag/nextcloud-spreed-signaling/log"
)
@ -274,9 +275,9 @@ func IsValidContinent(continent string) bool {
}
}
func LoadGeoIPOverrides(ctx context.Context, config *goconf.ConfigFile, ignoreErrors bool) (map[*net.IPNet]string, error) {
func LoadGeoIPOverrides(ctx context.Context, cfg *goconf.ConfigFile, ignoreErrors bool) (map[*net.IPNet]string, error) {
logger := log.LoggerFromContext(ctx)
options, _ := GetStringOptions(config, "geoip-overrides", true)
options, _ := config.GetStringOptions(cfg, "geoip-overrides", true)
if len(options) == 0 {
return nil, nil
}

View file

@ -39,6 +39,7 @@ import (
status "google.golang.org/grpc/status"
"github.com/strukturag/nextcloud-spreed-signaling/api"
"github.com/strukturag/nextcloud-spreed-signaling/config"
"github.com/strukturag/nextcloud-spreed-signaling/log"
)
@ -86,9 +87,9 @@ type GrpcServer struct {
hub GrpcServerHub
}
func NewGrpcServer(ctx context.Context, config *goconf.ConfigFile, version string) (*GrpcServer, error) {
func NewGrpcServer(ctx context.Context, cfg *goconf.ConfigFile, version string) (*GrpcServer, error) {
var listener net.Listener
if addr, _ := GetStringOptionWithEnv(config, "grpc", "listen"); addr != "" {
if addr, _ := config.GetStringOptionWithEnv(cfg, "grpc", "listen"); addr != "" {
var err error
listener, err = net.Listen("tcp", addr)
if err != nil {
@ -97,7 +98,7 @@ func NewGrpcServer(ctx context.Context, config *goconf.ConfigFile, version strin
}
logger := log.LoggerFromContext(ctx)
creds, err := NewReloadableCredentials(logger, config, true)
creds, err := NewReloadableCredentials(logger, cfg, true)
if err != nil {
return nil, err
}

35
hub.go
View file

@ -53,6 +53,7 @@ import (
"github.com/strukturag/nextcloud-spreed-signaling/api"
"github.com/strukturag/nextcloud-spreed-signaling/async"
"github.com/strukturag/nextcloud-spreed-signaling/config"
"github.com/strukturag/nextcloud-spreed-signaling/container"
"github.com/strukturag/nextcloud-spreed-signaling/internal"
"github.com/strukturag/nextcloud-spreed-signaling/log"
@ -222,9 +223,9 @@ type Hub struct {
blockedCandidates atomic.Pointer[container.IPList]
}
func NewHub(ctx context.Context, config *goconf.ConfigFile, events AsyncEvents, rpcServer *GrpcServer, rpcClients *GrpcClients, etcdClient *EtcdClient, r *mux.Router, version string) (*Hub, error) {
func NewHub(ctx context.Context, cfg *goconf.ConfigFile, events AsyncEvents, rpcServer *GrpcServer, rpcClients *GrpcClients, etcdClient *EtcdClient, r *mux.Router, version string) (*Hub, error) {
logger := log.LoggerFromContext(ctx)
hashKey, _ := GetStringOptionWithEnv(config, "sessions", "hashkey")
hashKey, _ := config.GetStringOptionWithEnv(cfg, "sessions", "hashkey")
switch len(hashKey) {
case 32:
case 64:
@ -232,7 +233,7 @@ func NewHub(ctx context.Context, config *goconf.ConfigFile, events AsyncEvents,
logger.Printf("WARNING: The sessions hash key should be 32 or 64 bytes but is %d bytes", len(hashKey))
}
blockKey, _ := GetStringOptionWithEnv(config, "sessions", "blockkey")
blockKey, _ := config.GetStringOptionWithEnv(cfg, "sessions", "blockkey")
blockBytes := []byte(blockKey)
switch len(blockKey) {
case 0:
@ -249,51 +250,51 @@ func NewHub(ctx context.Context, config *goconf.ConfigFile, events AsyncEvents,
return nil, fmt.Errorf("error creating session id codec: %w", err)
}
internalClientsSecret, _ := GetStringOptionWithEnv(config, "clients", "internalsecret")
internalClientsSecret, _ := config.GetStringOptionWithEnv(cfg, "clients", "internalsecret")
if internalClientsSecret == "" {
logger.Println("WARNING: No shared secret has been set for internal clients.")
}
maxConcurrentRequestsPerHost, _ := config.GetInt("backend", "connectionsperhost")
maxConcurrentRequestsPerHost, _ := cfg.GetInt("backend", "connectionsperhost")
if maxConcurrentRequestsPerHost <= 0 {
maxConcurrentRequestsPerHost = defaultMaxConcurrentRequestsPerHost
}
backend, err := NewBackendClient(ctx, config, maxConcurrentRequestsPerHost, version, etcdClient)
backend, err := NewBackendClient(ctx, cfg, maxConcurrentRequestsPerHost, version, etcdClient)
if err != nil {
return nil, err
}
logger.Printf("Using a maximum of %d concurrent backend connections per host", maxConcurrentRequestsPerHost)
backendTimeoutSeconds, _ := config.GetInt("backend", "timeout")
backendTimeoutSeconds, _ := cfg.GetInt("backend", "timeout")
if backendTimeoutSeconds <= 0 {
backendTimeoutSeconds = defaultBackendTimeoutSeconds
}
backendTimeout := time.Duration(backendTimeoutSeconds) * time.Second
logger.Printf("Using a timeout of %s for backend connections", backendTimeout)
mcuTimeoutSeconds, _ := config.GetInt("mcu", "timeout")
mcuTimeoutSeconds, _ := cfg.GetInt("mcu", "timeout")
if mcuTimeoutSeconds <= 0 {
mcuTimeoutSeconds = defaultMcuTimeoutSeconds
}
mcuTimeout := time.Duration(mcuTimeoutSeconds) * time.Second
allowSubscribeAnyStream, _ := config.GetBool("app", "allowsubscribeany")
allowSubscribeAnyStream, _ := cfg.GetBool("app", "allowsubscribeany")
if allowSubscribeAnyStream {
logger.Printf("WARNING: Allow subscribing any streams, this is insecure and should only be enabled for testing")
}
trustedProxies, _ := config.GetString("app", "trustedproxies")
trustedProxies, _ := cfg.GetString("app", "trustedproxies")
trustedProxiesIps, err := container.ParseIPList(trustedProxies)
if err != nil {
return nil, err
}
skipFederationVerify, _ := config.GetBool("federation", "skipverify")
skipFederationVerify, _ := cfg.GetBool("federation", "skipverify")
if skipFederationVerify {
logger.Println("WARNING: Federation target verification is disabled!")
}
federationTimeoutSeconds, _ := config.GetInt("federation", "timeout")
federationTimeoutSeconds, _ := cfg.GetInt("federation", "timeout")
if federationTimeoutSeconds <= 0 {
federationTimeoutSeconds = defaultFederationTimeoutSeconds
}
@ -321,12 +322,12 @@ func NewHub(ctx context.Context, config *goconf.ConfigFile, events AsyncEvents,
return nil, err
}
geoipUrl, _ := config.GetString("geoip", "url")
geoipUrl, _ := cfg.GetString("geoip", "url")
if geoipUrl == "default" || geoipUrl == "none" {
geoipUrl = ""
}
if geoipUrl == "" {
if geoipLicense, _ := config.GetString("geoip", "license"); geoipLicense != "" {
if geoipLicense, _ := cfg.GetString("geoip", "license"); geoipLicense != "" {
geoipUrl = GetGeoIpDownloadUrl(geoipLicense)
}
}
@ -347,7 +348,7 @@ func NewHub(ctx context.Context, config *goconf.ConfigFile, events AsyncEvents,
logger.Printf("Not using GeoIP database")
}
geoipOverrides, err := LoadGeoIPOverrides(ctx, config, false)
geoipOverrides, err := LoadGeoIPOverrides(ctx, cfg, false)
if err != nil {
return nil, err
}
@ -418,7 +419,7 @@ func NewHub(ctx context.Context, config *goconf.ConfigFile, events AsyncEvents,
skipFederationVerify: skipFederationVerify,
federationTimeout: federationTimeout,
}
if value, _ := config.GetString("mcu", "allowedcandidates"); value != "" {
if value, _ := cfg.GetString("mcu", "allowedcandidates"); value != "" {
allowed, err := container.ParseIPList(value)
if err != nil {
return nil, fmt.Errorf("invalid allowedcandidates: %w", err)
@ -429,7 +430,7 @@ func NewHub(ctx context.Context, config *goconf.ConfigFile, events AsyncEvents,
} else {
logger.Printf("No candidates allowlist")
}
if value, _ := config.GetString("mcu", "blockedcandidates"); value != "" {
if value, _ := cfg.GetString("mcu", "blockedcandidates"); value != "" {
blocked, err := container.ParseIPList(value)
if err != nil {
return nil, fmt.Errorf("invalid blockedcandidates: %w", err)

View file

@ -47,6 +47,7 @@ import (
"github.com/strukturag/nextcloud-spreed-signaling/api"
"github.com/strukturag/nextcloud-spreed-signaling/async"
"github.com/strukturag/nextcloud-spreed-signaling/config"
"github.com/strukturag/nextcloud-spreed-signaling/internal"
"github.com/strukturag/nextcloud-spreed-signaling/log"
)
@ -1589,8 +1590,8 @@ func (m *mcuProxy) GetBandwidthLimits() (api.Bandwidth, api.Bandwidth) {
return m.settings.MaxStreamBitrate(), m.settings.MaxScreenBitrate()
}
func (m *mcuProxy) loadContinentsMap(config *goconf.ConfigFile) error {
options, err := GetStringOptions(config, "continent-overrides", false)
func (m *mcuProxy) loadContinentsMap(cfg *goconf.ConfigFile) error {
options, err := config.GetStringOptions(cfg, "continent-overrides", false)
if err != nil {
return err
}

View file

@ -37,7 +37,7 @@ import (
"github.com/dlintw/goconf"
"github.com/gorilla/mux"
signaling "github.com/strukturag/nextcloud-spreed-signaling"
"github.com/strukturag/nextcloud-spreed-signaling/config"
"github.com/strukturag/nextcloud-spreed-signaling/internal"
signalinglog "github.com/strukturag/nextcloud-spreed-signaling/log"
)
@ -78,7 +78,7 @@ func main() {
logger.Printf("Starting up version %s/%s as pid %d", version, runtime.Version(), os.Getpid())
config, err := goconf.ReadConfigFile(*configFlag)
cfg, err := goconf.ReadConfigFile(*configFlag)
if err != nil {
logger.Fatal("Could not read configuration: ", err)
}
@ -87,22 +87,22 @@ func main() {
r := mux.NewRouter()
proxy, err := NewProxyServer(stopCtx, r, version, config)
proxy, err := NewProxyServer(stopCtx, r, version, cfg)
if err != nil {
logger.Fatal(err)
}
if err := proxy.Start(config); err != nil {
if err := proxy.Start(cfg); err != nil {
logger.Fatal(err)
}
defer proxy.Stop()
if addr, _ := signaling.GetStringOptionWithEnv(config, "http", "listen"); addr != "" {
readTimeout, _ := config.GetInt("http", "readtimeout")
if addr, _ := config.GetStringOptionWithEnv(cfg, "http", "listen"); addr != "" {
readTimeout, _ := cfg.GetInt("http", "readtimeout")
if readTimeout <= 0 {
readTimeout = defaultReadTimeout
}
writeTimeout, _ := config.GetInt("http", "writetimeout")
writeTimeout, _ := cfg.GetInt("http", "writetimeout")
if writeTimeout <= 0 {
writeTimeout = defaultWriteTimeout
}

View file

@ -52,6 +52,7 @@ import (
signaling "github.com/strukturag/nextcloud-spreed-signaling"
"github.com/strukturag/nextcloud-spreed-signaling/api"
"github.com/strukturag/nextcloud-spreed-signaling/async"
"github.com/strukturag/nextcloud-spreed-signaling/config"
"github.com/strukturag/nextcloud-spreed-signaling/container"
"github.com/strukturag/nextcloud-spreed-signaling/log"
)
@ -424,13 +425,13 @@ func (s *ProxyServer) checkOrigin(r *http.Request) bool {
return true
}
func (s *ProxyServer) Start(config *goconf.ConfigFile) error {
s.url, _ = signaling.GetStringOptionWithEnv(config, "mcu", "url")
func (s *ProxyServer) Start(cfg *goconf.ConfigFile) error {
s.url, _ = config.GetStringOptionWithEnv(cfg, "mcu", "url")
if s.url == "" {
return errors.New("no MCU server url configured")
}
mcuType, _ := config.GetString("mcu", "type")
mcuType, _ := cfg.GetString("mcu", "type")
if mcuType == "" {
mcuType = signaling.McuTypeDefault
}
@ -447,7 +448,7 @@ func (s *ProxyServer) Start(config *goconf.ConfigFile) error {
for {
switch mcuType {
case signaling.McuTypeJanus:
mcu, err = signaling.NewMcuJanus(ctx, s.url, config)
mcu, err = signaling.NewMcuJanus(ctx, s.url, cfg)
if err == nil {
signaling.RegisterJanusMcuStats()
}

View file

@ -30,7 +30,7 @@ import (
"github.com/dlintw/goconf"
"github.com/golang-jwt/jwt/v5"
signaling "github.com/strukturag/nextcloud-spreed-signaling"
"github.com/strukturag/nextcloud-spreed-signaling/config"
"github.com/strukturag/nextcloud-spreed-signaling/log"
)
@ -64,8 +64,8 @@ func (t *tokensStatic) Get(id string) (*ProxyToken, error) {
return token, nil
}
func (t *tokensStatic) load(config *goconf.ConfigFile, ignoreErrors bool) error {
options, err := signaling.GetStringOptions(config, "tokens", ignoreErrors)
func (t *tokensStatic) load(cfg *goconf.ConfigFile, ignoreErrors bool) error {
options, err := config.GetStringOptions(cfg, "tokens", ignoreErrors)
if err != nil {
return err
}

View file

@ -30,6 +30,7 @@ import (
"github.com/dlintw/goconf"
"github.com/strukturag/nextcloud-spreed-signaling/config"
"github.com/strukturag/nextcloud-spreed-signaling/internal"
"github.com/strukturag/nextcloud-spreed-signaling/log"
)
@ -70,11 +71,11 @@ func NewProxyConfigStatic(logger log.Logger, config *goconf.ConfigFile, proxy Mc
return result, nil
}
func (p *proxyConfigStatic) configure(config *goconf.ConfigFile, fromReload bool) error {
func (p *proxyConfigStatic) configure(cfg *goconf.ConfigFile, fromReload bool) error {
p.mu.Lock()
defer p.mu.Unlock()
dnsDiscovery, _ := config.GetBool("mcu", "dnsdiscovery")
dnsDiscovery, _ := cfg.GetBool("mcu", "dnsdiscovery")
if dnsDiscovery != p.dnsDiscovery {
if !dnsDiscovery {
for _, ips := range p.connectionsMap {
@ -89,7 +90,7 @@ func (p *proxyConfigStatic) configure(config *goconf.ConfigFile, fromReload bool
remove := maps.Clone(p.connectionsMap)
mcuUrl, _ := GetStringOptionWithEnv(config, "mcu", "url")
mcuUrl, _ := config.GetStringOptionWithEnv(cfg, "mcu", "url")
for u := range internal.SplitEntries(mcuUrl, " ") {
if existing, found := remove[u]; found {
// Proxy connection still exists in new configuration

View file

@ -42,6 +42,7 @@ import (
"github.com/gorilla/mux"
signaling "github.com/strukturag/nextcloud-spreed-signaling"
"github.com/strukturag/nextcloud-spreed-signaling/config"
"github.com/strukturag/nextcloud-spreed-signaling/internal"
signalinglog "github.com/strukturag/nextcloud-spreed-signaling/log"
"github.com/strukturag/nextcloud-spreed-signaling/nats"
@ -168,7 +169,7 @@ func main() {
logger.Printf("Starting up version %s/%s as pid %d", version, runtime.Version(), os.Getpid())
config, err := goconf.ReadConfigFile(*configFlag)
cfg, err := goconf.ReadConfigFile(*configFlag)
if err != nil {
logger.Fatal("Could not read configuration: ", err)
}
@ -177,7 +178,7 @@ func main() {
signaling.RegisterStats()
natsUrl, _ := signaling.GetStringOptionWithEnv(config, "nats", "url")
natsUrl, _ := config.GetStringOptionWithEnv(cfg, "nats", "url")
if natsUrl == "" {
natsUrl = nats.DefaultURL
}
@ -203,7 +204,7 @@ func main() {
}
defer dnsMonitor.Stop()
etcdClient, err := signaling.NewEtcdClient(logger, config, "mcu")
etcdClient, err := signaling.NewEtcdClient(logger, cfg, "mcu")
if err != nil {
logger.Fatalf("Could not create etcd client: %s", err)
}
@ -213,7 +214,7 @@ func main() {
}
}()
rpcServer, err := signaling.NewGrpcServer(stopCtx, config, version)
rpcServer, err := signaling.NewGrpcServer(stopCtx, cfg, version)
if err != nil {
logger.Fatalf("Could not create RPC server: %s", err)
}
@ -224,20 +225,20 @@ func main() {
}()
defer rpcServer.Close()
rpcClients, err := signaling.NewGrpcClients(stopCtx, config, etcdClient, dnsMonitor, version)
rpcClients, err := signaling.NewGrpcClients(stopCtx, cfg, etcdClient, dnsMonitor, version)
if err != nil {
logger.Fatalf("Could not create RPC clients: %s", err)
}
defer rpcClients.Close()
r := mux.NewRouter()
hub, err := signaling.NewHub(stopCtx, config, events, rpcServer, rpcClients, etcdClient, r, version)
hub, err := signaling.NewHub(stopCtx, cfg, events, rpcServer, rpcClients, etcdClient, r, version)
if err != nil {
logger.Fatal("Could not create hub: ", err)
}
mcuUrl, _ := signaling.GetStringOptionWithEnv(config, "mcu", "url")
mcuType, _ := config.GetString("mcu", "type")
mcuUrl, _ := config.GetStringOptionWithEnv(cfg, "mcu", "url")
mcuType, _ := cfg.GetString("mcu", "type")
if mcuType == "" && mcuUrl != "" {
logger.Printf("WARNING: Old-style MCU configuration detected with url but no type, defaulting to type %s", signaling.McuTypeJanus)
mcuType = signaling.McuTypeJanus
@ -256,11 +257,11 @@ func main() {
ctx := context.TODO()
switch mcuType {
case signaling.McuTypeJanus:
mcu, err = signaling.NewMcuJanus(ctx, mcuUrl, config)
mcu, err = signaling.NewMcuJanus(ctx, mcuUrl, cfg)
signaling.UnregisterProxyMcuStats()
signaling.RegisterJanusMcuStats()
case signaling.McuTypeProxy:
mcu, err = signaling.NewMcuProxy(ctx, config, etcdClient, rpcClients, dnsMonitor)
mcu, err = signaling.NewMcuProxy(ctx, cfg, etcdClient, rpcClients, dnsMonitor)
signaling.UnregisterJanusMcuStats()
signaling.RegisterProxyMcuStats()
default:
@ -285,11 +286,11 @@ func main() {
switch sig {
case syscall.SIGHUP:
logger.Printf("Received SIGHUP, reloading %s", *configFlag)
if config, err = goconf.ReadConfigFile(*configFlag); err != nil {
if cfg, err = goconf.ReadConfigFile(*configFlag); err != nil {
logger.Printf("Could not read configuration from %s: %s", *configFlag, err)
} else {
mcuUrl, _ = signaling.GetStringOptionWithEnv(config, "mcu", "url")
mcuType, _ = config.GetString("mcu", "type")
mcuUrl, _ = config.GetStringOptionWithEnv(cfg, "mcu", "url")
mcuType, _ = cfg.GetString("mcu", "type")
if mcuType == "" && mcuUrl != "" {
logger.Printf("WARNING: Old-style MCU configuration detected with url but no type, defaulting to type %s", signaling.McuTypeJanus)
mcuType = signaling.McuTypeJanus
@ -316,7 +317,7 @@ func main() {
go hub.Run()
defer hub.Stop()
server, err := signaling.NewBackendServer(stopCtx, config, hub, version)
server, err := signaling.NewBackendServer(stopCtx, cfg, hub, version)
if err != nil {
logger.Fatal("Could not create backend server: ", err)
}
@ -328,18 +329,18 @@ func main() {
logger: logger,
}
if saddr, _ := signaling.GetStringOptionWithEnv(config, "https", "listen"); saddr != "" {
cert, _ := config.GetString("https", "certificate")
key, _ := config.GetString("https", "key")
if saddr, _ := config.GetStringOptionWithEnv(cfg, "https", "listen"); saddr != "" {
cert, _ := cfg.GetString("https", "certificate")
key, _ := cfg.GetString("https", "key")
if cert == "" || key == "" {
logger.Fatal("Need a certificate and key for the HTTPS listener")
}
readTimeout, _ := config.GetInt("https", "readtimeout")
readTimeout, _ := cfg.GetInt("https", "readtimeout")
if readTimeout <= 0 {
readTimeout = defaultReadTimeout
}
writeTimeout, _ := config.GetInt("https", "writetimeout")
writeTimeout, _ := cfg.GetInt("https", "writetimeout")
if writeTimeout <= 0 {
writeTimeout = defaultWriteTimeout
}
@ -366,12 +367,12 @@ func main() {
}
}
if addr, _ := signaling.GetStringOptionWithEnv(config, "http", "listen"); addr != "" {
readTimeout, _ := config.GetInt("http", "readtimeout")
if addr, _ := config.GetStringOptionWithEnv(cfg, "http", "listen"); addr != "" {
readTimeout, _ := cfg.GetInt("http", "readtimeout")
if readTimeout <= 0 {
readTimeout = defaultReadTimeout
}
writeTimeout, _ := config.GetInt("http", "writetimeout")
writeTimeout, _ := cfg.GetInt("http", "writetimeout")
if writeTimeout <= 0 {
writeTimeout = defaultWriteTimeout
}