Skip to content

Commit 559e31c

Browse files
Merge pull request #896 from yggdrasil-network/develop
Version 0.4.3
2 parents e4e5883 + 31717a8 commit 559e31c

File tree

20 files changed

+612
-68
lines changed

20 files changed

+612
-68
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2525
- in case of vulnerabilities.
2626
-->
2727

28+
## [0.4.3] - 2022-02-06
29+
### Added
30+
- `bytes_sent`, `bytes_recvd` and `uptime` have been added to `getPeers`
31+
- Clearer logging when connections are rejected due to incompatible peer versions
32+
33+
### Fixed
34+
- Latency-based parent selection tiebreak is now reliable on platforms even with low timer resolution
35+
- Tree distance calculation offsets have been corrected
36+
2837
## [0.4.2] - 2021-11-03
2938
### Fixed
3039
- Reverted a dependency update which resulted in problems building with Go 1.16 and running on Windows

appveyor.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ environment:
99
CHERE_INVOKING: enabled_from_arguments
1010

1111
build_script:
12-
- cmd: >-
13-
cd %APPVEYOR_BUILD_FOLDER%
12+
- cmd: cd %APPVEYOR_BUILD_FOLDER%
13+
- curl -o C:\projects\golang.zip https://dl.google.com/go/go1.17.5.windows-amd64.zip
14+
- 7z x C:\projects\golang.zip -oC:\projects\
15+
- cmd: set PATH=C:\projects\go\bin;%PATH%
16+
- cmd: set GOROOT=C:\projects\go
1417
- c:\msys64\usr\bin\bash -lc "./contrib/msi/build-msi.sh x64"
1518
- c:\msys64\usr\bin\bash -lc "./contrib/msi/build-msi.sh x86"
1619

build

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ PKGVER=${PKGVER:-$(sh contrib/semver/version.sh --bare)}
99
LDFLAGS="-X $PKGSRC.buildName=$PKGNAME -X $PKGSRC.buildVersion=$PKGVER"
1010
ARGS="-v"
1111

12-
while getopts "uaitc:l:dro:p" option
12+
while getopts "utc:l:dro:p" option
1313
do
1414
case "$option"
1515
in
1616
u) UPX=true;;
17-
i) IOS=true;;
18-
a) ANDROID=true;;
1917
t) TABLES=true;;
2018
c) GCFLAGS="$GCFLAGS $OPTARG";;
2119
l) LDFLAGS="$LDFLAGS $OPTARG";;
@@ -30,25 +28,11 @@ if [ -z $TABLES ] && [ -z $DEBUG ]; then
3028
LDFLAGS="$LDFLAGS -s -w"
3129
fi
3230

33-
if [ $IOS ]; then
34-
echo "Building framework for iOS"
35-
go get golang.org/x/mobile/bind
36-
gomobile bind -target ios -tags mobile -o Yggdrasil.framework -ldflags="$LDFLAGS $STRIP" -gcflags="$GCFLAGS" \
37-
github.com/yggdrasil-network/yggdrasil-extras/src/mobile \
38-
github.com/yggdrasil-network/yggdrasil-go/src/config
39-
elif [ $ANDROID ]; then
40-
echo "Building aar for Android"
41-
go get golang.org/x/mobile/bind
42-
gomobile bind -target android -tags mobile -o yggdrasil.aar -ldflags="$LDFLAGS $STRIP" -gcflags="$GCFLAGS" \
43-
github.com/yggdrasil-network/yggdrasil-extras/src/mobile \
44-
github.com/yggdrasil-network/yggdrasil-go/src/config
45-
else
46-
for CMD in yggdrasil yggdrasilctl ; do
47-
echo "Building: $CMD"
48-
go build $ARGS -ldflags="$LDFLAGS" -gcflags="$GCFLAGS" ./cmd/$CMD
31+
for CMD in yggdrasil yggdrasilctl ; do
32+
echo "Building: $CMD"
33+
go build $ARGS -ldflags="$LDFLAGS" -gcflags="$GCFLAGS" ./cmd/$CMD
4934

50-
if [ $UPX ]; then
51-
upx --brute $CMD
52-
fi
53-
done
54-
fi
35+
if [ $UPX ]; then
36+
upx --brute $CMD
37+
fi
38+
done

