From e99903bf725de434b76ea3c790afdd2b43e894cb Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 1 Mar 2019 19:26:50 +0000 Subject: [PATCH 1/3] 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 From 12e088ab9e282663d48334b30a27b4975e9bee6d Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 1 Mar 2019 19:34:53 +0000 Subject: [PATCH 2/3] Remove unnecessary Cgo line --- src/yggdrasil/multicast_darwin.go | 1 - 1 file changed, 1 deletion(-) diff --git a/src/yggdrasil/multicast_darwin.go b/src/yggdrasil/multicast_darwin.go index 9c5d0b2d..66c18241 100644 --- a/src/yggdrasil/multicast_darwin.go +++ b/src/yggdrasil/multicast_darwin.go @@ -7,7 +7,6 @@ package yggdrasil #cgo LDFLAGS: -framework Foundation #import void WakeUpAWDL() { - id delegateObject; // Assume this exists. NSNetServiceBrowser *serviceBrowser; serviceBrowser = [[NSNetServiceBrowser alloc] init]; From b401b92a75a8da0fba86d2d2e4b34fb05f097e97 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 2 Mar 2019 00:38:18 +0000 Subject: [PATCH 3/3] Try updating circleci workflow --- .circleci/config.yml | 119 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 107 insertions(+), 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 82a68aad..871d2faf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ # Check https://circleci.com/docs/2.0/language-go/ for more details version: 2 jobs: - build: + build-linux: docker: - image: circleci/golang:1.11 @@ -43,17 +43,97 @@ jobs: sudo alien --to-rpm yggdrasil*.deb --scripts --keep-version && mv *.rpm /tmp/upload/; mv *.deb /tmp/upload/ + - run: + name: Build for EdgeRouter + command: | + rm -f {yggdrasil,yggdrasilctl} + git clone https://github.com/neilalexander/vyatta-yggdrasil /tmp/vyatta-yggdrasil; + cd /tmp/vyatta-yggdrasil; + BUILDDIR_YGG=$CIRCLE_WORKING_DIRECTORY ./build-edgerouter-x $CIRCLE_BRANCH; + BUILDDIR_YGG=$CIRCLE_WORKING_DIRECTORY ./build-edgerouter-lite $CIRCLE_BRANCH; + mv *.deb /tmp/upload; + + - persist_to_workspace: + root: /tmp + paths: + - upload + + build-macos: + macos: + xcode: "10.0.0" + + working_directory: ~/go/src/github.com/yggdrasil-network/yggdrasil-go + + steps: + - checkout + + - run: + name: Create artifact upload directory and set variables + command: | + mkdir /tmp/upload + echo 'export CINAME=$(sh contrib/semver/name.sh)' >> $BASH_ENV + echo 'export CIVERSION=$(sh contrib/semver/version.sh --bare)' >> $BASH_ENV + echo 'export PATH=$PATH:/usr/local/go/bin:~/go/bin' >> $BASH_ENV + git config --global user.email "$(git log --format='%ae' HEAD -1)"; + git config --global user.name "$(git log --format='%an' HEAD -1)"; + echo -e "Host *\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config + + - run: + name: Install Go 1.11 + command: | + cd /tmp + curl -LO https://dl.google.com/go/go1.11.5.darwin-amd64.pkg + sudo installer -pkg /tmp/go1.11.5.darwin-amd64.pkg -target / + + - run: + name: Install Gomobile + command: | + GO111MODULE=off go get golang.org/x/mobile/cmd/gomobile + gomobile init + - run: name: Build for macOS command: | rm -f {yggdrasil,yggdrasilctl} - GOOS=darwin GOARCH=amd64 ./build && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-darwin-amd64 && mv yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-darwin-amd64; + GO111MODULE=on GOOS=darwin GOARCH=amd64 ./build + mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-darwin-amd64 + mv yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-darwin-amd64; - run: name: Build for macOS (.pkg format) command: | rm -rf {yggdrasil,yggdrasilctl} - GOOS=darwin GOARCH=amd64 ./build && PKGARCH=amd64 sh contrib/macos/create-pkg.sh && mv *.pkg /tmp/upload/ + PKGARCH=amd64 sh contrib/macos/create-pkg.sh + mv *.pkg /tmp/upload/ + + #- run: + # name: Build framework for iOS (.framework format) + # command: | + # sudo GO111MODULE=off go get -v github.com/yggdrasil-network/yggdrasil-go/cmd/... + # sudo GO111MODULE=off go get -v github.com/yggdrasil-network/yggdrasil-go/src/... + # GO111MODULE=off ./build -i + # mv *.framework /tmp/upload + + - persist_to_workspace: + root: /tmp + paths: + - upload + + build-other: + docker: + - image: circleci/golang:1.11 + + steps: + - checkout + + - run: + name: Create artifact upload directory and set variables + command: | + mkdir /tmp/upload + echo 'export CINAME=$(sh contrib/semver/name.sh)' >> $BASH_ENV + echo 'export CIVERSION=$(sh contrib/semver/version.sh --bare)' >> $BASH_ENV + git config --global user.email "$(git log --format='%ae' HEAD -1)"; + git config --global user.name "$(git log --format='%an' HEAD -1)"; - run: name: Build for OpenBSD @@ -83,16 +163,31 @@ jobs: GOOS=windows GOARCH=amd64 ./build && mv yggdrasil.exe /tmp/upload/$CINAME-$CIVERSION-windows-amd64.exe && mv yggdrasilctl.exe /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-windows-amd64.exe; GOOS=windows GOARCH=386 ./build && mv yggdrasil.exe /tmp/upload/$CINAME-$CIVERSION-windows-i386.exe && mv yggdrasilctl.exe /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-windows-i386.exe; - - run: - name: Build for EdgeRouter - command: | - rm -f {yggdrasil,yggdrasilctl} - git clone https://github.com/neilalexander/vyatta-yggdrasil /tmp/vyatta-yggdrasil; - cd /tmp/vyatta-yggdrasil; - BUILDDIR_YGG=$CIRCLE_WORKING_DIRECTORY ./build-edgerouter-x $CIRCLE_BRANCH; - BUILDDIR_YGG=$CIRCLE_WORKING_DIRECTORY ./build-edgerouter-lite $CIRCLE_BRANCH; - mv *.deb /tmp/upload; + - persist_to_workspace: + root: /tmp + paths: + - upload + + upload: + machine: true + + steps: + - attach_workspace: + at: /tmp - store_artifacts: path: /tmp/upload destination: / + +workflows: + version: 2 + build-all: + jobs: + - build-linux + - build-macos + - build-other + - upload: + requires: + - build-linux + - build-macos + - build-other