Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove stunlist #2572

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ type ServerConfig struct {
NetmakerTenantID string `yaml:"netmaker_tenant_id"`
IsPro string `yaml:"is_ee" json:"IsEE"`
StunPort int `yaml:"stun_port"`
StunList string `yaml:"stun_list"`
TurnServer string `yaml:"turn_server"`
TurnApiServer string `yaml:"turn_api_server"`
TurnPort int `yaml:"turn_port"`
Expand Down
39 changes: 16 additions & 23 deletions models/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,23 +248,22 @@ type NodeJoinResponse struct {

// ServerConfig - struct for dealing with the server information for a netclient
type ServerConfig struct {
CoreDNSAddr string `yaml:"corednsaddr"`
API string `yaml:"api"`
APIPort string `yaml:"apiport"`
DNSMode string `yaml:"dnsmode"`
Version string `yaml:"version"`
MQPort string `yaml:"mqport"`
MQUserName string `yaml:"mq_username"`
MQPassword string `yaml:"mq_password"`
Server string `yaml:"server"`
Broker string `yaml:"broker"`
IsPro bool `yaml:"isee" json:"Is_EE"`
StunPort int `yaml:"stun_port"`
StunList []StunServer `yaml:"stun_list"`
TrafficKey []byte `yaml:"traffickey"`
TurnDomain string `yaml:"turn_domain"`
TurnPort int `yaml:"turn_port"`
UseTurn bool `yaml:"use_turn"`
CoreDNSAddr string `yaml:"corednsaddr"`
API string `yaml:"api"`
APIPort string `yaml:"apiport"`
DNSMode string `yaml:"dnsmode"`
Version string `yaml:"version"`
MQPort string `yaml:"mqport"`
MQUserName string `yaml:"mq_username"`
MQPassword string `yaml:"mq_password"`
Server string `yaml:"server"`
Broker string `yaml:"broker"`
IsPro bool `yaml:"isee" json:"Is_EE"`
StunPort int `yaml:"stun_port"`
TrafficKey []byte `yaml:"traffickey"`
TurnDomain string `yaml:"turn_domain"`
TurnPort int `yaml:"turn_port"`
UseTurn bool `yaml:"use_turn"`
}

// User.NameInCharset - returns if name is in charset below or not
Expand All @@ -290,12 +289,6 @@ type JoinData struct {
Key string `json:"key" yaml:"key"`
}

// StunServer - struct to hold data required for using stun server
type StunServer struct {
Domain string `json:"domain" yaml:"domain"`
Port int `json:"port" yaml:"port"`
}

// HookDetails - struct to hold hook info
type HookDetails struct {
Hook func() error
Expand Down
72 changes: 0 additions & 72 deletions servercfg/serverconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func GetServerConfig() config.ServerConfig {
cfg.FrontendURL = GetFrontendURL()
cfg.Telemetry = Telemetry()
cfg.Server = GetServer()
cfg.StunList = GetStunListString()
cfg.Verbosity = GetVerbosity()
cfg.IsPro = "no"
if IsPro {
Expand All @@ -112,7 +111,6 @@ func GetServerInfo() models.ServerConfig {
cfg.Version = GetVersion()
cfg.IsPro = IsPro
cfg.StunPort = GetStunPort()
cfg.StunList = GetStunList()
cfg.TurnDomain = GetTurnHost()
cfg.TurnPort = GetTurnPort()
cfg.UseTurn = IsUsingTurn()
Expand Down Expand Up @@ -223,46 +221,6 @@ func GetAPIPort() string {
return apiport
}

// GetStunList - gets the stun servers
func GetStunList() []models.StunServer {
stunList := []models.StunServer{
{
Domain: "stun1.netmaker.io",
Port: 3478,
},
{
Domain: "stun2.netmaker.io",
Port: 3478,
},
}
parsed := false
if os.Getenv("STUN_LIST") != "" {
stuns, err := parseStunList(os.Getenv("STUN_LIST"))
if err == nil {
parsed = true
stunList = stuns
}
}
if !parsed && config.Config.Server.StunList != "" {
stuns, err := parseStunList(config.Config.Server.StunList)
if err == nil {
stunList = stuns
}
}
return stunList
}

// GetStunList - gets the stun servers w/o parsing to struct
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
}

// GetCoreDNSAddr - gets the core dns address
func GetCoreDNSAddr() string {
addr, _ := GetPublicIP()
Expand Down Expand Up @@ -784,33 +742,3 @@ func GetEnvironment() string {
}
return ""
}

// parseStunList - turn string into slice of StunServers
func parseStunList(stunString string) ([]models.StunServer, error) {
var err error
stunServers := []models.StunServer{}
stuns := strings.Split(stunString, ",")
if len(stuns) == 0 {
return stunServers, errors.New("no stun servers provided")
}
for _, stun := range stuns {
stun = strings.Trim(stun, " ")
stunInfo := strings.Split(stun, ":")
if len(stunInfo) != 2 {
continue
}
port, err := strconv.Atoi(stunInfo[1])
if err != nil || port == 0 {
continue
}
stunServers = append(stunServers, models.StunServer{
Domain: stunInfo[0],
Port: port,
})

}
if len(stunServers) == 0 {
err = errors.New("no stun entries parsable")
}
return stunServers, err
}