support multiple STUN servers

This commit is contained in:
David Zhao
2020-10-08 00:12:57 -07:00
parent 0a4ce6e742
commit 32af882b99
2 changed files with 11 additions and 4 deletions

View File

@@ -15,8 +15,8 @@ type Config struct {
MultiNode bool `yaml:"multi_node"`
Development bool `yaml:"development"`
// Stun server
StunServer string `yaml:"stun_server"`
// STUN
StunServers []string `yaml:"stun_servers"`
}
func NewConfig(confString string) (*Config, error) {
@@ -26,7 +26,9 @@ func NewConfig(confString string) (*Config, error) {
RTCPort: 7881,
UDPRangeStart: 10000,
UDPRangeEnd: 11000,
StunServer: "stun.l.google.com:19302",
StunServers: []string{
"stun.l.google.com:19302",
},
}
if confString != "" {
yaml.Unmarshal([]byte(confString), conf)

View File

@@ -1,6 +1,8 @@
package node
import (
"errors"
"github.com/google/uuid"
"github.com/google/wire"
"github.com/pion/stun"
@@ -45,7 +47,10 @@ func NewLocalNode(conf *config.Config) (*Node, error) {
}
func (n *Node) DiscoverNetworkInfo() error {
c, err := stun.Dial("udp", n.config.StunServer)
if len(n.config.StunServers) == 0 {
return errors.New("STUN servers are required but not defined")
}
c, err := stun.Dial("udp", n.config.StunServers[0])
if err != nil {
return err
}