Browse Source

add stunlist string to serverconfig

afeiszli 2 years ago
parent
commit
dba954c529
2 changed files with 20 additions and 0 deletions
  1. 1 0
      config/config.go
  2. 19 0
      servercfg/serverconf.go

+ 1 - 0
config/config.go

@@ -72,6 +72,7 @@ type ServerConfig struct {
 	NetmakerAccountID    string `yaml:"netmaker_account_id"`
 	NetmakerAccountID    string `yaml:"netmaker_account_id"`
 	IsEE                 string `yaml:"is_ee"`
 	IsEE                 string `yaml:"is_ee"`
 	StunPort             int    `yaml:"stun_port"`
 	StunPort             int    `yaml:"stun_port"`
+	StunList             string `yaml:"stun_list"`
 	Proxy                string `yaml:"proxy"`
 	Proxy                string `yaml:"proxy"`
 }
 }
 
 

+ 19 - 0
servercfg/serverconf.go

@@ -73,6 +73,7 @@ func GetServerConfig() config.ServerConfig {
 	cfg.FrontendURL = GetFrontendURL()
 	cfg.FrontendURL = GetFrontendURL()
 	cfg.Telemetry = Telemetry()
 	cfg.Telemetry = Telemetry()
 	cfg.Server = GetServer()
 	cfg.Server = GetServer()
+	cfg.StunList = GetStunListString()
 	cfg.Verbosity = GetVerbosity()
 	cfg.Verbosity = GetVerbosity()
 	cfg.IsEE = "no"
 	cfg.IsEE = "no"
 	if Is_EE {
 	if Is_EE {
@@ -188,12 +189,30 @@ func GetStunList() []models.StunServer {
 			Port:   3478,
 			Port:   3478,
 		},
 		},
 	}
 	}
+	parsed := false
 	if os.Getenv("STUN_LIST") != "" {
 	if os.Getenv("STUN_LIST") != "" {
 		stuns, err := parseStunList(os.Getenv("STUN_LIST"))
 		stuns, err := parseStunList(os.Getenv("STUN_LIST"))
 		if err == nil {
 		if err == nil {
+			parsed = true
 			stunList = stuns
 			stunList = stuns
 		}
 		}
 	}
 	}
+	if !parsed && config.Config.Server.StunList != "" {
+		stuns, err := parseStunList(config.Config.Server.StunList)
+		if err == nil {
+			stunList = stuns
+		}
+	}
+	return stunList
+}
+
+func GetStunListString() string {
+	stunList := "stun1.netmaker.io:3478,stun2.netmaker.io:3478"
+	if os.Getenv("STUN_LIST") != "" {
+		stunList = os.Getenv("STUN_LIST")
+	} else if config.Config.Server.StunList != "" {
+		stunList = config.Config.Server.StunList
+	}
 	return stunList
 	return stunList
 }
 }