Merge pull request #377 from neilalexander/awdl-fixes

AWDL fixes for macOS
This commit is contained in:
Neil Alexander 2019-03-10 18:08:30 +00:00 committed by GitHub
commit c48cbfa78b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 16 deletions

View File

@ -57,7 +57,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.multicastStarted()
go m.listen()
go m.announce()
}

View File

@ -6,24 +6,46 @@ package yggdrasil
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation
#import <Foundation/Foundation.h>
void WakeUpAWDL() {
NSNetServiceBrowser *serviceBrowser;
serviceBrowser = [[NSNetServiceBrowser alloc] init];
serviceBrowser.includesPeerToPeer = YES;
NSNetServiceBrowser *serviceBrowser;
void StartAWDLBrowsing() {
if (serviceBrowser == nil) {
serviceBrowser = [[NSNetServiceBrowser alloc] init];
serviceBrowser.includesPeerToPeer = YES;
}
[serviceBrowser searchForServicesOfType:@"_yggdrasil._tcp" inDomain:@""];
}
void StopAWDLBrowsing() {
if (serviceBrowser == nil) {
return;
}
[serviceBrowser stop];
}
*/
import "C"
import "syscall"
import "golang.org/x/sys/unix"
import (
"syscall"
"time"
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()
"golang.org/x/sys/unix"
)
var awdlGoroutineStarted bool
func (m *multicast) multicastStarted() {
if awdlGoroutineStarted {
return
}
m.core.log.Infoln("Multicast discovery will wake up AWDL if required")
awdlGoroutineStarted = true
for {
C.StopAWDLBrowsing()
for _, intf := range m.interfaces() {
if intf.Name == "awdl0" {
C.StartAWDLBrowsing()
break
}
}
time.Sleep(time.Minute)
}
}

View File

@ -4,7 +4,7 @@ package yggdrasil
import "syscall"
func (m *multicast) multicastWake() {
func (m *multicast) multicastStarted() {
}

View File

@ -5,7 +5,7 @@ package yggdrasil
import "syscall"
import "golang.org/x/sys/unix"
func (m *multicast) multicastWake() {
func (m *multicast) multicastStarted() {
}

View File

@ -5,7 +5,7 @@ package yggdrasil
import "syscall"
import "golang.org/x/sys/windows"
func (m *multicast) multicastWake() {
func (m *multicast) multicastStarted() {
}