From ebdd968c246e281f73133d83b0b072464b133050 Mon Sep 17 00:00:00 2001 From: Mikhail Novosyolov Date: Tue, 5 Feb 2019 14:15:17 +0300 Subject: [PATCH 1/7] Fail build script if building of any target fails E.g, I had a build error of yggdrasil, but ./build returned exit code 0: + ./build -t -l -linkmode=external Building: yggdrasil github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil /home/user/go/src/github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil/multicast.go:39:9: undefined: net.ListenConfig Building: yggdrasilctl + exit 0 --- build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build b/build index 7ceb4c9a..f6c72466 100755 --- a/build +++ b/build @@ -1,5 +1,7 @@ #!/bin/sh +set -ef + PKGSRC=${PKGSRC:-github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil} PKGNAME=${PKGNAME:-$(sh contrib/semver/name.sh)} PKGVER=${PKGVER:-$(sh contrib/semver/version.sh --bare)} From 41f49faaa0b86b6b42420eb2bcc384dc3af0df51 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Tue, 5 Feb 2019 17:39:59 -0600 Subject: [PATCH 2/7] get code running in the netns test again, remove unnecessary allocations that were found in profiling --- misc/run-schannel-netns | 12 ++++++------ src/yggdrasil/admin.go | 6 +++++- src/yggdrasil/stream.go | 16 ++++++++-------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/misc/run-schannel-netns b/misc/run-schannel-netns index 9723e73b..74a02942 100755 --- a/misc/run-schannel-netns +++ b/misc/run-schannel-netns @@ -51,12 +51,12 @@ ip netns exec node4 ip link set lo up ip netns exec node5 ip link set lo up ip netns exec node6 ip link set lo up -ip netns exec node1 env PPROFLISTEN=localhost:6060 ./run --autoconf &> /dev/null & -ip netns exec node2 env PPROFLISTEN=localhost:6060 ./run --autoconf &> /dev/null & -ip netns exec node3 env PPROFLISTEN=localhost:6060 ./run --autoconf &> /dev/null & -ip netns exec node4 env PPROFLISTEN=localhost:6060 ./run --autoconf &> /dev/null & -ip netns exec node5 env PPROFLISTEN=localhost:6060 ./run --autoconf &> /dev/null & -ip netns exec node6 env PPROFLISTEN=localhost:6060 ./run --autoconf &> /dev/null & +echo '{AdminListen: "none"}' | ip netns exec node1 env PPROFLISTEN=localhost:6060 ./yggdrasil --useconf &> /dev/null & +echo '{AdminListen: "none"}' | ip netns exec node2 env PPROFLISTEN=localhost:6060 ./yggdrasil --useconf &> /dev/null & +echo '{AdminListen: "none"}' | ip netns exec node3 env PPROFLISTEN=localhost:6060 ./yggdrasil --useconf &> /dev/null & +echo '{AdminListen: "none"}' | ip netns exec node4 env PPROFLISTEN=localhost:6060 ./yggdrasil --useconf &> /dev/null & +echo '{AdminListen: "none"}' | ip netns exec node5 env PPROFLISTEN=localhost:6060 ./yggdrasil --useconf &> /dev/null & +echo '{AdminListen: "none"}' | ip netns exec node6 env PPROFLISTEN=localhost:6060 ./yggdrasil --useconf &> /dev/null & echo "Started, to continue you should (possibly w/ sudo):" echo "kill" $(jobs -p) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index b54ac5cf..f8347f0d 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -388,7 +388,11 @@ func (a *admin) start() error { // cleans up when stopping func (a *admin) close() error { - return a.listener.Close() + if a.listener != nil { + return a.listener.Close() + } else { + return nil + } } // listen is run by start and manages API connections. diff --git a/src/yggdrasil/stream.go b/src/yggdrasil/stream.go index db2cdf7e..4d73844f 100644 --- a/src/yggdrasil/stream.go +++ b/src/yggdrasil/stream.go @@ -12,8 +12,10 @@ import ( var _ = linkInterfaceMsgIO(&stream{}) type stream struct { - rwc io.ReadWriteCloser - inputBuffer []byte // Incoming packet stream + rwc io.ReadWriteCloser + inputBuffer []byte // Incoming packet stream + frag [2 * streamMsgSize]byte // Temporary data read off the underlying rwc, on its way to the inputBuffer + outputBuffer [2 * streamMsgSize]byte // Temporary data about to be written to the rwc } func (s *stream) close() error { @@ -32,10 +34,9 @@ func (s *stream) init(rwc io.ReadWriteCloser) { // writeMsg writes a message with stream padding, and is *not* thread safe. func (s *stream) writeMsg(bs []byte) (int, error) { - buf := util.GetBytes() - defer util.PutBytes(buf) + buf := s.outputBuffer[:0] buf = append(buf, streamMsg[:]...) - buf = append(buf, wire_encode_uint64(uint64(len(bs)))...) + buf = wire_put_uint64(uint64(len(bs)), buf) padLen := len(buf) buf = append(buf, bs...) var bn int @@ -69,10 +70,9 @@ func (s *stream) readMsg() ([]byte, error) { return msg, nil default: // Wait for the underlying reader to return enough info for us to proceed - frag := make([]byte, 2*streamMsgSize) - n, err := s.rwc.Read(frag) + n, err := s.rwc.Read(s.frag[:]) if n > 0 { - s.inputBuffer = append(s.inputBuffer, frag[:n]...) + s.inputBuffer = append(s.inputBuffer, s.frag[:n]...) } else if err != nil { return nil, err } From ad43558fbb312e58614ca03f530ca0ace6185da9 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 9 Feb 2019 15:30:17 -0600 Subject: [PATCH 3/7] fix bug in switch time --- src/yggdrasil/switch.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index db39d010..9d1f870a 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -415,6 +415,7 @@ func (t *switchTable) unlockedHandleMsg(msg *switchMsg, fromPort switchPort, rep // Update the matrix of peer "faster" thresholds if reprocessing { sender.faster = oldSender.faster + sender.time = oldSender.time } else { sender.faster = make(map[switchPort]uint64, len(oldSender.faster)) for port, peer := range t.data.peers { From 0ca64b0abe4735a91f8440b45a9b4e7088cd8c98 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sun, 10 Feb 2019 12:13:49 +0000 Subject: [PATCH 4/7] Remove ReadTimeout configuration option --- cmd/yggdrasil/main.go | 5 +++-- src/config/config.go | 1 - src/yggdrasil/tcp.go | 6 ------ 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/cmd/yggdrasil/main.go b/cmd/yggdrasil/main.go index f67bbcef..aa5a7494 100644 --- a/cmd/yggdrasil/main.go +++ b/cmd/yggdrasil/main.go @@ -77,6 +77,7 @@ func readConfig(useconf *bool, useconffile *string, normaliseconf *bool) *nodeCo // names have changed recently. changes := map[string]string{ "Multicast": "", + "ReadTimeout": "", "LinkLocal": "MulticastInterfaces", "BoxPub": "EncryptionPublicKey", "BoxPriv": "EncryptionPrivateKey", @@ -89,11 +90,11 @@ func readConfig(useconf *bool, useconffile *string, normaliseconf *bool) *nodeCo if _, ok := dat[from]; ok { if to == "" { if !*normaliseconf { - log.Println("Warning: Deprecated config option", from, "- please remove") + log.Println("Warning: Config option", from, "is deprecated") } } else { if !*normaliseconf { - log.Println("Warning: Deprecated config option", from, "- please rename to", to) + log.Println("Warning: Config option", from, "has been renamed - please change to", to) } // If the configuration file doesn't already contain a line with the // new name then set it to the old value. This makes sure that we diff --git a/src/config/config.go b/src/config/config.go index 192b94e5..14b16490 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -16,7 +16,6 @@ type NodeConfig struct { AdminListen string `comment:"Listen address for admin connections. Default is to listen for local\nconnections either on TCP/9001 or a UNIX socket depending on your\nplatform. Use this value for yggdrasilctl -endpoint=X. To disable\nthe admin socket, use the value \"none\" instead."` Peers []string `comment:"List of connection strings for static peers in URI format, e.g.\ntcp://a.b.c.d:e or socks://a.b.c.d:e/f.g.h.i:j."` InterfacePeers map[string][]string `comment:"List of connection strings for static peers in URI format, arranged\nby source interface, e.g. { \"eth0\": [ tcp://a.b.c.d:e ] }. Note that\nSOCKS peerings will NOT be affected by this option and should go in\nthe \"Peers\" section instead."` - ReadTimeout int32 `comment:"Read timeout for connections, specified in milliseconds. If less\nthan 6000 and not negative, 6000 (the default) is used. If negative,\nreads won't time out."` AllowedEncryptionPublicKeys []string `comment:"List of peer encryption public keys to allow or incoming TCP\nconnections from. If left empty/undefined then all connections\nwill be allowed by default."` EncryptionPublicKey string `comment:"Your public encryption key. Your peers may ask you for this to put\ninto their AllowedEncryptionPublicKeys configuration."` EncryptionPrivateKey string `comment:"Your private encryption key. DO NOT share this with anyone!"` diff --git a/src/yggdrasil/tcp.go b/src/yggdrasil/tcp.go index 979bc81b..c65e2e66 100644 --- a/src/yggdrasil/tcp.go +++ b/src/yggdrasil/tcp.go @@ -36,7 +36,6 @@ type tcpInterface struct { reconfigure chan chan error serv net.Listener stop chan bool - timeout time.Duration addr string mutex sync.Mutex // Protecting the below calls map[string]struct{} @@ -106,13 +105,8 @@ func (iface *tcpInterface) listen() error { iface.core.configMutex.RLock() iface.addr = iface.core.config.Listen - iface.timeout = time.Duration(iface.core.config.ReadTimeout) * time.Millisecond iface.core.configMutex.RUnlock() - if iface.timeout >= 0 && iface.timeout < default_timeout { - iface.timeout = default_timeout - } - ctx := context.Background() lc := net.ListenConfig{ Control: iface.tcpContext, From 9f7609817e146088dd6dbf192b621808a48f4ef8 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sun, 10 Feb 2019 12:22:39 +0000 Subject: [PATCH 5/7] Remove yggdrasil-resume.service from systemd contrib and Debian package --- contrib/deb/generate.sh | 2 -- contrib/systemd/yggdrasil-resume.service | 10 ---------- contrib/systemd/yggdrasil.service | 1 - 3 files changed, 13 deletions(-) delete mode 100644 contrib/systemd/yggdrasil-resume.service diff --git a/contrib/deb/generate.sh b/contrib/deb/generate.sh index 6c8f955d..6879a2d8 100644 --- a/contrib/deb/generate.sh +++ b/contrib/deb/generate.sh @@ -110,12 +110,10 @@ EOF cp yggdrasil /tmp/$PKGNAME/usr/bin/ cp yggdrasilctl /tmp/$PKGNAME/usr/bin/ cp contrib/systemd/yggdrasil.service /tmp/$PKGNAME/etc/systemd/system/ -cp contrib/systemd/yggdrasil-resume.service /tmp/$PKGNAME/etc/systemd/system/ tar -czvf /tmp/$PKGNAME/data.tar.gz -C /tmp/$PKGNAME/ \ usr/bin/yggdrasil usr/bin/yggdrasilctl \ etc/systemd/system/yggdrasil.service \ - etc/systemd/system/yggdrasil-resume.service tar -czvf /tmp/$PKGNAME/control.tar.gz -C /tmp/$PKGNAME/debian . echo 2.0 > /tmp/$PKGNAME/debian-binary diff --git a/contrib/systemd/yggdrasil-resume.service b/contrib/systemd/yggdrasil-resume.service deleted file mode 100644 index c725127b..00000000 --- a/contrib/systemd/yggdrasil-resume.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Restart yggdrasil on resume from sleep -After=sleep.target - -[Service] -Type=oneshot -ExecStart=/bin/systemctl restart yggdrasil - -[Install] -WantedBy=sleep.target diff --git a/contrib/systemd/yggdrasil.service b/contrib/systemd/yggdrasil.service index 1b6f1f07..6adf1ef5 100644 --- a/contrib/systemd/yggdrasil.service +++ b/contrib/systemd/yggdrasil.service @@ -18,4 +18,3 @@ Restart=always [Install] WantedBy=multi-user.target -Also=yggdrasil-resume.service From fe09c234bc89aa79befb42aa13dcb79c129e4c44 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sun, 10 Feb 2019 12:29:04 +0000 Subject: [PATCH 6/7] Fix Debian generate.sh --- contrib/deb/generate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/deb/generate.sh b/contrib/deb/generate.sh index 6879a2d8..4433a9d9 100644 --- a/contrib/deb/generate.sh +++ b/contrib/deb/generate.sh @@ -113,7 +113,7 @@ cp contrib/systemd/yggdrasil.service /tmp/$PKGNAME/etc/systemd/system/ tar -czvf /tmp/$PKGNAME/data.tar.gz -C /tmp/$PKGNAME/ \ usr/bin/yggdrasil usr/bin/yggdrasilctl \ - etc/systemd/system/yggdrasil.service \ + etc/systemd/system/yggdrasil.service tar -czvf /tmp/$PKGNAME/control.tar.gz -C /tmp/$PKGNAME/debian . echo 2.0 > /tmp/$PKGNAME/debian-binary From 30320801d380d3e90b32adee53361106b4b3aa31 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sun, 10 Feb 2019 15:23:49 +0000 Subject: [PATCH 7/7] Don't build 32-bit builds for macOS --- .circleci/config.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8725e443..82a68aad 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -48,14 +48,12 @@ jobs: 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; - GOOS=darwin GOARCH=386 ./build && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-darwin-i386 && mv yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-darwin-i386; - 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/ - GOOS=darwin GOARCH=386 ./build && PKGARCH=i386 sh contrib/macos/create-pkg.sh && mv *.pkg /tmp/upload/ - run: name: Build for OpenBSD