mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 22:55:06 +03:00
Allow setting priority on listeners and multicast interfaces
This commit is contained in:
parent
7ae30eed44
commit
bb389dbddd
9 changed files with 44 additions and 29 deletions
|
@ -335,10 +335,11 @@ func run(args yggArgs, ctx context.Context) {
|
||||||
options := []multicast.SetupOption{}
|
options := []multicast.SetupOption{}
|
||||||
for _, intf := range cfg.MulticastInterfaces {
|
for _, intf := range cfg.MulticastInterfaces {
|
||||||
options = append(options, multicast.MulticastInterface{
|
options = append(options, multicast.MulticastInterface{
|
||||||
Regex: regexp.MustCompile(intf.Regex),
|
Regex: regexp.MustCompile(intf.Regex),
|
||||||
Beacon: intf.Beacon,
|
Beacon: intf.Beacon,
|
||||||
Listen: intf.Listen,
|
Listen: intf.Listen,
|
||||||
Port: intf.Port,
|
Port: intf.Port,
|
||||||
|
Priority: intf.Priority,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if n.multicast, err = multicast.New(n.core, logger, options...); err != nil {
|
if n.multicast, err = multicast.New(n.core, logger, options...); err != nil {
|
||||||
|
|
|
@ -83,10 +83,11 @@ func (m *Yggdrasil) StartJSON(configjson []byte) error {
|
||||||
options := []multicast.SetupOption{}
|
options := []multicast.SetupOption{}
|
||||||
for _, intf := range m.config.MulticastInterfaces {
|
for _, intf := range m.config.MulticastInterfaces {
|
||||||
options = append(options, multicast.MulticastInterface{
|
options = append(options, multicast.MulticastInterface{
|
||||||
Regex: regexp.MustCompile(intf.Regex),
|
Regex: regexp.MustCompile(intf.Regex),
|
||||||
Beacon: intf.Beacon,
|
Beacon: intf.Beacon,
|
||||||
Listen: intf.Listen,
|
Listen: intf.Listen,
|
||||||
Port: intf.Port,
|
Port: intf.Port,
|
||||||
|
Priority: intf.Priority,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
m.multicast, err = multicast.New(m.core, logger, options...)
|
m.multicast, err = multicast.New(m.core, logger, options...)
|
||||||
|
|
|
@ -40,10 +40,11 @@ type NodeConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type MulticastInterfaceConfig struct {
|
type MulticastInterfaceConfig struct {
|
||||||
Regex string
|
Regex string
|
||||||
Beacon bool
|
Beacon bool
|
||||||
Listen bool
|
Listen bool
|
||||||
Port uint16
|
Port uint16
|
||||||
|
Priority uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSigningKeys replaces the signing keypair in the NodeConfig with a new
|
// NewSigningKeys replaces the signing keypair in the NodeConfig with a new
|
||||||
|
|
|
@ -362,3 +362,12 @@ func (c *linkConn) Write(p []byte) (n int, err error) {
|
||||||
atomic.AddUint64(&c.tx, uint64(n))
|
atomic.AddUint64(&c.tx, uint64(n))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func linkOptionsForListener(u *url.URL) (l linkOptions) {
|
||||||
|
if p := u.Query().Get("priority"); p != "" {
|
||||||
|
if pi, err := strconv.ParseUint(p, 10, 8); err == nil {
|
||||||
|
l.priority = uint8(pi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ func (l *linkTCP) listen(url *url.URL, sintf string) (*Listener, error) {
|
||||||
addr := conn.RemoteAddr().(*net.TCPAddr)
|
addr := conn.RemoteAddr().(*net.TCPAddr)
|
||||||
name := fmt.Sprintf("tls://%s", addr)
|
name := fmt.Sprintf("tls://%s", addr)
|
||||||
info := linkInfoFor("tcp", sintf, strings.SplitN(addr.IP.String(), "%", 2)[0])
|
info := linkInfoFor("tcp", sintf, strings.SplitN(addr.IP.String(), "%", 2)[0])
|
||||||
if err = l.handler(name, info, conn, linkOptions{}, true); err != nil {
|
if err = l.handler(name, info, conn, linkOptionsForListener(url), true); err != nil {
|
||||||
l.core.log.Errorln("Failed to create inbound link:", err)
|
l.core.log.Errorln("Failed to create inbound link:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ func (l *linkTLS) listen(url *url.URL, sintf string) (*Listener, error) {
|
||||||
addr := conn.RemoteAddr().(*net.TCPAddr)
|
addr := conn.RemoteAddr().(*net.TCPAddr)
|
||||||
name := fmt.Sprintf("tls://%s", addr)
|
name := fmt.Sprintf("tls://%s", addr)
|
||||||
info := linkInfoFor("tls", sintf, strings.SplitN(addr.IP.String(), "%", 2)[0])
|
info := linkInfoFor("tls", sintf, strings.SplitN(addr.IP.String(), "%", 2)[0])
|
||||||
if err = l.handler(name, info, conn, linkOptions{}, true); err != nil {
|
if err = l.handler(name, info, conn, linkOptionsForListener(url), true); err != nil {
|
||||||
l.core.log.Errorln("Failed to create inbound link:", err)
|
l.core.log.Errorln("Failed to create inbound link:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ func (l *linkUNIX) listen(url *url.URL, _ string) (*Listener, error) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
info := linkInfoFor("unix", "", url.String())
|
info := linkInfoFor("unix", "", url.String())
|
||||||
if err = l.handler(url.String(), info, conn, linkOptions{}, true); err != nil {
|
if err = l.handler(url.String(), info, conn, linkOptionsForListener(url), true); err != nil {
|
||||||
l.core.log.Errorln("Failed to create inbound link:", err)
|
l.core.log.Errorln("Failed to create inbound link:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,11 +37,12 @@ type Multicast struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type interfaceInfo struct {
|
type interfaceInfo struct {
|
||||||
iface net.Interface
|
iface net.Interface
|
||||||
addrs []net.Addr
|
addrs []net.Addr
|
||||||
beacon bool
|
beacon bool
|
||||||
listen bool
|
listen bool
|
||||||
port uint16
|
port uint16
|
||||||
|
priority uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
type listenerInfo struct {
|
type listenerInfo struct {
|
||||||
|
@ -190,10 +191,11 @@ func (m *Multicast) _getAllowedInterfaces() map[string]*interfaceInfo {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
interfaces[iface.Name] = &interfaceInfo{
|
interfaces[iface.Name] = &interfaceInfo{
|
||||||
iface: iface,
|
iface: iface,
|
||||||
beacon: ifcfg.Beacon,
|
beacon: ifcfg.Beacon,
|
||||||
listen: ifcfg.Listen,
|
listen: ifcfg.Listen,
|
||||||
port: ifcfg.Port,
|
port: ifcfg.Port,
|
||||||
|
priority: ifcfg.Priority,
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -383,7 +385,7 @@ func (m *Multicast) listen() {
|
||||||
})
|
})
|
||||||
if info, ok := interfaces[from.Zone]; ok && info.listen {
|
if info, ok := interfaces[from.Zone]; ok && info.listen {
|
||||||
addr.Zone = ""
|
addr.Zone = ""
|
||||||
pin := fmt.Sprintf("/?key=%s", hex.EncodeToString(key))
|
pin := fmt.Sprintf("/?key=%s&priority=%d", hex.EncodeToString(key), info.priority)
|
||||||
u, err := url.Parse("tls://" + addr.String() + pin)
|
u, err := url.Parse("tls://" + addr.String() + pin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.log.Debugln("Call from multicast failed, parse error:", addr.String(), err)
|
m.log.Debugln("Call from multicast failed, parse error:", addr.String(), err)
|
||||||
|
|
|
@ -16,10 +16,11 @@ type SetupOption interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type MulticastInterface struct {
|
type MulticastInterface struct {
|
||||||
Regex *regexp.Regexp
|
Regex *regexp.Regexp
|
||||||
Beacon bool
|
Beacon bool
|
||||||
Listen bool
|
Listen bool
|
||||||
Port uint16
|
Port uint16
|
||||||
|
Priority uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
type GroupAddress string
|
type GroupAddress string
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue