From d0c2ce90bbf194995f331003f10852a29872f49f Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 7 Dec 2018 22:03:57 +0000 Subject: [PATCH 1/8] Fix semver when git history is not present --- contrib/semver/name.sh | 4 ++-- contrib/semver/version.sh | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/contrib/semver/name.sh b/contrib/semver/name.sh index d749d3ff..9dbdca33 100644 --- a/contrib/semver/name.sh +++ b/contrib/semver/name.sh @@ -1,10 +1,10 @@ #!/bin/sh # Get the branch name, removing any "/" characters from pull requests -BRANCH=$(git symbolic-ref --short HEAD | tr -d "/" 2>/dev/null) +BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null | tr -d "/") # Check if the branch name is not master -if [ "$BRANCH" = "master" ]; then +if [ "$BRANCH" = "master" ] || [ $? != 0 ]; then printf "yggdrasil" exit 0 fi diff --git a/contrib/semver/version.sh b/contrib/semver/version.sh index 6eeffc5f..c23abf41 100644 --- a/contrib/semver/version.sh +++ b/contrib/semver/version.sh @@ -16,6 +16,11 @@ PATCH=$(git rev-list $TAG..master --count --merges --grep="from $DEVELOPBRANCH" if [ $? != 0 ]; then PATCH=$(git rev-list HEAD --count 2>/dev/null) + if [ $? != 0 ]; then + printf 'unknown' + exit -1 + fi + printf 'v0.0.%d' "$PATCH" exit -1 fi From 8bd566d4d8bb35ad47b414574d2315ed17ec6a3b Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 7 Dec 2018 22:05:36 +0000 Subject: [PATCH 2/8] Remove VERSION --- VERSION | 1 - 1 file changed, 1 deletion(-) delete mode 100644 VERSION diff --git a/VERSION b/VERSION deleted file mode 100644 index 3b04cfb6..00000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.2 From 4bc009d8457f40dfaef4addc23bf9baabe1f360a Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 7 Dec 2018 22:17:09 +0000 Subject: [PATCH 3/8] Update semver behaviour --- contrib/semver/name.sh | 15 ++++++++++++--- contrib/semver/version.sh | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/contrib/semver/name.sh b/contrib/semver/name.sh index 9dbdca33..9cab7e96 100644 --- a/contrib/semver/name.sh +++ b/contrib/semver/name.sh @@ -1,10 +1,19 @@ #!/bin/sh -# Get the branch name, removing any "/" characters from pull requests -BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null | tr -d "/") +# Get the current branch name +BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null) + +# Complain if the git history is not available +if [ $? != 0 ]; then + printf "unknown" + exit -1 +fi + +# Remove "/" characters from the branch name if present +BRANCH=$(echo $BRANCH | tr -d "/") # Check if the branch name is not master -if [ "$BRANCH" = "master" ] || [ $? != 0 ]; then +if [ "$BRANCH" = "master" ]; then printf "yggdrasil" exit 0 fi diff --git a/contrib/semver/version.sh b/contrib/semver/version.sh index c23abf41..f7769a34 100644 --- a/contrib/semver/version.sh +++ b/contrib/semver/version.sh @@ -16,6 +16,7 @@ PATCH=$(git rev-list $TAG..master --count --merges --grep="from $DEVELOPBRANCH" if [ $? != 0 ]; then PATCH=$(git rev-list HEAD --count 2>/dev/null) + # Complain if the git history is not available if [ $? != 0 ]; then printf 'unknown' exit -1 From 8e784438c7ebb77eb903c964192012d8a0826d02 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 7 Dec 2018 22:20:11 +0000 Subject: [PATCH 4/8] Imprint build name and version number if available --- build | 5 +++-- src/yggdrasil/core.go | 21 +++++++++++++++++++++ yggdrasil.go | 5 +++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/build b/build index c07e5eac..2e7c20cc 100755 --- a/build +++ b/build @@ -14,10 +14,11 @@ 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)" if [ $DEBUG ]; then - go build -tags debug -v $file + go build -ldflags="$IMPRINT" -tags debug -v $file else - go build -ldflags="-s -w" -v $file + go build -ldflags="$IMPRINT -s -w" -v $file fi if [ $UPX ]; then upx --brute ${file%.go} diff --git a/src/yggdrasil/core.go b/src/yggdrasil/core.go index 706b8aa3..54f1820c 100644 --- a/src/yggdrasil/core.go +++ b/src/yggdrasil/core.go @@ -12,6 +12,9 @@ import ( "yggdrasil/defaults" ) +var buildName string +var buildVersion string + // The Core object represents the Yggdrasil node. You should create a Core // object for each Yggdrasil node you plan to run. type Core struct { @@ -59,6 +62,24 @@ func (c *Core) init(bpub *boxPubKey, c.tun.init(c) } +// Get the current build name. This is usually injected if built from git, +// or returns "unknown" otherwise. +func GetBuildName() string { + if buildName == "" { + return "unknown" + } + return buildName +} + +// Get the current build version. This is usually injected if built from git, +// or returns "unknown" otherwise. +func GetBuildVersion() string { + if buildVersion == "" { + return "unknown" + } + return buildVersion +} + // Starts up Yggdrasil using the provided NodeConfig, and outputs debug logging // through the provided log.Logger. The started stack will include TCP and UDP // sockets, a multicast discovery socket, an admin socket, router, switch and diff --git a/yggdrasil.go b/yggdrasil.go index 5244a8ec..d326d18e 100644 --- a/yggdrasil.go +++ b/yggdrasil.go @@ -100,10 +100,15 @@ func main() { normaliseconf := flag.Bool("normaliseconf", false, "use in combination with either -useconf or -useconffile, outputs your configuration normalised") confjson := flag.Bool("json", false, "print configuration from -genconf or -normaliseconf as JSON instead of HJSON") autoconf := flag.Bool("autoconf", false, "automatic mode (dynamic IP, peer with IPv6 neighbors)") + version := flag.Bool("version", false, "prints the version of this build") flag.Parse() var cfg *nodeConfig switch { + case *version: + fmt.Println("Build name:", yggdrasil.GetBuildName()) + fmt.Println("Build version:", yggdrasil.GetBuildVersion()) + os.Exit(0) case *autoconf: // Use an autoconf-generated config, this will give us random keys and // port numbers, and will use an automatically selected TUN/TAP interface. From 3524c6eff617ede773ee83dce1d50a2601088846 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 7 Dec 2018 22:22:46 +0000 Subject: [PATCH 5/8] Add build name and version to getSelf call on admin socket --- src/yggdrasil/admin.go | 2 ++ yggdrasilctl.go | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index 2b5bc645..af59734e 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -556,6 +556,8 @@ func (a *admin) getData_getSelf() *admin_nodeInfo { table := a.core.switchTable.table.Load().(lookupTable) coords := table.self.getCoords() self := admin_nodeInfo{ + {"build_name", GetBuildName()}, + {"build_version", GetBuildVersion()}, {"box_pub_key", hex.EncodeToString(a.core.boxPub[:])}, {"ip", a.core.GetAddress().String()}, {"subnet", a.core.GetSubnet().String()}, diff --git a/yggdrasilctl.go b/yggdrasilctl.go index 79b5f86d..6919ec33 100644 --- a/yggdrasilctl.go +++ b/yggdrasilctl.go @@ -181,6 +181,12 @@ func main() { } case "getself": for k, v := range res["self"].(map[string]interface{}) { + if buildname, ok := v.(map[string]interface{})["build_name"].(string); ok { + fmt.Println("Build name:", buildname) + } + if buildversion, ok := v.(map[string]interface{})["build_version"].(string); ok { + fmt.Println("Build version:", buildversion) + } fmt.Println("IPv6 address:", k) if subnet, ok := v.(map[string]interface{})["subnet"].(string); ok { fmt.Println("IPv6 subnet:", subnet) From 5149c6c349d6540772799259c6a0e30a3aa66f33 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 7 Dec 2018 22:24:01 +0000 Subject: [PATCH 6/8] Show build name and version at startup if available --- src/yggdrasil/core.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/yggdrasil/core.go b/src/yggdrasil/core.go index 54f1820c..b57bd863 100644 --- a/src/yggdrasil/core.go +++ b/src/yggdrasil/core.go @@ -86,6 +86,14 @@ func GetBuildVersion() string { // DHT node. func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) error { c.log = log + + if buildName != "" { + c.log.Println("Build name:", buildName) + } + if buildVersion != "" { + c.log.Println("Build version:", buildVersion) + } + c.log.Println("Starting up...") var boxPub boxPubKey From f99c2241719e74b175abf5af74cdf938d78c034d Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 7 Dec 2018 22:31:37 +0000 Subject: [PATCH 7/8] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b91caca4..fa5d08dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - New macOS .pkgs built automatically by CircleCI - Add Docker support - Add `-json` command line flag for generating and normalising configuration in plain JSON +- Build nae and version numbers are now imprinted onto the build, accessible through `yggdrasil -version` and `yggdrasilctl getSelf` ### Changed - Switched to Chord DHT (instead of Kademlia, although protocol-compatible) From ffbdef292f3c2638263b6f5d4bfb3a46ac8fd92e Mon Sep 17 00:00:00 2001 From: Arceliar Date: Fri, 7 Dec 2018 17:30:07 -0600 Subject: [PATCH 8/8] Fix typo in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa5d08dc..1791bb74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - New macOS .pkgs built automatically by CircleCI - Add Docker support - Add `-json` command line flag for generating and normalising configuration in plain JSON -- Build nae and version numbers are now imprinted onto the build, accessible through `yggdrasil -version` and `yggdrasilctl getSelf` +- Build name and version numbers are now imprinted onto the build, accessible through `yggdrasil -version` and `yggdrasilctl getSelf` ### Changed - Switched to Chord DHT (instead of Kademlia, although protocol-compatible)