diff --git a/.circleci/config.yml b/.circleci/config.yml index 90bba23b..32a789c2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,8 +7,6 @@ jobs: docker: - image: circleci/golang:1.11 - working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}} - steps: - checkout diff --git a/CHANGELOG.md b/CHANGELOG.md index 1791bb74..cc31b965 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Admin socket clean-up (making some names consistent) - Latency-based parent selection for the switch instead of uptime-based - Real peering endpoints now shown in the admin socket `getPeers` call +- Reuse the multicast port on supported platforms so that multiple Yggdrasil processes can run ### Fixed - Memory leaks in the DHT fixed diff --git a/README.md b/README.md index 15731952..11a4cbe5 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ You're encouraged to play with it, but it is strongly advised not to use it for ## Building -1. Install Go (tested on 1.9+, [godeb](https://github.com/niemeyer/godeb) is recommended for debian-based linux distributions). +1. Install Go (requires 1.11 or later, [godeb](https://github.com/niemeyer/godeb) is recommended for Debian-based Linux distributions). 2. Clone this repository. 2. `./build` diff --git a/build b/build index 2e7c20cc..a62c92d4 100755 --- a/build +++ b/build @@ -7,20 +7,16 @@ do d) DEBUG=true;; esac done -export GOPATH=$PWD echo "Downloading..." -go get -d -v -go get -d -v yggdrasil -for file in *.go ; do - echo "Building: $file" - #go build $@ $file - IMPRINT="-X yggdrasil.buildName=$(sh contrib/semver/name.sh) -X yggdrasil.buildVersion=$(sh contrib/semver/version.sh)" +for CMD in `ls cmd/` ; do + echo "Building: $CMD" + IMPRINT="-X github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil.buildName=$(sh contrib/semver/name.sh) -X github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil.buildVersion=$(sh contrib/semver/version.sh)" if [ $DEBUG ]; then - go build -ldflags="$IMPRINT" -tags debug -v $file + go build -ldflags="$IMPRINT" -tags debug -v ./cmd/$CMD else - go build -ldflags="$IMPRINT -s -w" -v $file + go build -ldflags="$IMPRINT -s -w" -v ./cmd/$CMD fi if [ $UPX ]; then - upx --brute ${file%.go} + upx --brute $CMD fi done diff --git a/yggdrasil.go b/cmd/yggdrasil/main.go similarity index 98% rename from yggdrasil.go rename to cmd/yggdrasil/main.go index d326d18e..5b756908 100644 --- a/yggdrasil.go +++ b/cmd/yggdrasil/main.go @@ -21,9 +21,9 @@ import ( "github.com/mitchellh/mapstructure" "github.com/neilalexander/hjson-go" - "yggdrasil" - "yggdrasil/config" - "yggdrasil/defaults" + "github.com/yggdrasil-network/yggdrasil-go/src/config" + "github.com/yggdrasil-network/yggdrasil-go/src/defaults" + "github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil" ) type nodeConfig = config.NodeConfig diff --git a/yggdrasilctl.go b/cmd/yggdrasilctl/main.go similarity index 98% rename from yggdrasilctl.go rename to cmd/yggdrasilctl/main.go index 6919ec33..ca3078b1 100644 --- a/yggdrasilctl.go +++ b/cmd/yggdrasilctl/main.go @@ -1,17 +1,19 @@ package main -import "errors" -import "flag" -import "fmt" -import "strings" -import "net" -import "net/url" -import "sort" -import "encoding/json" -import "strconv" -import "os" +import ( + "encoding/json" + "errors" + "flag" + "fmt" + "net" + "net/url" + "os" + "sort" + "strconv" + "strings" -import "yggdrasil/defaults" + "github.com/yggdrasil-network/yggdrasil-go/src/defaults" +) type admin_info map[string]interface{} diff --git a/contrib/.DS_Store b/contrib/.DS_Store deleted file mode 100644 index 799616ae..00000000 Binary files a/contrib/.DS_Store and /dev/null differ diff --git a/contrib/config/yggdrasilconf.go b/contrib/config/yggdrasilconf.go index bc6e1326..78c0e6d7 100644 --- a/contrib/config/yggdrasilconf.go +++ b/contrib/config/yggdrasilconf.go @@ -17,7 +17,7 @@ import ( "github.com/neilalexander/hjson-go" "golang.org/x/text/encoding/unicode" - "yggdrasil/config" + "github.com/yggdrasil-network/yggdrasil-go/src/config" ) type nodeConfig = config.NodeConfig diff --git a/contrib/deb/generate.sh b/contrib/deb/generate.sh index 9d5064bd..f99d8348 100644 --- a/contrib/deb/generate.sh +++ b/contrib/deb/generate.sh @@ -7,7 +7,7 @@ if [ `pwd` != `git rev-parse --show-toplevel` ] then echo "You should run this script from the top-level directory of the git repo" - exit -1 + exit 1 fi PKGBRANCH=$(basename `git name-rev --name-only HEAD`) @@ -29,7 +29,7 @@ elif [ $PKGARCH = "armhf" ]; then GOARCH=arm GOOS=linux GOARM=7 ./build elif [ $PKGARCH = "arm64" ]; then GOARCH=arm64 GOOS=linux ./build else echo "Specify PKGARCH=amd64,i386,mips,mipsel,armhf,arm64" - exit -1 + exit 1 fi echo "Building $PKGFILE" diff --git a/contrib/semver/name.sh b/contrib/semver/name.sh index 9cab7e96..935cc750 100644 --- a/contrib/semver/name.sh +++ b/contrib/semver/name.sh @@ -6,7 +6,7 @@ BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null) # Complain if the git history is not available if [ $? != 0 ]; then printf "unknown" - exit -1 + exit 1 fi # Remove "/" characters from the branch name if present diff --git a/contrib/semver/version.sh b/contrib/semver/version.sh index f7769a34..143bd906 100644 --- a/contrib/semver/version.sh +++ b/contrib/semver/version.sh @@ -19,11 +19,11 @@ if [ $? != 0 ]; then # Complain if the git history is not available if [ $? != 0 ]; then printf 'unknown' - exit -1 + exit 1 fi printf 'v0.0.%d' "$PATCH" - exit -1 + exit 1 fi # Get the number of merges on the current branch since the last tag diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..1622ad40 --- /dev/null +++ b/go.mod @@ -0,0 +1,14 @@ +module github.com/yggdrasil-network/yggdrasil-go + +require ( + github.com/docker/libcontainer v2.2.1+incompatible + github.com/kardianos/minwinsvc v0.0.0-20151122163309-cad6b2b879b0 + github.com/mitchellh/mapstructure v1.1.2 + github.com/neilalexander/hjson-go v3.0.0+incompatible + github.com/songgao/packets v0.0.0-20160404182456-549a10cd4091 + github.com/yggdrasil-network/water v0.0.0-20180615095340-f732c88f34ae + golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 + golang.org/x/net v0.0.0-20181207154023-610586996380 + golang.org/x/sys v0.0.0-20181206074257-70b957f3b65e + golang.org/x/text v0.3.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..2c8b145d --- /dev/null +++ b/go.sum @@ -0,0 +1,20 @@ +github.com/docker/libcontainer v2.2.1+incompatible h1:++SbbkCw+X8vAd4j2gOCzZ2Nn7s2xFALTf7LZKmM1/0= +github.com/docker/libcontainer v2.2.1+incompatible/go.mod h1:osvj61pYsqhNCMLGX31xr7klUBhHb/ZBuXS0o1Fvwbw= +github.com/kardianos/minwinsvc v0.0.0-20151122163309-cad6b2b879b0 h1:YnZmFjg0Nvk8851WTVWlqMC1ecJH07Ctz+Ezxx4u54g= +github.com/kardianos/minwinsvc v0.0.0-20151122163309-cad6b2b879b0/go.mod h1:rUi0/YffDo1oXBOGn1KRq7Fr07LX48XEBecQnmwjsAo= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/neilalexander/hjson-go v3.0.0+incompatible h1:MRqki7QoLwAe9kD12DF4yy6r04KKxvjBcMGvVGNNQ8g= +github.com/neilalexander/hjson-go v3.0.0+incompatible/go.mod h1:l+Zao6IpQ+6d/y7LnYnOfbfOeU/9xRiTi4HLVpnkcTg= +github.com/songgao/packets v0.0.0-20160404182456-549a10cd4091 h1:1zN6ImoqhSJhN8hGXFaJlSC8msLmIbX8bFqOfWLKw0w= +github.com/songgao/packets v0.0.0-20160404182456-549a10cd4091/go.mod h1:N20Z5Y8oye9a7HmytmZ+tr8Q2vlP0tAHP13kTHzwvQY= +github.com/yggdrasil-network/water v0.0.0-20180615095340-f732c88f34ae h1:MYCANF1kehCG6x6G+/9txLfq6n3lS5Vp0Mxn1hdiBAc= +github.com/yggdrasil-network/water v0.0.0-20180615095340-f732c88f34ae/go.mod h1:R0SBCsugm+Sf1katgTb2t7GXMm+nRIv43tM4VDZbaOs= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/net v0.0.0-20181207154023-610586996380 h1:zPQexyRtNYBc7bcHmehl1dH6TB3qn8zytv8cBGLDNY0= +golang.org/x/net v0.0.0-20181207154023-610586996380/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/sys v0.0.0-20181206074257-70b957f3b65e h1:njOxP/wVblhCLIUhjHXf6X+dzTt5OQ3vMQo9mkOIKIo= +golang.org/x/sys v0.0.0-20181206074257-70b957f3b65e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/misc/genkeys.go b/misc/genkeys.go index 6e2df3f9..e995805f 100644 --- a/misc/genkeys.go +++ b/misc/genkeys.go @@ -16,7 +16,7 @@ import "encoding/hex" import "flag" import "fmt" import "runtime" -import . "yggdrasil" +import . "github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil" var doSig = flag.Bool("sig", false, "generate new signing keys instead") diff --git a/misc/sim/run-sim b/misc/sim/run-sim index abe108cf..14057e81 100755 --- a/misc/sim/run-sim +++ b/misc/sim/run-sim @@ -1,4 +1,2 @@ #!/bin/bash -export GOPATH=$PWD -go get -d yggdrasil go run -tags debug misc/sim/treesim.go "$@" diff --git a/misc/sim/treesim.go b/misc/sim/treesim.go index 8a4bb2a1..f4cd75fa 100644 --- a/misc/sim/treesim.go +++ b/misc/sim/treesim.go @@ -12,7 +12,7 @@ import "runtime" import "runtime/pprof" import "flag" -import . "yggdrasil" +import . "github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil" //////////////////////////////////////////////////////////////////////////////// diff --git a/src/yggdrasil/config/config.go b/src/config/config.go similarity index 100% rename from src/yggdrasil/config/config.go rename to src/config/config.go diff --git a/src/yggdrasil/config/i2p.go b/src/config/i2p.go similarity index 100% rename from src/yggdrasil/config/i2p.go rename to src/config/i2p.go diff --git a/src/yggdrasil/config/tor.go b/src/config/tor.go similarity index 100% rename from src/yggdrasil/config/tor.go rename to src/config/tor.go diff --git a/src/yggdrasil/defaults/defaults.go b/src/defaults/defaults.go similarity index 100% rename from src/yggdrasil/defaults/defaults.go rename to src/defaults/defaults.go diff --git a/src/yggdrasil/defaults/defaults_darwin.go b/src/defaults/defaults_darwin.go similarity index 100% rename from src/yggdrasil/defaults/defaults_darwin.go rename to src/defaults/defaults_darwin.go diff --git a/src/yggdrasil/defaults/defaults_freebsd.go b/src/defaults/defaults_freebsd.go similarity index 100% rename from src/yggdrasil/defaults/defaults_freebsd.go rename to src/defaults/defaults_freebsd.go diff --git a/src/yggdrasil/defaults/defaults_linux.go b/src/defaults/defaults_linux.go similarity index 100% rename from src/yggdrasil/defaults/defaults_linux.go rename to src/defaults/defaults_linux.go diff --git a/src/yggdrasil/defaults/defaults_netbsd.go b/src/defaults/defaults_netbsd.go similarity index 100% rename from src/yggdrasil/defaults/defaults_netbsd.go rename to src/defaults/defaults_netbsd.go diff --git a/src/yggdrasil/defaults/defaults_openbsd.go b/src/defaults/defaults_openbsd.go similarity index 100% rename from src/yggdrasil/defaults/defaults_openbsd.go rename to src/defaults/defaults_openbsd.go diff --git a/src/yggdrasil/defaults/defaults_other.go b/src/defaults/defaults_other.go similarity index 100% rename from src/yggdrasil/defaults/defaults_other.go rename to src/defaults/defaults_other.go diff --git a/src/yggdrasil/defaults/defaults_windows.go b/src/defaults/defaults_windows.go similarity index 100% rename from src/yggdrasil/defaults/defaults_windows.go rename to src/defaults/defaults_windows.go diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index af59734e..7d82b135 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -14,7 +14,7 @@ import ( "sync/atomic" "time" - "yggdrasil/defaults" + "github.com/yggdrasil-network/yggdrasil-go/src/defaults" ) // TODO: Add authentication @@ -739,6 +739,10 @@ func (a *admin) admin_dhtPing(keyString, coordString, targetString string) (dhtR } var coords []byte for _, cstr := range strings.Split(strings.Trim(coordString, "[]"), " ") { + if cstr == "" { + // Special case, happens if trimmed is the empty string, e.g. this is the root + continue + } if u64, err := strconv.ParseUint(cstr, 10, 8); err != nil { return dhtRes{}, err } else { diff --git a/src/yggdrasil/core.go b/src/yggdrasil/core.go index b57bd863..682d815e 100644 --- a/src/yggdrasil/core.go +++ b/src/yggdrasil/core.go @@ -8,8 +8,8 @@ import ( "net" "regexp" - "yggdrasil/config" - "yggdrasil/defaults" + "github.com/yggdrasil-network/yggdrasil-go/src/config" + "github.com/yggdrasil-network/yggdrasil-go/src/defaults" ) var buildName string diff --git a/src/yggdrasil/debug.go b/src/yggdrasil/debug.go index 7da84749..e463518d 100644 --- a/src/yggdrasil/debug.go +++ b/src/yggdrasil/debug.go @@ -22,7 +22,7 @@ import "net/http" import "runtime" import "os" -import "yggdrasil/defaults" +import "github.com/yggdrasil-network/yggdrasil-go/src/defaults" // Start the profiler in debug builds, if the required environment variable is set. func init() { diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index 920926b4..99ed25b4 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -268,7 +268,7 @@ func (t *switchTable) forgetPeer(port switchPort) { // Clean all unresponsive peers from the table, needed in case a peer stops updating. // Needed in case a non-parent peer keeps the connection open but stops sending updates. // Also reclaims space from deleted peers by copying the map. -func (t switchTable) cleanPeers() { +func (t *switchTable) cleanPeers() { now := time.Now() for port, peer := range t.data.peers { if now.Sub(peer.time) > switch_timeout+switch_throttle { diff --git a/src/yggdrasil/tun.go b/src/yggdrasil/tun.go index 4b3617c0..e4625020 100644 --- a/src/yggdrasil/tun.go +++ b/src/yggdrasil/tun.go @@ -6,10 +6,11 @@ import ( "bytes" "errors" "time" - "yggdrasil/defaults" "github.com/songgao/packets/ethernet" "github.com/yggdrasil-network/water" + + "github.com/yggdrasil-network/yggdrasil-go/src/defaults" ) const tun_IPv6_HEADER_LENGTH = 40