support multiple STUN servers
This commit is contained in:
@@ -15,8 +15,8 @@ type Config struct {
|
|||||||
MultiNode bool `yaml:"multi_node"`
|
MultiNode bool `yaml:"multi_node"`
|
||||||
Development bool `yaml:"development"`
|
Development bool `yaml:"development"`
|
||||||
|
|
||||||
// Stun server
|
// STUN
|
||||||
StunServer string `yaml:"stun_server"`
|
StunServers []string `yaml:"stun_servers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig(confString string) (*Config, error) {
|
func NewConfig(confString string) (*Config, error) {
|
||||||
@@ -26,7 +26,9 @@ func NewConfig(confString string) (*Config, error) {
|
|||||||
RTCPort: 7881,
|
RTCPort: 7881,
|
||||||
UDPRangeStart: 10000,
|
UDPRangeStart: 10000,
|
||||||
UDPRangeEnd: 11000,
|
UDPRangeEnd: 11000,
|
||||||
StunServer: "stun.l.google.com:19302",
|
StunServers: []string{
|
||||||
|
"stun.l.google.com:19302",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
if confString != "" {
|
if confString != "" {
|
||||||
yaml.Unmarshal([]byte(confString), conf)
|
yaml.Unmarshal([]byte(confString), conf)
|
||||||
|
|||||||
+6
-1
@@ -1,6 +1,8 @@
|
|||||||
package node
|
package node
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/google/wire"
|
"github.com/google/wire"
|
||||||
"github.com/pion/stun"
|
"github.com/pion/stun"
|
||||||
@@ -45,7 +47,10 @@ func NewLocalNode(conf *config.Config) (*Node, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) DiscoverNetworkInfo() 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user