contrib/macos/create-pkg.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ PKGNAME=$(sh contrib/semver/name.sh)
7979
PKGVERSION=$(sh contrib/semver/version.sh --bare)
8080
PKGARCH=${PKGARCH-amd64}
8181
PAYLOADSIZE=$(( $(wc -c pkgbuild/flat/base.pkg/Payload | awk '{ print $1 }') / 1024 ))
82+
[ "$PKGARCH" = "amd64" ] && PKGHOSTARCH="x86_64" || PKGHOSTARCH=${PKGARCH}
8283

8384
# Create the PackageInfo file
8485
cat > pkgbuild/flat/base.pkg/PackageInfo << EOF
@@ -98,7 +99,7 @@ cat > pkgbuild/flat/Distribution << EOF
9899
<?xml version="1.0" encoding="utf-8"?>
99100
<installer-script minSpecVersion="1.000000" authoringTool="com.apple.PackageMaker" authoringToolVersion="3.0.3" authoringToolBuild="174">
100101
<title>Yggdrasil (${PKGNAME}-${PKGVERSION})</title>
101-
<options customize="never" allow-external-scripts="no"/>
102+
<options customize="never" allow-external-scripts="no" hostArchitectures="${PKGHOSTARCH}" />
102103
<domains enable_anywhere="true"/>
103104
<installation-check script="pm_install_check();"/>
104105
<script>

contrib/mobile/build

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
3+
set -ef
4+
5+
[ ! -d contrib/mobile ] && (echo "Must run ./contrib/mobile/build [-i] [-a] from the repository top level folder"; exit 1)
6+
7+
PKGSRC=${PKGSRC:-github.com/yggdrasil-network/yggdrasil-go/src/version}
8+
PKGNAME=${PKGNAME:-$(sh contrib/semver/name.sh)}
9+
PKGVER=${PKGVER:-$(sh contrib/semver/version.sh --bare)}
10+
11+
LDFLAGS="-X $PKGSRC.buildName=$PKGNAME -X $PKGSRC.buildVersion=$PKGVER"
12+
ARGS="-v"
13+
14+
while getopts "aitc:l:d" option
15+
do
16+
case "$option"
17+
in
18+
i) IOS=true;;
19+
a) ANDROID=true;;
20+
t) TABLES=true;;
21+
c) GCFLAGS="$GCFLAGS $OPTARG";;
22+
l) LDFLAGS="$LDFLAGS $OPTARG";;
23+
d) ARGS="$ARGS -tags debug" DEBUG=true;;
24+
esac
25+
done
26+
27+
if [ -z $TABLES ] && [ -z $DEBUG ]; then
28+
LDFLAGS="$LDFLAGS -s -w"
29+
fi
30+
31+
if [ ! $IOS ] && [ ! $ANDROID ]; then
32+
echo "Must specify -a (Android), -i (iOS) or both"
33+
exit 1
34+
fi
35+
36+
if [ $IOS ]; then
37+
echo "Building framework for iOS"
38+
go get golang.org/x/mobile/bind
39+
gomobile bind \
40+
-target ios -tags mobile -o Yggdrasil.xcframework \
41+
-ldflags="$LDFLAGS $STRIP" -gcflags="$GCFLAGS" \
42+
./contrib/mobile ./src/config;
43+
fi
44+
45+
if [ $ANDROID ]; then
46+
echo "Building aar for Android"
47+
go get golang.org/x/mobile/bind
48+
gomobile bind \
49+
-target android -tags mobile -o yggdrasil.aar \
50+
-ldflags="$LDFLAGS $STRIP" -gcflags="$GCFLAGS" \
51+
./contrib/mobile ./src/config;
52+
fi

