mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
Merge pull request #350 from neilalexander/awdl
Wake AWDL for multicast peering on macOS
This commit is contained in:
commit
3c733eadb4
6 changed files with 147 additions and 17 deletions
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -2,10 +2,32 @@
|
|||
|
||||
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;
|
||||
[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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue