5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-23 00:51:35 +00:00

Wake up AWDL on Darwin if awdl0 is an enabled multicast interface

This commit is contained in:
Neil Alexander 2019-03-01 19:26:50 +00:00
parent 58757bb955
commit e99903bf72
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
5 changed files with 41 additions and 5 deletions

View File

@ -50,7 +50,7 @@ func (m *multicast) start() error {
} }
listenString := fmt.Sprintf("[::]:%v", addr.Port) listenString := fmt.Sprintf("[::]:%v", addr.Port)
lc := net.ListenConfig{ lc := net.ListenConfig{
Control: multicastReuse, Control: m.multicastReuse,
} }
conn, err := lc.ListenPacket(context.Background(), "udp6", listenString) conn, err := lc.ListenPacket(context.Background(), "udp6", listenString)
if err != nil { 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 // Windows can't set this flag, so we need to handle it in other ways
} }
m.multicastWake()
go m.listen() go m.listen()
go m.announce() go m.announce()
} }

View File

@ -2,10 +2,33 @@
package yggdrasil package yggdrasil
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation
#import <Foundation/Foundation.h>
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 "syscall"
import "golang.org/x/sys/unix" 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 control error
var reuseport error var reuseport error
var recvanyif error var recvanyif error

View File

@ -4,6 +4,10 @@ package yggdrasil
import "syscall" 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 return nil
} }

View File

@ -5,7 +5,11 @@ package yggdrasil
import "syscall" import "syscall"
import "golang.org/x/sys/unix" 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 control error
var reuseport error var reuseport error

View File

@ -5,7 +5,11 @@ package yggdrasil
import "syscall" import "syscall"
import "golang.org/x/sys/windows" 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 control error
var reuseaddr error var reuseaddr error