contrib/mobile/mobile.go

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
package mobile
2+
3+
import (
4+
"encoding/hex"
5+
"encoding/json"
6+
"fmt"
7+
"net"
8+
9+
"github.com/gologme/log"
10+
11+
"github.com/yggdrasil-network/yggdrasil-go/src/address"
12+
"github.com/yggdrasil-network/yggdrasil-go/src/config"
13+
"github.com/yggdrasil-network/yggdrasil-go/src/core"
14+
"github.com/yggdrasil-network/yggdrasil-go/src/defaults"
15+
"github.com/yggdrasil-network/yggdrasil-go/src/ipv6rwc"
16+
"github.com/yggdrasil-network/yggdrasil-go/src/multicast"
17+
"github.com/yggdrasil-network/yggdrasil-go/src/version"
18+
19+
_ "golang.org/x/mobile/bind"
20+
)
21+
22+
// Yggdrasil mobile package is meant to "plug the gap" for mobile support, as
23+
// Gomobile will not create headers for Swift/Obj-C etc if they have complex
24+
// (non-native) types. Therefore for iOS we will expose some nice simple
25+
// functions. Note that in the case of iOS we handle reading/writing to/from TUN
26+
// in Swift therefore we use the "dummy" TUN interface instead.
27+
type Yggdrasil struct {
28+
core core.Core
29+
iprwc *ipv6rwc.ReadWriteCloser
30+
config *config.NodeConfig
31+
multicast multicast.Multicast
32+
log MobileLogger
33+
}
34+
35+
// StartAutoconfigure starts a node with a randomly generated config
36+
func (m *Yggdrasil) StartAutoconfigure() error {
37+
return m.StartJSON([]byte("{}"))
38+
}
39+
40+
// StartJSON starts a node with the given JSON config. You can get JSON config
41+
// (rather than HJSON) by using the GenerateConfigJSON() function
42+
func (m *Yggdrasil) StartJSON(configjson []byte) error {
43+
logger := log.New(m.log, "", 0)
44+
logger.EnableLevel("error")
45+
logger.EnableLevel("warn")
46+
logger.EnableLevel("info")
47+
m.config = defaults.GenerateConfig()
48+
if err := json.Unmarshal(configjson, &m.config); err != nil {
49+
return err
50+
}
51+
m.config.IfName = "none"
52+
if err := m.core.Start(m.config, logger); err != nil {
53+
logger.Errorln("An error occured starting Yggdrasil:", err)
54+
return err
55+
}
56+
mtu := m.config.IfMTU
57+
m.iprwc = ipv6rwc.NewReadWriteCloser(&m.core)
58+
if m.iprwc.MaxMTU() < mtu {
59+
mtu = m.iprwc.MaxMTU()
60+
}
61+
m.iprwc.SetMTU(mtu)
62+
if len(m.config.MulticastInterfaces) > 0 {
63+
if err := m.multicast.Init(&m.core, m.config, logger, nil); err != nil {
64+
logger.Errorln("An error occurred initialising multicast:", err)
65+
return err
66+
}
67+
if err := m.multicast.Start(); err != nil {
68+
logger.Errorln("An error occurred starting multicast:", err)
69+
return err
70+
}
71+
}
72+
return nil
73+
}
74+
75+
// Send sends a packet to Yggdrasil. It should be a fully formed
76+
// IPv6 packet
77+
func (m *Yggdrasil) Send(p []byte) error {
78+
if m.iprwc == nil {
79+
return nil
80+
}
81+
_, _ = m.iprwc.Write(p)
82+
return nil
83+
}
84+
85+
// Recv waits for and reads a packet coming from Yggdrasil. It
86+
// will be a fully formed IPv6 packet
87+
func (m *Yggdrasil) Recv() ([]byte, error) {
88+
if m.iprwc == nil {
89+
return nil, nil
90+
}
91+
var buf [65535]byte
92+
n, _ := m.iprwc.Read(buf[:])
93+
return buf[:n], nil
94+
}
95+
96+
// Stop the mobile Yggdrasil instance
97+
func (m *Yggdrasil) Stop() error {
98+
logger := log.New(m.log, "", 0)
99+
logger.EnableLevel("info")
100+
logger.Infof("Stop the mobile Yggdrasil instance %s", "")
101+
if err := m.multicast.Stop(); err != nil {
102+
return err
103+
}
104+
m.core.Stop()
105+
return nil
106+
}
107+
108+
// GenerateConfigJSON generates mobile-friendly configuration in JSON format
109+
func GenerateConfigJSON() []byte {
110+
nc := defaults.GenerateConfig()
111+
nc.IfName = "none"
112+
if json, err := json.Marshal(nc); err == nil {
113+
return json
114+
}
115+
return nil
116+
}
117+
118+
// GetAddressString gets the node's IPv6 address
119+
func (m *Yggdrasil) GetAddressString() string {
120+
ip := m.core.Address()
121+
return ip.String()
122+
}
123+
124+
// GetSubnetString gets the node's IPv6 subnet in CIDR notation
125+
func (m *Yggdrasil) GetSubnetString() string {
126+
subnet := m.core.Subnet()
127+
return subnet.String()
128+
}
129+
130+
// GetPublicKeyString gets the node's public key in hex form
131+
func (m *Yggdrasil) GetPublicKeyString() string {
132+
return hex.EncodeToString(m.core.GetSelf().Key)
133+
}
134+
135+
// GetCoordsString gets the node's coordinates
136+
func (m *Yggdrasil) GetCoordsString() string {
137+
return fmt.Sprintf("%v", m.core.GetSelf().Coords)
138+
}
139+
140+
func (m *Yggdrasil) GetPeersJSON() (result string) {
141+
peers := []struct {
142+
core.Peer
143+
IP string
144+
}{}
145+
for _, v := range m.core.GetPeers() {
146+
a := address.AddrForKey(v.Key)
147+
ip := net.IP(a[:]).String()
148+
peers = append(peers, struct {
149+
core.Peer
150+
IP string
151+
}{
152+
Peer: v,
153+
IP: ip,
154+
})
155+
}
156+
if res, err := json.Marshal(peers); err == nil {
157+
return string(res)
158+
} else {
159+
return "{}"
160+
}
161+
}
162+
163+
func (m *Yggdrasil) GetDHTJSON() (result string) {
164+
if res, err := json.Marshal(m.core.GetDHT()); err == nil {
165+
return string(res)
166+
} else {
167+
return "{}"
168+
}
169+
}
170+
171+
// GetMTU returns the configured node MTU. This must be called AFTER Start.
172+
func (m *Yggdrasil) GetMTU() int {
173+
return int(m.core.MTU())
174+
}
175+
176+
func GetVersion() string {
177+
return version.BuildVersion()
178+
}

contrib/mobile/mobile_android.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// +build android
2+
3+
package mobile
4+
5+
import "log"
6+
7+
type MobileLogger struct{}
8+
9+
func (nsl MobileLogger) Write(p []byte) (n int, err error) {
10+
log.Println(string(p))
11+
return len(p), nil
12+
}

contrib/mobile/mobile_ios.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// +build ios
2+
3+
package mobile
4+
5+
/*
6+
#cgo CFLAGS: -x objective-c
7+
#cgo LDFLAGS: -framework Foundation
8+
#import <Foundation/Foundation.h>
9+
void Log(const char *text) {
10+
NSString *nss = [NSString stringWithUTF8String:text];
11+
NSLog(@"%@", nss);
12+
}
13+
*/
14+
import "C"
15+
import (
16+
"unsafe"
17+
)
18+
19+
type MobileLogger struct {
20+
}
21+
22+
func (nsl MobileLogger) Write(p []byte) (n int, err error) {
23+
p = append(p, 0)
24+
cstr := (*C.char)(unsafe.Pointer(&p[0]))
25+
C.Log(cstr)
26+
return len(p), nil
27+
}

contrib/mobile/mobile_other.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// +build !android,!ios
2+
3+
package mobile
4+
5+
import "fmt"
6+
7+
type MobileLogger struct {
8+
}
9+
10+
func (nsl MobileLogger) Write(p []byte) (n int, err error) {
11+
fmt.Print(string(p))
12+
return len(p), nil
13+
}

contrib/mobile/mobile_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package mobile
2+
3+
import "testing"
4+
5+
func TestStartYggdrasil(t *testing.T) {
6+
ygg := &Yggdrasil{}
7+
if err := ygg.StartAutoconfigure(); err != nil {
8+
t.Fatalf("Failed to start Yggdrasil: %s", err)
9+
}
10+
t.Log("Address:", ygg.GetAddressString())
11+
t.Log("Subnet:", ygg.GetSubnetString())
12+
t.Log("Coords:", ygg.GetCoordsString())
13+
if err := ygg.Stop(); err != nil {
14+
t.Fatalf("Failed to stop Yggdrasil: %s", err)
15+
}
16+
}

0 commit comments

Comments
 (0)