From e99903bf725de434b76ea3c790afdd2b43e894cb Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 1 Mar 2019 19:26:50 +0000 Subject: [PATCH] Wake up AWDL on Darwin if awdl0 is an enabled multicast interface --- src/yggdrasil/multicast.go | 3 ++- src/yggdrasil/multicast_darwin.go | 25 ++++++++++++++++++++++++- src/yggdrasil/multicast_other.go | 6 +++++- src/yggdrasil/multicast_unix.go | 6 +++++- src/yggdrasil/multicast_windows.go | 6 +++++- 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/yggdrasil/multicast.go b/src/yggdrasil/multicast.go index 42651deb..b20ee94d 100644 --- a/src/yggdrasil/multicast.go +++ b/src/yggdrasil/multicast.go @@ -50,7 +50,7 @@ func (m *multicast) start() error { } listenString := fmt.Sprintf("[::]:%v", addr.Port) lc := net.ListenConfig{ - Control: multicastReuse, + Control: m.multicastReuse, } conn, err := lc.ListenPacket(context.Background(), "udp6", listenString) if err != nil { @@ -61,6 +61,7 @@ func (m *multicast) start() error { // Windows can't set this flag, so we need to handle it in other ways } + m.multicastWake() go m.listen() go m.announce() } diff --git a/src/yggdrasil/multicast_darwin.go b/src/yggdrasil/multicast_darwin.go index 71eecce4..9c5d0b2d 100644 --- a/src/yggdrasil/multicast_darwin.go +++ b/src/yggdrasil/multicast_darwin.go @@ -2,10 +2,33 @@ package yggdrasil +/* +#cgo CFLAGS: -x objective-c +#cgo LDFLAGS: -framework Foundation +#import +void WakeUpAWDL() { + id delegateObject; // Assume this exists. + NSNetServiceBrowser *serviceBrowser; + + serviceBrowser = [[NSNetServiceBrowser alloc] init]; + serviceBrowser.includesPeerToPeer = YES; + [serviceBrowser searchForServicesOfType:@"_yggdrasil._tcp" inDomain:@""]; +} +*/ +import "C" import "syscall" import "golang.org/x/sys/unix" -func multicastReuse(network string, address string, c syscall.RawConn) error { +func (m *multicast) multicastWake() { + for _, intf := range m.interfaces() { + if intf.Name == "awdl0" { + m.core.log.Infoln("Multicast discovery is waking up AWDL") + C.WakeUpAWDL() + } + } +} + +func (m *multicast) multicastReuse(network string, address string, c syscall.RawConn) error { var control error var reuseport error var recvanyif error diff --git a/src/yggdrasil/multicast_other.go b/src/yggdrasil/multicast_other.go index 8a4ce56c..043dd3ae 100644 --- a/src/yggdrasil/multicast_other.go +++ b/src/yggdrasil/multicast_other.go @@ -4,6 +4,10 @@ package yggdrasil import "syscall" -func multicastReuse(network string, address string, c syscall.RawConn) error { +func (m *multicast) multicastWake() { + +} + +func (m *multicast) multicastReuse(network string, address string, c syscall.RawConn) error { return nil } diff --git a/src/yggdrasil/multicast_unix.go b/src/yggdrasil/multicast_unix.go index 54bbc645..4237481c 100644 --- a/src/yggdrasil/multicast_unix.go +++ b/src/yggdrasil/multicast_unix.go @@ -5,7 +5,11 @@ package yggdrasil import "syscall" import "golang.org/x/sys/unix" -func multicastReuse(network string, address string, c syscall.RawConn) error { +func (m *multicast) multicastWake() { + +} + +func (m *multicast) multicastReuse(network string, address string, c syscall.RawConn) error { var control error var reuseport error diff --git a/src/yggdrasil/multicast_windows.go b/src/yggdrasil/multicast_windows.go index 13f20315..14c93129 100644 --- a/src/yggdrasil/multicast_windows.go +++ b/src/yggdrasil/multicast_windows.go @@ -5,7 +5,11 @@ package yggdrasil import "syscall" import "golang.org/x/sys/windows" -func multicastReuse(network string, address string, c syscall.RawConn) error { +func (m *multicast) multicastWake() { + +} + +func (m *multicast) multicastReuse(network string, address string, c syscall.RawConn) error { var control error var reuseaddr error