From 7f9d4f3f6d06262e212a8dd101d51fda134332da Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 28 Oct 2023 18:21:26 +0100 Subject: [PATCH 1/2] Don't import `LDFLAGS` from the environment --- build | 2 +- contrib/deb/generate.sh | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build b/build index de5d9edca..c72144388 100755 --- a/build +++ b/build @@ -6,7 +6,7 @@ PKGSRC=${PKGSRC:-github.com/yggdrasil-network/yggdrasil-go/src/version} PKGNAME=${PKGNAME:-$(sh contrib/semver/name.sh)} PKGVER=${PKGVER:-$(sh contrib/semver/version.sh --bare)} -LDFLAGS="${LDFLAGS} -X $PKGSRC.buildName=$PKGNAME -X $PKGSRC.buildVersion=$PKGVER" +LDFLAGS="-X $PKGSRC.buildName=$PKGNAME -X $PKGSRC.buildVersion=$PKGVER" ARGS="-v" while getopts "utc:l:dro:p" option diff --git a/contrib/deb/generate.sh b/contrib/deb/generate.sh index 69eaa764c..8d39eb1dc 100644 --- a/contrib/deb/generate.sh +++ b/contrib/deb/generate.sh @@ -21,16 +21,16 @@ if [ $PKGBRANCH = "master" ]; then PKGREPLACES=yggdrasil-develop fi -export LDFLAGS="-X github.com/yggdrasil-network/yggdrasil-go/src/config.defaultConfig=/etc/yggdrasil/yggdrasil.conf" -export LDFLAGS="${LDFLAGS} -X github.com/yggdrasil-network/yggdrasil-go/src/config.defaultAdminListen=unix:///var/run/yggdrasil/yggdrasil.sock" - -if [ $PKGARCH = "amd64" ]; then GOARCH=amd64 GOOS=linux ./build -elif [ $PKGARCH = "i386" ]; then GOARCH=386 GOOS=linux ./build -elif [ $PKGARCH = "mipsel" ]; then GOARCH=mipsle GOOS=linux ./build -elif [ $PKGARCH = "mips" ]; then GOARCH=mips64 GOOS=linux ./build -elif [ $PKGARCH = "armhf" ]; then GOARCH=arm GOOS=linux GOARM=6 ./build -elif [ $PKGARCH = "arm64" ]; then GOARCH=arm64 GOOS=linux ./build -elif [ $PKGARCH = "armel" ]; then GOARCH=arm GOOS=linux GOARM=5 ./build +GOLDFLAGS="-X github.com/yggdrasil-network/yggdrasil-go/src/config.defaultConfig=/etc/yggdrasil/yggdrasil.conf" +GOLDFLAGS="${GOLDFLAGS} -X github.com/yggdrasil-network/yggdrasil-go/src/config.defaultAdminListen=unix:///var/run/yggdrasil/yggdrasil.sock" + +if [ $PKGARCH = "amd64" ]; then GOARCH=amd64 GOOS=linux ./build -l "${GOLDFLAGS}" +elif [ $PKGARCH = "i386" ]; then GOARCH=386 GOOS=linux ./build -l "${GOLDFLAGS}" +elif [ $PKGARCH = "mipsel" ]; then GOARCH=mipsle GOOS=linux ./build -l "${GOLDFLAGS}" +elif [ $PKGARCH = "mips" ]; then GOARCH=mips64 GOOS=linux ./build -l "${GOLDFLAGS}" +elif [ $PKGARCH = "armhf" ]; then GOARCH=arm GOOS=linux GOARM=6 ./build -l "${GOLDFLAGS}" +elif [ $PKGARCH = "arm64" ]; then GOARCH=arm64 GOOS=linux ./build -l "${GOLDFLAGS}" +elif [ $PKGARCH = "armel" ]; then GOARCH=arm GOOS=linux GOARM=5 ./build -l "${GOLDFLAGS}" else echo "Specify PKGARCH=amd64,i386,mips,mipsel,armhf,arm64,armel" exit 1 From e41b838d8f119b4c71f7a27995c5a941185164c5 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 28 Oct 2023 21:28:38 +0100 Subject: [PATCH 2/2] Don't panic at startup when duplicate peers are configured Fixes #1077 --- src/core/options.go | 10 +++++++++- src/core/options_test.go | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/core/options_test.go diff --git a/src/core/options.go b/src/core/options.go index ffbdae73c..581c033b7 100644 --- a/src/core/options.go +++ b/src/core/options.go @@ -13,7 +13,15 @@ func (c *Core) _applyOption(opt SetupOption) (err error) { if err != nil { return fmt.Errorf("unable to parse peering URI: %w", err) } - return c.links.add(u, v.SourceInterface, linkTypePersistent) + err = c.links.add(u, v.SourceInterface, linkTypePersistent) + switch err { + case ErrLinkAlreadyConfigured: + // Don't return this error, otherwise we'll panic at startup + // if there are multiple of the same peer configured + return nil + default: + return err + } case ListenAddress: c.config._listeners[v] = struct{}{} case NodeInfo: diff --git a/src/core/options_test.go b/src/core/options_test.go new file mode 100644 index 000000000..bab22fb13 --- /dev/null +++ b/src/core/options_test.go @@ -0,0 +1,41 @@ +package core + +import ( + "net/url" + "testing" + + "github.com/yggdrasil-network/yggdrasil-go/src/config" +) + +// Tests that duplicate peers in the configuration file +// won't cause an error when the node starts. Otherwise +// we can panic unnecessarily. +func TestDuplicatePeerAtStartup(t *testing.T) { + cfg := config.GenerateConfig() + for i := 0; i < 5; i++ { + cfg.Peers = append(cfg.Peers, "tcp://1.2.3.4:4321") + } + if _, err := New(cfg.Certificate, nil); err != nil { + t.Fatal(err) + } +} + +// Tests that duplicate peers given to us through the +// API will still error as expected, even if they didn't +// at startup. We expect to notify the user through the +// admin socket if they try to add a peer that is already +// configured. +func TestDuplicatePeerFromAPI(t *testing.T) { + cfg := config.GenerateConfig() + c, err := New(cfg.Certificate, nil) + if err != nil { + t.Fatal(err) + } + u, _ := url.Parse("tcp://1.2.3.4:4321") + if err := c.AddPeer(u, ""); err != nil { + t.Fatalf("Adding peer failed on first attempt: %s", err) + } + if err := c.AddPeer(u, ""); err == nil { + t.Fatalf("Adding peer should have failed on second attempt") + } +}