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
|
@ -339,6 +339,7 @@ func run(args yggArgs, ctx context.Context) {
|
|||
Beacon: intf.Beacon,
|
||||
Listen: intf.Listen,
|
||||
Port: intf.Port,
|
||||
Priority: intf.Priority,
|
||||
})
|
||||
}
|
||||
if n.multicast, err = multicast.New(n.core, logger, options...); err != nil {
|
||||
|
|
|
@ -87,6 +87,7 @@ func (m *Yggdrasil) StartJSON(configjson []byte) error {
|
|||
Beacon: intf.Beacon,
|
||||
Listen: intf.Listen,
|
||||
Port: intf.Port,
|
||||
Priority: intf.Priority,
|
||||
})
|
||||
}
|
||||
m.multicast, err = multicast.New(m.core, logger, options...)
|
||||
|
|
|
@ -44,6 +44,7 @@ type MulticastInterfaceConfig struct {
|
|||
Beacon bool
|
||||
Listen bool
|
||||
Port uint16
|
||||
Priority uint8
|
||||
}
|
||||
|
||||
// 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))
|
||||
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)
|
||||
name := fmt.Sprintf("tls://%s", addr)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ func (l *linkTLS) listen(url *url.URL, sintf string) (*Listener, error) {
|
|||
addr := conn.RemoteAddr().(*net.TCPAddr)
|
||||
name := fmt.Sprintf("tls://%s", addr)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ func (l *linkUNIX) listen(url *url.URL, _ string) (*Listener, error) {
|
|||
break
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ type interfaceInfo struct {
|
|||
beacon bool
|
||||
listen bool
|
||||
port uint16
|
||||
priority uint8
|
||||
}
|
||||
|
||||
type listenerInfo struct {
|
||||
|
@ -194,6 +195,7 @@ func (m *Multicast) _getAllowedInterfaces() map[string]*interfaceInfo {
|
|||
beacon: ifcfg.Beacon,
|
||||
listen: ifcfg.Listen,
|
||||
port: ifcfg.Port,
|
||||
priority: ifcfg.Priority,
|
||||
}
|
||||
break
|
||||
}
|
||||
|
@ -383,7 +385,7 @@ func (m *Multicast) listen() {
|
|||
})
|
||||
if info, ok := interfaces[from.Zone]; ok && info.listen {
|
||||
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)
|
||||
if err != nil {
|
||||
m.log.Debugln("Call from multicast failed, parse error:", addr.String(), err)
|
||||
|
|
|
@ -20,6 +20,7 @@ type MulticastInterface struct {
|
|||
Beacon bool
|
||||
Listen bool
|
||||
Port uint16
|
||||
Priority uint8
|
||||
}
|
||||
|
||||
type GroupAddress string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue