Version 0.4.6

This commit is contained in:
Neil Alexander 2022-10-26 18:25:48 +01:00
parent b8a2d9f125
commit 4c66a13b93
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
17 changed files with 174 additions and 115 deletions

View file

@ -37,11 +37,12 @@ type Multicast struct {
}
type interfaceInfo struct {
iface net.Interface
addrs []net.Addr
beacon bool
listen bool
port uint16
iface net.Interface
addrs []net.Addr
beacon bool
listen bool
port uint16
priority uint8
}
type listenerInfo struct {
@ -77,7 +78,11 @@ func (m *Multicast) _start() error {
if m._isOpen {
return fmt.Errorf("multicast module is already started")
}
if len(m.config._interfaces) == 0 {
var anyEnabled bool
for intf := range m.config._interfaces {
anyEnabled = anyEnabled || intf.Beacon || intf.Listen
}
if !anyEnabled {
return nil
}
m.log.Debugln("Starting multicast module")
@ -190,10 +195,11 @@ func (m *Multicast) _getAllowedInterfaces() map[string]*interfaceInfo {
continue
}
interfaces[iface.Name] = &interfaceInfo{
iface: iface,
beacon: ifcfg.Beacon,
listen: ifcfg.Listen,
port: ifcfg.Port,
iface: iface,
beacon: ifcfg.Beacon,
listen: ifcfg.Listen,
port: ifcfg.Port,
priority: ifcfg.Priority,
}
break
}
@ -383,7 +389,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)

View file

@ -15,15 +15,19 @@ func (m *Multicast) _multicastStarted() {
func (m *Multicast) multicastReuse(network string, address string, c syscall.RawConn) error {
var control error
var reuseport error
var reuseaddr error
control = c.Control(func(fd uintptr) {
reuseport = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
// Previously we used SO_REUSEPORT here, but that meant that machines running
// Yggdrasil nodes as different users would inevitably fail with EADDRINUSE.
// The behaviour for multicast is similar with both, so we'll use SO_REUSEADDR
// instead.
reuseaddr = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1)
})
switch {
case reuseport != nil:
return reuseport
case reuseaddr != nil:
return reuseaddr
default:
return control
}

View file

@ -16,10 +16,11 @@ type SetupOption interface {
}
type MulticastInterface struct {
Regex *regexp.Regexp
Beacon bool
Listen bool
Port uint16
Regex *regexp.Regexp
Beacon bool
Listen bool
Port uint16
Priority uint8
}
type GroupAddress string