Compare commits

..

1363 commits

Author SHA1 Message Date
Sergey Alirzaev
47818a1a7c
apparmor: add yggdrasilctl policy (#1235)
Some checks failed
Yggdrasil / Lint (push) Has been cancelled
Yggdrasil / Analyse (push) Has been cancelled
Yggdrasil / Build & Test (Linux, Go 1.22) (push) Has been cancelled
Yggdrasil / Build & Test (Linux, Go 1.23) (push) Has been cancelled
Yggdrasil / Build & Test (Linux, Go 1.24) (push) Has been cancelled
Yggdrasil / Build & Test (Windows, Go 1.22) (push) Has been cancelled
Yggdrasil / Build & Test (Windows, Go 1.23) (push) Has been cancelled
Yggdrasil / Build & Test (Windows, Go 1.24) (push) Has been cancelled
Yggdrasil / Build & Test (macOS, Go 1.22) (push) Has been cancelled
Yggdrasil / Build & Test (macOS, Go 1.23) (push) Has been cancelled
Yggdrasil / Build & Test (macOS, Go 1.24) (push) Has been cancelled
Yggdrasil / Build (Cross freebsd, Go 1.22) (push) Has been cancelled
Yggdrasil / Build (Cross freebsd, Go 1.23) (push) Has been cancelled
Yggdrasil / Build (Cross freebsd, Go 1.24) (push) Has been cancelled
Yggdrasil / Build (Cross openbsd, Go 1.22) (push) Has been cancelled
Yggdrasil / Build (Cross openbsd, Go 1.23) (push) Has been cancelled
Yggdrasil / Build (Cross openbsd, Go 1.24) (push) Has been cancelled
Yggdrasil / All tests passed (push) Has been cancelled
2025-04-15 17:17:52 +01:00
Sergey Alirzaev
6377d7f071
contrib/openrc: remove SIGHUP logic (#1236)
as it is long gone from the daemon code
and unexpectedly kills the daemon
2025-04-15 17:15:09 +01:00
Neil Alexander
5b8dbc8b1e
Add summary helpers to mobile wrapper
Some checks failed
Yggdrasil / Lint (push) Has been cancelled
Yggdrasil / Analyse (push) Has been cancelled
Yggdrasil / Build & Test (Linux, Go 1.22) (push) Has been cancelled
Yggdrasil / Build & Test (Linux, Go 1.23) (push) Has been cancelled
Yggdrasil / Build & Test (Linux, Go 1.24) (push) Has been cancelled
Yggdrasil / Build & Test (Windows, Go 1.22) (push) Has been cancelled
Yggdrasil / Build & Test (Windows, Go 1.23) (push) Has been cancelled
Yggdrasil / Build & Test (Windows, Go 1.24) (push) Has been cancelled
Yggdrasil / Build & Test (macOS, Go 1.22) (push) Has been cancelled
Yggdrasil / Build & Test (macOS, Go 1.23) (push) Has been cancelled
Yggdrasil / Build & Test (macOS, Go 1.24) (push) Has been cancelled
Yggdrasil / Build (Cross freebsd, Go 1.22) (push) Has been cancelled
Yggdrasil / Build (Cross freebsd, Go 1.23) (push) Has been cancelled
Yggdrasil / Build (Cross freebsd, Go 1.24) (push) Has been cancelled
Yggdrasil / Build (Cross openbsd, Go 1.22) (push) Has been cancelled
Yggdrasil / Build (Cross openbsd, Go 1.23) (push) Has been cancelled
Yggdrasil / Build (Cross openbsd, Go 1.24) (push) Has been cancelled
Yggdrasil / All tests passed (push) Has been cancelled
2025-03-31 10:18:57 +01:00
patrini32
73705ff09d
Typo fix (#1232)
Some checks failed
Yggdrasil / Analyse (push) Has been cancelled
Yggdrasil / Lint (push) Has been cancelled
Yggdrasil / Build & Test (Linux, Go 1.22) (push) Has been cancelled
Yggdrasil / Build & Test (Linux, Go 1.23) (push) Has been cancelled
Yggdrasil / Build & Test (Linux, Go 1.24) (push) Has been cancelled
Yggdrasil / Build & Test (Windows, Go 1.22) (push) Has been cancelled
Yggdrasil / Build & Test (Windows, Go 1.23) (push) Has been cancelled
Yggdrasil / Build & Test (Windows, Go 1.24) (push) Has been cancelled
Yggdrasil / Build & Test (macOS, Go 1.22) (push) Has been cancelled
Yggdrasil / Build & Test (macOS, Go 1.23) (push) Has been cancelled
Yggdrasil / Build & Test (macOS, Go 1.24) (push) Has been cancelled
Yggdrasil / Build (Cross freebsd, Go 1.22) (push) Has been cancelled
Yggdrasil / Build (Cross freebsd, Go 1.23) (push) Has been cancelled
Yggdrasil / Build (Cross freebsd, Go 1.24) (push) Has been cancelled
Yggdrasil / Build (Cross openbsd, Go 1.22) (push) Has been cancelled
Yggdrasil / Build (Cross openbsd, Go 1.23) (push) Has been cancelled
Yggdrasil / Build (Cross openbsd, Go 1.24) (push) Has been cancelled
Yggdrasil / All tests passed (push) Has been cancelled
2025-02-20 09:45:49 +00:00
Neil Alexander
3b18909f70
Update dependencies
Some checks failed
Yggdrasil / Lint (push) Has been cancelled
Yggdrasil / Analyse (push) Has been cancelled
Yggdrasil / Build & Test (Linux, Go 1.22) (push) Has been cancelled
Yggdrasil / Build & Test (Linux, Go 1.23) (push) Has been cancelled
Yggdrasil / Build & Test (Linux, Go 1.24) (push) Has been cancelled
Yggdrasil / Build & Test (Windows, Go 1.22) (push) Has been cancelled
Yggdrasil / Build & Test (Windows, Go 1.23) (push) Has been cancelled
Yggdrasil / Build & Test (Windows, Go 1.24) (push) Has been cancelled
Yggdrasil / Build & Test (macOS, Go 1.22) (push) Has been cancelled
Yggdrasil / Build & Test (macOS, Go 1.23) (push) Has been cancelled
Yggdrasil / Build & Test (macOS, Go 1.24) (push) Has been cancelled
Yggdrasil / Build (Cross freebsd, Go 1.22) (push) Has been cancelled
Yggdrasil / Build (Cross freebsd, Go 1.23) (push) Has been cancelled
Yggdrasil / Build (Cross freebsd, Go 1.24) (push) Has been cancelled
Yggdrasil / Build (Cross openbsd, Go 1.22) (push) Has been cancelled
Yggdrasil / Build (Cross openbsd, Go 1.23) (push) Has been cancelled
Yggdrasil / Build (Cross openbsd, Go 1.24) (push) Has been cancelled
Yggdrasil / All tests passed (push) Has been cancelled
2025-02-18 12:57:58 +00:00
Neil Alexander
58b727d1f0
Add Go 1.24 to CI 2025-02-18 12:52:21 +00:00
Klemens Nanni
782c0250d7
Use pledge(2) on OpenBSD (#1215)
Straight forward thanks to all privileged operations being done early
enough during startup.
2024-12-22 11:04:26 +00:00
Neil Alexander
213f72b840
Yggdrasil 0.5.12 2024-12-18 22:34:30 +00:00
Neil Alexander
1fbcf3b3c2
Rename latency_ms to latency in getPeers response since it isn't even milliseconds anymore 2024-12-18 22:21:23 +00:00
Peter Gervai
22bc9c44e2
genkeys print the number of generated keys (#1217)
It is good to know how many resources have we carelessly wasted. :-)
2024-12-18 19:56:46 +00:00
Neil
9c73bacab9
Update to Go 1.22, quic-go/quic-go@v0.48.2 (#1218)
Our dependencies are now moving beyond Go 1.21 so need to update.

Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2024-12-13 23:33:26 +00:00
Neil Alexander
04be129878
Update to Arceliar/ironwood@743fe2f 2024-12-13 23:12:36 +00:00
Neil Alexander
657f7e0db3
Fix empty user/group detection on chuser
This should fix #1216.
2024-12-13 16:55:25 +00:00
Neil
7adf5f18b7
Yggdrasil 0.5.11 (#1214)
Changelog updates.

Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2024-12-12 19:26:54 +00:00
Neil Alexander
69451fe969
Specify TLS 1.2-TLS 1.3 supported range for client connections
Should fix #1208.
2024-12-12 19:07:55 +00:00
Klemens Nanni
2d587740c1
genkeys, yggdrasilctl: Use pledge(2) on OpenBSD (#1193)
Restrict system operations of CLI tools with
https://man.openbsd.org/pledge.2.

https://pkg.go.dev/suah.dev/protect abstracts the OS specific code, i.e.
is a NOOP on non-OpenBSD systems.

This PR is to gauge upstream interest in this direction; my OpenBSD port
of yggdrasil already pledges the daemon,
resulting in minimal runtime privileges, but there are still a few rough
edges:

https://github.com/jasperla/openbsd-wip/blob/master/net/yggdrasil/patches/patch-cmd_yggdrasil_main_go#L80

---------

Co-authored-by: Neil <git@neilalexander.dev>
2024-12-12 18:48:24 +00:00
Neil Alexander
b2b0396d48
Update dependencies 2024-12-12 18:42:53 +00:00
Klemens Nanni
83ec58afc7
Use unveil(2) on OpenBSD (#1194)
After #1175 removed ioctl(2) fallback code shelling out to ifconfig(8),
there is no code left (compiled on OpenBSD) that would fork(2) or
execve(2).

Drop the ability to run any executable file to double down on this, thus
reducing the attack surface of this this experimental, internet facing
daemon running as root.

pledge(2) is doable, but needs more polish.
unveil(2), however, is as simple as it gets.

On other systems, this code is a NOOP, but can still help to implement
similar safety belts.
2024-12-12 18:37:02 +00:00
Neil Alexander
b436052b2d
Update to Arceliar/ironwood@9deb08d 2024-12-10 19:02:13 +00:00
Neil
3ed4a92288
Yggdrasil 0.5.10 (#1207)
Changelog updates.

Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2024-11-24 12:56:24 +00:00
Neil Alexander
bdb2d399c5
Update dependencies 2024-11-23 14:55:14 +00:00
Neil Alexander
7790a19e4c
New detail in getMulticastInterfaces admin endpoint 2024-11-23 14:49:48 +00:00
Neil Alexander
d3b4de46ea
Improvements to how link shutdowns are handled 2024-11-23 13:43:34 +00:00
Neil Alexander
2454970e4d
Tweaks to configuration 2024-11-22 09:47:33 +00:00
Neil Alexander
b98f98318f
Tweaks to link handling 2024-11-22 09:44:30 +00:00
Neil Alexander
ff9e90c5aa
Update link cost calculation and next-hop selection (update to Arceliar/ironwood@75a6e82) 2024-11-22 09:31:38 +00:00
Neil
9398cae230
Expose download/upload rate per peer (#1206) 2024-11-19 08:42:27 +00:00
Klemens Nanni
c22a746a1d
Rewrite chuser() for simplicity and correctness (#1203)
- Use unambiguous variable names (w/o package name conflict).
- Fail on invalid input such as the empty string or `:`.
- Do not change group without user, i.e. fail on `:group`.
- Parse input using mnemonic APIs.
- Do not juggle between integer types.
- Unset supplementary groups.
- Use set[ug]id(2) to follow the idiom of OpenBSD base programs.
  (cannot use setres[ug]id(2) as macOS does not have them.)

Includes/Supersedes #1202.
Fixes #927.

I only tested on OpenBSD (so far), but other systems should just work.
2024-11-17 21:37:07 +00:00
Neil Alexander
67ec5a92b3
Fix some lint issues 2024-11-17 21:29:26 +00:00
Neil Alexander
42873be09b
Reusable peer lookup/dial logic 2024-11-17 21:14:54 +00:00
Klemens Nanni
75d2080e53
Set groups when dropping privileges to not leak supplementary group access (#1202)
Changing the real and effective user/group IDs and the saved
set-user/group-ID is not enough to get rid of intial access permissions.

The list of groups must be cleared also, otherwise a process changing
from, e.g. `root:root` to `nobody:nobody` retains rights to access
`:wheel` files (assuming `root` is a member of the `wheel` group).

For example:
```
# id
uid=0(root) gid=0(wheel) groups=0(wheel), 2(kmem), 3(sys), 4(tty), 5(operator), 20(staff), 31(guest)
# ./yggdrasil -autoconf -logto /dev/null -user nobody &
[1] 4337
# ps -o command,user,group,supgrp -U nobody
COMMAND          USER     GROUP    SUPGRP
./yggdrasil -aut nobody   nobody   wheel,kmem,sys,tty,operator,staff,guest
```

Fix that so the process runs as mere
```
COMMAND          USER     GROUP    SUPGRP
./yggdrasil -aut nobody   nobody   nobody
```

Fixes #927.
2024-11-11 19:28:28 +00:00
Klemens Nanni
834680045a
Create admin socket synchronously before privdrop (#1201)
Creating UNIX sockets the listen() goroutine that races against the main
one dropping to an unprivileged user may cause startup failure when
privdrop happens before privileged filesystem access.

Setup or fail in New() and only do listen(2) in listen() to avoid this.

```
# yggdrasil -autoconf -user nobody
2024/11/03 21:15:27 Build name: yggdrasil-go
2024/11/03 21:15:27 Build version: 0.5.9
...
2024/11/03 21:15:27 Admin socket failed to listen: listen unix /var/run/yggdrasil.sock: bind: permission denied
```

Rerun, now the order is flipped:
```
# yggdrasil -autoconf -user nobody
2024/11/03 21:15:34 Build name: yggdrasil-go
2024/11/03 21:15:34 Build version: 0.5.9
[...]
2024/11/03 21:15:34 UNIX admin socket listening on /var/run/yggdrasil.sock
[...]
```

Fixes #927.
2024-11-11 19:27:02 +00:00
Neil Alexander
eef613993f
Raise link error when SNI supplied on unsupported link type
Closes #1196
2024-10-27 21:06:56 +00:00
Neil Alexander
ff0ef7ff56
Update comments in default configuration file 2024-10-27 20:59:05 +00:00
Neil Alexander
ef110b0181
Update Debian package metadata 2024-10-27 20:38:15 +00:00
Neil Alexander
b20ad846a1
When IfName is none, start queue goroutine, otherwise iprwc blocks and some handlers don't run 2024-10-20 21:28:04 +01:00
Neil
0b9c8bd020
Yggdrasil 0.5.9 (#1191)
Changelog updates.

Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2024-10-19 17:09:46 +01:00
Neil Alexander
0b9469100c
Update dependencies 2024-10-17 13:23:11 +01:00
Klemens Nanni
a6429390da
Use UNIX socket patch from url struct (#1186)
No need to extract it again when the url package provides it for us:
```
$ jq -n '{"AdminListen":"unix:///tmp/ygg.sock"}' | ./yggdrasil -useconf | grep 'admin socket'
2024/10/08 22:41:11 UNIX admin socket listening on /tmp/ygg.sock
```

Follow-up on #1176
2024-10-17 13:22:46 +01:00
Klemens Nanni
1ee61dcefa
zap obsolete nonexistent command from usage (#1184) 2024-10-17 13:22:22 +01:00
Neil Alexander
81e345c1ae
Update to Arceliar/ironwood@f6fb9da97a 2024-10-16 09:46:36 +01:00
Neil Alexander
a038a6a8ef
Update to Arceliar/ironwood@4ea1ec6d68 2024-10-13 21:33:47 +01:00
Neil Alexander
01e73792fe
Update to Arceliar/ironwood@0ac2ff3eef 2024-10-13 20:06:07 +01:00
Neil Alexander
d22dc9ecc9
TUN: Skip ErrTooManySegments 2024-10-10 09:23:13 +01:00
Klemens Nanni
874083da79
Replace repeated subscripts with single TrimPrefix (#1176)
This stood out to me while reading the code: [7:] is skipping "unix://",
so why not do that?

Doing so reveals a bug in the last line changed, where chmod(2) failure
would print just the prefix, not everything but it... easy to miss, but
now this kind of bug can no longer happen.
2024-09-30 14:25:04 +01:00
Klemens Nanni
ccda1075c0
Fix ioctl(2) code for OpenBSD (#1175)
This cleans up the mess to configure an IP address on a tun(4) device.

Handrolling a hardcoded ioctl(2) request is far from perfect, but Go
(golang.org/sys/unix) is to blame here.

Tested on OpenBSD 7.6 -current where yggdrasil now drives the interface
would use of ifconfig or other helpers.
2024-09-30 14:24:20 +01:00
Neil Alexander
6d5243bd9a
Add unit test for AllowedPublicKeys 2024-09-29 22:04:41 +01:00
Neil Alexander
377bc664c9
The AllowedPublicKeys option should not apply to multicast listeners
Another fix for #1141.
2024-09-29 21:38:56 +01:00
Neil Alexander
d1b849588f
Fix bug where ephemeral links would try to reconnect in a fast loop
Helps #1141, although not a complete solution.
2024-09-29 21:24:39 +01:00
Sergey Bobrenok
d6fd305f12
Fix Android build with Go 1.23.0 or later (#1166)
The `github.com/wlynxg/anet` library depends on the `//go:linkname`
linker feature [1]. However, since Go 1.23.0, the usage of
`//go:linkname` has been restricted [2]. And now it's necessary to
explicitly specify `-checklinkname=0` linker flag to use it.

[1]
https://github.com/wlynxg/anet/blob/main/README.md#how-to-build-with-go-1230-or-later
[2] https://tip.golang.org/doc/go1.23#linker

Resolves: #1165
2024-09-29 21:06:36 +01:00
Klemens Nanni
98a6fdb4f2
tun: bsd: remove redundant ioctl to set MTU (#1172)
wireguard's CreateTUN() sets the MTU using the same ioctl(2), on both
FreeBSD and OpenBSD.

Tested on OpenBSD (outputwith this patch):

```
# ktrace ./yggdrasil -autoconf | grep Interface
2024/09/24 17:26:29 Interface name: tun0
2024/09/24 17:26:29 Interface IPv6: 201:26e:68f0:502e:f445:13eb:2fe1:f7cd/7
2024/09/24 17:26:29 Interface MTU: 16384
```

```
$ ifconfig tun0 | head -n1
tun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 16384
```

```
# kdump | grep ioctl
 53097 yggdrasil CALL  ioctl(10,SIOCGIFMTU,0xc0000376b8)
 53097 yggdrasil RET   ioctl 0
 53097 yggdrasil CALL  ioctl(10,SIOCSIFMTU,0xc0000376c0)
 53097 yggdrasil RET   ioctl 0
 53097 yggdrasil CALL  ioctl(10,SIOCGIFMTU,0xc0000377f8)
 53097 yggdrasil RET   ioctl 0
 53097 yggdrasil CALL  ioctl(10,_IOW('i',12,0x20),0xc00003777c)
 53097 yggdrasil RET   ioctl -1 errno 25 Inappropriate ioctl for device
       "2024/09/24 17:26:29 Error in SIOCSIFADDR_IN6: inappropriate ioctl for device
```

(The completely broken address ioctl is another story...)
2024-09-29 21:05:38 +01:00
Neil Alexander
c00779c7d3
Multicast interface detection and shutdown tweaks
May help with #1173.
2024-09-29 20:58:10 +01:00
Arceliar
43a1a3de64 update ironwood dependency 2024-09-28 18:52:04 -05:00
Neil Alexander
b8ab843a98
Update admin socket response sorting 2024-09-23 22:40:52 +01:00
Neil Alexander
e138fa679c
Fix link panic when shutting down (closes #1168) 2024-09-22 17:05:25 +01:00
Neil Alexander
361b9fd6fc
Update WebSocket dependency to new import path 2024-09-22 16:54:58 +01:00
Neil Alexander
5461bb380e
Update dependencies 2024-09-22 16:51:04 +01:00
cathugger
34f087de1c
argument to change uid/gid (#927)
different from
https://github.com/yggdrasil-network/yggdrasil-go/pull/817 in that it
can resolve user names, automatically use user's primary gid & allows
specifying gid in the same argument, with `:` eg `username:groupname`.
feel free to criticize & suggest different argument name & description
because i didn't put much of thought to that.

---------

Co-authored-by: Neil <git@neilalexander.dev>
Co-authored-by: VNAT <xepjk@protonmail.com>
Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2024-09-22 15:46:54 +00:00
Neil
c4b29b735c
Link costing based on average RTT (#1171)
This PR updates Ironwood to include the new RTT-based link costing and
updates `yggdrasilctl` to report the cost in `getPeers`.

Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2024-09-21 22:05:23 +00:00
Sergey Bobrenok
947b6ad7aa
Restore local peer discovery mechanism on Android 11+ (#1158)
This solution is bases on https://github.com/wlynxg/anet project.
`github.com/wlynxg/anet` is a partial alternative implementation of the
`golang.org/x/net` module. The goal of `anet` module is to provide
workarounds of the issues https://github.com/golang/go/issues/40569 and
https://github.com/golang/go/issues/68082 on Android 11+.

Tested on AOSP 13.

Resolves: #1149
2024-08-16 18:28:57 +01:00
Neil Alexander
340cedbe14
Yggdrasil 0.5.8 2024-08-12 19:17:40 +01:00
Neil Alexander
b1283e15f6
Link state tracking tweaks and improved shutdown 2024-08-11 10:42:25 +01:00
Neil Alexander
ef989bef63
Multicast module state tweaks 2024-08-11 10:41:58 +01:00
Neil Alexander
af9ff34995
Fix macOS build 2024-08-07 19:55:10 +01:00
Neil Alexander
63cd757525
Remove waitForTUNUp from TUN
Causes issues such as #1156.
2024-08-07 19:52:19 +01:00
Revertron
5e5de3a343
Fixed wait for TUN to come up (#1157)
So, the function waiting for TUN to come up never succeeds:
```
func waitForTUNUp(ch <-chan wgtun.Event) bool {
	t := time.After(time.Second * 5)
	for {
		select {
		case ev := <-ch:
			if ev == wgtun.EventUp {
				return true
			}
		case <-t:
			return false
		}
	}
}
```
I've tried the sleep for one second, and it works flawlessly on several
PCs.

Another point - sometimes, if the service stop abruptly (in case of some
errors) there is an old hidden device in the system, that we need to
uninstall, and then create new.
2024-08-06 10:28:15 +01:00
Neil Alexander
edf179ed26
Yggdrasil 0.5.7 2024-08-05 19:18:38 +01:00
Neil Alexander
9950d1225d
Improve link and handshake errors 2024-08-01 21:53:48 +01:00
Revertron
4fbdeb4e3f
Fixed Windows service life-cycle. (#1153)
This fix fixes two issues:
https://github.com/yggdrasil-network/yggdrasil-go/issues/993 &
https://github.com/yggdrasil-network/yggdrasil-go/issues/1098
2024-07-25 13:55:14 +01:00
Vasyl Gello
5ea16e63a1
Implement websocket (ws:// and wss://) links (#1152)
ws:// can be listened and dialed
wss:// is a convenience link for ws:// that supports dialing to ws://
peer.

---------

Signed-off-by: Vasyl Gello <vasek.gello@gmail.com>
Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2024-07-23 22:58:11 +01:00
Neil Alexander
da7ebde828
Update dependencies 2024-07-20 15:37:31 +01:00
Neil
02d92ff81c
TUN vectorised reads/writes (#1145)
This PR updates the Wireguard dependency and updates to use new
vectorised reads/writes, which should reduce the number of syscalls and
improve performance.

This will only make a difference on Linux as this is the only platform
for which the Wireguard TUN library supports vectorised reads/writes.
For other platforms, single reads and writes will be performed as usual.

---------

Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2024-07-20 15:24:30 +01:00
Neil Alexander
04c0acf71b
Various clean-ups 2024-07-20 12:31:58 +01:00
Neil Alexander
8ecc402d7c
Allow multiple connections to the same link-local address
Note that this may mean that currently we end up with two links to each multicast-discovered peer, one incoming and one outgoing
2024-07-20 11:31:08 +01:00
Neil Alexander
c505097be0
Update mobile build for iOS/macOS framework generation 2024-06-26 23:17:11 +01:00
Neil
fec96a38a4
Release: Yggdrasil v0.5.6 (#1144)
* Changelog updates for Yggdrasil v0.5.6

* Fix spelling error

---------

Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
Co-authored-by: Arceliar <Arceliar@users.noreply.github.com>
2024-05-30 23:30:05 +01:00
Neil
f788a18bef
Measure RTT, report in getPeers (#1143)
Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2024-05-30 22:46:06 +01:00
Neil Alexander
fcefb20993
Fix interval check when sending multicast beacons 2024-05-28 10:03:48 +01:00
Neil Alexander
2831d73f73
Try to fix WiX for Windows MSI builds 2024-05-27 22:52:48 +01:00
Neil Alexander
c2811c0cdc
Update more GHA actions due to deprecations 2024-05-27 22:14:28 +01:00
Neil Alexander
5d9c5b3c9b
Minimum Go 1.21, update quic-go, update some CI actions 2024-05-27 22:03:41 +01:00
Paul Donald
f56f9c124c
Minor Fixes (#1107)
* Minor comment fixes.

* Optimize PeerEntry for memory efficiency

* Improve NodeConfig for memory alignment
2024-05-27 21:57:28 +01:00
trashpile-shenanigans
5da1fbe397
Bump minimum required go version to 1.20 in documentation as required by quic-go dependency (#1138) 2024-05-27 21:53:52 +01:00
Arceliar
6f3a0a71d4 update ironwood and other dependencies 2024-05-25 06:16:11 -05:00
Arceliar
6cbe56adfe fix incorrect pool use 2024-05-25 06:15:36 -05:00
Arceliar
2d644eabc3 update ironwood (updates bloom dependency) 2024-03-21 21:33:07 -05:00
Neil Alexander
2c20a04369
Release: Yggdrasil 0.5.5 2024-01-27 22:54:54 +00:00
Neil Alexander
81f2c711b4
Fix panic in getPeers on abstract UNIX socket names
Fixes #1111
2024-01-15 23:14:43 +00:00
Neil
180d7bf499
Adjust default backoff max to just over 1 hour, add ?maxbackoff= peer option (#1124)
Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2024-01-15 23:09:07 +00:00
Neil Alexander
9f4c89acad
Update dependencies 2024-01-15 23:00:58 +00:00
Neil Alexander
5da4c1131e
Update ironwood to ddd1fa6 2024-01-15 19:07:17 +00:00
Neil Alexander
768278a8e6
Improve getPeers sorting 2024-01-11 22:37:05 +00:00
Neil Alexander
1e9a59edf9
Update behaviour in QUIC listener handler 2024-01-05 11:45:20 +00:00
Neil Alexander
3dfa6d0cc9
Validate public key lengths on debug_ API endpoints (fixes #1113) 2023-12-03 17:55:12 +00:00
Neil Alexander
6b6cd0bed5
Fix PPROFLISTEN 2023-11-28 13:24:54 +00:00
Neil Alexander
3d15da34ad
Release: Yggdrasil 0.5.4 2023-11-27 14:17:16 +00:00
Arceliar
741f825b8e update ironwood dependency, should fix bloom filter encoding crash 2023-11-27 07:18:16 -06:00
Neil Alexander
676ae52503
Release: Yggdrasil 0.5.3 2023-11-26 18:42:08 +00:00
Neil Alexander
fef553ed18
Tweak logging 2023-11-26 16:28:48 +00:00
Neil Alexander
f6f669617f
Fix -normaliseconf when using PrivateKeyPath 2023-11-26 16:20:52 +00:00
Neil Alexander
39c4b24395
Don't use 0-RTT for QUIC 2023-11-26 16:19:00 +00:00
Arceliar
0d676c6a3b update ironwood dependency 2023-11-26 04:56:44 -06:00
Neil Alexander
a0b3897278
Cap link backoff at roughly 4.5 hours 2023-11-21 23:54:27 +00:00
Arceliar
abec2256ae
Merge pull request #1105 from yggdrasil-network/neil/backoff
Tweak backoff success handling
2023-11-21 04:49:41 -06:00
Neil Alexander
7aca869170
Tweak backoff success handling 2023-11-21 10:35:17 +00:00
Arceliar
b759683b76 Merge branch 'develop' of https://github.com/yggdrasil-network/yggdrasil-go into develop 2023-11-09 22:06:38 -06:00
Arceliar
6677d70648 update ironwood, fixed data race from buffered pathfinder traffic 2023-11-09 22:06:19 -06:00
Neil Alexander
7ac38e3e58
Release: Yggdrasil 0.5.2 2023-11-06 09:25:15 +00:00
Neil
49c424ef21
Add -publickey command line switch (#1096)
Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2023-11-04 18:42:51 +00:00
Neil
0346af46da
Don't panic when connect returns nil (fixes #1086) (#1089)
* Don't panic when connect returns `nil` (fixes #1086)

It isn't clear to me why this would happen but let's guard the condition anyway.

* Log inconsistent error state

---------

Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2023-11-04 18:42:42 +00:00
Neil
93a5adfd18
Add sockstls:// (#1090)
Closes #1087.

Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2023-11-04 17:57:15 +00:00
Neil
ddb75700a0
Report errors during handshake stage (#1091)
Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2023-11-04 17:57:04 +00:00
Neil
ae997a5acb
Improve TUN setup logging (#1093) (#1095)
Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2023-11-04 17:56:52 +00:00
Arceliar
6a9c90d3eb Merge branch 'develop' of https://github.com/yggdrasil-network/yggdrasil-go into develop 2023-11-03 21:56:26 -05:00
Arceliar
41e045fe5b update ironwood dependency 2023-11-03 21:55:42 -05:00
Neil
e5e8c84d7c
Merge pull request #1078 from yggdrasil-network/duplicate-peers
Don't panic at startup when duplicate peers are configured
2023-10-28 22:21:04 +01:00
Neil Alexander
e41b838d8f
Don't panic at startup when duplicate peers are configured
Fixes #1077
2023-10-28 21:34:15 +01:00
Neil Alexander
7f9d4f3f6d
Don't import LDFLAGS from the environment 2023-10-28 18:21:26 +01:00
Neil Alexander
a6b316ef08
Release: Yggdrasil 0.5.1 2023-10-28 16:21:50 +01:00
Neil Alexander
d781fef760
Release: Yggdrasil 0.5.0 2023-10-28 15:23:01 +01:00
Neil Alexander
b332664acb
Release: Yggdrasil 0.5.0 2023-10-28 15:11:34 +01:00
Neil Alexander
01c1498bd5
Yggdrasil 0.5 release notes 2023-10-28 15:07:45 +01:00
Neil
0b578a637a
Debian package updates (#1073)
* Update Debian package

* Don't put `AdminListen` in config by default, fix path in Debian package

* Fix path in unit file

* Preserve original service files for other packages

---------

Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2023-10-28 14:58:52 +01:00
Arceliar
82c54f87ea clean up some debug API output 2023-10-28 06:36:01 -05:00
Arceliar
d17ac39789 update ironwood dependency, add a debug API call for lookups 2023-10-28 05:26:43 -05:00
Neil Alexander
ea6ccf552f
Update dependencies, test cross-builds for FreeBSD and OpenBSD in CI 2023-10-27 23:16:13 +01:00
Neil
1ac3d540e7
Merge pull request #1070 from Revertron/fix_mobile 2023-10-25 20:31:15 +01:00
Revertron
6873fd44ff Fixes logger, adds some log messages. 2023-10-25 20:59:19 +02:00
Neil Alexander
8afa737a8d
Use ubuntu-20.04 image for router packages in CI 2023-10-24 22:44:33 +01:00
Neil Alexander
7934158f5f
Use ubuntu-20.04 image for Debian packages in CI 2023-10-24 12:10:48 +01:00
Neil Alexander
a60771344a
Remove DHT from yggdrasilctl help text (fixes #1069) 2023-10-23 23:42:31 +01:00
Neil Alexander
90c6288f7c
Yggdrasil 0.5 RC3 2023-10-23 22:26:53 +01:00
Neil Alexander
094f80f39c
Fix RetryPeersNow, move startup logging, don't set TUN address if not available 2023-10-22 15:51:30 +01:00
Neil Alexander
955aa4af79
Remove unnecessary pprof log line 2023-10-22 10:29:19 +01:00
Neil Alexander
73c6c25bd9
Restore removePeer method 2023-10-22 10:27:41 +01:00
Neil Alexander
80e56eafcd
Allow PPROFLISTEN on all builds 2023-10-21 21:36:28 +01:00
Alex Akselrod
6a9493757d
mobile: add support for Listen in config (#1063)
Co-authored-by: Neil <git@neilalexander.dev>
2023-10-21 17:33:17 +00:00
John Jolly
8ea20cd205 Add output for threadcount and key generation time to cmd/genkey
This change is to display information about the key generation process.

Specifically, two bits of information are now displayed
 * The number of threads created to search for keys, and
 * The time taken to generate a successful "next best" key
2023-10-21 18:21:47 +01:00
Neil Alexander
a2dffeff33
Version 0.5 RC2 release notes 2023-10-18 22:52:37 +01:00
Neil Alexander
a2053b51fe
Yggdrasil 0.5 RC2 2023-10-18 22:44:14 +01:00
Neil Alexander
aceb037c57
Fix panic in mobile GetPeersJSON 2023-10-18 22:38:10 +01:00
Neil Alexander
bcd80b043f
Don't tightloop when a listener can no longer accept connections 2023-10-17 21:41:21 +01:00
Neil Alexander
74ca02edfd
Don't require TLS client certificate 2023-10-15 23:06:10 +01:00
Neil
e110dd46fd
Yggdrasil 0.5 RC1 (merge future into develop)
Merge `future` into `develop`
2023-10-15 17:29:59 +01:00
Neil Alexander
88b773cd0a
Version 0.5 RC1 release notes 2023-10-15 17:09:12 +01:00
Neil Alexander
efb4b4635d
Don't send a TLS ALPN name 2023-10-14 20:26:30 +01:00
Neil Alexander
117e4b88f8
Fix panic on invalid handshake length 2023-10-12 19:12:17 +01:00
Neil Alexander
4b48fd0b5f
Fix Windows TUN build 2023-10-12 00:08:16 +01:00
Neil
854cd75f04
Merge pull request #1042 from pfactum/syslog-no-timestamp
cmd/yggdrasil: do not log timestamps to syslog
2023-10-11 23:58:12 +01:00
Neil Alexander
4f656685ef
Revert Wireguard TUN upgrade (needs work for vectorised reads) 2023-10-11 23:52:39 +01:00
Neil Alexander
ed8ba584e2
Update dependencies 2023-10-11 23:42:37 +01:00
Neil Alexander
2a21241738
Multicast passwords 2023-10-11 19:28:28 +01:00
Neil Alexander
45b773eade
Remove TLS root validation
This is just too complicated compared to the per-peer/per-listener/per-interface password
approach.
2023-10-11 18:25:35 +01:00
Neil Alexander
6dc847de31
Merge branch 'neil/password' into future 2023-10-11 17:06:58 +01:00
Neil Alexander
bd7e699130
Add unit test for password auth 2023-10-09 22:28:20 +01:00
Neil Alexander
268ffbfd14
Add authenticated handshake, support for passwords 2023-10-09 17:17:12 +01:00
Neil Alexander
490c11c29e
Fix more codefactor suggestions 2023-09-03 13:49:21 +01:00
Neil Alexander
991ea8b876
Fix codefactor suggestion 2023-09-03 13:32:15 +01:00
Neil Alexander
68d1036de8
Fix mobile unit test 2023-09-03 13:30:48 +01:00
Neil Alexander
fa3d943ba9
Don't set BBR for TCP peerings 2023-09-03 13:30:41 +01:00
Neil
9defa35c66
Merge branch 'develop' into future 2023-09-03 13:18:47 +01:00
Neil Alexander
c8b9aaeb67
Only set mobile memory limit on supported Go versions 2023-09-03 13:13:53 +01:00
Neil Alexander
8f3ab1d83c
Merge branch 'develop' into future 2023-09-03 13:08:40 +01:00
Neil Alexander
12a3a8c73b
Fix build tags for setupFD 2023-09-03 13:08:13 +01:00
Neil
6ab0639b82
Merge branch 'develop' into future 2023-09-03 12:58:55 +01:00
Neil Alexander
fbc5f62add
Fix missing setupFD stubs 2023-08-17 14:08:03 +01:00
Neil Alexander
5b203ad8c5
Use Go 1.21 in CI, update minimum version to Go 1.20, lint fixes, update quic-go 2023-08-12 18:12:58 +01:00
Arceliar
fe14981dda update ironwood 2023-08-05 04:01:15 -05:00
Neil Alexander
63b214f6b7
Fix negotiating priority on connection 2023-07-15 22:34:29 +01:00
Neil Alexander
ff96740ac7
Fail to start if no configuration provided 2023-07-15 20:12:14 +01:00
Arceliar
7f94463332
Merge pull request #1037 from yggdrasil-network/neil/quic
QUIC interface support
2023-06-19 06:27:09 -05:00
Arceliar
bcbabff80f
Merge pull request #1038 from yggdrasil-network/neil/multicast
Revise multicast format to include protocol version, discriminator for TLS roots
2023-06-19 06:26:58 -05:00
Arceliar
99dd8f85d3
Merge pull request #1046 from yggdrasil-network/neil/handshake
Tweak link handshake
2023-06-19 06:23:47 -05:00
Neil Alexander
57d9a2399f
Revise multicast format to include protocol version, discriminator for TLS roots 2023-06-18 20:54:49 +01:00
Neil Alexander
423fc248d2
Remove debug lines 2023-06-18 20:54:16 +01:00
Neil Alexander
516fcce6b3
Keepalives are needed to stop the connection inactivity timeout 2023-06-18 20:54:16 +01:00
Neil Alexander
d8dc6b2670
QUIC interface support 2023-06-18 20:54:14 +01:00
Neil Alexander
109f59c7dc
Tweak link handshake 2023-06-18 20:28:14 +01:00
Neil Alexander
002b984c04
Fix private key setup when certificate not specified 2023-06-18 18:10:27 +01:00
Neil Alexander
5e684550a8
Take interface in tun.New 2023-06-18 15:45:04 +01:00
Neil
80724438c9
Merge pull request #1045 from yggdrasil-network/neil/tunintf
Define interface for RWCs
2023-06-18 15:43:16 +01:00
Neil Alexander
b0f8d8af13
Define interface for RWCs 2023-06-18 15:36:14 +01:00
Arceliar
31177f5a73
Merge pull request #1044 from yggdrasil-network/arc/linkfix
Fix duplicate connections
2023-06-18 08:49:20 -05:00
Arceliar
c1ae9ea0d4 Switch back to using an actor to manage link state, and slighty randomize the delay between multicast announcements. This seems to fix the issue with duplicate connections (and breaks a livelock in the multicast code where both nodes keep closing the listen side of their connection, but that's kind of a hack, we need a better solution) 2023-06-18 03:40:40 -05:00
Oleksandr Natalenko
f6c0d8406d cmd/yggdrasil: do not log timestamps to syslog
It is expected a syslog implementation be it rsyslog or journald to
have their own timestamping, so there's no point in duplicating that
info.

Signed-off-by: Oleksandr Natalenko <oleksandr@natalenko.name>
2023-06-08 21:44:46 +02:00
Neil Alexander
db9b57c052
Update contrib/mobile for the latest iOS build 2023-06-06 22:11:49 +01:00
Neil Alexander
2eda59d9e4
Improve link setup locking and guards 2023-05-23 22:39:10 +01:00
Neil Alexander
06ca8941c7
Fix race condition between incoming and outgoing connection setup 2023-05-22 23:10:44 +01:00
Arceliar
8562b6b86e
Merge pull request #1040 from yggdrasil-network/Arceliar/allocs
Reduce allocations
2023-05-21 12:56:37 -05:00
Arceliar
e94985c583 try to cheer up the linter again 2023-05-21 12:49:49 -05:00
Arceliar
5a6f27e732 cheer up the linter 2023-05-21 12:43:03 -05:00
Arceliar
8b5add5301 reduce allocations (also pulls in updated ironwood to do the same) 2023-05-21 12:38:16 -05:00
Neil
52709696a5
Merge pull request #1036 from yggdrasil-network/neil/linktweaks
Tweak link state locking, add comments, listener priority, other fixes
2023-05-21 00:06:43 +01:00
Neil Alexander
cb8333f9ff
Tweak lock behaviour 2023-05-21 00:02:04 +01:00
Neil Alexander
333561f4e1
Tweak link state locking, add comments, listener priority, other fixes 2023-05-20 23:44:31 +01:00
Neil
2565cbf11b
Merge pull request #1034 from yggdrasil-network/neil/futurelink2
Link refactoring, admin socket changes, TLS changes
2023-05-20 23:02:44 +01:00
Arceliar
19ca25538f
Merge pull request #1033 from yggdrasil-network/ironwood-experimental
Update to experimental ironwood
2023-05-20 17:00:23 -05:00
Neil Alexander
aff3201084
Fix incoming connection handlers 2023-05-20 22:22:15 +01:00
Neil Alexander
c0188f5600
Discriminate multicast peers more loosely 2023-05-20 21:18:49 +01:00
Neil Alexander
e0b39b303f
Use regular mutex instead (less type assertions)
This reverts commit 5ba9dadc49.
2023-05-20 18:36:44 +01:00
Neil Alexander
5ba9dadc49
Use sync.Map instead of link actor 2023-05-20 18:31:01 +01:00
Neil Alexander
6e338b6f89
Fix con urrent map accesses 2023-05-20 18:21:02 +01:00
Neil Alexander
e290e744f4
Fix -autoconf 2023-05-20 10:54:49 +01:00
Neil Alexander
a233e775eb
yggdrasilctl tweaks 2023-05-19 20:57:14 +01:00
Neil Alexander
6ac2fae845
Fix Windows build 2023-05-19 20:34:51 +01:00
Neil Alexander
7b1635245f
Add missing path notify and bloom transform 2023-05-19 19:33:40 +01:00
Neil Alexander
a9ec3877b5
Fix unit test 2023-05-19 19:09:06 +01:00
Neil Alexander
7afa23be4c
Link refactoring, admin socket changes 2023-05-19 19:09:05 +01:00
Arceliar
c7ee7d9681 update ironwood dependency (it should build now...) 2023-05-14 21:24:08 -05:00
Arceliar
ffb2f06992 Merge branch 'ironwood-experimental' of https://github.com/yggdrasil-network/yggdrasil-go into ironwood-experimental 2023-05-14 21:14:32 -05:00
Arceliar
101189a9dc update ironwood dependency 2023-05-14 21:13:53 -05:00
Neil Alexander
c7ea223a9a
Update mobile bindings 2023-05-14 10:16:33 +01:00
Arceliar
669e61af9a update to bugfixed ironwood, fix broken core test, add getPaths handler to admin socket 2023-05-13 16:15:04 -05:00
Arceliar
5e95246c26 update to ironwood v0.0.0-20230513191034-495699d87ae4 with API changes 2023-05-13 14:44:38 -05:00
Neil Alexander
1345960d5f
Update to Arceliar/ironwood@14d951a 2023-05-07 17:29:46 +01:00
Arceliar
8696650958
Update go.mod 2023-03-26 17:06:18 -05:00
Arceliar
ebd3596c2c
Update ci.yml 2023-03-26 17:05:55 -05:00
Arceliar
e99c870d51 update admin functions and fix core tests 2023-03-26 16:49:40 -05:00
Arceliar
abbe94fa80 fix core tests and run gofmt on src 2023-03-26 16:34:49 -05:00
Arceliar
fc632c5caa comment out some unused ipv6rwc code 2023-03-26 16:17:31 -05:00
Arceliar
5b6d9d52f3 update ironwood replace, update ipv6rwc to work (may need updates later if interface changes) 2023-03-26 16:12:45 -05:00
Neil Alexander
5a243d5b95
Update ironwood replace 2023-03-19 21:44:34 +00:00
Neil Alexander
a148f4cfec
More updates for Ygg v0.5 2023-03-19 10:33:07 +00:00
Neil Alexander
83c1a810b5
New handshake, use softcrdt upstream 2023-03-18 12:14:32 +00:00
Neil
1420ea5662
Merge pull request #1004 from Dry-Leaf/bsd_build_fix
Added member to Logger struct expected by tun_bsd.go
2023-02-26 22:01:32 +00:00
Neil
a8f0ada7ee
Merge branch 'develop' into bsd_build_fix 2023-02-26 21:54:50 +00:00
Neil
1685b87a04
Merge pull request #1021 from yggdrasil-network/dependabot/go_modules/golang.org/x/net-0.7.0
Bump golang.org/x/net from 0.0.0-20221014081412-f15817d10f9b to 0.7.0
2023-02-26 21:43:51 +00:00
Neil
9ee6c46b1d
Merge branch 'develop' into bsd_build_fix 2023-02-26 21:40:29 +00:00
Neil
3b0a819e68
Merge branch 'develop' into dependabot/go_modules/golang.org/x/net-0.7.0 2023-02-26 21:36:09 +00:00
Neil Alexander
38736358dd
Fix lint error properly this time 2023-02-26 21:35:56 +00:00
Neil Alexander
1dd1d0ab8c
Build packages with Go 1.20 2023-02-26 21:32:26 +00:00
Neil Alexander
6d6c408957
Test against Go 1.20, maybe fix lint issue 2023-02-26 21:31:20 +00:00
Neil
783b4d3de6
Merge branch 'develop' into bsd_build_fix 2023-02-26 21:28:29 +00:00
Neil
a6f742ee93
Merge branch 'develop' into dependabot/go_modules/golang.org/x/net-0.7.0 2023-02-26 21:27:56 +00:00
Neil
4189053cfc
Merge pull request #981 from yggdrasil-network/neilalexander/tryall
Try all addresses when connecting to a DNS name
2023-02-26 21:24:01 +00:00
dependabot[bot]
886281af7c
Bump golang.org/x/net from 0.0.0-20221014081412-f15817d10f9b to 0.7.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.0.0-20221014081412-f15817d10f9b to 0.7.0.
- [Release notes](https://github.com/golang/net/releases)
- [Commits](https://github.com/golang/net/commits/v0.7.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-25 02:28:24 +00:00
anon
9cbc71bc8a Added member to Logger struct expected by tun_bsd.go 2022-12-18 00:37:34 -05:00
Neil Alexander
723097fbf6
Deduplicate some logic 2022-11-26 16:18:15 +00:00
Neil Alexander
1adc88ec77
Merge branch 'develop' into neilalexander/tryall 2022-11-26 16:00:46 +00:00
Neil Alexander
14f1cd4696
Version 0.4.7
Merge pull request #986 from yggdrasil-network/develop
2022-11-20 21:20:11 +00:00
Neil Alexander
b0f6544b07
Update changelog date 2022-11-20 21:14:33 +00:00
Neil Alexander
48d278bd2a
Version 0.4.7 changelog (#985) 2022-11-15 19:06:14 +00:00
Neil Alexander
596f16aa6c
Reduce allocations in encrypted package (update to Arceliar/ironwood@ec61cea) 2022-11-15 12:46:08 +00:00
Neil Alexander
ae24f5de38 Less aggressive key ratcheting (update to Arceliar/ironwood@bf5f12a) 2022-11-12 16:55:23 +00:00
Neil Alexander
cba667f28d Fix race conditions (update to Arceliar/ironwood@2c0740b) 2022-11-12 16:47:20 +00:00
Neil Alexander
9df3bc0066
Update to Arceliar/ironwood@846a97f5e5 2022-11-12 15:26:43 +00:00
Neil Alexander
e824c73e21
Fix crash 2022-11-12 11:56:50 +00:00
Neil Alexander
7efd66932f
Redial failed connections if possible (#983) 2022-11-12 11:30:03 +00:00
solanav
0da871f528
Fix #884 (#916)
* Fixed #884

* Remove yggdrasil and yggdrasilctl

* Fixed #884

Co-authored-by: asolana <asolana@deloitte.es>
Co-authored-by: solanav <solanav1337@gmail.com>
Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2022-11-08 22:19:43 +00:00
majestrate
6fed2a75d7
Make TLS certs never expire (#977)
According to RFC5280 we can make TLS certs never expire by setting their `NotAfter` date to a value that is basically the end of time.

Fixes #976.
2022-11-08 22:11:22 +00:00
Neil Alexander
110613b234 Try all addresses when connecting to a DNS name
Fixes #980
2022-11-08 21:59:13 +00:00
Neil Alexander
6112c9cf18
Fix build 2022-11-01 18:34:49 +00:00
Neil Alexander
590d83aa9c
Fix #975 by not exporting uint8 2022-11-01 17:42:52 +00:00
Revertron
ee33bd248f
Added two new methods to mobile package (#974)
* Added two new methods

In order to implement https://github.com/yggdrasil-network/yggdrasil-android/issues/25 we need these new methods.

* Renamed methods, changed comments
2022-11-01 12:10:50 +00:00
Neil Alexander
cfa293d189 Fix bug in admin socket where requests fail unless "arguments":{} is specified in the JSON 2022-10-26 22:29:19 +01:00
Neil Alexander
98b0aaf747
Merge branch 'master' into develop 2022-10-26 18:26:37 +01:00
Neil Alexander
4c66a13b93
Version 0.4.6 2022-10-26 18:25:48 +01:00
Neil Alexander
f08dec822a
Priority support (#964)
* Allow setting link priorities

* Fix a bug

* Allow setting priority on listeners and multicast interfaces

* Update `yggdrasilctl`

* Update to Arceliar/ironwood#5
2022-10-26 09:24:24 +01:00
Neil Alexander
9a9452dcc8 Fix panic in GetPeers that may happen mid-link setup 2022-10-25 18:58:52 +01:00
Neil Alexander
65e350153e Don't start multicast module if all Beacon and Listen are disabled 2022-10-22 18:05:14 +01:00
Neil Alexander
35ea66d651 Varying connection check strictness based on scope 2022-10-22 17:45:09 +01:00
Neil Alexander
8fe1c41295 Don't reject multiple genuine links from the same host 2022-10-22 16:59:25 +01:00
Neil Alexander
d66b3ffb7a Always allow link-local peerings again 2022-10-22 16:23:25 +01:00
Neil Alexander
63c4cb5c21 Fix reporting name for TCP 2022-10-22 15:47:09 +01:00
Neil Alexander
0a1a155e66 Use SO_REUSEADDR instead of SO_REUSEPORT on Linux 2022-10-22 14:56:29 +01:00
Neil Alexander
c55611a478 Tweak logging for connections 2022-10-22 14:56:11 +01:00
Neil Alexander
22caddef63 Don't log duplicate connection attempt 2022-10-21 19:49:49 +01:00
Neil Alexander
81839ad50d Fix InterfacePeers 2022-10-21 19:49:15 +01:00
Neil Alexander
b8a2d9f125
Version 0.4.5 (#957)
* Version 0.4.5 changelog

* Update changelog
2022-10-18 23:04:06 +01:00
Neil Alexander
8ce7c86383 Update some dependencies 2022-10-15 17:45:41 +01:00
Neil Alexander
69782ad87b Improve shutdown behaviour (fixes #891) 2022-10-15 16:07:32 +01:00
Neil Alexander
ee21c56e43 Fix setting nodeinfo (closes #954) 2022-10-15 15:42:52 +01:00
Neil Alexander
69632bacb5 Tidy up 2022-10-02 13:20:39 +01:00
Neil Alexander
962665189c Tweaks to yggdrasilctl 2022-10-02 13:15:11 +01:00
Neil Alexander
428d2375da Don't allow configuring the same peer more than once 2022-10-02 12:39:18 +01:00
Neil Alexander
8cf76f841d Silence already connected to this node 2022-10-02 12:36:51 +01:00
ehmry
7db934488e
Reimplement AddPeer and RemovePeer for admin socket (#951)
* Reimplement AddPeer and RemovePeer for admin socket

Fix #950

* Disconnect the peer on `removePeer`

Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2022-10-02 12:35:43 +01:00
Neil Alexander
c922eba2d8
Fix sending arguments to the admin socket in yggdrasilctl 2022-09-24 21:28:09 +01:00
Neil Alexander
1de587a971
Update to Arceliar/ironwood@ed4b6d4 2022-09-24 17:06:24 +01:00
Neil Alexander
d9fe6f72ac
Lint tweaks 2022-09-24 17:05:44 +01:00
Neil Alexander
d24d3fa047
Use deadline for link handshake (#949)
This uses a 6 second deadline for timeouts instead of using `util.FuncTimeout` at 30 seconds for the read and then again for the write.

If the handshake doesn't complete within 6 seconds then it's going to probably collapse when we give the connection to Ironwood and it tries to do a keepalive anyway.
2022-09-24 16:51:31 +01:00
Neil Alexander
e165b1fa0c
Add quote marks to InterfacePeers comment
Fixes #945.
2022-09-24 14:44:50 +01:00
Neil Alexander
01c44a087b
Rename tuntap package to tun
We haven't had TAP support in ages.
2022-09-24 14:41:47 +01:00
Neil Alexander
217ac39e77
Allow setting default config path and AdminListen at compile time
By providing the following items to `LDFLAGS`:

* `-X github.com/yggdrasil-network/yggdrasil-go/src/defaults.defaultConfig=/path/to/config`
* '-X github.com/yggdrasil-network/yggdrasil-go/src/defaults.defaultAdminListen=unix://path/to/sock'

Closes #818.
2022-09-24 14:09:08 +01:00
Neil Alexander
0abfe78858
Silence error when reconnecting to already connected peer 2022-09-24 13:46:22 +01:00
Neil Alexander
5ad8c33d26
Remove packaging from main CI run 2022-09-24 13:38:14 +01:00
Neil Alexander
b67c313f44
Admin socket and yggdrasilctl improvements
This refactors the request parsing, as well as improving the output for some request types. It also tweaks `yggdrasilctl` output, which should help with #947.
2022-09-24 12:22:38 +01:00
Neil Alexander
5ef61faeff
Link refactor (#941)
* Link refactoring

* More refactoring

* More tweaking

* Cleaner shutdowns, UNIX socket support, more tweaks

* Actorise links, remove mutex

* SOCKS support
2022-09-17 20:07:00 +01:00
Alexander Ivanov
414aaf6eb9
Update mobile.go (#942) 2022-09-05 12:55:35 +01:00
Neil Alexander
88a393a7b3 Load listen addresses 2022-09-03 17:26:12 +01:00
Neil Alexander
dc9720e580 Extend getSessions admin call to include uptime/TX/RX 2022-09-03 16:55:57 +01:00
Neil Alexander
5477566fa9 Length not capacity 2022-09-03 12:38:42 +01:00
Neil Alexander
9cdfd59476 Tidy up a bit, make sure to copy the private key at startup 2022-09-03 12:34:29 +01:00
Neil Alexander
a7d06e048a Refactor TUN setup (isolated config) 2022-09-03 12:20:57 +01:00
Neil Alexander
b1f61fb0a8 Refactor admin socket setup (isolated config) 2022-09-03 11:54:46 +01:00
Neil Alexander
493208fb37 Refactor multicast setup (isolated config, etc) 2022-09-03 11:42:05 +01:00
Neil Alexander
dad0b10dfe Move Core._applyOption 2022-09-03 10:51:44 +01:00
Neil Alexander
c6fe81b5d2
Admin socket and yggdrasilctl refactoring (#939) 2022-09-03 10:50:43 +01:00
Neil Alexander
4f2abece81
Fix panic in tcp.init for incorrectly formatted listen addresses 2022-09-01 16:56:42 +01:00
Karandashov Daniil
486ffebedd
Delete unused param (#935) 2022-08-29 20:40:19 +01:00
Arceliar
af99fa4f6b
Merge pull request #929 from yggdrasil-network/neilalexander/refactor
Node setup refactoring
2022-08-28 13:46:42 -05:00
Arceliar
a182fad8d6
Merge branch 'develop' into neilalexander/refactor 2022-08-28 13:39:26 -05:00
Alexander Ivanov
f8e626dbe1
Fix Android multicast crash (#930)
* Do not exit on multicast errors (mobile)

* Consistency with cmd/yggdrasil/main.go

Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2022-08-10 22:54:02 +01:00
Neil Alexander
dd66e8a9c9
Merge branch 'develop' into neilalexander/refactor 2022-08-06 15:23:44 +01:00
Neil Alexander
16b8149052 No longer use ioutil which is deprecated 2022-08-06 15:21:21 +01:00
Neil Alexander
d5c0dc9bee Go 1.19 in CI 2022-08-06 15:19:01 +01:00
Neil Alexander
4c889703b1 Continue refactoring 2022-08-06 15:05:12 +01:00
Neil Alexander
5616b9fc84
Don't lose my work 2022-07-24 10:23:25 +01:00
Neil Alexander
41b4bf69cf Version 0.4.4 2022-07-07 18:36:11 +01:00
Neil Alexander
36c754cd0d
Merge branch 'develop' into v044 2022-07-07 18:19:24 +01:00
Neil Alexander
8c454a146c
Silence incorrect linter warning 2022-07-07 18:19:15 +01:00
Neil Alexander
df7ca3a5b8
Update changelog 2022-07-07 18:17:39 +01:00
Neil Alexander
234addc81f
Update changelog 2022-07-07 18:17:27 +01:00
Neil Alexander
96ba6f0fd9
Merge branch 'develop' into v044 2022-07-07 18:16:05 +01:00
Neil Alexander
e4ec277683
Merge pull request #902 from Rubikoid/getself-fix-coords
Fix printing self coordinates in getself command of yggdrasilctl
2022-07-07 18:15:27 +01:00
Neil Alexander
88a0a3e8fb
Fix data races in handleProto (observed by @majestrate) 2022-07-07 17:03:29 +01:00
Rubikoid
c19319df5e Fix coords print 2022-05-03 11:40:19 +03:00
Neil Alexander
4ddebb338d Update changelog 2022-04-18 15:29:43 +01:00
Neil Alexander
e13657d2ca Version 0.4.4 changelog 2022-04-18 15:27:47 +01:00
Neil Alexander
42d4298e19 Update ironwood to latest commit on archive-ygg0.4 branch 2022-04-18 15:23:52 +01:00
Neil Alexander
5e89ab706f
Update README.md 2022-04-18 15:20:45 +01:00
Neil Alexander
b77b018c4d Modify workflow strategy 2022-04-18 10:35:05 +01:00
Neil Alexander
c3de1542b0 Move CodeQL into main CI workflow 2022-04-18 10:33:33 +01:00
Neil Alexander
55f7874b35 Limit concurrency of CI runs 2022-04-18 10:30:40 +01:00
Neil Alexander
e9caf989b8
Enable CodeQL 2022-04-18 10:27:43 +01:00
Neil Alexander
d2308f8d3a Remove Appveyor and CircleCI configs 2022-04-18 10:25:05 +01:00
Neil Alexander
bc78530fcb Build packages in GitHub Actions 2022-04-17 23:38:16 +01:00
Neil Alexander
073799d3de Require Go 1.17 2022-04-17 18:22:26 +01:00
Neil Alexander
41d890bb64 Run goimports 2022-04-17 18:02:25 +01:00
Neil Alexander
90f9be38c5 Fix lint errors 2022-04-17 17:56:54 +01:00
Neil Alexander
c7ffbc05a5 Update GitHub Actions 2022-04-17 17:53:55 +01:00
Neil Alexander
93c94e38f9
GitHub Actions 2022-04-17 17:24:34 +01:00
Neil Alexander
6c4778bb67
Merge pull request #907 from yggdrasil-network/neilalexander/pmtud 2022-04-03 17:45:33 +01:00
Neil Alexander
0c4c385885
Fix regression in Path MTU discovery
In the past we used to send back anything up to 900 bytes of the packet in the ICMPv6 Packet Too Big response, whereas now we seemingly only send back 40 bytes.

It turns out that sending back only the 40 bytes of IPv6 headers isn't enough for most operating systems to positively ID the flow to reduce the MTU. This PR updates it so that we can send up to 512 bytes instead (900 is probably excessive) — that should leave plenty of room for any number of IPv6 extension headers and the next protocol headers and some of the payload.

This seems to fix the problem in my testing.
2022-04-03 12:48:06 +01:00
Neil Alexander
559e31c502
Merge pull request #896 from yggdrasil-network/develop
Version 0.4.3
2022-02-06 15:24:01 +00:00
Neil Alexander
31717a8578
Version 0.4.3 changelog (#895)
* Version 0.4.3 changelog

* Update CHANGELOG.md
2022-02-06 15:16:54 +00:00
Neil Alexander
315e222173 Update to Arceliar/ironwood@8951369625 2022-02-01 21:53:55 +00:00
Neil Alexander
2d2ad4692b
Restore uptime, bytes_sent and bytes_recvd to getPeers (#888)
* Restore `uptime`, `bytes_sent` and `bytes_recvd` to the admin API for peers

* Wrap conn in Yggdrasil instead, so not necessary to do so in Ironwood

* Shuffle struct for alignment
2022-02-01 13:37:45 +00:00
Tom
9f5cc0eecb
Make message clearer and downgrade (#812)
* Make message clearer and downgrade

* Differentiate between incoming and outgoing conn
2022-01-30 21:58:57 +00:00
R4SAS
620b901473
Revert downgrading of wireguard and update wintun in windows installer (#865)
* Revert "Revert Wireguard update"

This reverts commit 03a5cce5bb.

Signed-off-by: R4SAS <r4sas@i2pmail.org>

* [win] update installer build script

Signed-off-by: R4SAS <r4sas@i2pmail.org>

* [appveyor] use golang 1.17.3 for building

Signed-off-by: R4SAS <r4sas@i2pmail.org>

* [appveyor] use golang 1.17.5 for building

Signed-off-by: R4SAS <r4sas@i2pmail.org>

* test script

Signed-off-by: R4SAS <r4sas@i2pmail.org>

* test msi and semver scripts

Signed-off-by: R4SAS <r4sas@i2pmail.org>

Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2022-01-30 21:57:10 +00:00
Neil Alexander
09ea351682
Update build 2022-01-30 19:59:17 +00:00
Neil Alexander
6d92edd405
Move src/mobile into main repository (#864)
* Move `src/mobile` into main repository

* Update go.mod/go.sum

* Move to `contrib`, separate mobile build script
2022-01-30 19:48:32 +00:00
Neil Alexander
a4bdf3de32
Remove CAP_NET_RAW from systemd service unit, as it's not clear why it is there in the first place 2022-01-15 22:17:49 +00:00
Neil Alexander
408d381591 Set hostArchitectures in macOS .pkg installer 2021-12-06 11:19:58 +00:00
Alex Kotov
87e936195e
Add some tests (#828)
* Add tests

* Add tests

* Add tests

* Add tests

* Fix code style

* Remove unnecessary tests
2021-11-04 08:05:53 +00:00
Neil Alexander
e4e58831bf Version 0.4.2 2021-11-03 22:16:53 +00:00
Neil Alexander
03a5cce5bb Revert Wireguard update
This reverts commit 5c19f3f88c.
2021-11-03 20:03:27 +00:00
Neil Alexander
1f64319712 Version 0.4.1 2021-11-03 17:53:35 +00:00
Neil Alexander
4f3117d81d Use network-online.target instead of network.target for systemd service unit 2021-11-03 17:40:06 +00:00
Neil Alexander
5c19f3f88c Update dependencies 2021-11-03 10:33:00 +00:00
Arceliar
feb02c485a
Merge pull request #861 from yggdrasil-network/fix860
Fix panic in `address.GetKey()`
2021-11-02 17:30:50 -05:00
Neil Alexander
4859accbb0 Fix panic in address.GetKey() (fixes #860) 2021-11-02 18:03:16 +00:00
Neil Alexander
99227b60ce Update CI to use Go 1.17, produce Apple Silicon builds (closes #844) 2021-09-28 11:02:15 +01:00
Arceliar
f92d812f3c
Merge pull request #822 from yggdrasil-network/sni
TLS Server Name Indication
2021-09-24 05:14:28 -05:00
Arceliar
6af9b61b15
Merge pull request #842 from Arceliar/mutex
Fix incorrect mutex use in ipv6rwc
2021-09-24 04:43:44 -05:00
Arceliar
f2d1eff8f6
Merge pull request #835 from kotovalexarian/test-and-refactor-proto-handler
Really tiny refactoring of "src/core"
2021-09-24 04:43:06 -05:00
Neil Alexander
9a1d1df85e
Use newer Xcode image for macOS builds in CircleCI 2021-09-23 12:11:03 +01:00
Arceliar
e5d638ff4b better way to empty ipv6rwc buffer 2021-09-23 04:39:12 -05:00
Arceliar
86e5306eec fix race from mutex that wasn't held long enough 2021-09-23 04:35:31 -05:00
Arceliar
529a33034b gofmt to add new build comments 2021-09-23 04:34:58 -05:00
Paul Dee
1c7deb72db
Align struct elements to byte boundaries: reduce memory footprint. (#834) 2021-09-21 21:19:40 +01:00
Fyodor Ustinov
52345a2de4
Check tun.config is not equal to nil before usage (#830)
We have to check tun.config is not nil before first use, not after.
2021-09-21 21:19:25 +01:00
Alex Kotov
571186ca77
Rename protohandler attributes 2021-09-03 01:45:30 +05:00
Alex Kotov
3c89781057
Align and reorder code for lesser diff 2021-09-01 07:58:11 +05:00
Alex Kotov
a5f2ba80a2
Organize code in "src/core/proto.go" 2021-09-01 07:50:03 +05:00
Alex Kotov
538ee13669
Add type core.AddHandlerFunc 2021-09-01 06:16:57 +05:00
Arceliar
3613614b41 Revert "Add IPReadWriteCloser interface"
This reverts commit ebe366ef3b.
2021-08-07 12:56:36 -05:00
Neil Alexander
ebe366ef3b Add IPReadWriteCloser interface 2021-08-07 10:17:21 +01:00
Alex Kotov
cbb6dc1b7d
Split yggdrasilctl code into separate functions (refactoring) (#815)
* Move yggdrasilctl responses to separate functions

* Move yggdrasilctl request switch to separate function

* Add empty lines

* Create struct CmdLine for yggdrasilctl

* Move yggdrasilctl command line parsing to separate func

* Turn struct CmdLine into CmdLineEnv

* Rename func parseCmdLine to parseFlagsAndArgs

* Move yggdrasilctl endpoint setting logic into separate func

* Function to create yggdrasilctl CmdLineEnv

* Reorder code

* Move struct fields into lines

* Turn yggdrasilctl CmdLineEnv funcs to methods

* Move yggdrasilctl connection code to separate func

* Rename functions

* Move yggdrasilctl command line env to separate mod

* Move yggdrasilctl command line env to main mod

* Run goimports

Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2021-08-02 22:47:38 +01:00
Neil Alexander
d1cd671bec Fix bug 2021-08-01 21:39:49 +01:00
Neil Alexander
bbdff033ce Update SNI code 2021-08-01 21:36:51 +01:00
Neil Alexander
f094cf34bf Set SNI by default if the peering URI contains a DNS name 2021-07-28 22:23:33 +01:00
Neil Alexander
d8df9755f2 Allow specifying TLS SNI with ?sni= in peering URI 2021-07-28 22:11:20 +01:00
Neil Alexander
b333c7d7f3
Merge pull request #813 from cofob/patch-1
Allow yggdrasil bind to ports <1024
2021-07-22 12:18:11 +01:00
cofob
6a0ddc20ef
Allow yggdrasil bind to ports <1024 2021-07-21 17:57:59 +07:00
Neil Alexander
52309d094c
Merge pull request #800 from yggdrasil-network/iprwc
Refactor PacketConn/ReadWriteCloser interfaces
2021-07-15 09:39:03 +01:00
Arceliar
747a2538d7
Merge pull request #801 from tdemin/develop
Preallocate memory when deriving address from key
2021-07-08 17:47:43 -05:00
Timur Demin
04ecdf6045
Preallocate memory when deriving address from key
This makes src/address.AddrForKey preallocate 32 bytes before starting
the address derivation. As benches in syg_go show, reallocating temp
takes 20% of the function runtime.
2021-07-08 16:04:43 +05:00
Arceliar
cd5383f7b7 fix core tests 2021-07-07 18:36:51 -05:00
Arceliar
3704ebf4cb fix debug rpcs and cleanup core.Close/core.Stop 2021-07-06 19:45:12 -05:00
Neil Alexander
e224c02d6d Revert "Add LocalAddr to complete net.PacketConn interface"
This reverts commit e4ce2c79a9.
2021-07-05 22:35:46 +01:00
Neil Alexander
e4ce2c79a9 Add LocalAddr to complete net.PacketConn interface 2021-07-05 22:26:09 +01:00
Arceliar
f990a56046 have the core wrap and export the underlying PacketConn, move IPv6 ReadWriteCloser wrapper logic to a separate package 2021-07-05 13:14:12 -05:00
Neil Alexander
35e8ff7c9d
Merge pull request #799 from yggdrasil-network/develop
Version 0.4.0
2021-07-04 09:34:38 +01:00
Neil Alexander
2fc34bbd5a Revert "Merge pull request #796 from Chaz6/update-systemd-files"
This reverts commit 88bd098f91, reversing
changes made to 4d798a3494.
2021-07-04 09:26:17 +01:00
Neil Alexander
88bd098f91
Merge pull request #796 from Chaz6/update-systemd-files
Update executable path in systemd service files to match the installation instructions.
2021-07-04 09:24:40 +01:00
Neil Alexander
4d798a3494
Merge pull request #781 from yggdrasil-network/future
Main v0.4 routing changes
2021-07-04 09:22:43 +01:00
Arceliar
92ef49987a Merge branch 'future' of https://github.com/yggdrasil-network/yggdrasil-go into future 2021-07-03 17:27:13 -05:00
Arceliar
5844079f67 make sure genconf exits, clean up some commented out code 2021-07-03 17:27:00 -05:00
Neil Alexander
f7b91a8f93 Update README.md 2021-07-02 23:24:34 +01:00
Neil Alexander
4d47ba8bf4 Update README.md 2021-07-02 23:21:38 +01:00
Neil Alexander
540e0bc2ce Update changelog 2021-07-02 23:11:16 +01:00
Neil Alexander
ccf03847fc Update changelog 2021-07-02 23:07:44 +01:00
Chris Hills
9391430bc0 Update binary path in systemd service files to match the website. 2021-07-02 13:14:13 +01:00
Arceliar
9239ed70e4 changelog revisions 2021-07-01 20:06:05 -05:00
Arceliar
b07caa1e0a add first draft of changelog 2021-07-01 19:32:55 -05:00
Arceliar
df44b0227b disable SIGHUP handling for now 2021-07-01 08:54:14 -05:00
Arceliar
ff44417dec listen for SIGHUP, restart node (reload config file, listen for stdin again, etc) if we receive one 2021-07-01 08:04:01 -05:00
Neil Alexander
9b28f725e2 Fix core_test.go 2021-06-28 18:28:56 +01:00
Neil Alexander
3646a8674c Yggdrasil v0.4.0rc4 2021-06-28 18:21:53 +01:00
Arceliar
de853fed10 multicast configuration changes 2021-06-27 17:24:46 -05:00
Neil Alexander
4701f941a9 Remove debug line 2021-06-27 09:42:46 +01:00
Arceliar
a42b77db84 attempt to convert old multicast listen regexps into new struct format 2021-06-27 03:33:29 -05:00
Arceliar
2874ce1327 change multicast config format 2021-06-27 03:15:41 -05:00
Arceliar
2a7a53b6b6 move GenerateConfig to defaults, to adjust dependency ordering, needed for stuff later 2021-06-27 02:18:51 -05:00
Arceliar
2db46c1250 make socks connect to tls listeners, TODO make that configurable 2021-06-25 21:40:19 -05:00
Arceliar
d1dfe38683 remove string from multicast announcement format 2021-06-25 21:27:29 -05:00
Arceliar
3b38ed082f make failed sends a debug log, instead of error 2021-06-25 21:15:40 -05:00
Neil Alexander
50bd16d524 Remove doc folder, out of date 2021-06-19 18:02:38 +01:00
Arceliar
9b9ef2fad7 tidy 2021-06-19 11:56:03 -05:00
Neil Alexander
39361af789 Update config comments 2021-06-19 17:51:11 +01:00
Arceliar
b7f57c0617 use TLS for multicast peers, fix TLS listener type in log output 2021-06-19 10:42:38 -05:00
Arceliar
5564de94ba when using tls, if no pinned key is set, pin the key from the cert. require that cert keys match a pinned key 2021-06-19 09:53:11 -05:00
Arceliar
1bf751a474 update ironwood, only store 1 packet in the pre-session buffer 2021-06-19 07:44:37 -05:00
Arceliar
b34c3230f8 fix core_test.go and a race in setting/using mtu 2021-06-13 13:40:20 -05:00
Arceliar
cb81be94ec skip multicast packets sent from our own key 2021-06-13 12:31:52 -05:00
Neil Alexander
1083131533 Update build script for Android/iOS 2021-06-13 16:52:14 +01:00
Arceliar
da82308d7c update ironwood, fixes bug where sessions could become stuck after a node restarts 2021-06-13 10:30:16 -05:00
Arceliar
2726dc0076 don't return an error if the source address is wrong, since this happens very frequently for link-local traffic 2021-06-13 09:51:53 -05:00
Arceliar
c6a7a077a3 add remote URI to GetPeers (fallback to net.Conn.RemoteAddr().String() if the uri is unknown) 2021-06-13 09:25:08 -05:00
Arceliar
6c63b02385 Merge branch 'future' of https://github.com/yggdrasil-network/yggdrasil-go into future 2021-06-13 05:44:32 -05:00
Arceliar
8f91f0c050 fix nodeinfo and debug admin functions, this is ugly / a hack, but it works i guess... 2021-06-13 05:43:03 -05:00
Neil Alexander
c8938a3527 Add missing icmpv6.go 2021-06-13 11:34:59 +01:00
Neil Alexander
48938282b7 Upgrade appveyor runner 2017 -> 2019 2021-06-13 11:28:41 +01:00
Arceliar
736c619057 Merge branch 'core' into future 2021-06-13 05:25:23 -05:00
Arceliar
3393db8e77 move ICMP PacketTooBig sending into core 2021-06-13 05:25:13 -05:00
Neil Alexander
9b68ac5702 Fix wintun hopefully 2021-06-13 11:13:02 +01:00
Neil Alexander
38e05b5f4c Download wintun on first pass 2021-06-13 11:07:19 +01:00
Neil Alexander
8621223a1f Remove -aslr 2021-06-13 11:04:27 +01:00
Neil Alexander
272670b85b Fix version numbers in MSI 2021-06-13 11:03:01 +01:00
Neil Alexander
63967462d9 Update MSI build again 2021-06-13 10:58:15 +01:00
Arceliar
4244b38f2b Merge branch 'future' of https://github.com/yggdrasil-network/yggdrasil-go into future 2021-06-13 04:55:02 -05:00
Arceliar
816356ea65 mostly finish migration of IP stuff to core, tuntap is still responsible for ICMP PacketTooBig 2021-06-13 04:54:06 -05:00
Neil Alexander
3b669a15ed Update build-msi.sh 2021-06-13 10:47:14 +01:00
Neil Alexander
45d6a1e6e5 Revert "Build MSIs for Windows using CircleCI (#766)"
This reverts commit f0a5cd542c.
2021-06-13 10:42:31 +01:00
Arceliar
1147ee1934 WIP moving IP-specific checks from tuntap to core 2021-06-13 04:22:21 -05:00
Neil Alexander
bb66851c2b Update dependencies 2021-06-12 21:46:17 +01:00
Arceliar
91235980af fix logging for socks 2021-06-12 07:03:32 -05:00
Arceliar
eeadffe4a5 move position of log line on shutdown 2021-06-12 06:07:33 -05:00
Arceliar
5b6f730f18 keep a context in the core, use it for listen/dial, cancel it when closing 2021-06-12 06:06:39 -05:00
Arceliar
3815b13ad5 use DialContext 2021-06-12 05:58:14 -05:00
Neil Alexander
acdc3dd3c0 Replace ?ed25519= with ?key= in peering URIs 2021-06-11 21:12:27 +01:00
Arceliar
f7607557c1 fix nBytes check in multicast code 2021-06-06 04:48:00 -05:00
Arceliar
e7da3d72c4 remove session firewall, this can't prevent memory use so it's better to just use OS native tools 2021-06-06 02:35:02 -05:00
Arceliar
838bca083d remove bashisms for semver 2021-06-06 02:33:11 -05:00
Arceliar
ae196a7ede update ironwood dependency 2021-06-06 00:52:03 -05:00
Neil Alexander
2b6aa3e2d7 Semver version fix 2021-06-05 22:38:37 +01:00
Neil Alexander
c5529a3a38 Use git describe again 2021-06-05 22:28:29 +01:00
Neil Alexander
e827e5d313 Go back to old semver version for now 2021-06-05 22:09:15 +01:00
Neil Alexander
2e2566d248 Remove src/core/doc.go 2021-06-05 21:56:31 +01:00
Neil Alexander
d46a883020 Include public key in yggdrasilctl getSelf output for v0.4 nodes 2021-06-05 21:54:05 +01:00
Neil Alexander
80b6bf0c78 Further tweaks to transition handling 2021-06-05 21:49:11 +01:00
Neil Alexander
4a684e7caf Don't add mutex to config output 2021-06-05 21:48:20 +01:00
Neil Alexander
54cced0b89 Ensure PublicKey is correct when extracting from old config 2021-06-05 21:40:58 +01:00
Neil Alexander
5cede61a34 Use git describe output for versions 2021-06-05 21:32:18 +01:00
Neil Alexander
05ad5df8ab Run tests in CI 2021-06-05 21:32:12 +01:00
Neil Alexander
ea15eeee7e Ensure PublicKey option is unused, map old config options 2021-06-05 21:32:04 +01:00
Neil Alexander
99973b2757 Remove module package, it didn't really give us anything anyway 2021-06-05 20:57:03 +01:00
Neil Alexander
cb536a7322 Clean up util package 2021-06-05 20:55:08 +01:00
Arceliar
e67ee9232d fix nil pointer when attempting to access node config 2021-06-05 06:00:33 -05:00
Arceliar
414c100125 add public keys to multicast, public key pinning to multicast peering 2021-06-05 05:07:04 -05:00
Neil Alexander
ff751a5409 Fix lint error 2021-06-02 14:46:04 +01:00
Neil Alexander
8932ab0519 Fix lint errors 2021-06-02 14:40:09 +01:00
Neil Alexander
166336a418 Remove config.NodeState (hot reconfig is no longer supported) 2021-06-02 14:19:32 +01:00
Arceliar
978124dbb1 update dependency (ironwood), fix units in core benchmark 2021-05-31 06:39:53 -05:00
Arceliar
1db7437b80 more cleanup and fix a busyloop when the admin socket is shut down 2021-05-29 21:37:13 -05:00
Arceliar
e25ad9ed21 cleanup unused code 2021-05-29 20:42:06 -05:00
Arceliar
180654c495 possibly fix src/core/core_test.go 2021-05-29 11:13:59 -05:00
Arceliar
8a60c605f6 remove metric stuff, there's already enough new stuff to test, maybe revisit this in a future release 2021-05-24 18:53:54 -05:00
Arceliar
c60dd42baa cleanup 2021-05-23 21:51:09 -05:00
Arceliar
5f2bcaa71f add Listen to api and listenURL to tcp 2021-05-23 21:47:12 -05:00
Arceliar
fd5cda6329 read metric from urls for listen and peers 2021-05-23 20:58:34 -05:00
Arceliar
70c5b06286 use url.URL in place of string for most internal listen/peer address handling 2021-05-23 20:34:13 -05:00
Arceliar
58af92812e add metric to metadata exchange, but currently left at default 0 value 2021-05-23 18:40:36 -05:00
Arceliar
6bc2044ced update ironwood dependency, fix ansible code, go mod tidy 2021-05-23 17:52:10 -05:00
Arceliar
018f35d9a2 rename src/yggdrasil to src/core 2021-05-23 14:42:26 -05:00
Arceliar
0343dad934 remove obsolete crypto package 2021-05-23 14:33:28 -05:00
Arceliar
f69f02386d rename debug admin socket functions 2021-05-23 13:37:46 -05:00
Arceliar
e6f86a9bd7 cleanup proto admin socket response formats 2021-05-23 12:19:27 -05:00
Arceliar
29dda650b5 tun session protocol traffic cleanup 2021-05-23 11:58:52 -05:00
Arceliar
233cf0c962 add remote debugGetSelf and fix some return type things in the other debug functions 2021-05-22 21:27:11 -05:00
Arceliar
c7b004d36f get debugGetPeers and debugGetDHT working in the admin socket 2021-05-22 20:25:14 -05:00
Arceliar
8668abf481 WIP adding crawling debug packets 2021-05-22 19:54:52 -05:00
Arceliar
b11cf7a2f2 update ironwood dependency, fix api 2021-05-18 20:43:38 -05:00
Arceliar
8d09e68e80 admin socket getpaths 2021-05-16 16:16:58 -05:00
Arceliar
eb4a22724f possibly fix admin socket getnodeinfo 2021-05-16 15:55:30 -05:00
Arceliar
fad071ffe9 WIP on nodeinfo admin handler 2021-05-16 15:27:51 -05:00
Neil Alexander
058dec0cca Fix getself, gettuntap etc 2021-05-16 21:01:59 +01:00
Neil Alexander
31c1c9b586 Fix admin socket list 2021-05-16 20:53:40 +01:00
Neil Alexander
3e10b964cb
Merge pull request #783 from yggdrasil-network/cleanup
Admin socket cleanup
2021-05-16 20:11:21 +01:00
Neil Alexander
6413e95c48 Fix bug 2021-05-16 20:05:22 +01:00
Neil Alexander
62a13e87c4
Merge branch 'future' into cleanup 2021-05-16 20:02:28 +01:00
Neil Alexander
416eadbcff Use uint64 for MTU for forward-compatibility 2021-05-16 20:00:45 +01:00
Arceliar
a6c254c87a more nodeinfo WIP, still needs admin socket support 2021-05-16 14:00:37 -05:00
Arceliar
2e45e970c6 work-in-progress adding nodeinfo 2021-05-16 13:52:52 -05:00
Neil Alexander
2d01386d6e Refactor admin socket, export request/response structs, remove types package 2021-05-16 19:51:09 +01:00
Arceliar
2c7b22db92 allow for multiple traffic types inside the session at the tuntap level, only implement typeSessionTraffic for now 2021-05-16 13:01:54 -05:00
Arceliar
dfca87ba80 start a reader to disard traffic if the tun is disabled 2021-05-15 16:44:56 -05:00
Arceliar
f61507238e cleanup unused MTU code from tun keystore 2021-05-15 16:23:44 -05:00
Arceliar
5b00273dfc move sessionfirewall into the tuntap. this needs testing. the name is also slightly wrong, since a crypto session can still be set up, packets are just accepted/rejected at the tun/tap level instead 2021-05-15 15:55:47 -05:00
Arceliar
7e10025ef0 get minimal admin socket working (introspection only, no ability to add peers etc) 2021-05-15 15:16:35 -05:00
Arceliar
85fae23919 remove TunnelRouting from config, remove Signing from key names 2021-05-15 15:00:12 -05:00
Arceliar
e83b5d08a8 remove ckr 2021-05-15 14:54:25 -05:00
Arceliar
cd4144f22b add minimal src/yggdrasil/api.go functions inspect internal state 2021-05-15 14:50:56 -05:00
Arceliar
7d49b86456 set version to an obviously unstable value, fix peer address formatting in the connect/disconnect messages 2021-05-15 13:44:55 -05:00
Neil Alexander
577b7118ad remove debug logging 2021-05-10 23:16:22 +01:00
Neil Alexander
815f2a2822 Respond with ICMPv6 Packet Too Big over network 2021-05-10 23:09:59 +01:00
Neil Alexander
57ea61b338 Remove reconfiguration on SIGHUP - it didn't work reliably anyway 2021-05-10 22:47:28 +01:00
Neil Alexander
e12c639c21 Remove obsolete switch options 2021-05-10 22:42:57 +01:00
Neil Alexander
05caf36f4e Fix AllowedPublicKeys 2021-05-10 22:39:12 +01:00
Neil Alexander
c20b66f3b6 Metadata/version tweaks 2021-05-10 22:31:01 +01:00
Neil Alexander
bb92e61e68 Remove encryption public key options (they are now derived from ed25519 key conversion in IW), also bump link version number 2021-05-10 22:06:38 +01:00
Arceliar
6cb958e3dc update genkeys to new address format 2021-05-10 05:58:06 -05:00
Arceliar
b48962a69a limit MTU to no more than what the packetconn claims to support 2021-05-09 11:27:37 -05:00
Arceliar
3bfd891fd4 reduce time keystore mutex is held and (apparently) fix a deadlock 2021-05-09 09:20:28 -05:00
Arceliar
ed85cf08f2 WIP close the ironwood PacketConn when shutting down 2021-05-08 12:31:26 -05:00
Arceliar
b4224aa02d fix ironwood dependency version 2021-05-08 11:57:54 -05:00
Arceliar
e6e55fb4d1 dependency update 2021-05-08 11:53:44 -05:00
Arceliar
8bed79370b (broken state) WIP, compiles and passes the netns ping test 2021-05-08 11:52:22 -05:00
Arceliar
b345806e3f (broken state) more WIP (cleanup) 2021-05-08 11:35:04 -05:00
Arceliar
0f787364de (broken state) more tuntap WIP to add out-of-band key lookup 2021-05-08 11:32:57 -05:00
Arceliar
5b22392c66 (broken state) more WIP on tuntap stuff 2021-05-08 11:14:50 -05:00
Arceliar
0cff56fcc1 (broken state) WIP on tuntap 2021-05-08 10:39:07 -05:00
Arceliar
f1c37f8440 (broken state) WIP rewriting core to use ironwood 2021-05-08 08:35:58 -05:00
Arceliar
ace7b43b6d (broken state) WIP address migration 2021-05-08 07:25:53 -05:00
Arceliar
ae96148008 Merge branch 'pathfinder' of https://github.com/Arceliar/yggdrasil-go into future 2021-05-08 06:45:10 -05:00
Neil Alexander
3c2e14801d
Merge pull request #772 from cwinfo/develop-something
Update Dockerfile
2021-03-24 13:41:53 +00:00
Christer Warén
9b67eb7ef2
Update Dockerfile
Removing personal information
2021-03-24 15:39:55 +02:00
Neil Alexander
983dfdb553
Merge pull request #770 from yggdrasil-network/develop
Version 0.3.16
2021-03-18 22:20:56 +00:00
Arceliar
ac375917c9
Update changelog for v0.3.16 release (#769)
* draft of changelog

* more changelog
2021-03-18 18:58:20 +00:00
Neil Alexander
f0a5cd542c
Build MSIs for Windows using CircleCI (#766)
* Try to build MSIs from CircleCI using wixl/msitools

* Upload msis

* Change condition

* Update Platform

* Update Platform

* Don't build ARM, it's apparently not well supported

* Don't build ARM, it's apparently not well supported

* Remove appveyor config

* Update comments

* newline
2021-03-07 14:03:34 +00:00
Neil Alexander
7174cfce40
Move up to Go 1.16, upgrade dependencies (#765) 2021-03-07 08:45:47 +00:00
Neil Alexander
0ab2685489 Fix wireguard dependency 2021-02-18 09:36:45 +00:00
Arceliar
6eb74a40e1
Merge pull request #751 from Arceliar/bugfix
Fix goroutine leak in link.go
2020-12-19 11:04:13 -06:00
Arceliar
78073429a2 Merge branch 'pathfinder' of https://github.com/Arceliar/yggdrasil-go into pathfinder 2020-12-19 06:03:59 -06:00
Arceliar
0ba2ad74fe use source routes in the dht (when available) 2020-12-19 06:03:28 -06:00
Arceliar
a8810c7ee9 if the link handler exits early due to an existing connection, then have it return a channel to that connection which closes when the connection is closed, so we can choose to block on that to avoid spamming connection attempts with dial 2020-12-13 16:29:03 -06:00
Arceliar
1daf3e7bd7 remove link.go block on oldIntf if we already have a connection to the same node, this spams connections, so it's not a good long-term fix if that's where the goroutine leak is 2020-12-13 16:16:14 -06:00
rany
5b326d8bb8
Update generate.sh (#736)
The AppArmor profile in contrib forbids `/usr/bin/yggdrasil` from reading the file in `/var/backups/yggdrasil.conf...`. This works around that restriction by having the shell do the reading of `/var/backups/yggdrasil.conf...` file while providing the same exact functionality without making the AppArmor profile less restrictive. 

Another change is the safe perms for the `/etc/yggdrasil.conf` (so that config will have 0640 permissions). This is important because if we kept the default of 644 then any user (privileged or unprivileged) will have the ability to read the yggdrasil private key. We use a restrictive umask of 0027 to make this possible.
2020-12-06 20:52:54 +00:00
rany
709ea6976c
apparmor: allow yggdrasil to resolve hostnames (#739)
The apparmor profile in it's current state won't allow resolving hostnames. We need `<abstractions/nameservice>` because we simply can't just allow `/etc/resolv.conf`. This is because systemd-resolved, resolvconf, and others rely on symbolic links to `/etc/resolv.conf` which would make this extremely complicated.  `<abstractions/nameservice>` deals with this complexity to allow every single one of those packages (systemd-resolved, resolvconf, ... ).

```
  network inet stream,
  network inet dgram,
  network inet6 dgram,
  network inet6 stream,
  network netlink raw,
```
was removed because it's already included in `<abstractions/nameservice>`. Some permissions that are no longer needed in newer yggdrasil versions were also removed.

`owner /sys/kernel/mm/transparent_hugepage/hpage_pmd_size r,` was changed to `/sys/kernel/mm/transparent_hugepage/hpage_pmd_size r,` because there is no guarantee that yggdrasil will always be run as root. (`owner` makes sure that the process's user and the file have the same owner, in that case, root. This might not always be the case so `owner` was removed)
2020-12-06 20:52:10 +00:00
Neil Alexander
b9f35c5530
Return ICMPv6 Destination Unreachable for unknown destinations (#748)
* Return ICMPv6 Destination Unreachable for unknown destinations

* Update go.mod/go.sum for yggdrasil-extras

* go mod tidy
2020-12-06 19:47:25 +00:00
Neil Alexander
cb3d8647de
Merge pull request #744 from octeep/master
Fix DefaultIfName for OpenBSD
2020-12-06 13:48:09 +00:00
Arceliar
df1239b054 attempting to debug/fix a possible goroutine leak 2020-11-25 02:44:13 -06:00
Neil Alexander
ea58a0f181
Clean go.mod/go.sum 2020-11-15 13:32:28 +00:00
Arceliar
939ffb02f8 adjust when dht reqs are reset 2020-11-14 15:05:02 -06:00
octeep
04e890fcc3
Change DefaultIfName from "/dev/tun0" to "tun0"
Specifying the full path to the interface in OpenBSD would result in:
panic: Interface name must be tun[0-9]*

Therefore, DefaultIfName should be changed to tun0 in order to make yggdrasil work out of the box.
2020-11-13 06:38:27 +00:00
Arceliar
428789f24c simplify switch parent selection and minor source routing improvements 2020-11-09 19:01:11 -06:00
Arceliar
144d42c773 send dht responses via reverse path (fixes some possible DDoS issues with the old coord approach) 2020-11-08 06:09:55 -06:00
Arceliar
0ac203b007 adjust how sessions learn source routes, try to recover faster if coords change (but assume the old path still works until we get a ping through that gives us a new path) 2020-11-08 05:39:30 -06:00
Arceliar
e19e938f64 safer pathfinding behavior 2020-11-07 15:19:09 -06:00
Arceliar
994c26e5f7 simplify pathfinder 2020-11-07 12:08:01 -06:00
Arceliar
b5cd40b801 WIP very simple insecure proof-of-concept for pathfinding and source routing 2020-11-07 10:50:55 -06:00
Arceliar
e2521de94d add path information to (protocol) traffic packets as they flow through the network, and a field for a reply path 2020-11-07 09:44:34 -06:00
Arceliar
36e4ce4b0b WIP rough implementation of the source routed part of hybrid routing, does not work if coord length is too long (>127 hops) 2020-11-07 07:10:13 -06:00
Arceliar
92dbb48eda add (but don't use) offset field for (protocol) traffic packets 2020-11-07 06:18:09 -06:00
Arceliar
f1e9837a98
Merge pull request #738 from Arceliar/bugfix
Listener bugfix
2020-11-07 05:51:04 -06:00
Arceliar
1d1c6efa1f attempt to keep TCP listener alive if there's a temporary error (e.g. too many open files), just pause and retry later 2020-10-18 11:01:18 -05:00
Neil Alexander
9eb4981ac1
Merge pull request #734 from yggdrasil-network/develop-future
Future → Develop
2020-10-11 16:45:24 +01:00
Neil Alexander
e90d40a49e
Don't require lint in pipeline 2020-10-11 16:41:40 +01:00
Arceliar
b6c894bc01 Merge branch 'future' of https://github.com/yggdrasil-network/yggdrasil-go into develop-future 2020-10-11 07:35:28 -05:00
Arceliar
afebc1f93d
Merge pull request #712 from Arceliar/bugfix
[future] possibly fix missing switch peer issue
2020-10-11 07:34:19 -05:00
Neil Alexander
fdb296047b
Merge branch 'future' into develop-future 2020-09-27 20:28:26 +01:00
Neil Alexander
d3672545a3
Version 0.3.15 (#731) 2020-09-27 15:50:58 +01:00
Neil Alexander
ba7be10a2f
Update changelog 2020-09-27 15:05:14 +01:00
Ryan Westlund
d6d2d9c19a
Accept some golint suggestions (#690)
* Fixed some linter issues

* Simplified isBetter method

* Accept some linter suggestions

* Fix typo

Co-authored-by: klesomik <klesomiks@gmail.com>
Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2020-09-27 14:42:46 +01:00
Neil Alexander
1492738c9e
golangci-lint in CI (#733)
* golangci-lint in CI

* Put CI in own job

* Run verify job

* Use go get

* Fix typo

* Name lint instead of verify

* Read the config

* Use debug tag

* Tweaks
2020-09-27 14:28:25 +01:00
Neil Alexander
48bf0ce210
Revert "Fix build"
This reverts commit e09ca6a089.
2020-09-27 13:28:13 +01:00
Neil Alexander
e09ca6a089
Fix build 2020-09-27 13:26:37 +01:00
asymmetric
7588a55e84
README: mention Nix package (#689) 2020-09-27 13:24:19 +01:00
Ryan Westlund
fcb6f5ca36
Set default conf file on FreeBSD to /usr/local/etc/yggdrasil.conf (#717) 2020-09-27 13:22:49 +01:00
Arceliar
33e3679458
multicast, use the prebuilt interface map when checking active listeners (#707) 2020-09-27 13:16:51 +01:00
Neil Alexander
d9fd68f18c
Fix build 2020-07-06 14:21:28 +01:00
Neil Alexander
a4a346c498
Merge branch 'develop' into future 2020-07-06 14:16:38 +01:00
George
48f008a8e2
Implement Core.RemovePeer method (#699) (#709)
Co-authored-by: George <zhoreeq@users.noreply.github.com>
2020-07-06 14:14:34 +01:00
Arceliar
3fded209df try to fix some possible races with how peers are added/removed and how they're blocked in the switch when they enter a bad state 2020-06-06 12:30:54 -05:00
Arceliar
aec82d7a39
Merge pull request #702 from Arceliar/switch
Precompute more for the switch lookup table
2020-05-30 18:39:43 -05:00
Arceliar
a1856258a9
Merge pull request #704 from Arceliar/queues
Faster queue logic
2020-05-30 18:39:33 -05:00
Arceliar
35e7542889
Merge pull request #706 from Arceliar/buffers
More buffer fine-tuning
2020-05-30 18:39:24 -05:00
Arceliar
c83b070c69 remove old switch lookup functions 2020-05-30 13:12:49 -05:00
Arceliar
0f28862e99 remove unused sequence number from switch 2020-05-30 10:48:59 -05:00
Arceliar
5e170e22e1 more switch fixes 2020-05-30 10:47:54 -05:00
Arceliar
3dc2242712 fix handling of keepAliveTimer and blocked state in link.go 2020-05-30 10:32:15 -05:00
Arceliar
8775075c18 debugging 2020-05-27 19:35:19 -05:00
Arceliar
905c28f7b2 fix some issues with the rewritten switch lookup tables 2020-05-27 19:31:17 -05:00
Arceliar
1df305d31c simplify how blocking is detected and packets are dequeued 2020-05-27 18:53:14 -05:00
Arceliar
09f9f4e8e4 use heap.Fix instead of heap.Remove + heap.Push when updating queues, this is theoretically faster 2020-05-25 20:09:57 -05:00
Arceliar
674d8b58b6 get things compiling again 2020-05-25 19:27:17 -05:00
Arceliar
152e9057a0 Merge branch 'develop' of https://github.com/yggdrasil-network/yggdrasil-go into future 2020-05-25 19:25:05 -05:00
Arceliar
ed3bf5ef07
Merge pull request #705 from Arceliar/bugfix
Ygg-over-ygg bugfix
2020-05-25 19:24:34 -05:00
Arceliar
85eec5ba8e tcp ygg-over-ygg debug logging 2020-05-25 19:13:37 -05:00
Arceliar
8345ae1fa3 don't allow ygg tcp connections to/from a local ygg address 2020-05-25 19:08:04 -05:00
Arceliar
dbc3b9b4c4
Merge pull request #701 from Arceliar/buffers
More buffer fine-tuning
2020-05-25 16:30:43 -05:00
Arceliar
366a8ba3dd Merge branch 'develop' of https://github.com/yggdrasil-network/yggdrasil-go into future 2020-05-25 16:28:12 -05:00
Neil Alexander
45810fa184
Merge pull request #703 from Arceliar/dht
Store less in the DHT
2020-05-25 22:18:00 +01:00
Neil Alexander
895bd681a1
Merge pull request #700 from Arceliar/multicast
Multicast
2020-05-25 22:17:50 +01:00
Neil Alexander
8cca565ac4
Update go.mod/go.sum for yggdrasil-extras for iOS builds 2020-05-25 22:08:53 +01:00
Arceliar
1f65ffb310 work-in-progress heap-based queue structure 2020-05-25 16:07:56 -05:00
Arceliar
761ae531cb work-in-progress faster queue logic 2020-05-25 15:19:32 -05:00
Arceliar
eefabb5f9f disregard nodes if they're unimportant, even if they're already in the DHT 2020-05-25 12:44:06 -05:00
Arceliar
40bfd207f5 don't store every node we hear from in the DHT, only ones we already know about or that are important 2020-05-25 12:23:38 -05:00
Arceliar
f9bc0b7aee use a more elaborate precomputed lookup table from the switch 2020-05-25 11:49:25 -05:00
Arceliar
38dcbb1e2f cleaner way to handle seq/idle checks for the peer 2020-05-24 17:49:48 -05:00
Arceliar
4382368b08 make sure the peer isn't idle before entering drop mode 2020-05-24 17:43:35 -05:00
Arceliar
9574308545 have the peer delay setting a max buffer size, in case things have unblocked in the mean time 2020-05-24 17:35:49 -05:00
Arceliar
7778a47a8f fix darwin compile problem 2020-05-24 15:46:18 -05:00
Arceliar
98816f34b2 don't spam calls to net.Interfaces and net.Interface.Addrs (hopefully) 2020-05-24 15:24:39 -05:00
Arceliar
1e471e3712 back to master's version of multicast, lets try rewriting it again 2020-05-24 14:43:38 -05:00
Arceliar
c2d6e9e8f1 close listener when a multicast interface is removed 2020-05-24 14:09:06 -05:00
Arceliar
28d6e3e605
Merge pull request #693 from Arceliar/buffers
Update queue behavior
2020-05-24 09:41:20 -05:00
Arceliar
eefa49708e Merge branch 'future' of https://github.com/yggdrasil-network/yggdrasil-go into buffers 2020-05-24 09:12:35 -05:00
Arceliar
0a10a3d263
Merge pull request #692 from Arceliar/updates
Misc updates for the future branch
2020-05-24 09:09:00 -05:00
Arceliar
0188f14caa Merge branch 'develop' of https://github.com/yggdrasil-network/yggdrasil-go into future 2020-05-23 14:08:31 -05:00
Arceliar
77ded84ea5 simplify routerInterface 2020-05-23 12:21:23 -05:00
Arceliar
f2b9e95895 simplify routerInterface 2020-05-23 12:21:01 -05:00
Arceliar
07206b5d46 resolve merge conflicts 2020-05-23 11:33:37 -05:00
Arceliar
169b8747d4
Merge pull request #696 from Arceliar/bugfix
Bugfix
2020-05-23 11:24:03 -05:00
Arceliar
7063ddcc73 slightly cleaner fix to conn String deadlock issue 2020-05-23 11:16:03 -05:00
Arceliar
bc48e4bb80 fix deadlock in conn (unsafe use of phony.Block) 2020-05-23 11:11:11 -05:00
Arceliar
59896f17fd more cleanup 2020-05-23 10:28:57 -05:00
Arceliar
ef1e506a0c work-in-progress on more cleanup 2020-05-23 10:23:55 -05:00
Arceliar
59c5644a52 some peer/link cleanup 2020-05-23 10:08:23 -05:00
Arceliar
cf2edc99d1 correctly set peer.max 2020-05-17 13:32:58 -05:00
Arceliar
d43b93f60a safer check for the queues if we're blocked on a send, should work even if we're blocked on a link packet send 2020-05-17 13:23:15 -05:00
Arceliar
ff3c8cb687 less aggresive queue size reduction 2020-05-17 12:58:57 -05:00
Arceliar
d96ae156a1 slight change to peer function names/args 2020-05-17 12:27:43 -05:00
Arceliar
7720e169f2 when we detect we're blocked, only drop packets often enough to make sure the existing queue's size is non-increasing, and always drop the worst packet from a random flow with odds based on the total size of packets queued for that flow 2020-05-17 12:09:40 -05:00
Arceliar
6e92af1cd2 re-enable a minimum queue size of ~1 big packet 2020-05-17 08:49:40 -05:00
Arceliar
0dcc555eab cleaner startup/shutdown of the link writer's worker 2020-05-17 08:34:22 -05:00
Arceliar
15ac2595aa use a dedicated per-stream writer goroutine, send messages to it over a 1-buffered channel, this eliminates most of the false positive blocking that causes drops 2020-05-17 08:22:02 -05:00
Arceliar
527d443916 move where the queue size check before dropping would occur 2020-05-17 07:21:09 -05:00
Arceliar
62b9fab5f8 more work-in-progress, debugging why things are dropping so often 2020-05-16 18:56:04 -05:00
Arceliar
b17a035a05 workarounds to dropping being too aggressive 2020-05-16 17:40:11 -05:00
Arceliar
b132560f65 it helps to actually run the notifyQueued stuff... 2020-05-16 17:24:26 -05:00
Arceliar
052de98f12 work-in-progress on buffering overhaul 2020-05-16 17:07:47 -05:00
Arceliar
dc128121e5 update switch blockPeer/unblockPeer logic and dht reset when coords change 2020-05-16 09:25:57 -05:00
Arceliar
dd548fc0fa
Merge pull request #685 from yggdrasil-network/neilalexander/pinning
Public key pinning support
2020-05-09 07:09:15 -05:00
Neil Alexander
f70b2ebcea
Fix bad check 2020-05-09 12:49:02 +01:00
Neil Alexander
2a2ad76479
Use maps instead of slices 2020-05-09 12:38:20 +01:00
Arceliar
433e392bdf Merge branch 'develop' of https://github.com/yggdrasil-network/yggdrasil-go into future 2020-05-09 06:13:52 -05:00
Neil Alexander
a59fd2a489
Merge branch 'develop' into neilalexander/pinning 2020-05-09 12:12:24 +01:00
Neil Alexander
d0f2d889af
Merge pull request #687 from yggdrasil-network/neilalexander/hjson
Fix hjson dependency?
2020-05-09 12:12:12 +01:00
Neil Alexander
9dfe0f4b4b
Fix hjson dependency? 2020-05-09 12:08:29 +01:00
Arceliar
dafaef898b
Merge pull request #686 from Arceliar/multicast
maybe fix multicast deadlock on darwin
2020-05-09 06:07:16 -05:00
Arceliar
7779d86c5b maybe fix multicast deadlock on darwin 2020-05-09 05:56:36 -05:00
Neil Alexander
13a2d99fdc
Set SOCKS peer addr to resolved address 2020-05-09 11:26:09 +01:00
Neil Alexander
8b180e941a
Add SOCKS proxy auth (closes #423) 2020-05-09 11:24:32 +01:00
Neil Alexander
58345ac198
Track proxy addr and real peer addr in SOCKS mode 2020-05-09 10:53:58 +01:00
Neil Alexander
fbf59184ee
Use query string instead, allow specifying multiple keys (might be useful for DNS RR) 2020-05-09 00:43:19 +01:00
Neil Alexander
e849b3e119
Initial support for pinning public keys in peering strings 2020-05-08 23:23:48 +01:00
Arceliar
107d9f0e8b Merge branch 'develop' of https://github.com/yggdrasil-network/yggdrasil-go into future 2020-05-03 05:20:30 -05:00
Neil Alexander
b4d72dc604
Merge pull request #684 from yggdrasil-network/neilalexander/multicast
Refactor the multicast code a bit
2020-05-03 11:14:27 +01:00
Arceliar
95f4ec52a4 save only the link-local addresses for multicast 2020-05-03 05:06:59 -05:00
Arceliar
de79401bb2 only call (net.Interface).Addrs() once per minute per interface 2020-05-03 02:50:04 -05:00
Arceliar
02e1cb180d possibly reduce multicast cpu usage even more 2020-05-02 17:23:20 -05:00
Neil Alexander
127b7e311c
Clean up a bit 2020-05-02 22:37:12 +01:00
Neil Alexander
0c7cf65d27
Move some logging back to debug 2020-05-02 22:33:25 +01:00
Neil Alexander
a115d18595
Refactor the multicast code a bit 2020-05-02 22:26:41 +01:00
Arceliar
90b7d9ef97
Merge pull request #683 from Arceliar/sim
Sim
2020-05-02 11:52:13 -05:00
Arceliar
20ef591013 fix some crashes with races during peer setup 2020-05-02 11:16:11 -05:00
Arceliar
402cfc0f00 undo remaining trivial change to build 2020-05-02 10:56:17 -05:00
Arceliar
15162ee952 fix a panic from a doubly closed channel in the simlink 2020-05-02 10:51:26 -05:00
Arceliar
12d448f6d5 Merge branch 'future' of https://github.com/yggdrasil-network/yggdrasil-go into sim 2020-05-02 10:40:00 -05:00
Arceliar
8b888305e0
Merge pull request #682 from Arceliar/bytes
remove util.GetBytes/util.PutBytes and use local sync.Pools instead
2020-05-02 10:39:41 -05:00
Arceliar
22526d89ec Merge branch 'future' of https://github.com/yggdrasil-network/yggdrasil-go into sim 2020-05-02 10:09:03 -05:00
Arceliar
349c6dbad4
Merge pull request #675 from Arceliar/buffers
Buffers
2020-05-02 10:08:30 -05:00
Arceliar
72afa05029 test dial/listen in the sim 2020-05-02 10:01:09 -05:00
Arceliar
6d89570860 eliminate most sync.Pool use, gives a safer but slightly slower interface 2020-05-02 06:44:51 -05:00
Arceliar
5db93be4df more sim work 2020-04-26 09:59:30 -05:00
Arceliar
9c818c6278 work-in-progress on a new sim 2020-04-26 07:33:03 -05:00
Arceliar
9d0969db2b prevent a hypothetical block on link message sending 2020-04-05 14:57:05 -05:00
Arceliar
09efdfef9a fix bug in switch actor's cleanRoot, strict nonce handling at the session level, and add separate queues per stream to the packetqueue code 2020-04-03 19:26:48 -05:00
Arceliar
03a19997b8 Merge branch 'develop' of https://github.com/yggdrasil-network/yggdrasil-go into buffers 2020-04-03 00:33:01 -05:00
Arceliar
945930aa2c WIP have peer actors queue packets, temporarily a single simple FIFO queue with head drop 2020-04-03 00:32:26 -05:00
Neil Alexander
78b5f88e4b
Version 0.3.14
Merge remote-tracking branch 'origin/develop'
2020-04-01 20:32:25 +01:00
Neil Alexander
52491d63ab
Merge pull request #672 from Arceliar/bugfix
check if an error was returned by Core._init and return it if so
2020-04-01 08:48:16 +01:00
Arceliar
7a314afb31 check if an error was returned by Core._init and return it if so 2020-03-31 18:14:20 -05:00
Arceliar
9834f222db more work in progress actorizing the remaining parts of the switch 2020-03-29 19:01:50 -05:00
Arceliar
15b850be6e fix deadlock when running updateTable in the switch 2020-03-29 01:38:32 -05:00
Arceliar
d47797088f fix shutdown deadlock 2020-03-29 00:48:41 -05:00
Arceliar
e926a3be6d work in progress actorizing core.peers and replacing switch worker with per-peer switch-generated lookupTable 2020-03-29 00:23:38 -05:00
Arceliar
16309d2862 Merge branch 'develop' of https://github.com/yggdrasil-network/yggdrasil-go into buffers 2020-03-28 21:10:34 -05:00
Neil Alexander
05c6006f51
Update changelog 2020-03-28 20:46:00 +00:00
Neil Alexander
a6275b48a3
Merge pull request #667 from yggdrasil-network/neilalexander/go1141
Use Go 1.14.1 for CircleCI builds
2020-03-25 22:50:16 +00:00
Neil Alexander
aa4def2f8d
Use Go 1.14.1 to build, update wireguard package references 2020-03-25 22:46:01 +00:00
Neil Alexander
e7228c7ae4
Merge pull request #666 from jcgruenhage/ansible-genkeys-progress-bar
add a progress bar to the ansible key generator
2020-03-25 20:55:15 +00:00
Neil Alexander
83c41d57c2
Merge pull request #663 from rany0/patch-3
Update usr.bin.yggdrasil
2020-03-25 20:54:53 +00:00
Neil Alexander
389c519d9e
Merge pull request #665 from Arceliar/search
More reliable search
2020-03-25 20:53:27 +00:00
Arceliar
1ac3a18aab
Fix a typo in search.go's comments 2020-03-23 18:03:31 -05:00
Jan Christian Grünhage
30bfa04c47 add a progress bar to the ansible key generator 2020-03-23 23:26:41 +01:00
Arceliar
a09a83530f update search description in comments 2020-03-22 18:42:42 -05:00
Arceliar
b651e57203 allow searches to continue as long as the next hop is closer than the Nth closest node found so far where N is currently 16 instead of 1 (makes searches more reliable), and cache all intermediate search steps in the dht 2020-03-19 21:11:17 -05:00
Rany
c1816ae86f
Update usr.bin.yggdrasil 2020-03-10 16:47:41 +02:00
Arceliar
4809879995 refactor switch code so calling lookupTable.lookup does most of the important work 2020-03-10 01:03:07 -05:00
Arceliar
cfd8641925 fix conflicts with memleak bugfix 2020-03-10 00:03:26 -05:00
Arceliar
ea7e074cf0
Merge pull request #662 from Arceliar/memleak
Fix memory leak
2020-03-09 23:57:15 -05:00
Arceliar
8075a60900 possibly fix memory leak (if this works, i don't yet understand how the leak was happening originally) 2020-03-08 19:32:14 -05:00
Neil Alexander
d160eccab0
Hopefully really actually fix it this time 2020-02-21 19:32:36 +00:00
Neil Alexander
7d590e31b0
Include yggdrasil-default-config.service 2020-02-21 19:14:40 +00:00
Neil Alexander
c3f8db6991
Merge pull request #653 from yggdrasil-network/develop
Version 0.3.13
2020-02-21 18:30:59 +00:00
Neil Alexander
d41da9a97f
Update README.md 2020-02-20 23:22:42 +00:00
Arceliar
f308e81bf3 in the switch, keep a separate set of queues per peer instead of a global queue 2020-02-18 20:13:39 -06:00
Neil Alexander
012bd9195d
Update CHANGELOG.md 2020-02-17 19:49:03 +00:00
Neil Alexander
0b26551f07
Merge pull request #652 from yggdrasil-network/neilalexander/api
Use public keys in API functions
2020-02-17 00:00:08 +00:00
Neil Alexander
471fcd7fdf
Update doc.go dial example 2020-02-16 23:57:05 +00:00
Neil Alexander
6c731c4efc
Fix comment on LocalAddr 2020-02-16 23:45:11 +00:00
Neil Alexander
429189d11d
Use 'curve25519' instead of 'pubkey' 2020-02-16 23:44:20 +00:00
Neil Alexander
6b0b704645
Update comments 2020-02-16 23:30:47 +00:00
Neil Alexander
d16505e417
Update CKR 2020-02-16 23:26:18 +00:00
Neil Alexander
63936c11b5
Update tuntap module, return pointers 2020-02-16 23:21:58 +00:00
Neil Alexander
c107f891d2
Implement pubkeys in API functions 2020-02-16 23:12:39 +00:00
Arceliar
a101fc0556
Merge pull request #651 from Arceliar/search
Search
2020-02-13 20:35:52 -06:00
Arceliar
657777881b actually schedule the search cleanup code to run 2020-02-08 20:33:35 -06:00
Arceliar
8e05c6c6a7 better search cleanup, but needs more testing to make sure it really works 2020-02-08 20:26:37 -06:00
Arceliar
d0e6846173 work in progress to make searches use parallel threads per response, so one malicious node doesn't block progress from honest ones 2020-02-08 20:15:48 -06:00
Arceliar
d7d0c2629c don't deduplicate search responses, but limit the max number of nodes handled per response 2020-02-08 17:04:00 -06:00
Arceliar
cd9613fddc add some additional debug timing info and logging to dials, and fix an unnecessary delay in search startup 2020-02-07 22:34:54 -06:00
Arceliar
3faa0b2854 deduplicate the list of nodes to visit in a search (keeping newest rumors) 2020-02-06 20:47:53 -06:00
Arceliar
1104d12540
Merge pull request #650 from Arceliar/search
More search updates
2020-02-06 20:26:07 -06:00
Arceliar
7c2cb9a02d more search fixes/updates 2020-02-06 20:21:17 -06:00
Arceliar
cd856426e5 search timing changes 2020-02-06 18:37:58 -06:00
Arceliar
b8bab06f95
Merge pull request #649 from Arceliar/switch
Sort search response results before sending requests
2020-02-06 17:48:26 -06:00
Arceliar
70659bfb91 sort search response results before sending requests 2020-02-06 17:38:42 -06:00
Arceliar
0da433f5d2
Merge pull request #648 from Arceliar/search
Search updates
2020-02-01 14:15:30 -06:00
Arceliar
7e64f54c1f log some info about searches and reduce search traffic (especially when things dead-end) 2020-02-01 13:58:08 -06:00
Neil Alexander
819cf234ae
update Wireguard library 2020-02-01 16:32:22 +00:00
Neil Alexander
c48c4ddc80
Merge pull request #641 from Arceliar/misc
Misc tuning
2020-01-10 11:35:51 +00:00
Neil Alexander
2fc6f9a71d
Merge pull request #643 from adamruzicka/mtu
Unify MTU datatypes across the codebase
2020-01-07 22:39:38 +00:00
Neil Alexander
ef4d5553b6
Merge pull request #636 from cathugger/develop
util: fix possible OOB in IPv4 flowkey calc, use switch there
2020-01-07 22:38:31 +00:00
Arceliar
c3b1a6af65 some nodeinfo actor fixes and adjust search timeout 2020-01-06 18:37:43 -06:00
Neil Alexander
507c95efa9
Don't preserve LDFLAGS from environment after all since they are probably go-specific 2020-01-06 19:37:24 +00:00
Neil Alexander
da9f02a381
Add -p for PIE builds, preserve environment LDFLAGS 2020-01-06 19:34:03 +00:00
Neil Alexander
a5bcc227ca
Update go.mod/go.sum for golang.org/x dependencies (may resolve #635 possibly?) 2020-01-05 23:43:27 +00:00
Neil Alexander
8c12fc4fdb
Merge branch 'develop' into misc 2020-01-05 23:04:51 +00:00
Neil Alexander
8e74881c35
Merge pull request #645 from neilalexander/nodeinfo
Actorise NodeInfo
2020-01-05 23:04:26 +00:00
Neil Alexander
9304873047
Convert nodeinfo to actor 2020-01-05 22:15:52 +00:00
Neil Alexander
7ca45aaa0c
Merge pull request #644 from wfleurant/docker-genkeys
docker: build and copy genkeys
2020-01-05 21:15:42 +00:00
William Fleurant
a2adcbd7e4 docker: build and copy genkeys 2020-01-05 15:26:08 -05:00
Adam Ruzicka
8358fe5c5c Unify MTU datatypes across the codebase
The codebase uses int and unit16 to represent MTU randomly. This change
unifies it to a MTU type from types package, which is currently uint16.
2020-01-05 18:01:22 +00:00
Arceliar
8513f8f4dc constant space searches that should play nicer if searching for an unreachable destination 2020-01-04 16:08:48 -06:00
Arceliar
201dbec63d always keep the 2 closest nodes in each direction around the dht ring, possibly helps things recover faster after joins/leaves 2019-12-25 19:01:20 -06:00
Arceliar
9fac5355eb make searches more parallel 2019-12-25 18:55:29 -06:00
Arceliar
5bd9391c61 slightly cleaner way for yggdrasilctl to os.exit, making sure defers are called 2019-12-25 17:45:24 -06:00
cathugger
ff5de89762
util: fix possible OOB in IPv4 flowkey calc, use switch there
ihl may grow upto 15*4=60 so extract and check it before using it as offset in flowkey calculation.
also replace IFs with switches for protocol matching as it's less redundant and nicer to document.
2019-12-11 15:24:43 +02:00
Neil Alexander
4b16c325a3
Merge pull request #607 from Arano-kai/feature/systemd_modular_unit
Systemd: move config generation to a separate unit
2019-12-10 12:02:46 +00:00
Neil Alexander
b1bd84540f
Merge pull request #634 from yggdrasil-network/moremsifixes
MSI bugfixes
2019-12-10 11:44:06 +00:00
Neil Alexander
1a1e32c411
Fix syntax error in build-msi.sh 2019-12-10 11:40:16 +00:00
Neil Alexander
4762edc2b3
Package display name 2019-12-10 11:38:58 +00:00
Neil Alexander
6f927b0613
Reverse upgrade condition 2019-12-10 11:33:52 +00:00
Neil Alexander
3e388cd7f9
Try to avoid breaking Wintun during upgrades 2019-12-10 11:27:49 +00:00
Neil Alexander
152f5838f8
Update metadata 2019-12-10 11:17:15 +00:00
Neil Alexander
1d41199501
Move Wintun to separate feature 2019-12-10 10:55:20 +00:00
Neil Alexander
bf5d5b2269
Rename service from 'yggdrasil' to 'Yggdrasil' 2019-12-04 09:29:30 +00:00
Neil Alexander
6d64a31188
Merge pull request #629 from armatusmiles/adjust-logger
Use loglevel instead comma-separated list of logging
2019-12-02 21:22:02 +00:00
Neil Alexander
fdecf8dbd6
Merge pull request #628 from armatusmiles/develop
Fix return value in Multicast.Stop()
2019-12-02 21:21:23 +00:00
Anatolii Kurotych
468e366168 Use loglevel instead comma-separated list of logging 2019-12-01 11:27:20 +02:00
Anatolii Kurotych
4159ccb893 Fix return value in Multicast.Stop() 2019-11-30 16:05:44 +02:00
Neil Alexander
287d3cf9c4
Merge pull request #625 from rex4539/develop
Fix typos
2019-11-29 23:47:51 +00:00
Arceliar
729d2ca2ba
Update crypto.go 2019-11-29 17:14:27 -06:00
Neil Alexander
16e55992b6
Move yggdrasil.conf to ALLUSERSPROFILE 2019-11-29 11:06:08 +00:00
Dimitris Apostolou
73f50af3b7
Fix typos 2019-11-29 11:45:02 +02:00
Arceliar
9967541627
Merge pull request #618 from yggdrasil-network/goodbyewater
Replace Water library with Wireguard's tun package (inc. Wintun support on Windows)
2019-11-28 12:03:05 -06:00
Arceliar
c2a8b4bb57 get rid of an allocation in tunWriter's _write 2019-11-28 12:00:00 -06:00
Neil Alexander
71404f5270
Clean up appveyor.yml 2019-11-28 15:17:49 +00:00
Neil Alexander
c17c4af26d
Don't normalise on upgrade 2019-11-28 13:08:56 +00:00
Neil Alexander
3f29a2ff05
Some comments 2019-11-28 13:00:52 +00:00
Neil Alexander
9c113c05bf
Use appveyor build folder in case slugs are different 2019-11-28 12:57:19 +00:00
Neil Alexander
3734a73d6f
Don't impersonate user for updateconfig.bat 2019-11-28 11:16:36 +00:00
Neil Alexander
42d4a51765
Set output logging 2019-11-28 10:56:22 +00:00
Neil Alexander
724446bb04
Defer updateconfig 2019-11-28 10:42:57 +00:00
Neil Alexander
e64d661ab0
Fix update action 2019-11-28 10:19:47 +00:00
Neil Alexander
a673625e82
Configure service with -useconffile 2019-11-28 10:08:01 +00:00
Neil Alexander
b88a623a9f
Handle pull request branch 2019-11-28 09:56:14 +00:00
Neil Alexander
41a2e731eb
More MSI updates (#622)
* Try embedding config script

* Update config when installing

* Don't update config on uninstall
2019-11-28 09:52:14 +00:00
Neil Alexander
e1b0d0f20c
Appveyor MSI builds for Windows (#621)
* Try appveyor for MSI (not finished)

* build-msi.sh

* Don't shallow clone

* Don't set clone depth

* Build Yggdrasil for each arch

* Try to get rest of branches

* Allow upgrades (hopefully)

* Try using MajorUpgrade

* AllowDowngrades

* Try harder to build x86 :-)

* Bugfix

* Bugfix

* AllowSameVersionUpgrades

* AllowSameVersionUpgrades

* Generate new GUID for each build (might fix upgrades)
2019-11-28 00:35:29 +00:00
Neil Alexander
ad8d30ce74
Revert "Force packets through the switch to be buffered (seems to help the reordering problem on Windows)"
This reverts commit 837e7da792.
2019-11-26 09:44:35 +00:00
Neil Alexander
328dd6c054
Merge branch 'develop' into goodbyewater 2019-11-26 09:20:15 +00:00
Neil Alexander
ca193bbfcd
Merge pull request #619 from Arceliar/bugfix
Bugfix
2019-11-26 09:18:55 +00:00
Arceliar
98339cdc3f possible fix if monotonic time resolution is related to packet reordering 2019-11-25 17:40:58 -06:00
Neil Alexander
837e7da792
Force packets through the switch to be buffered (seems to help the reordering problem on Windows) 2019-11-25 20:13:41 +00:00
Neil Alexander
d8016c4113
Merge pull request #620 from yggdrasil-network/NET_CAP_RAW
Update yggdrasil.service
2019-11-25 08:54:12 +00:00
Arceliar
38c54efd73
Update yggdrasil.service 2019-11-24 22:54:30 -06:00
Arceliar
3e07995518 it helps to actually set the flag... 2019-11-24 18:53:58 -06:00
Arceliar
27cc57dbbc attempt to prevent incorrect idle notification in switch, needs testing 2019-11-24 18:24:17 -06:00
Arceliar
2e95a3131c comment out pointless error that prints on some platforms and not others 2019-11-24 15:37:37 -06:00
Arceliar
5f1ddbb038 Merge branch 'goodbyewater' of https://github.com/yggdrasil-network/yggdrasil-go into goodbyewater 2019-11-24 15:09:50 -06:00
Neil Alexander
8f323b740d
Revert "TUN_OFFSET_BYTES per platform"
This reverts commit 85c5bc61ac.
2019-11-24 21:09:29 +00:00
Arceliar
2982b53555 make offset generic over TUN_OFFSET_BYTES so we can make this platform dependent 2019-11-24 15:09:28 -06:00
Neil Alexander
85c5bc61ac
TUN_OFFSET_BYTES per platform 2019-11-24 21:03:02 +00:00
Arceliar
f6f9b3ef76 include offset in expected bytes written 2019-11-24 15:01:20 -06:00
Arceliar
6560aac1e9 fix error spam on shutdown 2019-11-24 13:42:56 -06:00
Neil Alexander
bd92c117e1
Merge branch 'develop' into goodbyewater 2019-11-24 17:33:01 +00:00
Neil Alexander
a9cfa5bc0d
Merge pull request #610 from yggdrasil-network/develop
Version 0.3.12
2019-11-24 09:47:16 +00:00
Neil Alexander
ebef3045e2
Update CHANGELOG.md 2019-11-24 09:44:52 +00:00
Arceliar
117d44d008
Update CHANGELOG.md 2019-11-23 15:47:08 -06:00
Neil Alexander
746fac6594
Fix go.mod/go.sum again and update DoAsSystem call 2019-11-23 13:56:48 +00:00
Neil Alexander
d0a307db97
Use Wireguard's DoAsSystem, fix build tags and go.mod/go.sum 2019-11-23 13:46:05 +00:00
Neil Alexander
0529910b01
Reuse GUID so Windows no longer keeps creating new networks each time Yggdrasil starts 2019-11-23 13:34:27 +00:00
Neil Alexander
baebaabc43
Fix typo 2019-11-22 20:16:24 +00:00
Neil Alexander
3a0870a448
Fix IfName 'auto' behaviour on Windows 2019-11-22 20:11:39 +00:00
Neil Alexander
f95ebeb821
Remove references to TAP 2019-11-22 20:08:19 +00:00
Neil Alexander
7d00206f4b
Update platform defaults, handling of 'auto' on Linux/Darwin 2019-11-22 20:07:08 +00:00
Neil Alexander
15726fe90d
Don't build for NetBSD (not supported by the TUN package right now) 2019-11-22 18:52:12 +00:00
Neil Alexander
b27ada9191
Fix bad Name() calls 2019-11-22 18:39:27 +00:00
Neil Alexander
235b64345e
Configure addresses and MTUs, fix bugs 2019-11-22 18:34:43 +00:00
Neil Alexander
f5517acc81
Drop Water, use Wireguard tun library, drop TAP support 2019-11-22 16:43:50 +00:00
Arceliar
07ce8cde7a
Merge pull request #613 from neilalexander/mtuagain
Add API functions for manipulating maximum session MTU
2019-11-21 19:29:06 -06:00
Arceliar
248a08b2f1 send a message to the sessions to update mtu instead of trying to update it directly 2019-11-21 19:23:44 -06:00
Neil Alexander
d3a2087e0f
Update changelog 2019-11-21 10:02:18 +00:00
Neil Alexander
7c18c6806d
Further updates, notify sessions about updated MTU from API call 2019-11-21 09:54:36 +00:00
Neil Alexander
d1c445dc41
Thread safety for MTU API functions 2019-11-21 09:28:36 +00:00
Neil Alexander
e90be6f569
Add API functions for manipulating maximum session MTU, fix TUN/TAP to use that 2019-11-21 00:02:39 +00:00
Neil Alexander
789307d52b
Merge pull request #612 from neilalexander/mtuagain
Fix couple of issues with MTU bounds
2019-11-20 22:43:46 +00:00
Neil Alexander
d06c40ad19
Use existing constant 2019-11-20 22:40:48 +00:00
Neil Alexander
9fca3640f9
Fix couple of issues with MTU calculations 2019-11-20 22:11:52 +00:00
Neil Alexander
ec46b217da
Update CHANGELOG.md 2019-11-20 19:25:57 +00:00
Neil Alexander
b70fbfa0f1
Update changelog for v0.3.12 2019-11-20 19:25:45 +00:00
Arceliar
5b8e9182f0
Merge pull request #609 from neilalexander/genkeys
Move genkeys into cmd/
2019-11-19 19:40:44 -06:00
Arceliar
6b6a5a2906
Merge pull request #608 from neilalexander/mtu
Improve MTU handling
2019-11-19 19:37:25 -06:00
Arceliar
c0be481cde
Merge pull request #605 from wfleurant/src-version
Src version: return unknown not yggdrasilctl
2019-11-19 19:35:45 -06:00
Neil Alexander
f984eaffab
Merge pull request #597 from Arano-kai/bugfix/systemd_unit_typo
FIX: Systemd: typo in directive
2019-11-19 14:41:54 +00:00
Neil Alexander
4b9bce855e
Only build yggdrasil/yggdrasilctl when running ./build 2019-11-19 14:37:16 +00:00
Neil Alexander
16a487cb1d
Move genkeys into cmd/ as this allows 'go run github.com/yggdrasil-network/yggdrasil-go/cmd/genkeys' 2019-11-19 14:34:10 +00:00
Neil Alexander
f49d9de421
Fix setting up of MTU when value is outside of acceptable bounds, also account for ethernet headers in calculations, notify about clipping to stdout 2019-11-19 14:20:11 +00:00
Arano-kai
7068160b20 Systemd: move config generation to a separate unit
- Modular unit composition: different tasks in separate units
- Use systemd tool set to run checks
- Avoid using inline shell in unit
2019-11-14 16:52:04 +02:00
Arceliar
17a711ab8a
Merge pull request #606 from Arceliar/bugfix
fix deadlock when AddPeer fails
2019-11-12 21:08:36 -06:00
Arceliar
5f1aea3636 fix deadlock when AddPeer fails 2019-11-12 21:01:32 -06:00
Neil Alexander
f330f2f5bc
Merge pull request #604 from neilalexander/addresssubnet
Add -address and -subnet command line options to cmd/yggdrasil
2019-11-11 09:42:23 +00:00
Neil Alexander
e310a25e59
Use crypto.GetNodeID instead of sha512 directly 2019-11-11 09:40:25 +00:00
William Fleurant
49ba5bae17 yggdrasil: buildName should report unknown 2019-11-11 00:24:50 -05:00
Neil Alexander
e3a5e4f3b7
Add -address and -subnet flag for getting address/subnet out of config 2019-11-10 19:38:35 +00:00
Arano-kai
74d824302b FIX: Systemd: typo in directive 2019-10-29 16:36:03 +02:00
Neil Alexander
1373800d26
Merge pull request #595 from Arceliar/race
Fix data race
2019-10-28 10:18:13 +00:00
Arceliar
6d3aefb825 fix a data race when an existing session's coords are updated in response to a successful search 2019-10-27 19:55:35 -05:00
Neil Alexander
cee28d11f8
Merge pull request #593 from Arceliar/bindtodevice
BindToDevice
2019-10-26 11:36:24 +01:00
Arceliar
710815fed5 add dummy functions for other platforms 2019-10-25 19:32:53 -05:00
Neil Alexander
76adfd166a
Merge pull request #594 from Arceliar/bugfix
fix a crash when shutting down if no multicast interfaces are configured
2019-10-26 00:50:34 +01:00
Arceliar
cfc1e6b83d fix a crash when shutting down if no multicast interfaces are configured 2019-10-25 18:40:09 -05:00
Arceliar
bcacfb0638 test adding BindToDevice to linux. if it works then we'll want to rethink slightly how we get the tcpContext on every platform, to make this compile everywhere and look a little cleaner 2019-10-25 18:33:23 -05:00
Neil Alexander
1fbab17b37
Merge pull request #587 from yggdrasil-network/develop
Version 0.3.11
2019-10-25 09:37:50 +01:00
Neil Alexander
0b932996a2
Merge pull request #591 from neilalexander/changelog
Changelog for v0.3.11
2019-10-25 08:49:14 +01:00
Arceliar
7f758b7bf7
Update CHANGELOG.md 2019-10-24 21:55:25 -05:00
Arceliar
80b7989675
Merge pull request #592 from Arceliar/tidy
update a few deps and run 'go mod tidy'
2019-10-24 21:53:51 -05:00
Arceliar
9337b17cff update a few deps and run 'go mod tidy' 2019-10-24 21:50:10 -05:00
Arceliar
97a85e1d44
Merge pull request #583 from neilalexander/modules
Define module.Module interface
2019-10-24 21:48:05 -05:00
Arceliar
4c7d04941a
Merge pull request #590 from neilalexander/multicast
No longer use atomic for isOpen in multicast
2019-10-24 21:47:42 -05:00
Arceliar
aea41f464e
Update CHANGELOG.md 2019-10-24 21:47:02 -05:00
Neil Alexander
ba43c1d874
Changelog for v0.3.11 2019-10-24 23:59:58 +01:00
Neil Alexander
cd93969930
Fix isOpen for TUN/TAP actor 2019-10-24 23:37:39 +01:00
Neil Alexander
de3bdfa524
No longer use atomic for isOpen in multicast 2019-10-24 23:31:47 +01:00
Neil Alexander
77ffb5efc4
Fix HJSON references in go.mod/go.sum, again... 2019-10-24 10:47:44 +01:00
Neil Alexander
d37133e311
Fix merge conflict from develop 2019-10-24 10:22:02 +01:00
Neil Alexander
41004ab155
Merge pull request #589 from neilalexander/fix581
Backport fix for #581 from #583
2019-10-24 10:20:09 +01:00
Neil Alexander
0e7ed4c997
Actually really use 1.13.3 for all the builds this time 2019-10-24 10:18:08 +01:00
Neil Alexander
ee644c47e8
Update go.mod/go.sum, go back to 1.13.3 circleci image again 2019-10-24 10:16:52 +01:00
Neil Alexander
51fe1940c5
Try go 1.13 to see if this fixes failing builds 2019-10-24 10:13:59 +01:00
Neil Alexander
5ca81f916e
Fix deadlocks 2019-10-24 09:54:57 +01:00
Neil Alexander
7341fcb9bc
Merge branch 'develop' into fix581 2019-10-24 09:29:29 +01:00
Neil Alexander
d58f88d29a
Update builds to Go 1.13 as this is required for TLS (apparently golang.org/x/crypto/ed25519 is not acceptable to the crypto/tls module and this prevents Yggdrasil from starting) 2019-10-24 09:28:09 +01:00
Neil Alexander
f784f33c2d
Backport fix for #581 from #583 2019-10-24 09:25:31 +01:00
Arceliar
c3dee478f5 fix ed25519 dependency for golang 1.12 and earlier, though we may want to update builds to 1.13 anyway... 2019-10-23 20:38:09 -05:00
Arceliar
0effbff97b
Merge pull request #588 from neilalexander/tls
Initial connection upgrade/TLS steganography
2019-10-23 20:30:25 -05:00
Arceliar
996c6b4f47 add one TODO comment and run gofmt 2019-10-23 20:28:11 -05:00
Neil Alexander
cd77727c1e
Set TCP socket options before upgrading connection 2019-10-23 18:24:08 +01:00
Neil Alexander
6a22e6c9de
Initial connection upgrade/TLS peering support 2019-10-23 17:26:35 +01:00
Neil Alexander
e220310890
Merge pull request #586 from yggdrasil-network/armel
Enable Linux armel builds in CircleCI
2019-10-23 14:03:21 +01:00
Neil Alexander
f6c7c1b8db
Produce armel build (closes #577) 2019-10-23 11:24:00 +01:00
Neil Alexander
9cb553e939
Merge pull request #584 from neilalexander/systemd
systemd: Allow ExecStartPre failures
2019-10-23 11:18:20 +01:00
Neil Alexander
b0bcf29d27
Allow ExecStartPre to fail for containers (#573) 2019-10-23 11:15:57 +01:00
Neil Alexander
337626a32c
Act multicast updates for safety 2019-10-23 11:12:51 +01:00
Neil Alexander
a072e063d8
Define module.Module interface, update admin/tuntap/multicast modules to comply with it, fix #581 2019-10-23 10:44:58 +01:00
Neil Alexander
fc71624919
Merge pull request #578 from Arceliar/netconn
Have listen and dial return a net.Conn
2019-10-22 11:28:46 +01:00
Arceliar
ea085663ea slight cleanup of dial's timeout 2019-10-21 20:52:16 -05:00
Arceliar
681c8ca6f9 safer dial timeout handling, in case it was used with a nil context or a context that had no timeout set 2019-10-21 20:47:50 -05:00
Arceliar
eccd9a348f give yggdrasil.Dialer the same interface as a net.Dialer, so the only differences are what fields exist in the struct 2019-10-21 19:44:06 -05:00
Arceliar
efc0b9ef9f Merge branch 'develop' into netconn 2019-10-21 18:47:40 -05:00
Neil Alexander
4efc32c121
Merge pull request #580 from Arceliar/bugfix
fix incorrectly held mutex in ckr getPublicKeyForAddress
2019-10-21 13:39:23 +01:00
Arceliar
a81476f489 fix incorrectly held mutex in ckr getPublicKeyForAddress 2019-10-20 20:00:55 -05:00
Arceliar
cb40874f97 have listener return a net.Conn, adjust yggdrasil.Conn to match this interface 2019-10-19 15:10:28 -05:00
Neil Alexander
d307ad4c91
Merge pull request #574 from Arceliar/bugfix
Search bugfix
2019-10-12 23:42:58 +01:00
Arceliar
3491292599 code cleanup 2019-10-12 15:46:56 -05:00
Arceliar
31ce854835 update session when a search for an existing session finishes 2019-10-12 15:37:40 -05:00
Neil Alexander
1c81e43fcd
Merge pull request #571 from yggdrasil-network/develop
Version 0.3.10
2019-10-10 21:14:46 +01:00
Neil Alexander
29198bc54b
Merge pull request #572 from yggdrasil-network/changelog
changelog for v0.3.10
2019-10-09 21:41:14 +01:00
Neil Alexander
14245b88fe
Pedantic grammar stuff in changelog 2019-10-09 21:40:54 +01:00
Arceliar
92b1bbf08d draft of changelog 2019-10-08 20:32:41 -05:00
Arceliar
5ae1503c5b
Merge pull request #570 from Arceliar/bugfix
fix nil pointer dereference in yggdrasil.Conn.search
2019-10-06 11:59:15 -05:00
Arceliar
a1c413f769 fix nil pointer dereference in yggdrasil.Conn.search 2019-10-06 11:53:14 -05:00
Arceliar
7f8dfe84cf fix race in phony 2019-10-05 13:19:17 -05:00
Arceliar
c38e40e8e3 actually use doCancel in writeNoCopy 2019-10-05 12:23:21 -05:00
Arceliar
83e3a24423
Merge pull request #562 from AwesomePatrol/dev/patrol/bench01
#60 Add simple tests and benchmark
2019-10-05 12:20:27 -05:00
Arceliar
56ac49861e
Merge pull request #569 from Arceliar/bbr
Enable bbr for tcp sockets on linux
2019-10-05 12:20:00 -05:00
Arceliar
f474869ad9 cleanup bad comment 2019-10-05 12:17:40 -05:00
Arceliar
b519802fcb update phony dependency 2019-10-05 12:16:22 -05:00
Arceliar
fb3430207c don't fail if there's an error setting bbr, just log it and continue 2019-10-05 11:03:38 -05:00
Arceliar
8e22d7137a use bbr congestion control on linux, note that we're not doing anything intelligent with the errors right now if setting it fails 2019-10-05 10:47:15 -05:00
Neil Alexander
c600711a8d
Merge pull request #563 from Arano-kai/feature/systemd_ensure_tun
Systemd: tun module and capabilities
2019-10-05 10:26:07 +01:00
Neil Alexander
b455c225fc
Merge pull request #566 from Arceliar/ckr
CKR deadlock fix
2019-10-05 10:24:44 +01:00
Arceliar
f22eac497b typo 2019-10-03 18:50:33 -05:00
Arceliar
b2922189b8 fix deadlock from use of phony.Block by actors when ckr is enabled 2019-10-03 18:44:47 -05:00
Arano-kai
045a24d74e Systemd: tun module and capabilities
- Enable (and limit to) capabilities that require to setup tun/tap interface.
- Ensure that tun module is active.
2019-10-02 00:36:33 +03:00
Aleksander Mistewicz
783959208c Add more comments to explain helper functions 2019-09-28 14:41:53 +02:00
Aleksander Mistewicz
8053766092 Add verbosity setting 2019-09-28 14:25:42 +02:00
Aleksander Mistewicz
21b236771b Add a simple transfer benchmark 2019-09-28 14:25:42 +02:00
Aleksander Mistewicz
8677a042cf Wait for nodes to negotiate 2019-09-28 14:25:42 +02:00
Aleksander Mistewicz
fffbbbcbd3 Pass message between nodes 2019-09-28 14:25:42 +02:00
Aleksander Mistewicz
d96fb27ab8 Add simple connection test 2019-09-28 14:25:42 +02:00
Neil Alexander
6ddb0f93f3
Merge pull request #552 from yggdrasil-network/develop
Version 0.3.9
2019-09-27 09:53:21 +01:00
Neil Alexander
5c3f7df77c
Update submodule doc/yggdrasil-network.github.io 2019-09-27 09:49:19 +01:00
Neil Alexander
21ff74fec6
Merge pull request #559 from yggdrasil-network/changelog
Changelog for v0.3.9
2019-09-27 09:45:29 +01:00
Neil Alexander
6ead31fb87
Remove RPM spec from contrib as it is now in yggdrasil-network/yggdrasil-package-rpm 2019-09-27 09:44:55 +01:00
Neil Alexander
d6ee20580d
Set TimeoutStopSec for systemd service 2019-09-27 09:37:34 +01:00
Arceliar
94f4d6e286
Update CHANGELOG.md 2019-09-26 18:21:35 -05:00
Arceliar
2b8b7118df
Merge pull request #560 from Arceliar/bugfix
Packet length checks and logging
2019-09-26 18:19:39 -05:00
Arceliar
0f99d590a1 typo, ipv6->ipv4 2019-09-26 18:15:26 -05:00
Arceliar
e16d3efb0a check packet length before checking if it's an ipv6 packet, and add some trace level logging whenever a packet is rejected for being too short to parse 2019-09-26 18:11:58 -05:00
Neil Alexander
19c2a573aa
Update changelog for v0.3.9 2019-09-26 22:56:45 +01:00
Arceliar
a87581b0fa
Merge pull request #556 from Arceliar/switch
Switch hack
2019-09-25 17:58:01 -05:00
Arceliar
97bec8631c Merge branch 'switch' of https://github.com/Arceliar/yggdrasil-go into switch 2019-09-25 17:53:58 -05:00
Arceliar
ac58c3586e cleanup/comments 2019-09-25 17:53:25 -05:00
Neil Alexander
d27891aaf6
Merge pull request #528 from yggdrasil-network/documentation
Documentation updates
2019-09-25 17:09:09 +01:00
Neil Alexander
2c66ff24a9
Merge branch 'develop' into switch 2019-09-25 11:15:52 +01:00
Arceliar
b9e74f34ec replace the send-to-self with a timer and an arbitrary timeout; i don't really like this but it seems to work better (1 ms is fast by human standards but an eternity for a syscall or the scheduler, so i think that's reasonable) 2019-09-24 18:28:13 -05:00
Arceliar
8c64e6fa09 explicitly notify the switch when a link appears to be blocked in a send instead of assuming this is the case for all idle links. how we decide when it's really blocked still needs testing/optimizing 2019-09-24 18:01:35 -05:00
Neil Alexander
606d9ac97b
Build VyOS amd64/i386 Vyatta packages as well as EdgeRouter packages 2019-09-24 22:06:12 +01:00
Arceliar
691192ff5a weird scheduler hack, seems to tend to make things more stable without actually locking streams to any particular link 2019-09-21 14:33:45 -05:00
Arceliar
2a76163c7e
Merge pull request #554 from Arceliar/switch
Switch
2019-09-20 23:45:14 -05:00
Arceliar
87658f83e9 Revert "force things to buffer in the switch if the best link is currently busy. note that other links can end up sending if they become non-idle for other reasons. this is a temporary workaround to packet reordering, until we can figure out a better solution"
This reverts commit 80ba24d512.
2019-09-20 23:09:12 -05:00
Arceliar
3571c437ac
Merge pull request #551 from neilalexander/multicastinterval
Gradually increase multicast interval from startup
2019-09-20 17:46:26 -05:00
Arceliar
8003ea0f3e use a separate multicast beacon interval per multicast interface 2019-09-20 17:42:42 -05:00
Neil Alexander
1cd4b6e8dd
Increase multicast interval at startup from 1s to 15s 2019-09-20 10:08:41 +01:00
Neil Alexander
6432eaa9f5
Merge pull request #548 from neilalexander/bugfixes
Bugfixes
2019-09-20 09:48:54 +01:00
Arceliar
f9163a56b6 fix race between listener accepting and shutting down 2019-09-19 19:50:45 -05:00
Arceliar
eeb34ce4e4 modify TcpListener 2019-09-19 19:45:17 -05:00
Arceliar
93e81867fd have link.stop signal active links to close, have tcp.stop wait for all listeners and active connections to close 2019-09-19 19:15:59 -05:00
Neil Alexander
39461cb603
Don't os.Exit 2019-09-19 09:56:27 +01:00
Neil Alexander
681e9afc79
Merge develop into bugfixes 2019-09-19 09:05:56 +01:00
Neil Alexander
7b1678a11d
Goroutines in _addPeerLoop from bugfixes 2019-09-19 09:04:25 +01:00
Neil Alexander
5a382e7e0b
Cherrypick fixes for _addPeerLoop memory leak for now 2019-09-19 08:55:55 +01:00
Arceliar
995d67cca8 fix leak in _addPeerLoop 2019-09-18 18:46:03 -05:00
Arceliar
92d9274f3f resolve conflicts 2019-09-18 18:40:01 -05:00
Arceliar
2d64a6380a misc other fixes 2019-09-18 18:33:51 -05:00
Neil Alexander
909e4e29a8
Don't spawn goroutines for addPeerLoop, TCP connect timeout of 5 seconds for now 2019-09-18 23:44:28 +01:00
Neil Alexander
64570a8d3e
Merge pull request #542 from Arceliar/switch
Switch
2019-09-18 20:26:48 +01:00
Neil Alexander
0a12e4b1c1
Revert "Catch a nil pointer when sending a session packet to a conn, this shouldn't happen but it's caused multiple crashes in conn.recvMsg"
This reverts commit be35675d0f.
2019-09-18 20:26:06 +01:00
Neil Alexander
d44a7faa04
semver: Don't return failure codes when git history is not present 2019-09-18 20:09:53 +01:00
Neil Alexander
ddaaa865cb
Be more verbose when a peer or listener is badly formatted 2019-09-18 19:58:41 +01:00
Neil Alexander
94cf2854a9
Fix panic where slice goes out of bounds because iface.Read returns less than zero (which might happen when the TUN/TAP interface is closed) 2019-09-18 19:48:53 +01:00
Neil Alexander
368f499f1d
Update apt before trying to pull in RPM dependencies 2019-09-18 19:48:35 +01:00
Neil Alexander
ae0b2672ff
Fix #539 2019-09-18 19:48:16 +01:00
Neil Alexander
2dc136f94a
Multicast actor to prevent races 2019-09-18 16:51:46 +01:00
Neil Alexander
b959f53fee
Shut down listeners when stopping 2019-09-18 16:32:22 +01:00
Neil Alexander
b0df9e2f31
Fix race when adding peers 2019-09-18 16:15:33 +01:00
Neil Alexander
c78a4cb28f
Only stop timers if they are running 2019-09-18 15:34:26 +01:00
Neil Alexander
366fe7e772
Allow multicast to be shut down more sanely 2019-09-18 15:31:43 +01:00
Neil Alexander
00a972b74e
Disconnect peers when stopping, stop modules before core 2019-09-18 15:22:17 +01:00
Neil Alexander
846df4789a
Be more verbose when a peer or listener is badly formatted 2019-09-18 15:01:19 +01:00
Neil Alexander
a62e029e21
Update apt before trying to pull in RPM dependencies 2019-09-18 14:37:25 +01:00
Neil Alexander
27158d7b44
Fix #509 2019-09-18 14:35:11 +01:00
Neil Alexander
200b3623b2
Fix #539 2019-09-18 14:32:28 +01:00
Neil Alexander
e9bacda0b3
Catch a nil pointer when sending a session packet to a conn, this shouldn't happen but it's caused multiple crashes in conn.recvMsg 2019-09-18 14:07:26 +01:00
Neil Alexander
c3016e680c
Fix panic where slice goes out of bounds because iface.Read returns less than zero (which might happen when the TUN/TAP interface is closed) 2019-09-18 14:05:18 +01:00
Neil Alexander
40204caab6
Try to fix race condition in sessions.reset 2019-09-18 14:03:31 +01:00
Neil Alexander
be35675d0f
Catch a nil pointer when sending a session packet to a conn, this shouldn't happen but it's caused multiple crashes in conn.recvMsg 2019-09-18 13:37:01 +01:00
Arceliar
80ba24d512 force things to buffer in the switch if the best link is currently busy. note that other links can end up sending if they become non-idle for other reasons. this is a temporary workaround to packet reordering, until we can figure out a better solution 2019-09-17 19:42:07 -05:00
Neil Alexander
f4e326f5dd
Merge pull request #544 from wfleurant/readme-url-platforms
README: update platforms link
2019-09-11 14:23:42 +01:00
William Fleurant
8ca1187451 README: update platforms link 2019-09-11 06:52:03 -04:00
Arceliar
0141180279 cleanup 2019-09-09 19:25:10 -05:00
Arceliar
10a828af2c when forwarding traffic, break distance ties by favoring the link that sent the most recent switch update the fastest 2019-09-09 19:20:46 -05:00
Arceliar
1b72a3f3d5
Merge pull request #537 from Arceliar/phony
update phony dependency
2019-09-06 22:47:59 -05:00
Arceliar
eec055313d update phony dependency 2019-09-06 22:20:36 -05:00
Neil Alexander
9da0c40239
Merge pull request #534 from Arceliar/bugfix
Fix race between router and dial code
2019-09-04 12:21:42 +01:00
Arceliar
2426a87ccc really finish initializing the session before returning it / giving up control of the router, in the Conn.search function used by Dial 2019-09-03 19:03:12 -05:00
Neil Alexander
af3dcb44d8
Update config.go godoc 2019-09-02 09:45:11 +01:00
Arceliar
b3361d4bbc package level documentation for address/crypto/util 2019-09-01 19:01:33 -05:00
Arceliar
cd99d04bd4 document address, crypto, and util 2019-09-01 18:53:45 -05:00
Neil Alexander
903a8921fc
Update api.go godoc 2019-09-01 23:47:47 +01:00
Neil Alexander
935324efe1
Update conn.go godoc 2019-09-01 23:33:51 +01:00
Neil Alexander
9e8e1c5a41
Documentation updates 2019-09-01 23:10:46 +01:00
Neil Alexander
01517e5dc3
Create doc.go for godoc preamble 2019-09-01 22:43:27 +01:00
Neil Alexander
174ebceaac
Fix hjson-go import in go.mod/go.sum 2019-09-01 21:32:40 +01:00
Arceliar
f72546c85d
Merge pull request #527 from Arceliar/bugfix
Bugfix
2019-09-01 14:15:00 -05:00
Arceliar
8c52ccadf9 make dial fail if a session to the same node already exists, fixes race between simultaneous connections to a node's 200 address and one of its 300 addresses, should also fix races between a search and an accepted listen 2019-09-01 14:07:00 -05:00
Arceliar
730fd08954
Merge pull request #526 from Arceliar/cleanup
Cleanup and possible bugfixes
2019-09-01 13:45:17 -05:00
Arceliar
8d2c31d39c add some artifical delay to windows netsh commands, since it seems like maybe they don't take effect immediately, and this was leading to races when setting MTU 2019-09-01 13:20:48 -05:00
Arceliar
c53831696b make tun stop check that iface is not nil, in case it wasn't set for some reason (windows bugs) 2019-09-01 13:06:25 -05:00
Arceliar
d08c2eb237 stop exporting ReadNoCopy and WriteNoCopy, since we use the actor functions / callbacks and everything else should use Read and Write instead... 2019-09-01 13:04:10 -05:00
Neil Alexander
1496b6af3b
Merge pull request #525 from Arceliar/memory
Memory
2019-09-01 17:55:24 +01:00
Neil Alexander
e0ea845cdc
Update build 2019-09-01 17:50:15 +01:00
Arceliar
3a493fe894 gc more often on mobile 2019-09-01 11:08:25 -05:00
Arceliar
cabdc27a54 change how nonce is tracked, so we allow packets if we've recently received a highest nonce ever, but don't bother tracking all received nonce values, this means duplicate packets are possible but only for a small window of time (and significantly reduces memory usage per session) 2019-08-31 17:39:05 -05:00
Arceliar
0806f3e6ea upgrade phony 2019-08-31 16:49:13 -05:00
Arceliar
a64f7320d8 update phony, add mobile versions of util bytes functions that don't try to store anything 2019-08-31 16:27:36 -05:00
Arceliar
5c0f79c4ed
Merge pull request #519 from Arceliar/actors
Actors
2019-08-31 12:02:50 -05:00
Arceliar
08f69de1e2 another phony update 2019-08-31 00:04:35 -05:00
Arceliar
32633011ef upgrade phony dependency 2019-08-30 22:10:34 -05:00
Arceliar
9e4d4f33ba upgrade to latest phony 2019-08-29 23:30:39 -05:00
Arceliar
7649ea0f9f remove sessionInfo.doFunc, have the api just use phony.Block instead 2019-08-29 21:59:28 -05:00
Neil Alexander
1f658cce76
Add Core actor 2019-08-28 19:53:52 +01:00
Neil Alexander
aa0770546e
Move responsibility for configuring max queue size into switch 2019-08-28 19:39:23 +01:00
Neil Alexander
fc9a1c6c31
Simplify reconfiguration 2019-08-28 19:31:04 +01:00
Neil Alexander
764f9c8e11
Remove legacy debug functions 2019-08-28 17:24:41 +01:00
Neil Alexander
881d0a1ada
Fix DEBUG_getDHTSize 2019-08-28 12:46:49 +01:00
Neil Alexander
e553f3e013
Reconfigure functions now ran by actors 2019-08-28 12:46:12 +01:00
Neil Alexander
607c906820
Pointer receivers for phony.Block 2019-08-28 12:26:44 +01:00
Neil Alexander
5d7d84f827
Remove router.doAdmin and switchTable.doAdmin 2019-08-28 12:17:19 +01:00
Arceliar
a8b323acdd have an actor manage the crypto worker pool instead of each session trying to use it directly, this should result in a fairer round-robin behavior in cases where crypto congestion is the bottleneck 2019-08-27 20:01:37 -05:00
Arceliar
3845f81357 update to latest phony, adjust interface use accordingly 2019-08-27 19:43:54 -05:00
Arceliar
4d9c6342a7 more link updates 2019-08-26 18:37:38 -05:00
Arceliar
f432875d87 Merge branch 'actors-linky' into actors 2019-08-26 00:38:29 -05:00
Arceliar
c97dd4ad28 fix dial bug 2019-08-26 00:38:14 -05:00
Arceliar
ab59129557 have the writer clean things up. note that their still seem to be bugs in the main linkInterface actor's state machine--links sometimes just die, presumably because they're dropped from the switch and never replaced 2019-08-25 23:24:18 -05:00
Arceliar
e5b88c0da3 update switch 2019-08-25 23:07:56 -05:00
Arceliar
bd3eaefb72 more link migration 2019-08-25 22:55:17 -05:00
Arceliar
b5b179904b ugly work-in-progress to migrate link to the actor model 2019-08-25 22:19:20 -05:00
Arceliar
dffd70119d remove session shutdown goroutine, just send a message instead 2019-08-25 19:13:47 -05:00
Arceliar
b2a2e251ad more TunAdapter migration 2019-08-25 18:53:11 -05:00
Arceliar
aaf34c6304 start migrating the TunAdapter to the actor model 2019-08-25 18:08:43 -05:00
Arceliar
502f2937a9 a couple race fixes and use timer.AfterFunc instead of sleeping goroutines or ticker in a few places 2019-08-25 17:00:02 -05:00
Arceliar
a3d4d8125b make the main library reconfiguration more actor-friendly 2019-08-25 12:10:59 -05:00
Arceliar
aa30c6cc98 upgrade phony dependency and switch to its new interface 2019-08-25 10:36:09 -05:00
Arceliar
cff1366146 update phony dependency 2019-08-24 22:28:20 -05:00
Arceliar
5312b21665 Merge branch 'develop' of https://github.com/yggdrasil-network/yggdrasil-go into actors 2019-08-24 18:30:15 -05:00
Arceliar
2872ab5231
Merge pull request #520 from Arceliar/bugfix
fix memory leak in session nonce map
2019-08-24 18:29:48 -05:00
Arceliar
f62bc842ae fix memory leak in session nonce map 2019-08-24 18:23:54 -05:00
Arceliar
68c380ff45 update phony dependency 2019-08-24 17:03:19 -05:00
Arceliar
48bbdac9b3 add a helper actor to the link reader to make it play nicer with backpressure 2019-08-24 16:27:12 -05:00
Arceliar
99be6b037d stop synchronizing message reads for now, not 100% safe but I don't have any better ideas 2019-08-24 16:13:34 -05:00
Arceliar
209d2ffea5 correctly call peer.sendPacketsFrom in the switch 2019-08-24 16:04:05 -05:00
Arceliar
8c7e9ec7c0 fix debug builds 2019-08-24 15:32:19 -05:00
Arceliar
c573170886 remove switch doworker loop, start a dummy loop to respond to (unused) reconfiguration instead 2019-08-24 15:27:56 -05:00
Arceliar
998c76fd8c more switch migration 2019-08-24 15:22:46 -05:00
Arceliar
555b4c18d4 a little switch cleanup 2019-08-24 15:05:18 -05:00
Arceliar
498bc395e2 start migrating switch to the actor model 2019-08-24 14:56:33 -05:00
Arceliar
b337228aa4 minor fixes to peer stuff 2019-08-24 14:24:42 -05:00
Arceliar
0539dee900 warning about possible deadlock in legacy channel send, need to migrate the link code to fix it 2019-08-24 13:25:38 -05:00
Arceliar
034fece33f more peer migration 2019-08-24 13:15:29 -05:00
Arceliar
ecd23ce9fc safer linkloop 2019-08-24 12:59:20 -05:00
Arceliar
88161009e9 more peer migration 2019-08-24 12:55:49 -05:00
Arceliar
775fb535dc start converting the peer struct into an actor 2019-08-24 12:46:24 -05:00
Arceliar
ef15a6bd79 tunConn cleanup 2019-08-24 11:44:21 -05:00
Arceliar
4893a07696 start migrating tunConn to the actor model 2019-08-24 11:38:47 -05:00
Arceliar
b582c444f8 minor cleanup 2019-08-24 01:57:08 -05:00
Arceliar
1e346aaad0 have the conn actor receive messages from the session actor and either pass them to a callback or buffer them in a channel for Read to use if no callback was set 2019-08-24 01:52:21 -05:00
Arceliar
9948e3d659 add Conn.WriteFrom to allow actor-based sending 2019-08-24 00:44:02 -05:00
Arceliar
da9f7151e3 more conn migration 2019-08-24 00:17:37 -05:00
Arceliar
6ecbc439f0 start migrating Conn to be an actor 2019-08-23 23:36:00 -05:00
Arceliar
cac3444d9a fix debug builds 2019-08-23 22:40:13 -05:00
Arceliar
cf9880464b explicitly consider the session finished case, and make a note that we could fix the packet drop situation by making the Conn into an actor too 2019-08-23 22:36:59 -05:00
Arceliar
e3603c0462 clean up unused session code 2019-08-23 22:25:40 -05:00
Arceliar
533da351f9 fix actor EnqueueFrom stack overflow (use nil now to send from self) and replace session send/recv workers with actor functions 2019-08-23 22:23:01 -05:00
Arceliar
436c84ca33 refactor sessions to store a pointer to router instead of core 2019-08-23 20:53:00 -05:00
Arceliar
5bb85cf07b refactor searches to store a pointer to router instead of core 2019-08-23 20:42:38 -05:00
Arceliar
e7024a00e7 have dht store a pointer to router instead of core 2019-08-23 20:35:54 -05:00
Arceliar
ebd806f27a move router member initialization into router.init 2019-08-23 20:29:16 -05:00
Arceliar
9835c63818 refactor things the router owns (dht, sessions, searches) into that struct, to make the ownership more explicit 2019-08-23 20:26:15 -05:00
Arceliar
bbcbbaf3b1 start migrating sessionInfo to be an actor 2019-08-23 20:05:18 -05:00
Arceliar
8e89816099 more router migration: rename functions that should only be called internally by the actor 2019-08-23 18:59:34 -05:00
Arceliar
232e6d3cb3 more router migration 2019-08-23 18:55:41 -05:00
Arceliar
9d7e7288c6 start migrating the router to an actor 2019-08-23 18:47:15 -05:00
Neil Alexander
562a7d1f19
Merge pull request #516 from yggdrasil-network/develop
Version 0.3.8
2019-08-21 18:19:56 +01:00
Neil Alexander
0cb99d522f
Update changelog 2019-08-21 18:18:46 +01:00
Neil Alexander
1308cb37b9
Merge pull request #515 from Arceliar/tidy
Clean up go.mod / go.sum
2019-08-21 07:11:07 +01:00
Arceliar
0d5dd9c455 update crypto dependency and run go mod tidy 2019-08-20 23:44:20 -05:00
Arceliar
12ce8c6a0a
Merge pull request #512 from neilalexander/cryptokey
Cryptokey routing changes
2019-08-20 20:23:00 -05:00
Arceliar
f9d28e80df
Merge pull request #514 from Arceliar/bugfix
hopefully prevent a deadlock
2019-08-20 19:13:00 -05:00
Arceliar
226dd6170d hopefully prevent a deadlock 2019-08-20 18:49:53 -05:00
Arceliar
4156aa3003 move ckr checks into the tunConn code 2019-08-20 18:10:08 -05:00
Neil Alexander
b79829c43b
Merge branch 'develop' into cryptokey 2019-08-20 09:43:17 +01:00
Neil Alexander
ca73cf9e98
Merge pull request #513 from Arceliar/speedup
More speedup
2019-08-20 09:43:00 +01:00
Neil Alexander
b6e67bc0ba
Check CKR remotes when receiving traffic 2019-08-20 09:38:46 +01:00
Neil Alexander
2b6462c8a9
Strict checking of Yggdrasil source/destination addresses 2019-08-20 09:38:27 +01:00
Arceliar
834a6a6f1a don't allocate a new child cancellation in Conn read/write calls if no deadline is set 2019-08-19 18:06:05 -05:00
Neil Alexander
2a629880fd
Rename crypto-key config options, improve control flow 2019-08-19 10:28:30 +01:00
Arceliar
c04816b4bd
Merge pull request #510 from Arceliar/streamWrites
Send multiple packets from the switch at once
2019-08-18 18:19:06 -05:00
Arceliar
8af1a7086c when a link becomes idle and packet are buffered that the link could send, send at least 65535 bytes worth instead of 1 packet, this reduces syscall overhead when small packets are sent through the network 2019-08-18 12:29:07 -05:00
Arceliar
62337bcd64 allow links to send multiple packets at once, currently we still only bother to send 1 at a time from the switch level 2019-08-18 12:17:54 -05:00
Neil Alexander
009d9c9ec0
Merge pull request #505 from yggdrasil-network/develop
Version 0.3.7
2019-08-18 11:20:50 +01:00
Arceliar
039dd98f0d
Update CHANGELOG.md 2019-08-17 12:46:34 -05:00
Arceliar
57e7acdda8
Update CHANGELOG.md 2019-08-17 12:42:17 -05:00
Neil Alexander
80535d402f
Merge pull request #508 from Arceliar/nonce
New nonce tracking
2019-08-17 10:55:21 +01:00
Arceliar
fd5f3ca764 fix heap pop order 2019-08-16 23:07:40 -05:00
Arceliar
03b8af9f1a keep track of recent nonces with a heap and a map instead of a fixed-size bitmask 2019-08-16 18:37:16 -05:00
Neil Alexander
fdac8932a8
Update changelog 2019-08-15 13:11:54 +01:00
Neil Alexander
ae0fe93de5
Update changelog 2019-08-15 12:54:04 +01:00
Neil Alexander
adf69d0127
Merge pull request #506 from Arceliar/switchorder
Switch priority change
2019-08-15 11:00:12 +01:00
Neil Alexander
5b054766a2
Update comments in handleIn, add switch_getFlowLabelFromCoords helper (in case it is useful if we try to consider flowlabels in multi-link scenarios) 2019-08-15 10:54:04 +01:00
Arceliar
382c2e6546 even more go.sum 2019-08-14 18:14:24 -05:00
Arceliar
1a2b7a8b60 test a change to how switch hops are selected when multiple links are idle 2019-08-14 17:57:36 -05:00
Neil Alexander
2abb71682f
Update changelog, readme, go.mod/go.sum 2019-08-14 22:21:30 +01:00
Neil Alexander
f26f071901
Merge pull request #497 from Slex/issues/488
Implement feature from https://github.com/yggdrasil-network/yggdrasil
2019-08-14 20:11:15 +01:00
Neil Alexander
02bfe28399
Minor tweaks 2019-08-14 20:09:02 +01:00
Neil Alexander
2cec5bf108
Merge pull request #504 from neilalexander/netlink
Use new netlink library (fixes #493)
2019-08-14 19:59:30 +01:00
Neil Alexander
33cd10c463
Merge branch 'issues/488' of github.com:slex/yggdrasil-go into issues/488 2019-08-14 19:58:45 +01:00
Neil Alexander
4702da2bcb
Use new netlink library (fixes #493) 2019-08-14 19:32:40 +01:00
Neil Alexander
d9fabad8bc
Merge pull request #502 from Arceliar/linkleak
Try to fix leaks in #501
2019-08-14 07:17:39 +01:00
Arceliar
46c5df1c23 when we abandon a link because we already have a connection to that peer, only wait for the connection to close if it's an *outgoing* link, otherwise incomming connection attempts can cause us to leak links 2019-08-13 18:49:49 -05:00
Neil Alexander
5e7df5a1c4
Merge pull request #499 from yggdrasil-network/sessionfix
Prevent session leaks or blocking if the listener is busy
2019-08-13 08:27:30 +01:00
Arceliar
b2cb1d965c avoid leaking sessions when no listener exists, or blocking if it's busy 2019-08-12 18:22:30 -05:00
Arceliar
c15976e4dc go.sum 2019-08-12 18:08:02 -05:00
Neil Alexander
70a118ae98
Update go.mod/go.sum 2019-08-12 11:41:29 +01:00
Neil Alexander
16076b53b9
Merge pull request #498 from Arceliar/search
Search fixes
2019-08-11 21:13:49 +01:00
Arceliar
277da1fe60 make sure searches don't end if try to continue (in parallel) with nowhere left to send, but we just sent a search and are still waiting for a response 2019-08-11 13:11:14 -05:00
Arceliar
7a28eb787e try to fix a few edge cases with searches that could lead them to ending without the callback being run or without cleaning up the old search info 2019-08-11 13:00:19 -05:00
Slex
589ad638ea Implement feature from https://github.com/yggdrasil-network/yggdrasil-go/issues/488 2019-08-11 00:31:22 +03:00
Arceliar
ae05683c73
Merge pull request #494 from Arceliar/bufpersession
Per-session front-dropping buffers for incoming traffic
2019-08-07 18:15:20 -05:00
Arceliar
5e81a0c421 Use a separate buffer per session for incoming packets, so 1 session that floods won't block other sessions 2019-08-07 18:08:31 -05:00
Arceliar
9ab08446ff make sure the sessionInfo.recvWorker doesn't block if sinfo.recv somehow fills 2019-08-07 17:40:50 -05:00
Neil Alexander
71e9ca25f7
Merge pull request #492 from neilalexander/fixlisten
Transform Listen statement to new format if needed
2019-08-07 10:57:55 +01:00
Neil Alexander
bbb35d7209
Transform Listen statement to new format if needed 2019-08-07 10:52:19 +01:00
Neil Alexander
c99ed9fb60
Merge pull request #491 from Arceliar/flowkey
Fix the old flowkey stuff so congestion control actually works...
2019-08-07 10:33:17 +01:00
Arceliar
d795ab1b65 minor allocation fix 2019-08-06 20:51:38 -05:00
Arceliar
790524bd1c copy/paste old flowkey logic into a util function, add a struct of key and packet, make WriteNoCopy accept this instead of a slice 2019-08-06 19:25:55 -05:00
Arceliar
6cb0ed91ad
Merge pull request #486 from Arceliar/bugfix
Conn/Session cleanup
2019-08-05 19:17:30 -05:00
Arceliar
679866d5ff have createSession fill the sessionInfo.cancel field, have Conn use Conn.session.cancel instead of storing its own cancellation, this should prevent any of these things from being both nil and reachable at the same time 2019-08-05 19:11:28 -05:00
Arceliar
032b86c9a3
Merge pull request #485 from Arceliar/bugfix
Bugfix
2019-08-05 18:57:14 -05:00
Arceliar
8a85149817 remove src/.DS_Store 2019-08-05 18:50:08 -05:00
Arceliar
84a4f54217 temporary fix to nil pointer, better to make sure it's never nil 2019-08-05 18:49:15 -05:00
Neil Alexander
bd3b42022b
Merge pull request #480 from Arceliar/speedup
Speedup
2019-08-05 10:24:54 +01:00
Neil Alexander
f046249ac6
Merge pull request #484 from neilalexander/config
API changes
2019-08-05 10:24:43 +01:00
Neil Alexander
2ee00fcc09
Return box_pub_key as hex string in JSON (replaces #481) 2019-08-05 10:21:40 +01:00
Neil Alexander
3a2ae9d902
Update API to represent coords as []uint64 2019-08-05 10:17:19 +01:00
Neil Alexander
37533f157d
Make some API changes (currently broken) 2019-08-05 00:30:12 +01:00
Arceliar
979c3d4c07 move some potentially blocking operations out of session pool workers, minor cleanup 2019-08-04 16:29:58 -05:00
Arceliar
c55d7b4705 have the switch queue drop packts to ourself when the total size of all packets is at least queueTotalMaxSize, instead of an arbitrary unconfigurable packet count 2019-08-04 16:16:49 -05:00
Arceliar
6803f209b0 have tuntap code use Conn.ReadNoCopy and Conn.WriteNoCopy to avoid copying between slices 2019-08-04 15:59:51 -05:00
Arceliar
5d5486049b add Conn.ReadNoCopy and Conn.WriteNoCopy that transfer ownership of a slice instead of copying, have Read and Write use the NoCopy versions under the hood and just manage copying as needed 2019-08-04 15:53:34 -05:00
Arceliar
07f14f92ed disable crypto and switch buffer changes from testing 2019-08-04 15:25:14 -05:00
Arceliar
0ba8c6a34f have the stream code use bufio instead of copying manually to an input buffer, slightly reduces total uses of memmove 2019-08-04 15:21:04 -05:00
Arceliar
75b931f37e eliminate some more copying between slices 2019-08-04 14:50:19 -05:00
Arceliar
f52955ee0f WARNING: CRYPTO DISABLED while speeding up stream writeMsg 2019-08-04 14:18:59 -05:00
Arceliar
1e6a6d2160 use session.cancel in the router to make blocking safe, reduce size of fromRouter buffer so the drops in the switch are closer to the intended front-drop behavior 2019-08-04 02:21:41 -05:00
Arceliar
7bf5884ac1 remove some lossy channel sends that should be safe to allow to block 2019-08-04 02:14:45 -05:00
Arceliar
6da5802ae5 don't block forever in Write if the session is cancelled, cleanup Conn.Read slightly 2019-08-04 02:08:47 -05:00
Arceliar
144c823bee just use a sync.Pool as the bytestore to not overcomplicate things, the allocations from interface{} casting don't seem to actually hurt in practice right now 2019-08-04 00:28:13 -05:00
Arceliar
cbbb61b019 fix another drain on the bytestore 2019-08-04 00:00:41 -05:00
Arceliar
00e9c3dbd9 do session crypto work using the worker pool 2019-08-03 23:27:52 -05:00
Arceliar
befd1b43a0 refactor session worker code slightly 2019-08-03 23:14:51 -05:00
Arceliar
7a9ad0c8cc add workerpool to util 2019-08-03 23:10:37 -05:00
Arceliar
b9987b4fdc reduce time spent with a mutex held in sessionInfo.recvWorker 2019-08-03 22:47:10 -05:00
Arceliar
099bd3ae1e reduce part of sendWorker that needs to keep a mutex 2019-08-03 22:35:10 -05:00
Arceliar
72ed541bf3 a little cleanup to Conn functions 2019-08-03 22:07:38 -05:00
Arceliar
5dfc71e1ee put bytes back when done 2019-08-03 22:00:47 -05:00
Arceliar
df0090e32a Add per-session read/write workers, work in progress, they still unfortunately need to take a mutex for safety 2019-08-03 21:46:18 -05:00
Neil Alexander
a2966291b9
Merge pull request #478 from yggdrasil-network/develop
Version 0.3.6
2019-08-03 12:00:00 +01:00
Neil Alexander
523f90bfc4
Merge pull request #477 from yggdrasil-network/changelog
Update CHANGELOG.md
2019-08-03 10:17:28 +01:00
Arceliar
1eabf88782 more updates to go.sum 2019-08-02 20:48:07 -05:00
Neil Alexander
68769efdc9
Update go.mod/go.sum 2019-08-02 20:05:15 +01:00
Neil Alexander
e6bca895bc
Update go.mod/go.sum 2019-07-30 11:52:30 +01:00
Neil Alexander
a3099894bd
Update CHANGELOG.md 2019-07-30 10:15:06 +01:00
Neil Alexander
92a611f34b
Merge pull request #476 from yggdrasil-network/build
Update build script
2019-07-30 00:14:03 +01:00
Neil Alexander
b4d08f9273
Try to be more POSIX-compliant 2019-07-30 00:03:17 +01:00
Neil Alexander
cafa20074c
Don't strip debug builds 2019-07-29 23:50:00 +01:00
Neil Alexander
750a79eb09
Update build script 2019-07-29 23:45:47 +01:00
Neil Alexander
853054eb62
Merge pull request #475 from Arceliar/misc
Misc
2019-07-29 20:24:49 +01:00
Arceliar
406e143f7f move some logic from TunAdapter.reader into a new function, TunAdapter.readerPacketHandler 2019-07-28 23:33:04 -05:00
Neil Alexander
7c4c1558ff
Merge pull request #474 from neilalexander/gomobile
Various API changes and simplifications to fix mobile builds
2019-07-28 19:34:06 +01:00
Neil Alexander
bb4abf575b
Fix build -i 2019-07-28 13:51:22 +01:00
Neil Alexander
cbc8711dd3
Remove mobile module, since it can now be moved into another repository 2019-07-28 13:39:29 +01:00
Neil Alexander
c9554f82be
Formatting tweaks in api.go 2019-07-28 11:35:16 +01:00
Neil Alexander
24f4754f2b
Export NodeInfoPayload type, rename some API functions 2019-07-28 11:30:24 +01:00
Arceliar
38e1503b28 split up some of the tun reader logic into a separate worker, so the main loop can be mostly just syscalls 2019-07-27 20:09:43 -05:00
Arceliar
b66bea813b rename a couple of things and move a PutBytes so it happens sooner 2019-07-27 18:23:55 -05:00
Arceliar
9e118884d4 remove some commented code 2019-07-27 18:12:06 -05:00
Arceliar
e0a3055c2f get rid of session workers, new util.PutBytes/GetBytes logic 2019-07-27 18:10:32 -05:00
Arceliar
39245f8134
Merge pull request #473 from Arceliar/macos
Possible fix for macos self-traffic
2019-07-27 11:12:03 -05:00
Neil Alexander
377f88512b
Remove commented out router function 2019-07-27 15:57:19 +01:00
Neil Alexander
de1005e4fa
Various API changes and simplifications to fix mobile builds 2019-07-27 15:00:09 +01:00
Neil Alexander
ad4ba6871e
Use Go 1.12.7 for macOS builds 2019-07-27 14:15:07 +01:00
Neil Alexander
d813105386
Export CIBRANCH to Bash env 2019-07-27 14:11:03 +01:00
Neil Alexander
4d4fa84123
Hopefully fix CircleCI builds on PRs 2019-07-27 13:57:19 +01:00
Neil Alexander
195d577151
Add IFF_NODAD/IFF_SECURED, define consts 2019-07-27 13:30:47 +01:00
Arceliar
e5bb9bcb8d change how searches are initialized so we actually send a dhtReq to ourself and get a response, in case we're the destination 2019-07-26 17:44:40 -05:00
Neil Alexander
9b99f0b5e4
Update go.mod/go.sum references 2019-07-25 08:40:45 +01:00
Neil Alexander
6263fa287c
Merge pull request #467 from neilalexander/debugtext
Send PPROF output text to stderr
2019-07-23 08:15:03 +01:00
Neil Alexander
f208b7f542
Merge pull request #469 from neilalexander/fix468
Don't send IP back twice with getPeers
2019-07-23 08:14:49 +01:00
Neil Alexander
837eb0131b
Merge pull request #470 from neilalexander/conndebug
Redirect Conn session closure errors to debug channel
2019-07-23 08:14:38 +01:00
Neil Alexander
de9d0a6cf1
Redirect Conn session closure errors to debug channel 2019-07-22 22:41:55 +01:00
Neil Alexander
8669091a08
Don't send IP back twice with getPeers 2019-07-22 19:45:48 +01:00
Neil Alexander
34ac5c9197
Send PPROF output text to stderr instead of stdout so that it doesn't break -genconf 2019-07-20 21:56:53 +01:00
Neil Alexander
48ad3c5d7f
Update water go.mod references, fix some bugs in TAP mode (which should hopefully fix Windows support too) 2019-07-20 16:13:54 +01:00
Neil Alexander
36201895e7
Don't mangle bs slice in TAP mode 2019-07-20 12:10:05 +01:00
Neil Alexander
2582df752d
Fix resetting Windows adapter (reverting previous change) 2019-07-20 11:43:30 +01:00
Neil Alexander
2aa57750a6
Merge branch 'windows' into develop 2019-07-20 11:15:05 +01:00
Neil Alexander
f3e3e4bca1
Update go.mod/go.sum again for Windows interface selection tweaks 2019-07-20 11:14:42 +01:00
Neil Alexander
4f3d29332d
Merge pull request #466 from neilalexander/windows
Fix a couple of Windows bugs
2019-07-19 22:37:27 +01:00
Neil Alexander
52080aa41e
Build with Go 1.12.7 2019-07-19 22:34:18 +01:00
Neil Alexander
613468e6a7
Update go.mod/go.sum again for BSD tweaks in Water due to failed CI build 2019-07-19 22:30:59 +01:00
Neil Alexander
1a5c2a4942
Update Windows module a bit - capture TAP setup errors earlier, refer to newer version of water which should fix #456 2019-07-19 22:21:30 +01:00
Neil Alexander
85881c04fa
Merge pull request #463 from Arceliar/cancellation
Cancellation
2019-07-18 11:14:11 +01:00
Arceliar
cf3ebe04a7 have Conn use Cancellation instead of manually setting up timers 2019-07-17 21:37:45 -05:00
Arceliar
6bf182e341 add util.CancellationChild() and run gofmt 2019-07-17 21:15:02 -05:00
Arceliar
06e8403aaf add cancellation code to util, like context but just the cancellation parts + some error logic 2019-07-17 21:09:22 -05:00
Arceliar
c36da7b814
Merge pull request #462 from Arceliar/fixes
fix possible unsafe memory use in Conn.Read
2019-07-17 18:33:35 -05:00
Arceliar
5301207480 fix possible unsafe memory use in Conn.Read 2019-07-17 18:25:38 -05:00
Neil Alexander
06330f503f
Recover if stillAlive fails 2019-07-18 00:02:16 +01:00
Neil Alexander
311c612f2e
Only flag stillAlive on successful write 2019-07-17 23:23:19 +01:00
Neil Alexander
307b24d8cb
Fix Conn.Read/Conn.Write behavior after Conn.Close, get rid of second TUN/TAP conn reader goroutine, no longer use deadlines 2019-07-17 21:42:17 +01:00
Neil Alexander
1bf1c6eb36
Revert "Remove stillAlive code from TUN/TAP conn as it is no longer required with the new deadlines"
This reverts commit eec70bf2f2.
2019-07-17 19:43:29 +01:00
Neil Alexander
eec70bf2f2
Remove stillAlive code from TUN/TAP conn as it is no longer required with the new deadlines 2019-07-17 13:53:16 +01:00
Neil Alexander
7d1c03d2ac
Only call stillAlive if channel read succeeds 2019-07-17 12:07:16 +01:00
Neil Alexander
747b50bb7c
Try to improve handling of timeouts 2019-07-17 11:13:53 +01:00
Neil Alexander
2532cd77e4
Merge pull request #461 from yggdrasil-network/connreader
Try to fix TUN/TAP conn reader leakage
2019-07-17 10:15:44 +01:00
Neil Alexander
d34600b5f9
Try to fix TUN/TAP conn reader leakage 2019-07-17 10:12:10 +01:00
Neil Alexander
7edcab8621
Merge pull request #433 from neilalexander/circlecirpm
Try to build the new RPM using CircleCI
2019-07-17 07:11:02 +01:00
Neil Alexander
fd2c7259b1
Merge pull request #460 from neilalexander/fix413
Fix #413
2019-07-17 07:10:43 +01:00
Neil Alexander
829a24a858
Fix default case 2019-07-16 11:48:31 +01:00
Neil Alexander
f3dd4320f7
Try to set Conflicts in RPM properly 2019-07-16 11:44:58 +01:00
Neil Alexander
0c4e2cc41e
Merge branch 'develop' into circlecirpm 2019-07-16 11:28:46 +01:00
Neil Alexander
145a43e5f0
Fix #413 by always generating public keys from private ones instead of trusting public keys supplied by config 2019-07-16 09:49:28 +01:00
Neil Alexander
a5152f1d44
Merge pull request #458 from reuank/patch-1
Correcting typo in headline
2019-07-09 11:33:08 +01:00
Leon Knauer
99aac19f98
Correcting typo in headline 2019-07-09 12:30:29 +02:00
Neil Alexander
f831f9d2cc
Merge pull request #395 from neilalexander/fix-385
Handle admin socket error cases better
2019-07-07 19:44:17 +01:00
Neil Alexander
ea9d5db16d
Make admin socket output a bit friendlier (fixes #385) 2019-07-07 19:41:53 +01:00
Neil Alexander
c9dc9507de
Merge pull request #455 from yggdrasil-network/tapfix
Fix TAP mode
2019-07-06 20:32:52 +01:00
Neil Alexander
30c03369cd
Try to fix CKR setup deadlock, fix some Windows output formatting 2019-07-06 20:08:32 +01:00
Neil Alexander
a10c141896
Fix data race on peermacs 2019-07-06 15:15:43 +01:00
Neil Alexander
e8272926a4
Fix TAP mode 2019-07-06 15:08:17 +01:00
Neil Alexander
912c181581
Merge pull request #453 from yggdrasil-network/stopfix
Bug fixes
2019-07-06 12:36:46 +01:00
Neil Alexander
4804ce39af
Tidy up the terminate path a bit 2019-07-06 12:17:40 +01:00
Neil Alexander
618d46a7b3
Don't block on adding peers in case one is unreachable and we are forced to wait for timeout 2019-07-06 12:12:30 +01:00
Neil Alexander
02c99d3e7d
More directly define a minwinsvc exit handler 2019-07-06 12:04:31 +01:00
Neil Alexander
12486b0557
Try to more gracefully handle shutdowns on Windows 2019-07-06 11:52:30 +01:00
Arceliar
b2607a7205
Merge pull request #447 from Arceliar/bugfixes
Another Conn bugfix
2019-07-01 19:09:36 -05:00
Arceliar
86c30a1fc4 fix another panic from a send on a closed session worker channel, from races between Conn.Read/Write/Close 2019-07-01 18:55:07 -05:00
Arceliar
cd29fde178 temporary workaround to concurrency bug in sessions.getSharedKey 2019-06-29 19:32:15 -05:00
Arceliar
fbe44ea973 fix bug in session api code 2019-06-29 19:25:34 -05:00
Arceliar
b8592669b8
Merge pull request #446 from Arceliar/bugfixes
Bugfixes
2019-06-29 19:00:11 -05:00
Arceliar
40553a6a44 make GetSessions use the session workers to avoid races 2019-06-29 18:56:26 -05:00
Arceliar
d39428735d recover if we try to send to a closed session worker due to a race between a Conn.Write call and a Conn.Close call 2019-06-29 18:50:21 -05:00
Arceliar
28db566b37 fix concurrency bug in iface.go 2019-06-29 18:44:24 -05:00
Arceliar
0fb1165b76
Merge pull request #445 from Arceliar/dial
more bugfixes
2019-06-29 17:48:12 -05:00
Arceliar
7d58a7ef3e fix channel multiple close bug and concurrency bug in the way sessionInfo.close was being called 2019-06-29 17:44:28 -05:00
Arceliar
43bcb9e154
Merge pull request #444 from Arceliar/dial
Dial fixes
2019-06-29 16:17:47 -05:00
Arceliar
818eca90db fix nil pointer deref if searches fail, block dial until a search exceeds or a timeout passes (todo: replace timer with context) 2019-06-29 16:10:02 -05:00
Arceliar
ca1f2bb0a2 add go-syslog to go.mod/go.sum 2019-06-29 12:33:00 -05:00
Arceliar
8ecf99d8a9
Merge pull request #443 from Arceliar/dial
Bugfix in dial code
2019-06-29 12:21:19 -05:00
Arceliar
784acba823 I think this fixes the concurrent map read/write panic 2019-06-29 12:14:44 -05:00
Neil Alexander
0d23342358
Merge pull request #441 from Arceliar/dial
Dial
2019-06-29 10:52:05 +01:00
Arceliar
e88bef35c0 get rid of old buffered session packets 2019-06-28 20:02:58 -05:00
Arceliar
e7cb76cea3 clean up unused old session maps 2019-06-28 19:21:44 -05:00
Arceliar
c808be514f make tunAdapter.wrap return the right thing 2019-06-28 19:11:28 -05:00
Arceliar
5df110ac79 make Dial block until the search finishes, and use it as such 2019-06-28 18:42:31 -05:00
Neil Alexander
ac8ff740ee
Merge pull request #438 from neilalexander/multicast
Try and solidify multicast interface behavior
2019-06-29 00:38:38 +01:00
Neil Alexander
721a8b5d27
Merge pull request #440 from neilalexander/logging
Add support for logging to file or syslog instead of stdout
2019-06-29 00:37:05 +01:00
Neil Alexander
23108e268b
Use go-syslog to fix builds on Windows 2019-06-29 00:32:23 +01:00
Neil Alexander
27b3b9b49b
Return new copy of interfaces on each Interfaces() call 2019-06-29 00:12:56 +01:00
Neil Alexander
93a323c62c
Add support for logging to file or syslog instead of stdout 2019-06-28 23:45:04 +01:00
Arceliar
29a0f8b572 some minor refactoring to dht callbacks and searches, work in progress 2019-06-25 19:31:29 -05:00
Neil Alexander
54f1804101
Try and solidify multicast interface behavior 2019-06-20 15:11:55 +01:00
Neil Alexander
2fd3ac6837
Merge pull request #432 from neilalexander/gatekeeper
Implement session gatekeeper functions
2019-06-13 23:41:42 +01:00
Neil Alexander
535ca06c07
Merge pull request #431 from neilalexander/defaults
Add multicast interfaces to platform-specific defaults
2019-06-13 23:41:28 +01:00
Neil Alexander
f545060e89
Add notes on isSessionAllowed checks 2019-06-13 23:37:53 +01:00
Neil Alexander
9a7d350884
Fix expressions 2019-06-11 23:48:00 +01:00
Neil Alexander
ec5bb84975
Try to build the new RPM using CircleCI 2019-06-11 15:30:55 +01:00
Neil Alexander
e229ad6e2b
Update comments 2019-06-11 12:52:13 +01:00
Neil Alexander
907986f200
Implement session firewall as gatekeeper func in cmd/yggdrasil 2019-06-11 12:50:01 +01:00
Neil Alexander
720a078a35
Add SetSessionGatekeeper
This allows you to define a function which determines whether a session connection (either incoming or outgoing) is allowed based on the public key.
2019-06-11 10:52:21 +01:00
Neil Alexander
17175b49f2
Add multicast interfaces to platform-specific defaults (this makes it easier to avoid bringing AWDL up by default on macOS as an example, or over L2 VPNs when not expected) 2019-06-11 10:18:59 +01:00
Neil Alexander
d4a3b2bc76
Merge pull request #429 from Arceliar/sessionfix
fix issue with sessions dying and never being fixed
2019-06-11 10:07:52 +01:00
Arceliar
4b56849b08 fix issue with sessions dying and never being fixed 2019-06-10 22:09:12 -05:00
Arceliar
cab4b5f793
Merge pull request #428 from Arceliar/readerror
Conn.Read don't return useless errors
2019-05-31 17:56:53 -05:00
Arceliar
1addf08ccd don't have Conn.Read return an error for temorary crypto failures from e.g. out of order packets, just drop the packet and keep blocking until there's usable traffic 2019-05-31 17:51:01 -05:00
Neil Alexander
7e837e97e9
Merge pull request #427 from neilalexander/ckrenabled
Fix panic when determining if CKR is enabled
2019-05-31 11:33:07 +01:00
Neil Alexander
f0422dbd8b
Fix panic when determining if CKR is enabled 2019-05-30 17:33:59 +01:00
Neil Alexander
e430d16018
Merge pull request #426 from neilalexander/errorhandle
Don't indefinitely block TUN/TAP reader goroutine after conn error
2019-05-30 12:52:35 +01:00
Neil Alexander
9e086e70f0
Don't indefinitely block TUN/TAP reader goroutine when a conn error happens 2019-05-30 12:44:47 +01:00
Neil Alexander
396c879d0f
Merge pull request #425 from neilalexander/sessionmtu
Re-add ICMPv6 packet too big handling
2019-05-29 20:19:41 +01:00
Neil Alexander
0096d1ae3e
Re-add ICMPv6 packet too big handling 2019-05-29 20:16:17 +01:00
Neil Alexander
75cc25b7f4
Merge pull request #424 from neilalexander/sessionmtu
Fix bug where MTU was ignored by sessions, resulting in default 1280
2019-05-29 19:17:10 +01:00
Neil Alexander
3b6c726a3c
Fix bug where MTU was ignored by sessions, resulting in default 1280 2019-05-29 19:11:12 +01:00
Neil Alexander
6b6266bfdd
Merge pull request #419 from yggdrasil-network/modular
Modular Yggdrasil
2019-05-29 18:19:13 +01:00
Neil Alexander
78eb40cbad
Record session uptime (purely for the admin socket) 2019-05-29 12:59:36 +01:00
Arceliar
b2513fce56 have the tunConn close things after a 2 minute timeout 2019-05-28 18:35:52 -05:00
Arceliar
5ea864869a don't spam searches for unused connections. todo: timeout old connections somehow 2019-05-23 20:27:52 -05:00
Neil Alexander
70774fc3de
Reimplement get/setTunnelRouting, add/removeSourceSubnet, add/removeRoute, getRoutes, getSourceSubnets, make CKR threadsafe 2019-05-20 21:45:33 +01:00
Neil Alexander
5b8d8a9341
Reimplement getNodeInfo, dhtPing, get/add/removeAllowedEncryptionPublicKey, add/removePeer 2019-05-20 19:51:44 +01:00
Neil Alexander
e9e2d7bc6f
Remove debug println 2019-05-19 22:03:20 +01:00
Neil Alexander
d575b83ec1
Refactor admin socket somewhat, allow modules to set up their own handlers 2019-05-19 22:02:04 +01:00
Neil Alexander
8ef1978cb1
Start factoring out the admin socket into a separate module (not all functions implemented yet) 2019-05-19 17:27:48 +01:00
Neil Alexander
7ca5a2533d
Implement GetDHT, GetSwitchQueues, GetSessions 2019-05-19 16:29:04 +01:00
Neil Alexander
8a6f6f3b2b
Implement GetPeers and GetSwitchPeers API functions in Core, in preparation for breaking out the admin socket into a separate module 2019-05-18 17:21:02 +01:00
Neil Alexander
ce60609906
Remove wrappedConn as unnecessary 2019-05-18 16:16:32 +01:00
Neil Alexander
5b09b45572
Merge pull request #416 from fifteenthcommotion/yggdrasil-brute-simple
contribute decently fast yggdrasil address generator in C
2019-05-18 12:28:49 +01:00
fifteenthcommotion
080052ce04 remove ygg-brute gitignore 2019-05-18 04:25:57 -07:00
Neil Alexander
1b3ec0b93f
Fix multicast start check so that it shouldn't give up if interfaces aren't up when Yggdrasil starts (fixes #405) 2019-05-17 22:59:29 +01:00
Neil Alexander
2df62e2b9b
Remove code that translates v0.2 config options (it was commented out anyway) 2019-05-17 22:52:14 +01:00
Neil Alexander
ae2cc13d14
Fix configuration reloading support 2019-05-17 22:29:52 +01:00
Neil Alexander
71ccaf753e
Add crypto-key routing into TUN/TAP 2019-05-17 22:09:20 +01:00
Arceliar
9c01947b1c reduce allocations in switch 2019-05-16 18:10:47 -05:00
Arceliar
522ed147b1 use the subnet derived ID/mask when creating a connection based on a subnet address, fix a potential blocking channel send in tuntap/conn.go, and get debug.go compiling well enough to profile things (the sim is currently still broken) 2019-05-15 18:01:26 -05:00
fifteenthcommotion
5bed78c7a7 add CC0 for good measure 2019-05-12 12:40:45 -07:00
fifteenthcommotion
db85a11194 unlicense and spacing perfectionism 2019-05-12 02:18:03 -07:00
fifteenthcommotion
5a3c730097 contribute decently fast yggdrasil address generator in C 2019-05-11 16:31:46 -07:00
Arceliar
efdaea1b5e fix some races and GetBytes/PutBytes usage, but this still seems to deadlock somewhere in iperf tests 2019-05-02 17:37:49 -05:00
Neil Alexander
5f66c4c95c
Try using separate workers for each TUN/TAP connection (sometimes produces duplicate packets when communicating with both the node address and a subnet address, sometimes also can't Ctrl-C to quit) 2019-04-28 17:14:09 +01:00
Arceliar
6469e39ff1 workaround to random timeouts 2019-04-26 22:42:05 -05:00
Arceliar
5d323861f0 properly fix the memory errors, it was caused by a function returning and PutBytes-ing a buffer before a worker had a chance to decrypt the buffer, so it would GetBytes the same buffer by dumb luck and then get an illegal overlap 2019-04-26 22:21:31 -05:00
Arceliar
01ea6d3d80 somehow this doesn't seem to deadlock or crash from buffer reuse (util.PutBytes), but I have no idea why it was doing that before and not now 2019-04-26 21:49:11 -05:00
Arceliar
15051b0a3c Add deadline timers, keep searches alive until they complete (or the conn is closed) to keep Write from blocking forever 2019-04-26 19:31:47 -05:00
Arceliar
0059baf36c add a newConn function that returns a pointer to a Conn with atomics properly initialized 2019-04-26 18:07:57 -05:00
Neil Alexander
75130f7735
Fix TAP support again 2019-04-23 11:46:16 +01:00
Neil Alexander
2b44f5d2f6
Fix TAP support 2019-04-23 11:37:32 +01:00
Neil Alexander
b4513ca2e8
Re-add support for TAP mode 2019-04-23 10:43:07 +01:00
Neil Alexander
870b2b6a2e
Remove CKR from src/yggdrasil (it will be moved into tuntap) 2019-04-23 10:28:40 +01:00
Neil Alexander
2bee3cd7ca
Update TODOs at top of tun.go 2019-04-23 00:04:22 +01:00
Neil Alexander
d7a1c04748
It works, sort of, amazingly 2019-04-22 23:58:59 +01:00
Neil Alexander
e1a2d666bf
Clean up router, tweaks 2019-04-22 23:12:13 +01:00
Neil Alexander
6e528799e9
Conn Read/Write operations will block while search completes 2019-04-22 22:38:37 +01:00
Neil Alexander
ea8948f378
TUN/TAP addr/subnet to Conn mappings, other fixes 2019-04-22 20:06:39 +01:00
Neil Alexander
9778f5d2b8
Fix search behaviour on closed Conns, various other fixes 2019-04-22 15:00:19 +01:00
Neil Alexander
bbd1246f7b
Fix bug in mask generation for outbound dials, change iface reader mutexes to read-only locks unless RW is needed 2019-04-22 11:49:47 +01:00
Neil Alexander
ccf03fd3b6
Don't write huge mostly empty buffers unnecessarily 2019-04-22 11:22:40 +01:00
Neil Alexander
47eb2fc47f
Break deadlock by creating session recv queue when session is created instead of repointing at search completion, also make expired atomic 2019-04-22 11:20:35 +01:00
Arceliar
5a02e2ff44 apparently it was these callbacks that were sometimes deadlocking things 2019-04-21 22:31:56 -05:00
Arceliar
9ce7fe2e3f fix tun/tap CIDR notation so things work on linux, may break other platforms for all I know 2019-04-21 20:56:12 -05:00
Arceliar
5dada3952c use a session worker to try to avoid mutex hell. compiles, but incomplete and doesn't work yet 2019-04-21 20:38:14 -05:00
Neil Alexander
0b8f5b5dda
Tweaks 2019-04-21 12:28:46 +01:00
Neil Alexander
781cd7571f
Fix race on tun conns, but still deadlocks if more than one connection is opened 2019-04-21 12:00:31 +01:00
Neil Alexander
79bcfbf175
Change some mutexes to atomics, change conns map to pointers, sort of works but seems to deadlock very easily 2019-04-21 11:50:41 +01:00
Neil Alexander
62621f2960
Some tweaks 2019-04-20 20:22:58 +01:00
Neil Alexander
d01662c1fb
Try to convert TUN/TAP to use new yggdrasil.Conn, search masks are still broken 2019-04-20 16:32:27 +01:00
Neil Alexander
319366513c
Allow building with race detector 2019-04-20 11:53:46 +01:00
Neil Alexander
f3e742a297
Squash a whole load of races (and mutex half the world) 2019-04-20 11:53:38 +01:00
Neil Alexander
24281d4049
Fix Read, update sample 2019-04-19 23:47:11 +01:00
Neil Alexander
693bcc5713
Update sample in cmd/yggdrasil 2019-04-19 23:30:57 +01:00
Neil Alexander
e31b914e38
Improve errors and handling of expired sessions 2019-04-19 23:30:43 +01:00
Neil Alexander
7e726b0afb
Listener should clean up a bit more when closing 2019-04-19 23:04:09 +01:00
Neil Alexander
aac88adbed
Listen-Accept-Read-Write pattern now works, amazingly 2019-04-19 22:57:52 +01:00
Neil Alexander
27b78b925d
Move mutexes around 2019-04-19 21:23:15 +01:00
Neil Alexander
e3eadba4b7
Protect session nonces with mutexes, modify sent/received bytes atomically 2019-04-19 20:10:41 +01:00
Neil Alexander
ade684beff
Signal when a session is closed, other tweaks 2019-04-19 10:55:15 +01:00
Neil Alexander
c593721362
Tweaks 2019-04-19 00:33:54 +01:00
Neil Alexander
b20c8b6da5
Move some things around a bit, delete session workers 2019-04-19 00:11:43 +01:00
Neil Alexander
b2f4f2e1b6
Update errors, update Write 2019-04-19 00:07:26 +01:00
Neil Alexander
160e01e84f
Searches called from api.go, various other tweaks, searches now have a callback for success/failure, node ID now reported by admin socket 2019-04-18 23:38:23 +01:00
Neil Alexander
eef2a02d0a
Experiment with new API 2019-04-18 16:38:24 +01:00
Neil Alexander
24fa8355f1
Merge pull request #401 from neilalexander/modular
Refactoring for Yggdrasil library
2019-04-17 18:35:10 +01:00
Neil Alexander
9bc24f8dbf
Return both current and previous config when replacing 2019-04-15 22:00:38 +01:00
Arceliar
53fba06382
Merge pull request #407 from cathugger/develop
wire: cleaner and faster wire_intToUint and wire_intFromUint
2019-04-11 00:28:27 -05:00
Neil Alexander
ed4e21478f
Merge pull request #409 from vpzomtrrfrt/armel
Add armel support to deb script
2019-04-07 23:30:07 +01:00
Colin Reeder
2465ad0384
Add armel to PKGARCH usage list 2019-04-07 16:14:58 -06:00
Colin Reeder
b5e3b05e77 Add armel support to deb script 2019-04-07 13:07:26 -06:00
cathugger
4488189a75
wire: cleaner and faster wire_intToUint and wire_intFromUint
Bit operations are much faster on most processors than multiplication.
Also specify that it's zigzag to ease finding additional documentation for it.
2019-04-06 21:34:47 +03:00
Neil Alexander
2e72c7c93d
Fix mobile logging 2019-04-01 22:45:30 +01:00
Neil Alexander
90feae6a7d
Comment out AWDL (doesn't work in iOS properly) and move out of main package 2019-04-01 20:12:39 +01:00
Neil Alexander
350b51cabb
TUN/TAP now uses config, log, etc from adapter.go 2019-04-01 20:10:14 +01:00
Neil Alexander
58f5cc88d0
Fix session bug, fix dummy adapter, fix mobile framework builds 2019-04-01 19:59:50 +01:00
Neil Alexander
047717abf2
Break out mobile and dummy adapter 2019-04-01 18:02:06 +01:00
Neil Alexander
39baf7365c
Unexport/modify some interfaces to revive broken iOS/Android builds 2019-03-30 00:09:35 +00:00
Neil Alexander
4c0c3a23cb
Fix bugs 2019-03-29 18:24:57 +00:00
Neil Alexander
f19a4e4398
More godoc improvements 2019-03-29 18:18:31 +00:00
Neil Alexander
b5ac65cacb
Rearrange public interface, godoc improvements 2019-03-29 18:05:17 +00:00
Neil Alexander
399e1a2ffe
Make AddPeer remember added peer (as opposed to CallPeer which does not) 2019-03-29 08:58:30 +00:00
Neil Alexander
a830521078
Don't crash if Yggdrasil is started with no router adapter 2019-03-29 08:38:09 +00:00
Neil Alexander
dd05a7f2a8
Tweaks 2019-03-28 19:09:19 +00:00
Neil Alexander
fd0b614f9c
Temporarily disable debug CircleCI builds as I don't know how badly I've broken the sim with this PR 2019-03-28 18:03:14 +00:00
Neil Alexander
7ea4e9575e
Break out multicast into a separate package 2019-03-28 16:13:14 +00:00
Neil Alexander
03bc7bbcd6
Fix TUN/TAP for non-Darwin platforms 2019-03-28 15:32:01 +00:00
Neil Alexander
eb22ed44ac
Add new reject channel to router so we can send back rejected packets to adapter (e.g. for ICMPv6 Packet Too Big), implement ICMPv6 PTB in TUN/TAP instead of router 2019-03-28 09:50:13 +00:00
Neil Alexander
0715e829c2
Fix adapter setup and no longer panics on packets shorter than IP header 2019-03-28 09:12:00 +00:00
Neil Alexander
0b494a8255
Refactoring: move tuntap and icmpv6 into separate package 2019-03-28 00:30:25 +00:00
Neil Alexander
67c670ab4c
Merge pull request #391 from aparcar/patch-1
README: add OpenWrt as supported platform
2019-03-19 16:39:02 +00:00
Paul Spooren
3f824ee99c
README: add OpenWrt as supported platform 2019-03-19 15:54:49 +01:00
166 changed files with 10418 additions and 14136 deletions

View file

@ -1,191 +0,0 @@
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2.1
jobs:
build-linux:
docker:
- image: circleci/golang:1.12
steps:
- checkout
- run:
name: Create artifact upload directory and set variables
command: |
mkdir /tmp/upload
echo 'export CINAME=$(sh contrib/semver/name.sh)' >> $BASH_ENV
echo 'export CIVERSION=$(sh contrib/semver/version.sh --bare)' >> $BASH_ENV
git config --global user.email "$(git log --format='%ae' HEAD -1)";
git config --global user.name "$(git log --format='%an' HEAD -1)";
- run:
name: Install alien
command: |
sudo apt-get install -y alien
- run:
name: Test debug builds
command: |
./build -d
test -f yggdrasil && test -f yggdrasilctl
- run:
name: Build for Linux (including Debian packages and RPMs)
command: |
rm -f {yggdrasil,yggdrasilctl}
PKGARCH=amd64 sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-linux-amd64 && mv yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-linux-amd64;
PKGARCH=i386 sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-linux-i386 && mv yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-linux-i386;
PKGARCH=mipsel sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-linux-mipsel && mv yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-linux-mipsel;
PKGARCH=mips sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-linux-mips && mv yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-linux-mips;
PKGARCH=armhf sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-linux-armhf && mv yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-linux-armhf;
PKGARCH=arm64 sh contrib/deb/generate.sh && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-linux-arm64 && mv yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-linux-arm64;
sudo alien --to-rpm yggdrasil*.deb --scripts --keep-version && mv *.rpm /tmp/upload/;
mv *.deb /tmp/upload/
- run:
name: Build for EdgeRouter
command: |
rm -f {yggdrasil,yggdrasilctl}
git clone https://github.com/neilalexander/vyatta-yggdrasil /tmp/vyatta-yggdrasil;
cd /tmp/vyatta-yggdrasil;
BUILDDIR_YGG=$CIRCLE_WORKING_DIRECTORY ./build-edgerouter-x $CIRCLE_BRANCH;
BUILDDIR_YGG=$CIRCLE_WORKING_DIRECTORY ./build-edgerouter-lite $CIRCLE_BRANCH;
mv *.deb /tmp/upload;
- persist_to_workspace:
root: /tmp
paths:
- upload
build-macos:
macos:
xcode: "10.0.0"
working_directory: ~/go/src/github.com/yggdrasil-network/yggdrasil-go
steps:
- checkout
- run:
name: Create artifact upload directory and set variables
command: |
mkdir /tmp/upload
echo 'export CINAME=$(sh contrib/semver/name.sh)' >> $BASH_ENV
echo 'export CIVERSION=$(sh contrib/semver/version.sh --bare)' >> $BASH_ENV
echo 'export PATH=$PATH:/usr/local/go/bin:~/go/bin' >> $BASH_ENV
git config --global user.email "$(git log --format='%ae' HEAD -1)";
git config --global user.name "$(git log --format='%an' HEAD -1)";
echo -e "Host *\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
- run:
name: Install Go 1.12
command: |
cd /tmp
curl -LO https://dl.google.com/go/go1.12.darwin-amd64.pkg
sudo installer -pkg /tmp/go1.12.darwin-amd64.pkg -target /
#- run:
# name: Install Gomobile
# command: |
# GO111MODULE=off go get golang.org/x/mobile/cmd/gomobile
# gomobile init
- run:
name: Build for macOS
command: |
GO111MODULE=on GOOS=darwin GOARCH=amd64 ./build
cp yggdrasil /tmp/upload/$CINAME-$CIVERSION-darwin-amd64
cp yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-darwin-amd64;
- run:
name: Build for macOS (.pkg format)
command: |
PKGARCH=amd64 sh contrib/macos/create-pkg.sh
mv *.pkg /tmp/upload/
#- run:
# name: Build framework for iOS (.framework format)
# command: |
# sudo GO111MODULE=off go get -v github.com/yggdrasil-network/yggdrasil-go/cmd/...
# sudo GO111MODULE=off go get -v github.com/yggdrasil-network/yggdrasil-go/src/...
# GO111MODULE=off ./build -i
# mv *.framework /tmp/upload
- persist_to_workspace:
root: /tmp
paths:
- upload
build-other:
docker:
- image: circleci/golang:1.12
steps:
- checkout
- run:
name: Create artifact upload directory and set variables
command: |
mkdir /tmp/upload
echo 'export CINAME=$(sh contrib/semver/name.sh)' >> $BASH_ENV
echo 'export CIVERSION=$(sh contrib/semver/version.sh --bare)' >> $BASH_ENV
git config --global user.email "$(git log --format='%ae' HEAD -1)";
git config --global user.name "$(git log --format='%an' HEAD -1)";
- run:
name: Build for OpenBSD
command: |
rm -f {yggdrasil,yggdrasilctl}
GOOS=openbsd GOARCH=amd64 ./build && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-openbsd-amd64 && mv yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-openbsd-amd64;
GOOS=openbsd GOARCH=386 ./build && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-openbsd-i386 && mv yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-openbsd-i386;
- run:
name: Build for FreeBSD
command: |
rm -f {yggdrasil,yggdrasilctl}
GOOS=freebsd GOARCH=amd64 ./build && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-freebsd-amd64 && mv yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-freebsd-amd64;
GOOS=freebsd GOARCH=386 ./build && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-freebsd-i386 && mv yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-freebsd-i386;
- run:
name: Build for NetBSD
command: |
rm -f {yggdrasil,yggdrasilctl}
GOOS=netbsd GOARCH=amd64 ./build && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-netbsd-amd64 && mv yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-netbsd-amd64;
GOOS=netbsd GOARCH=386 ./build && mv yggdrasil /tmp/upload/$CINAME-$CIVERSION-netbsd-i386 && mv yggdrasilctl /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-netbsd-i386;
- run:
name: Build for Windows
command: |
rm -f {yggdrasil,yggdrasilctl}
GOOS=windows GOARCH=amd64 ./build && mv yggdrasil.exe /tmp/upload/$CINAME-$CIVERSION-windows-amd64.exe && mv yggdrasilctl.exe /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-windows-amd64.exe;
GOOS=windows GOARCH=386 ./build && mv yggdrasil.exe /tmp/upload/$CINAME-$CIVERSION-windows-i386.exe && mv yggdrasilctl.exe /tmp/upload/$CINAME-$CIVERSION-yggdrasilctl-windows-i386.exe;
- persist_to_workspace:
root: /tmp
paths:
- upload
upload:
machine: true
steps:
- attach_workspace:
at: /tmp
- store_artifacts:
path: /tmp/upload
destination: /
workflows:
version: 2.1
build:
jobs:
- build-linux
- build-macos
- build-other
- upload:
requires:
- build-linux
- build-macos
- build-other

157
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,157 @@
name: Yggdrasil
on:
push:
pull_request:
release:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
go-version: stable
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
args: --issues-exit-code=1
codeql:
name: Analyse
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: go
- name: Autobuild
uses: github/codeql-action/autobuild@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
build-linux:
strategy:
fail-fast: false
matrix:
goversion: ["1.22", "1.23", "1.24"]
name: Build & Test (Linux, Go ${{ matrix.goversion }})
needs: [lint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.goversion }}
- name: Build Yggdrasil
run: go build -v ./...
- name: Unit tests
run: go test -v ./...
build-windows:
strategy:
fail-fast: false
matrix:
goversion: ["1.22", "1.23", "1.24"]
name: Build & Test (Windows, Go ${{ matrix.goversion }})
needs: [lint]
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.goversion }}
- name: Build Yggdrasil
run: go build -v ./...
- name: Unit tests
run: go test -v ./...
build-macos:
strategy:
fail-fast: false
matrix:
goversion: ["1.22", "1.23", "1.24"]
name: Build & Test (macOS, Go ${{ matrix.goversion }})
needs: [lint]
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.goversion }}
- name: Build Yggdrasil
run: go build -v ./...
- name: Unit tests
run: go test -v ./...
build-freebsd:
strategy:
fail-fast: false
matrix:
goversion: ["1.22", "1.23", "1.24"]
goos:
- freebsd
- openbsd
name: Build (Cross ${{ matrix.goos }}, Go ${{ matrix.goversion }})
needs: [lint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.goversion }}
- name: Build Yggdrasil
run: go build -v ./...
env:
GOOS: ${{ matrix.goos }}
tests-ok:
name: All tests passed
needs: [lint, codeql, build-linux, build-windows, build-macos]
runs-on: ubuntu-latest
if: ${{ !cancelled() }}
steps:
- name: Check all tests passed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}

140
.github/workflows/pkg.yml vendored Normal file
View file

@ -0,0 +1,140 @@
name: Packages
on:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-packages-debian:
strategy:
fail-fast: false
matrix:
pkgarch: ["amd64", "i386", "mips", "mipsel", "armhf", "armel", "arm64"]
name: Package (Debian, ${{ matrix.pkgarch }})
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "stable"
- name: Build package
env:
PKGARCH: ${{ matrix.pkgarch }}
run: sh contrib/deb/generate.sh
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: Debian package (${{ matrix.pkgarch }})
path: "*.deb"
if-no-files-found: error
build-packages-macos:
strategy:
fail-fast: false
matrix:
pkgarch: ["amd64", "arm64"]
name: Package (macOS, ${{ matrix.pkgarch }})
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "stable"
- name: Build package
env:
PKGARCH: ${{ matrix.pkgarch }}
run: sh contrib/macos/create-pkg.sh
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: macOS package (${{ matrix.pkgarch }})
path: "*.pkg"
if-no-files-found: error
build-packages-windows:
strategy:
fail-fast: false
matrix:
pkgarch: ["x64", "x86", "arm", "arm64"]
name: Package (Windows, ${{ matrix.pkgarch }})
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "stable"
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4
- name: Build package
run: sh contrib/msi/build-msi.sh ${{ matrix.pkgarch }}
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: Windows package (${{ matrix.pkgarch }})
path: "*.msi"
if-no-files-found: error
build-packages-router:
strategy:
fail-fast: false
matrix:
pkgarch: ["edgerouter-x", "edgerouter-lite", "vyos-amd64", "vyos-i386"]
name: Package (Router, ${{ matrix.pkgarch }})
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
path: yggdrasil
- uses: actions/checkout@v4
with:
repository: neilalexander/vyatta-yggdrasil
path: vyatta-yggdrasil
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "stable"
- name: Build package
env:
BUILDDIR_YGG: /home/runner/work/yggdrasil-go/yggdrasil-go/yggdrasil
run: cd /home/runner/work/yggdrasil-go/yggdrasil-go/vyatta-yggdrasil && ./build-${{ matrix.pkgarch }}
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: Router package (${{ matrix.pkgarch }})
path: "/home/runner/work/yggdrasil-go/yggdrasil-go/vyatta-yggdrasil/*.deb"
if-no-files-found: error

3
.gitmodules vendored
View file

@ -1,3 +0,0 @@
[submodule "doc/yggdrasil-network.github.io"]
path = doc/yggdrasil-network.github.io
url = https://github.com/yggdrasil-network/yggdrasil-network.github.io/

11
.golangci.yml Normal file
View file

@ -0,0 +1,11 @@
run:
build-tags:
- lint
issues-exit-code: 0 # TODO: change this to 1 when we want it to fail builds
issues:
exclude-dirs:
- contrib/
- misc/
linters:
disable:
- gocyclo

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,6 @@
# Yggdrasil
[![CircleCI](https://circleci.com/gh/yggdrasil-network/yggdrasil-go.svg?style=shield&circle-token=:circle-token
)](https://circleci.com/gh/yggdrasil-network/yggdrasil-go)
[![Build status](https://github.com/yggdrasil-network/yggdrasil-go/actions/workflows/ci.yml/badge.svg)](https://github.com/yggdrasil-network/yggdrasil-go/actions/workflows/ci.yml)
## Introduction
@ -11,44 +10,21 @@ allows pretty much any IPv6-capable application to communicate securely with
other Yggdrasil nodes. Yggdrasil does not require you to have IPv6 Internet
connectivity - it also works over IPv4.
Although Yggdrasil shares many similarities with
[cjdns](https://github.com/cjdelisle/cjdns), it employs a different routing
algorithm based on a globally-agreed spanning tree and greedy routing in a
metric space, and aims to implement some novel local backpressure routing
techniques. In theory, Yggdrasil should scale well on networks with
internet-like topologies.
## Supported Platforms
We actively support the following platforms, and packages are available for
some of the below:
Yggdrasil works on a number of platforms, including Linux, macOS, Ubiquiti
EdgeRouter, VyOS, Windows, FreeBSD, OpenBSD and OpenWrt.
- Linux
- `.deb` and `.rpm` packages are built by CI for Debian and Red Hat-based
distributions
- Void and Arch packages also available within their respective repositories
- macOS
- `.pkg` packages are built by CI
- Ubiquiti EdgeOS
- `.deb` Vyatta packages are built by CI
- Windows
- FreeBSD
- OpenBSD
- NetBSD
Please see our [Platforms](https://yggdrasil-network.github.io/) pages for more
specific information about each of our supported platforms, including
installation steps and caveats.
You may also find other platform-specific wrappers, scripts or tools in the
`contrib` folder.
Please see our [Installation](https://yggdrasil-network.github.io/installation.html)
page for more information. You may also find other platform-specific wrappers, scripts
or tools in the `contrib` folder.
## Building
If you want to build from source, as opposed to installing one of the pre-built
packages:
1. Install [Go](https://golang.org) (requires Go 1.11 or later)
1. Install [Go](https://golang.org) (requires Go 1.22 or later)
2. Clone this repository
2. Run `./build`
@ -80,6 +56,7 @@ other configuration such as listen addresses or multicast addresses, etc.
### Run Yggdrasil
To run with the generated static configuration:
```
./yggdrasil -useconffile /path/to/yggdrasil.conf
```
@ -97,21 +74,18 @@ by giving the Yggdrasil binary the `CAP_NET_ADMIN` capability.
## Documentation
Documentation is available on our [GitHub
Pages](https://yggdrasil-network.github.io) site, or in the base submodule
repository within `doc/yggdrasil-network.github.io`.
Documentation is available [on our website](https://yggdrasil-network.github.io).
- [Configuration file options](https://yggdrasil-network.github.io/configuration.html)
- [Platform-specific documentation](https://yggdrasil-network.github.io/platforms.html)
- [Installing Yggdrasil](https://yggdrasil-network.github.io/installation.html)
- [Configuring Yggdrasil](https://yggdrasil-network.github.io/configuration.html)
- [Frequently asked questions](https://yggdrasil-network.github.io/faq.html)
- [Admin API documentation](https://yggdrasil-network.github.io/admin.html)
- [Version changelog](CHANGELOG.md)
## Community
Feel free to join us on our [Matrix
channel](https://matrix.to/#/#yggdrasil:matrix.org) at `#yggdrasil:matrix.org`
or in the `#yggdrasil` IRC channel on Freenode.
or in the `#yggdrasil` IRC channel on [libera.chat](https://libera.chat).
## License

44
build
View file

@ -2,47 +2,37 @@
set -ef
PKGSRC=${PKGSRC:-github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil}
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="-X $PKGSRC.buildName=$PKGNAME -X $PKGSRC.buildVersion=$PKGVER"
ARGS="-v"
while getopts "udaitc:l:" option
while getopts "utc:l:dro:p" option
do
case "${option}"
case "$option"
in
u) UPX=true;;
d) DEBUG=true;;
i) IOS=true;;
a) ANDROID=true;;
t) TABLES=true;;
c) GCFLAGS="$GCFLAGS $OPTARG";;
l) LDFLAGS="$LDFLAGS $OPTARG";;
d) ARGS="$ARGS -tags debug" DEBUG=true;;
r) ARGS="$ARGS -race";;
o) ARGS="$ARGS -o $OPTARG";;
p) ARGS="$ARGS -buildmode=pie";;
esac
done
if [ -z $TABLES ]; then
STRIP="-s -w"
if [ -z $TABLES ] && [ -z $DEBUG ]; then
LDFLAGS="$LDFLAGS -s -w"
fi
if [ $IOS ]; then
echo "Building framework for iOS"
gomobile bind -target ios -tags mobile -ldflags="$LDFLAGS $STRIP" -gcflags="$GCFLAGS" github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil
elif [ $ANDROID ]; then
echo "Building aar for Android"
gomobile bind -target android -tags mobile -ldflags="$LDFLAGS $STRIP" -gcflags="$GCFLAGS" github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil
else
for CMD in `ls cmd/` ; do
echo "Building: $CMD"
for CMD in yggdrasil yggdrasilctl ; do
echo "Building: $CMD"
go build $ARGS -ldflags="$LDFLAGS" -gcflags="$GCFLAGS" ./cmd/$CMD
if [ $DEBUG ]; then
go build -ldflags="$LDFLAGS" -gcflags="$GCFLAGS" -tags debug -v ./cmd/$CMD
else
go build -ldflags="$LDFLAGS $STRIP" -gcflags="$GCFLAGS" -v ./cmd/$CMD
fi
if [ $UPX ]; then
upx --brute $CMD
fi
done
fi
if [ $UPX ]; then
upx --brute $CMD
fi
done

93
cmd/genkeys/main.go Normal file
View file

@ -0,0 +1,93 @@
/*
This file generates crypto keys.
It prints out a new set of keys each time if finds a "better" one.
By default, "better" means a higher NodeID (-> higher IP address).
This is because the IP address format can compress leading 1s in the address, to increase the number of ID bits in the address.
If run with the "-sig" flag, it generates signing keys instead.
A "better" signing key means one with a higher TreeID.
This only matters if it's high enough to make you the root of the tree.
*/
package main
import (
"crypto/ed25519"
"encoding/hex"
"fmt"
"net"
"runtime"
"time"
"suah.dev/protect"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
)
type keySet struct {
priv ed25519.PrivateKey
pub ed25519.PublicKey
count uint64
}
func main() {
if err := protect.Pledge("stdio"); err != nil {
panic(err)
}
threads := runtime.GOMAXPROCS(0)
fmt.Println("Threads:", threads)
start := time.Now()
var totalKeys uint64
totalKeys = 0
var currentBest ed25519.PublicKey
newKeys := make(chan keySet, threads)
for i := 0; i < threads; i++ {
go doKeys(newKeys)
}
for {
newKey := <-newKeys
if isBetter(currentBest, newKey.pub) || len(currentBest) == 0 {
totalKeys += newKey.count
currentBest = newKey.pub
fmt.Println("-----", time.Since(start), "---", totalKeys, "keys tried")
fmt.Println("Priv:", hex.EncodeToString(newKey.priv))
fmt.Println("Pub:", hex.EncodeToString(newKey.pub))
addr := address.AddrForKey(newKey.pub)
fmt.Println("IP:", net.IP(addr[:]).String())
}
}
}
func isBetter(oldPub, newPub ed25519.PublicKey) bool {
for idx := range oldPub {
if newPub[idx] < oldPub[idx] {
return true
}
if newPub[idx] > oldPub[idx] {
break
}
}
return false
}
func doKeys(out chan<- keySet) {
bestKey := make(ed25519.PublicKey, ed25519.PublicKeySize)
var count uint64
count = 0
for idx := range bestKey {
bestKey[idx] = 0xff
}
for {
pub, priv, err := ed25519.GenerateKey(nil)
count++
if err != nil {
panic(err)
}
if !isBetter(bestKey, pub) {
continue
}
bestKey = pub
out <- keySet{priv, pub, count}
count = 0
}
}

View file

@ -0,0 +1,10 @@
//go:build !aix && !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !solaris
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris
package main
import "errors"
func chuser(user string) error {
return errors.New("setting uid/gid is not supported on this platform")
}

View file

@ -0,0 +1,63 @@
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
package main
import (
"fmt"
"os/user"
"strconv"
"strings"
"golang.org/x/sys/unix"
)
func chuser(input string) error {
givenUser, givenGroup, _ := strings.Cut(input, ":")
if givenUser == "" {
return fmt.Errorf("user is empty")
}
if strings.Contains(input, ":") && givenGroup == "" {
return fmt.Errorf("group is empty")
}
var (
err error
usr *user.User
grp *user.Group
uid, gid int
)
if usr, err = user.LookupId(givenUser); err != nil {
if usr, err = user.Lookup(givenUser); err != nil {
return err
}
}
if uid, err = strconv.Atoi(usr.Uid); err != nil {
return err
}
if givenGroup != "" {
if grp, err = user.LookupGroupId(givenGroup); err != nil {
if grp, err = user.LookupGroup(givenGroup); err != nil {
return err
}
}
gid, _ = strconv.Atoi(grp.Gid)
} else {
gid, _ = strconv.Atoi(usr.Gid)
}
if err := unix.Setgroups([]int{gid}); err != nil {
return fmt.Errorf("setgroups: %d: %v", gid, err)
}
if err := unix.Setgid(gid); err != nil {
return fmt.Errorf("setgid: %d: %v", gid, err)
}
if err := unix.Setuid(uid); err != nil {
return fmt.Errorf("setuid: %d: %v", uid, err)
}
return nil
}

View file

@ -0,0 +1,80 @@
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
package main
import (
"os/user"
"testing"
)
// Usernames must not contain a number sign.
func TestEmptyString(t *testing.T) {
if chuser("") == nil {
t.Fatal("the empty string is not a valid user")
}
}
// Either omit delimiter and group, or omit both.
func TestEmptyGroup(t *testing.T) {
if chuser("0:") == nil {
t.Fatal("the empty group is not allowed")
}
}
// Either user only or user and group.
func TestGroupOnly(t *testing.T) {
if chuser(":0") == nil {
t.Fatal("group only is not allowed")
}
}
// Usenames must not contain the number sign.
func TestInvalidUsername(t *testing.T) {
const username = "#user"
if chuser(username) == nil {
t.Fatalf("'%s' is not a valid username", username)
}
}
// User IDs must be non-negative.
func TestInvalidUserid(t *testing.T) {
if chuser("-1") == nil {
t.Fatal("User ID cannot be negative")
}
}
// Change to the current user by ID.
func TestCurrentUserid(t *testing.T) {
usr, err := user.Current()
if err != nil {
t.Fatal(err)
}
if usr.Uid != "0" {
t.Skip("setgroups(2): Only the superuser may set new groups.")
}
if err = chuser(usr.Uid); err != nil {
t.Fatal(err)
}
}
// Change to a common user by name.
func TestCommonUsername(t *testing.T) {
usr, err := user.Current()
if err != nil {
t.Fatal(err)
}
if usr.Uid != "0" {
t.Skip("setgroups(2): Only the superuser may set new groups.")
}
if err := chuser("nobody"); err != nil {
if _, ok := err.(user.UnknownUserError); ok {
t.Skip(err)
}
t.Fatal(err)
}
}

View file

@ -1,291 +1,364 @@
package main
import (
"bytes"
"context"
"crypto/ed25519"
"encoding/hex"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"net"
"os"
"os/signal"
"regexp"
"strings"
"syscall"
"golang.org/x/text/encoding/unicode"
"suah.dev/protect"
"github.com/gologme/log"
"github.com/hjson/hjson-go"
gsyslog "github.com/hashicorp/go-syslog"
"github.com/hjson/hjson-go/v4"
"github.com/kardianos/minwinsvc"
"github.com/mitchellh/mapstructure"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
"github.com/yggdrasil-network/yggdrasil-go/src/admin"
"github.com/yggdrasil-network/yggdrasil-go/src/config"
"github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil"
"github.com/yggdrasil-network/yggdrasil-go/src/ipv6rwc"
"github.com/yggdrasil-network/yggdrasil-go/src/core"
"github.com/yggdrasil-network/yggdrasil-go/src/multicast"
"github.com/yggdrasil-network/yggdrasil-go/src/tun"
"github.com/yggdrasil-network/yggdrasil-go/src/version"
)
type nodeConfig = config.NodeConfig
type Core = yggdrasil.Core
type node struct {
core Core
}
func readConfig(useconf *bool, useconffile *string, normaliseconf *bool) *nodeConfig {
// Use a configuration file. If -useconf, the configuration will be read
// from stdin. If -useconffile, the configuration will be read from the
// filesystem.
var conf []byte
var err error
if *useconffile != "" {
// Read the file from the filesystem
conf, err = ioutil.ReadFile(*useconffile)
} else {
// Read the file from stdin.
conf, err = ioutil.ReadAll(os.Stdin)
}
if err != nil {
panic(err)
}
// If there's a byte order mark - which Windows 10 is now incredibly fond of
// throwing everywhere when it's converting things into UTF-16 for the hell
// of it - remove it and decode back down into UTF-8. This is necessary
// because hjson doesn't know what to do with UTF-16 and will panic
if bytes.Compare(conf[0:2], []byte{0xFF, 0xFE}) == 0 ||
bytes.Compare(conf[0:2], []byte{0xFE, 0xFF}) == 0 {
utf := unicode.UTF16(unicode.BigEndian, unicode.UseBOM)
decoder := utf.NewDecoder()
conf, err = decoder.Bytes(conf)
if err != nil {
panic(err)
}
}
// Generate a new configuration - this gives us a set of sane defaults -
// then parse the configuration we loaded above on top of it. The effect
// of this is that any configuration item that is missing from the provided
// configuration will use a sane default.
cfg := config.GenerateConfig()
var dat map[string]interface{}
if err := hjson.Unmarshal(conf, &dat); err != nil {
panic(err)
}
confJson, err := json.Marshal(dat)
if err != nil {
panic(err)
}
json.Unmarshal(confJson, &cfg)
// For now we will do a little bit to help the user adjust their
// configuration to match the new configuration format, as some of the key
// names have changed recently.
changes := map[string]string{
"Multicast": "",
"ReadTimeout": "",
"LinkLocal": "MulticastInterfaces",
"BoxPub": "EncryptionPublicKey",
"BoxPriv": "EncryptionPrivateKey",
"SigPub": "SigningPublicKey",
"SigPriv": "SigningPrivateKey",
"AllowedBoxPubs": "AllowedEncryptionPublicKeys",
}
// Loop over the mappings aove and see if we have anything to fix.
for from, to := range changes {
if _, ok := dat[from]; ok {
if to == "" {
if !*normaliseconf {
log.Println("Warning: Config option", from, "is deprecated")
}
} else {
if !*normaliseconf {
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
// don't overwrite something that was put there intentionally.
if _, ok := dat[to]; !ok {
dat[to] = dat[from]
}
}
}
}
// Check to see if the peers are in a parsable format, if not then default
// them to the TCP scheme
if peers, ok := dat["Peers"].([]interface{}); ok {
for index, peer := range peers {
uri := peer.(string)
if strings.HasPrefix(uri, "tcp://") || strings.HasPrefix(uri, "socks://") {
continue
}
if strings.HasPrefix(uri, "tcp:") {
uri = uri[4:]
}
(dat["Peers"].([]interface{}))[index] = "tcp://" + uri
}
}
// Now do the same with the interface peers
if interfacepeers, ok := dat["InterfacePeers"].(map[string]interface{}); ok {
for intf, peers := range interfacepeers {
for index, peer := range peers.([]interface{}) {
uri := peer.(string)
if strings.HasPrefix(uri, "tcp://") || strings.HasPrefix(uri, "socks://") {
continue
}
if strings.HasPrefix(uri, "tcp:") {
uri = uri[4:]
}
((dat["InterfacePeers"].(map[string]interface{}))[intf]).([]interface{})[index] = "tcp://" + uri
}
}
}
// Do a quick check for old-format Listen statement so that mapstructure
// doesn't fail and crash
if listen, ok := dat["Listen"].(string); ok {
if strings.HasPrefix(listen, "tcp://") {
dat["Listen"] = []string{listen}
} else {
dat["Listen"] = []string{"tcp://" + listen}
}
}
// Overlay our newly mapped configuration onto the autoconf node config that
// we generated above.
if err = mapstructure.Decode(dat, &cfg); err != nil {
panic(err)
}
return cfg
}
// Generates a new configuration and returns it in HJSON format. This is used
// with -genconf.
func doGenconf(isjson bool) string {
cfg := config.GenerateConfig()
var bs []byte
var err error
if isjson {
bs, err = json.MarshalIndent(cfg, "", " ")
} else {
bs, err = hjson.Marshal(cfg)
}
if err != nil {
panic(err)
}
return string(bs)
core *core.Core
tun *tun.TunAdapter
multicast *multicast.Multicast
admin *admin.AdminSocket
}
// The main function is responsible for configuring and starting Yggdrasil.
func main() {
// Configure the command line parameters.
// Not all operations are coverable with pledge(2), so immediately
// limit file system access with unveil(2), effectively preventing
// "proc exec" promises right from the start:
//
// - read arbitrary config file
// - create/write arbitrary log file
// - read/write/chmod/remove admin socket, if at all
if err := protect.Unveil("/", "rwc"); err != nil {
panic(fmt.Sprintf("unveil: / rwc: %v", err))
}
if err := protect.UnveilBlock(); err != nil {
panic(fmt.Sprintf("unveil: %v", err))
}
genconf := flag.Bool("genconf", false, "print a new config to stdout")
useconf := flag.Bool("useconf", false, "read HJSON/JSON config from stdin")
useconffile := flag.String("useconffile", "", "read HJSON/JSON config from specified file path")
normaliseconf := flag.Bool("normaliseconf", false, "use in combination with either -useconf or -useconffile, outputs your configuration normalised")
exportkey := flag.Bool("exportkey", false, "use in combination with either -useconf or -useconffile, outputs your private key in PEM format")
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")
logging := flag.String("logging", "info,warn,error", "comma-separated list of logging levels to enable")
ver := flag.Bool("version", false, "prints the version of this build")
logto := flag.String("logto", "stdout", "file path to log to, \"syslog\" or \"stdout\"")
getaddr := flag.Bool("address", false, "use in combination with either -useconf or -useconffile, outputs your IPv6 address")
getsnet := flag.Bool("subnet", false, "use in combination with either -useconf or -useconffile, outputs your IPv6 subnet")
getpkey := flag.Bool("publickey", false, "use in combination with either -useconf or -useconffile, outputs your public key")
loglevel := flag.String("loglevel", "info", "loglevel to enable")
chuserto := flag.String("user", "", "user (and, optionally, group) to set UID/GID to")
flag.Parse()
var cfg *nodeConfig
done := make(chan struct{})
defer close(done)
// Catch interrupts from the operating system to exit gracefully.
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
// Create a new logger that logs output to stdout.
var logger *log.Logger
switch *logto {
case "stdout":
logger = log.New(os.Stdout, "", log.Flags())
case "syslog":
if syslogger, err := gsyslog.NewLogger(gsyslog.LOG_NOTICE, "DAEMON", version.BuildName()); err == nil {
logger = log.New(syslogger, "", log.Flags()&^(log.Ldate|log.Ltime))
}
default:
if logfd, err := os.OpenFile(*logto, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644); err == nil {
logger = log.New(logfd, "", log.Flags())
}
}
if logger == nil {
logger = log.New(os.Stdout, "", log.Flags())
logger.Warnln("Logging defaulting to stdout")
}
if *normaliseconf {
setLogLevel("error", logger)
} else {
setLogLevel(*loglevel, logger)
}
cfg := config.GenerateConfig()
var err error
switch {
case *version:
fmt.Println("Build name:", yggdrasil.GetBuildName())
fmt.Println("Build version:", yggdrasil.GetBuildVersion())
os.Exit(0)
case *ver:
fmt.Println("Build name:", version.BuildName())
fmt.Println("Build version:", version.BuildVersion())
return
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.
cfg = config.GenerateConfig()
case *useconffile != "" || *useconf:
// Read the configuration from either stdin or from the filesystem
cfg = readConfig(useconf, useconffile, normaliseconf)
// If the -normaliseconf option was specified then remarshal the above
// configuration and print it back to stdout. This lets the user update
// their configuration file with newly mapped names (like above) or to
// convert from plain JSON to commented HJSON.
if *normaliseconf {
var bs []byte
if *confjson {
bs, err = json.MarshalIndent(cfg, "", " ")
} else {
bs, err = hjson.Marshal(cfg)
// port numbers, and will use an automatically selected TUN interface.
case *useconf:
if _, err := cfg.ReadFrom(os.Stdin); err != nil {
panic(err)
}
case *useconffile != "":
f, err := os.Open(*useconffile)
if err != nil {
panic(err)
}
if _, err := cfg.ReadFrom(f); err != nil {
panic(err)
}
_ = f.Close()
case *genconf:
cfg.AdminListen = ""
var bs []byte
if *confjson {
bs, err = json.MarshalIndent(cfg, "", " ")
} else {
bs, err = hjson.Marshal(cfg)
}
if err != nil {
panic(err)
}
fmt.Println(string(bs))
return
default:
fmt.Println("Usage:")
flag.PrintDefaults()
if *getaddr || *getsnet {
fmt.Println("\nError: You need to specify some config data using -useconf or -useconffile.")
}
return
}
privateKey := ed25519.PrivateKey(cfg.PrivateKey)
publicKey := privateKey.Public().(ed25519.PublicKey)
switch {
case *getaddr:
addr := address.AddrForKey(publicKey)
ip := net.IP(addr[:])
fmt.Println(ip.String())
return
case *getsnet:
snet := address.SubnetForKey(publicKey)
ipnet := net.IPNet{
IP: append(snet[:], 0, 0, 0, 0, 0, 0, 0, 0),
Mask: net.CIDRMask(len(snet)*8, 128),
}
fmt.Println(ipnet.String())
return
case *getpkey:
fmt.Println(hex.EncodeToString(publicKey))
return
case *normaliseconf:
cfg.AdminListen = ""
if cfg.PrivateKeyPath != "" {
cfg.PrivateKey = nil
}
var bs []byte
if *confjson {
bs, err = json.MarshalIndent(cfg, "", " ")
} else {
bs, err = hjson.Marshal(cfg)
}
if err != nil {
panic(err)
}
fmt.Println(string(bs))
return
case *exportkey:
pem, err := cfg.MarshalPEMPrivateKey()
if err != nil {
panic(err)
}
fmt.Println(string(pem))
return
}
n := &node{}
// Set up the Yggdrasil node itself.
{
iprange := net.IPNet{
IP: net.ParseIP("200::"),
Mask: net.CIDRMask(7, 128),
}
options := []core.SetupOption{
core.NodeInfo(cfg.NodeInfo),
core.NodeInfoPrivacy(cfg.NodeInfoPrivacy),
core.PeerFilter(func(ip net.IP) bool {
return !iprange.Contains(ip)
}),
}
for _, addr := range cfg.Listen {
options = append(options, core.ListenAddress(addr))
}
for _, peer := range cfg.Peers {
options = append(options, core.Peer{URI: peer})
}
for intf, peers := range cfg.InterfacePeers {
for _, peer := range peers {
options = append(options, core.Peer{URI: peer, SourceInterface: intf})
}
}
for _, allowed := range cfg.AllowedPublicKeys {
k, err := hex.DecodeString(allowed)
if err != nil {
panic(err)
}
fmt.Println(string(bs))
return
options = append(options, core.AllowedPublicKey(k[:]))
}
case *genconf:
// Generate a new configuration and print it to stdout.
fmt.Println(doGenconf(*confjson))
default:
// No flags were provided, therefore print the list of flags to stdout.
flag.PrintDefaults()
if n.core, err = core.New(cfg.Certificate, logger, options...); err != nil {
panic(err)
}
address, subnet := n.core.Address(), n.core.Subnet()
logger.Printf("Your public key is %s", hex.EncodeToString(n.core.PublicKey()))
logger.Printf("Your IPv6 address is %s", address.String())
logger.Printf("Your IPv6 subnet is %s", subnet.String())
}
// Have we got a working configuration? If we don't then it probably means
// that neither -autoconf, -useconf or -useconffile were set above. Stop
// if we don't.
if cfg == nil {
return
}
// Create a new logger that logs output to stdout.
logger := log.New(os.Stdout, "", log.Flags())
//logger.EnableLevel("error")
//logger.EnableLevel("warn")
//logger.EnableLevel("info")
if levels := strings.Split(*logging, ","); len(levels) > 0 {
for _, level := range levels {
l := strings.TrimSpace(level)
switch l {
case "error", "warn", "info", "trace", "debug":
logger.EnableLevel(l)
default:
continue
}
// Set up the admin socket.
{
options := []admin.SetupOption{
admin.ListenAddress(cfg.AdminListen),
}
if cfg.LogLookups {
options = append(options, admin.LogLookups{})
}
if n.admin, err = admin.New(n.core, logger, options...); err != nil {
panic(err)
}
if n.admin != nil {
n.admin.SetupAdminHandlers()
}
}
// Setup the Yggdrasil node itself. The node{} type includes a Core, so we
// don't need to create this manually.
n := node{}
// Now that we have a working configuration, we can now actually start
// Yggdrasil. This will start the router, switch, DHT node, TCP and UDP
// sockets, TUN/TAP adapter and multicast discovery port.
if err := n.core.Start(cfg, logger); err != nil {
logger.Errorln("An error occurred during startup")
panic(err)
}
// The Stop function ensures that the TUN/TAP adapter is correctly shut down
// before the program exits.
defer func() {
n.core.Stop()
}()
// Make some nice output that tells us what our IPv6 address and subnet are.
// This is just logged to stdout for the user.
address := n.core.GetAddress()
subnet := n.core.GetSubnet()
logger.Infof("Your IPv6 address is %s", address.String())
logger.Infof("Your IPv6 subnet is %s", subnet.String())
// Catch interrupts from the operating system to exit gracefully.
c := make(chan os.Signal, 1)
r := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
signal.Notify(r, os.Interrupt, syscall.SIGHUP)
// Create a function to capture the service being stopped on Windows.
winTerminate := func() {
c <- os.Interrupt
}
minwinsvc.SetOnExit(winTerminate)
// Wait for the terminate/interrupt signal. Once a signal is received, the
// deferred Stop function above will run which will shut down TUN/TAP.
for {
select {
case _ = <-r:
if *useconffile != "" {
cfg = readConfig(useconf, useconffile, normaliseconf)
n.core.UpdateConfig(cfg)
} else {
logger.Errorln("Reloading config at runtime is only possible with -useconffile")
}
case _ = <-c:
goto exit
// Set up the multicast module.
{
options := []multicast.SetupOption{}
for _, intf := range cfg.MulticastInterfaces {
options = append(options, multicast.MulticastInterface{
Regex: regexp.MustCompile(intf.Regex),
Beacon: intf.Beacon,
Listen: intf.Listen,
Port: intf.Port,
Priority: uint8(intf.Priority),
Password: intf.Password,
})
}
if n.multicast, err = multicast.New(n.core, logger, options...); err != nil {
panic(err)
}
if n.admin != nil && n.multicast != nil {
n.multicast.SetupAdminHandlers(n.admin)
}
}
// Set up the TUN module.
{
options := []tun.SetupOption{
tun.InterfaceName(cfg.IfName),
tun.InterfaceMTU(cfg.IfMTU),
}
if n.tun, err = tun.New(ipv6rwc.NewReadWriteCloser(n.core), logger, options...); err != nil {
panic(err)
}
if n.admin != nil && n.tun != nil {
n.tun.SetupAdminHandlers(n.admin)
}
}
//Windows service shutdown
minwinsvc.SetOnExit(func() {
logger.Infof("Shutting down service ...")
cancel()
// Wait for all parts to shutdown properly
<-done
})
// Change user if requested
if *chuserto != "" {
err = chuser(*chuserto)
if err != nil {
panic(err)
}
}
// Promise final modes of operation. At this point, if at all:
// - raw socket is created/open
// - admin socket is created/open
// - privileges are dropped to non-root user
//
// Peers, InterfacePeers, Listen can be UNIX sockets;
// Go's net.Listen.Close() deletes files on shutdown.
promises := []string{"stdio", "cpath", "inet", "unix", "dns"}
if len(cfg.MulticastInterfaces) > 0 {
promises = append(promises, "mcast")
}
if err := protect.Pledge(strings.Join(promises, " ")); err != nil {
panic(fmt.Sprintf("pledge: %v: %v", promises, err))
}
// Block until we are told to shut down.
<-ctx.Done()
// Shut down the node.
_ = n.admin.Stop()
_ = n.multicast.Stop()
_ = n.tun.Stop()
n.core.Stop()
}
func setLogLevel(loglevel string, logger *log.Logger) {
levels := [...]string{"error", "warn", "info", "debug", "trace"}
loglevel = strings.ToLower(loglevel)
contains := func() bool {
for _, l := range levels {
if l == loglevel {
return true
}
}
return false
}
if !contains() { // set default log level
logger.Infoln("Loglevel parse failed. Set default level(info)")
loglevel = "info"
}
for _, l := range levels {
logger.EnableLevel(l)
if l == loglevel {
break
}
}
exit:
}

View file

@ -0,0 +1,89 @@
package main
import (
"bytes"
"flag"
"fmt"
"log"
"os"
"github.com/hjson/hjson-go/v4"
"golang.org/x/text/encoding/unicode"
"github.com/yggdrasil-network/yggdrasil-go/src/config"
)
type CmdLineEnv struct {
args []string
endpoint, server string
injson, ver bool
}
func newCmdLineEnv() CmdLineEnv {
var cmdLineEnv CmdLineEnv
cmdLineEnv.endpoint = config.GetDefaults().DefaultAdminListen
return cmdLineEnv
}
func (cmdLineEnv *CmdLineEnv) parseFlagsAndArgs() {
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options] command [key=value] [key=value] ...\n\n", os.Args[0])
fmt.Println("Options:")
flag.PrintDefaults()
fmt.Println()
fmt.Println("Please note that options must always specified BEFORE the command\non the command line or they will be ignored.")
fmt.Println()
fmt.Println("Commands:\n - Use \"list\" for a list of available commands")
fmt.Println()
fmt.Println("Examples:")
fmt.Println(" - ", os.Args[0], "list")
fmt.Println(" - ", os.Args[0], "getPeers")
fmt.Println(" - ", os.Args[0], "-endpoint=tcp://localhost:9001 getPeers")
fmt.Println(" - ", os.Args[0], "-endpoint=unix:///var/run/ygg.sock getPeers")
}
server := flag.String("endpoint", cmdLineEnv.endpoint, "Admin socket endpoint")
injson := flag.Bool("json", false, "Output in JSON format (as opposed to pretty-print)")
ver := flag.Bool("version", false, "Prints the version of this build")
flag.Parse()
cmdLineEnv.args = flag.Args()
cmdLineEnv.server = *server
cmdLineEnv.injson = *injson
cmdLineEnv.ver = *ver
}
func (cmdLineEnv *CmdLineEnv) setEndpoint(logger *log.Logger) {
if cmdLineEnv.server == cmdLineEnv.endpoint {
if cfg, err := os.ReadFile(config.GetDefaults().DefaultConfigFile); err == nil {
if bytes.Equal(cfg[0:2], []byte{0xFF, 0xFE}) ||
bytes.Equal(cfg[0:2], []byte{0xFE, 0xFF}) {
utf := unicode.UTF16(unicode.BigEndian, unicode.UseBOM)
decoder := utf.NewDecoder()
cfg, err = decoder.Bytes(cfg)
if err != nil {
panic(err)
}
}
var dat map[string]interface{}
if err := hjson.Unmarshal(cfg, &dat); err != nil {
panic(err)
}
if ep, ok := dat["AdminListen"].(string); ok && (ep != "none" && ep != "") {
cmdLineEnv.endpoint = ep
logger.Println("Found platform default config file", config.GetDefaults().DefaultConfigFile)
logger.Println("Using endpoint", cmdLineEnv.endpoint, "from AdminListen")
} else {
logger.Println("Configuration file doesn't contain appropriate AdminListen option")
logger.Println("Falling back to platform default", config.GetDefaults().DefaultAdminListen)
}
} else {
logger.Println("Can't open config file from default location", config.GetDefaults().DefaultConfigFile)
logger.Println("Falling back to platform default", config.GetDefaults().DefaultAdminListen)
}
} else {
cmdLineEnv.endpoint = cmdLineEnv.server
logger.Println("Using endpoint", cmdLineEnv.endpoint, "from command line")
}
}

View file

@ -6,100 +6,70 @@ import (
"errors"
"flag"
"fmt"
"io/ioutil"
"log"
"net"
"net/url"
"os"
"sort"
"strconv"
"strings"
"time"
"golang.org/x/text/encoding/unicode"
"suah.dev/protect"
"github.com/hjson/hjson-go"
"github.com/yggdrasil-network/yggdrasil-go/src/defaults"
"github.com/olekukonko/tablewriter"
"github.com/yggdrasil-network/yggdrasil-go/src/admin"
"github.com/yggdrasil-network/yggdrasil-go/src/core"
"github.com/yggdrasil-network/yggdrasil-go/src/multicast"
"github.com/yggdrasil-network/yggdrasil-go/src/tun"
"github.com/yggdrasil-network/yggdrasil-go/src/version"
)
type admin_info map[string]interface{}
func main() {
// read config, speak DNS/TCP and/or over a UNIX socket
if err := protect.Pledge("stdio rpath inet unix dns"); err != nil {
panic(err)
}
// makes sure we can use defer and still return an error code to the OS
os.Exit(run())
}
func run() int {
logbuffer := &bytes.Buffer{}
logger := log.New(logbuffer, "", log.Flags())
defer func() {
defer func() int {
if r := recover(); r != nil {
logger.Println("Fatal error:", r)
fmt.Print(logbuffer)
os.Exit(1)
return 1
}
return 0
}()
endpoint := defaults.GetDefaults().DefaultAdminListen
cmdLineEnv := newCmdLineEnv()
cmdLineEnv.parseFlagsAndArgs()
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options] command [key=value] [key=value] ...\n\n", os.Args[0])
fmt.Println("Options:")
flag.PrintDefaults()
fmt.Println("\nPlease note that options must always specified BEFORE the command\non the command line or they will be ignored.\n")
fmt.Println("Commands:\n - Use \"list\" for a list of available commands\n")
fmt.Println("Examples:")
fmt.Println(" - ", os.Args[0], "list")
fmt.Println(" - ", os.Args[0], "getPeers")
fmt.Println(" - ", os.Args[0], "-v getSelf")
fmt.Println(" - ", os.Args[0], "setTunTap name=auto mtu=1500 tap_mode=false")
fmt.Println(" - ", os.Args[0], "-endpoint=tcp://localhost:9001 getDHT")
fmt.Println(" - ", os.Args[0], "-endpoint=unix:///var/run/ygg.sock getDHT")
if cmdLineEnv.ver {
fmt.Println("Build name:", version.BuildName())
fmt.Println("Build version:", version.BuildVersion())
fmt.Println("To get the version number of the running Yggdrasil node, run", os.Args[0], "getSelf")
return 0
}
server := flag.String("endpoint", endpoint, "Admin socket endpoint")
injson := flag.Bool("json", false, "Output in JSON format (as opposed to pretty-print)")
verbose := flag.Bool("v", false, "Verbose output (includes public keys)")
flag.Parse()
args := flag.Args()
if len(args) == 0 {
if len(cmdLineEnv.args) == 0 {
flag.Usage()
return
return 0
}
if *server == endpoint {
if config, err := ioutil.ReadFile(defaults.GetDefaults().DefaultConfigFile); err == nil {
if bytes.Compare(config[0:2], []byte{0xFF, 0xFE}) == 0 ||
bytes.Compare(config[0:2], []byte{0xFE, 0xFF}) == 0 {
utf := unicode.UTF16(unicode.BigEndian, unicode.UseBOM)
decoder := utf.NewDecoder()
config, err = decoder.Bytes(config)
if err != nil {
panic(err)
}
}
var dat map[string]interface{}
if err := hjson.Unmarshal(config, &dat); err != nil {
panic(err)
}
if ep, ok := dat["AdminListen"].(string); ok && (ep != "none" && ep != "") {
endpoint = ep
logger.Println("Found platform default config file", defaults.GetDefaults().DefaultConfigFile)
logger.Println("Using endpoint", endpoint, "from AdminListen")
} else {
logger.Println("Configuration file doesn't contain appropriate AdminListen option")
logger.Println("Falling back to platform default", defaults.GetDefaults().DefaultAdminListen)
}
} else {
logger.Println("Can't open config file from default location", defaults.GetDefaults().DefaultConfigFile)
logger.Println("Falling back to platform default", defaults.GetDefaults().DefaultAdminListen)
}
} else {
endpoint = *server
logger.Println("Using endpoint", endpoint, "from command line")
}
cmdLineEnv.setEndpoint(logger)
var conn net.Conn
u, err := url.Parse(endpoint)
u, err := url.Parse(cmdLineEnv.endpoint)
if err == nil {
switch strings.ToLower(u.Scheme) {
case "unix":
logger.Println("Connecting to UNIX socket", endpoint[7:])
conn, err = net.Dial("unix", endpoint[7:])
logger.Println("Connecting to UNIX socket", cmdLineEnv.endpoint[7:])
conn, err = net.Dial("unix", cmdLineEnv.endpoint[7:])
case "tcp":
logger.Println("Connecting to TCP socket", u.Host)
conn, err = net.Dial("tcp", u.Host)
@ -109,320 +79,255 @@ func main() {
}
} else {
logger.Println("Connecting to TCP socket", u.Host)
conn, err = net.Dial("tcp", endpoint)
conn, err = net.Dial("tcp", cmdLineEnv.endpoint)
}
if err != nil {
panic(err)
}
// config and socket are done, work without unprivileges
if err := protect.Pledge("stdio"); err != nil {
panic(err)
}
logger.Println("Connected")
defer conn.Close()
decoder := json.NewDecoder(conn)
encoder := json.NewEncoder(conn)
send := make(admin_info)
recv := make(admin_info)
for c, a := range args {
send := &admin.AdminSocketRequest{}
recv := &admin.AdminSocketResponse{}
args := map[string]string{}
for c, a := range cmdLineEnv.args {
if c == 0 {
if strings.HasPrefix(a, "-") {
logger.Printf("Ignoring flag %s as it should be specified before other parameters\n", a)
continue
}
logger.Printf("Sending request: %v\n", a)
send["request"] = a
send.Name = a
continue
}
tokens := strings.Split(a, "=")
if len(tokens) == 1 {
send[tokens[0]] = true
} else if len(tokens) > 2 {
send[tokens[0]] = strings.Join(tokens[1:], "=")
} else if len(tokens) == 2 {
if i, err := strconv.Atoi(tokens[1]); err == nil {
logger.Printf("Sending parameter %s: %d\n", tokens[0], i)
send[tokens[0]] = i
} else {
switch strings.ToLower(tokens[1]) {
case "true":
send[tokens[0]] = true
case "false":
send[tokens[0]] = false
default:
send[tokens[0]] = tokens[1]
}
logger.Printf("Sending parameter %s: %v\n", tokens[0], send[tokens[0]])
}
tokens := strings.SplitN(a, "=", 2)
switch {
case len(tokens) == 1:
logger.Println("Ignoring invalid argument:", a)
default:
args[tokens[0]] = tokens[1]
}
}
if send.Arguments, err = json.Marshal(args); err != nil {
panic(err)
}
if err := encoder.Encode(&send); err != nil {
panic(err)
}
logger.Printf("Request sent")
if err := decoder.Decode(&recv); err == nil {
logger.Printf("Response received")
if recv["status"] == "error" {
if err, ok := recv["error"]; ok {
fmt.Println("Admin socket returned an error:", err)
} else {
fmt.Println("Admin socket returned an error but didn't specify any error text")
}
os.Exit(1)
if err := decoder.Decode(&recv); err != nil {
panic(err)
}
if recv.Status == "error" {
if err := recv.Error; err != "" {
fmt.Println("Admin socket returned an error:", err)
} else {
fmt.Println("Admin socket returned an error but didn't specify any error text")
}
if _, ok := recv["request"]; !ok {
fmt.Println("Missing request in response (malformed response?)")
os.Exit(1)
return 1
}
if cmdLineEnv.injson {
if json, err := json.MarshalIndent(recv.Response, "", " "); err == nil {
fmt.Println(string(json))
}
if _, ok := recv["response"]; !ok {
fmt.Println("Missing response body (malformed response?)")
os.Exit(1)
}
req := recv["request"].(map[string]interface{})
res := recv["response"].(map[string]interface{})
if *injson {
if json, err := json.MarshalIndent(res, "", " "); err == nil {
fmt.Println(string(json))
}
os.Exit(0)
}
switch strings.ToLower(req["request"].(string)) {
case "dot":
fmt.Println(res["dot"])
case "list", "getpeers", "getswitchpeers", "getdht", "getsessions", "dhtping":
maxWidths := make(map[string]int)
var keyOrder []string
keysOrdered := false
for _, tlv := range res {
for slk, slv := range tlv.(map[string]interface{}) {
if !keysOrdered {
for k := range slv.(map[string]interface{}) {
if !*verbose {
if k == "box_pub_key" || k == "box_sig_key" || k == "nodeinfo" {
continue
}
}
keyOrder = append(keyOrder, fmt.Sprint(k))
}
sort.Strings(keyOrder)
keysOrdered = true
}
for k, v := range slv.(map[string]interface{}) {
if len(fmt.Sprint(slk)) > maxWidths["key"] {
maxWidths["key"] = len(fmt.Sprint(slk))
}
if len(fmt.Sprint(v)) > maxWidths[k] {
maxWidths[k] = len(fmt.Sprint(v))
if maxWidths[k] < len(k) {
maxWidths[k] = len(k)
}
}
}
}
if len(keyOrder) > 0 {
fmt.Printf("%-"+fmt.Sprint(maxWidths["key"])+"s ", "")
for _, v := range keyOrder {
fmt.Printf("%-"+fmt.Sprint(maxWidths[v])+"s ", v)
}
fmt.Println()
}
for slk, slv := range tlv.(map[string]interface{}) {
fmt.Printf("%-"+fmt.Sprint(maxWidths["key"])+"s ", slk)
for _, k := range keyOrder {
preformatted := slv.(map[string]interface{})[k]
var formatted string
switch k {
case "bytes_sent", "bytes_recvd":
formatted = fmt.Sprintf("%d", uint(preformatted.(float64)))
case "uptime", "last_seen":
seconds := uint(preformatted.(float64)) % 60
minutes := uint(preformatted.(float64)/60) % 60
hours := uint(preformatted.(float64) / 60 / 60)
formatted = fmt.Sprintf("%02d:%02d:%02d", hours, minutes, seconds)
default:
formatted = fmt.Sprint(preformatted)
}
fmt.Printf("%-"+fmt.Sprint(maxWidths[k])+"s ", formatted)
}
fmt.Println()
}
}
case "gettuntap", "settuntap":
for k, v := range res {
fmt.Println("Interface name:", k)
if mtu, ok := v.(map[string]interface{})["mtu"].(float64); ok {
fmt.Println("Interface MTU:", mtu)
}
if tap_mode, ok := v.(map[string]interface{})["tap_mode"].(bool); ok {
fmt.Println("TAP mode:", tap_mode)
}
}
case "getself":
for k, v := range res["self"].(map[string]interface{}) {
if buildname, ok := v.(map[string]interface{})["build_name"].(string); ok && buildname != "unknown" {
fmt.Println("Build name:", buildname)
}
if buildversion, ok := v.(map[string]interface{})["build_version"].(string); ok && buildversion != "unknown" {
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)
}
if coords, ok := v.(map[string]interface{})["coords"].(string); ok {
fmt.Println("Coords:", coords)
}
if *verbose {
if boxPubKey, ok := v.(map[string]interface{})["box_pub_key"].(string); ok {
fmt.Println("Public encryption key:", boxPubKey)
}
if boxSigKey, ok := v.(map[string]interface{})["box_sig_key"].(string); ok {
fmt.Println("Public signing key:", boxSigKey)
}
}
}
case "getswitchqueues":
maximumqueuesize := float64(4194304)
portqueues := make(map[float64]float64)
portqueuesize := make(map[float64]float64)
portqueuepackets := make(map[float64]float64)
v := res["switchqueues"].(map[string]interface{})
if queuecount, ok := v["queues_count"].(float64); ok {
fmt.Printf("Active queue count: %d queues\n", uint(queuecount))
}
if queuesize, ok := v["queues_size"].(float64); ok {
fmt.Printf("Active queue size: %d bytes\n", uint(queuesize))
}
if highestqueuecount, ok := v["highest_queues_count"].(float64); ok {
fmt.Printf("Highest queue count: %d queues\n", uint(highestqueuecount))
}
if highestqueuesize, ok := v["highest_queues_size"].(float64); ok {
fmt.Printf("Highest queue size: %d bytes\n", uint(highestqueuesize))
}
if m, ok := v["maximum_queues_size"].(float64); ok {
maximumqueuesize = m
fmt.Printf("Maximum queue size: %d bytes\n", uint(maximumqueuesize))
}
if queues, ok := v["queues"].([]interface{}); ok {
if len(queues) != 0 {
fmt.Println("Active queues:")
for _, v := range queues {
queueport := v.(map[string]interface{})["queue_port"].(float64)
queuesize := v.(map[string]interface{})["queue_size"].(float64)
queuepackets := v.(map[string]interface{})["queue_packets"].(float64)
queueid := v.(map[string]interface{})["queue_id"].(string)
portqueues[queueport]++
portqueuesize[queueport] += queuesize
portqueuepackets[queueport] += queuepackets
queuesizepercent := (100 / maximumqueuesize) * queuesize
fmt.Printf("- Switch port %d, Stream ID: %v, size: %d bytes (%d%% full), %d packets\n",
uint(queueport), []byte(queueid), uint(queuesize),
uint(queuesizepercent), uint(queuepackets))
}
}
}
if len(portqueuesize) > 0 && len(portqueuepackets) > 0 {
fmt.Println("Aggregated statistics by switchport:")
for k, v := range portqueuesize {
queuesizepercent := (100 / (portqueues[k] * maximumqueuesize)) * v
fmt.Printf("- Switch port %d, size: %d bytes (%d%% full), %d packets\n",
uint(k), uint(v), uint(queuesizepercent), uint(portqueuepackets[k]))
}
}
case "addpeer", "removepeer", "addallowedencryptionpublickey", "removeallowedencryptionpublickey", "addsourcesubnet", "addroute", "removesourcesubnet", "removeroute":
if _, ok := res["added"]; ok {
for _, v := range res["added"].([]interface{}) {
fmt.Println("Added:", fmt.Sprint(v))
}
}
if _, ok := res["not_added"]; ok {
for _, v := range res["not_added"].([]interface{}) {
fmt.Println("Not added:", fmt.Sprint(v))
}
}
if _, ok := res["removed"]; ok {
for _, v := range res["removed"].([]interface{}) {
fmt.Println("Removed:", fmt.Sprint(v))
}
}
if _, ok := res["not_removed"]; ok {
for _, v := range res["not_removed"].([]interface{}) {
fmt.Println("Not removed:", fmt.Sprint(v))
}
}
case "getallowedencryptionpublickeys":
if _, ok := res["allowed_box_pubs"]; !ok {
fmt.Println("All connections are allowed")
} else if res["allowed_box_pubs"] == nil {
fmt.Println("All connections are allowed")
} else {
fmt.Println("Connections are allowed only from the following public box keys:")
for _, v := range res["allowed_box_pubs"].([]interface{}) {
fmt.Println("-", v)
}
}
case "getmulticastinterfaces":
if _, ok := res["multicast_interfaces"]; !ok {
fmt.Println("No multicast interfaces found")
} else if res["multicast_interfaces"] == nil {
fmt.Println("No multicast interfaces found")
} else {
fmt.Println("Multicast peer discovery is active on:")
for _, v := range res["multicast_interfaces"].([]interface{}) {
fmt.Println("-", v)
}
}
case "getsourcesubnets":
if _, ok := res["source_subnets"]; !ok {
fmt.Println("No source subnets found")
} else if res["source_subnets"] == nil {
fmt.Println("No source subnets found")
} else {
fmt.Println("Source subnets:")
for _, v := range res["source_subnets"].([]interface{}) {
fmt.Println("-", v)
}
}
case "getroutes":
if routes, ok := res["routes"].(map[string]interface{}); !ok {
fmt.Println("No routes found")
} else {
if res["routes"] == nil || len(routes) == 0 {
fmt.Println("No routes found")
} else {
fmt.Println("Routes:")
for k, v := range routes {
if pv, ok := v.(string); ok {
fmt.Println("-", k, " via ", pv)
}
}
}
}
case "settunnelrouting":
fallthrough
case "gettunnelrouting":
if enabled, ok := res["enabled"].(bool); !ok {
fmt.Println("Tunnel routing is disabled")
} else if !enabled {
fmt.Println("Tunnel routing is disabled")
} else {
fmt.Println("Tunnel routing is enabled")
}
default:
if json, err := json.MarshalIndent(recv["response"], "", " "); err == nil {
fmt.Println(string(json))
}
}
} else {
logger.Println("Error receiving response:", err)
return 0
}
if v, ok := recv["status"]; ok && v != "success" {
os.Exit(1)
table := tablewriter.NewWriter(os.Stdout)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetAutoFormatHeaders(false)
table.SetCenterSeparator("")
table.SetColumnSeparator("")
table.SetRowSeparator("")
table.SetHeaderLine(false)
table.SetBorder(false)
table.SetTablePadding("\t") // pad with tabs
table.SetNoWhiteSpace(true)
table.SetAutoWrapText(false)
switch strings.ToLower(send.Name) {
case "list":
var resp admin.ListResponse
if err := json.Unmarshal(recv.Response, &resp); err != nil {
panic(err)
}
table.SetHeader([]string{"Command", "Arguments", "Description"})
for _, entry := range resp.List {
for i := range entry.Fields {
entry.Fields[i] = entry.Fields[i] + "=..."
}
table.Append([]string{entry.Command, strings.Join(entry.Fields, ", "), entry.Description})
}
table.Render()
case "getself":
var resp admin.GetSelfResponse
if err := json.Unmarshal(recv.Response, &resp); err != nil {
panic(err)
}
table.Append([]string{"Build name:", resp.BuildName})
table.Append([]string{"Build version:", resp.BuildVersion})
table.Append([]string{"IPv6 address:", resp.IPAddress})
table.Append([]string{"IPv6 subnet:", resp.Subnet})
table.Append([]string{"Routing table size:", fmt.Sprintf("%d", resp.RoutingEntries)})
table.Append([]string{"Public key:", resp.PublicKey})
table.Render()
case "getpeers":
var resp admin.GetPeersResponse
if err := json.Unmarshal(recv.Response, &resp); err != nil {
panic(err)
}
table.SetHeader([]string{"URI", "State", "Dir", "IP Address", "Uptime", "RTT", "RX", "TX", "Down", "Up", "Pr", "Cost", "Last Error"})
for _, peer := range resp.Peers {
state, lasterr, dir, rtt, rxr, txr := "Up", "-", "Out", "-", "-", "-"
if !peer.Up {
state, lasterr = "Down", fmt.Sprintf("%s ago: %s", peer.LastErrorTime.Round(time.Second), peer.LastError)
} else if rttms := float64(peer.Latency.Microseconds()) / 1000; rttms > 0 {
rtt = fmt.Sprintf("%.02fms", rttms)
}
if peer.Inbound {
dir = "In"
}
uristring := peer.URI
if uri, err := url.Parse(peer.URI); err == nil {
uri.RawQuery = ""
uristring = uri.String()
}
if peer.RXRate > 0 {
rxr = peer.RXRate.String() + "/s"
}
if peer.TXRate > 0 {
txr = peer.TXRate.String() + "/s"
}
table.Append([]string{
uristring,
state,
dir,
peer.IPAddress,
(time.Duration(peer.Uptime) * time.Second).String(),
rtt,
peer.RXBytes.String(),
peer.TXBytes.String(),
rxr,
txr,
fmt.Sprintf("%d", peer.Priority),
fmt.Sprintf("%d", peer.Cost),
lasterr,
})
}
table.Render()
case "gettree":
var resp admin.GetTreeResponse
if err := json.Unmarshal(recv.Response, &resp); err != nil {
panic(err)
}
//table.SetHeader([]string{"Public Key", "IP Address", "Port", "Rest"})
table.SetHeader([]string{"Public Key", "IP Address", "Parent", "Sequence"})
for _, tree := range resp.Tree {
table.Append([]string{
tree.PublicKey,
tree.IPAddress,
tree.Parent,
fmt.Sprintf("%d", tree.Sequence),
//fmt.Sprintf("%d", dht.Port),
//fmt.Sprintf("%d", dht.Rest),
})
}
table.Render()
case "getpaths":
var resp admin.GetPathsResponse
if err := json.Unmarshal(recv.Response, &resp); err != nil {
panic(err)
}
table.SetHeader([]string{"Public Key", "IP Address", "Path", "Seq"})
for _, p := range resp.Paths {
table.Append([]string{
p.PublicKey,
p.IPAddress,
fmt.Sprintf("%v", p.Path),
fmt.Sprintf("%d", p.Sequence),
})
}
table.Render()
case "getsessions":
var resp admin.GetSessionsResponse
if err := json.Unmarshal(recv.Response, &resp); err != nil {
panic(err)
}
table.SetHeader([]string{"Public Key", "IP Address", "Uptime", "RX", "TX"})
for _, p := range resp.Sessions {
table.Append([]string{
p.PublicKey,
p.IPAddress,
(time.Duration(p.Uptime) * time.Second).String(),
p.RXBytes.String(),
p.TXBytes.String(),
})
}
table.Render()
case "getnodeinfo":
var resp core.GetNodeInfoResponse
if err := json.Unmarshal(recv.Response, &resp); err != nil {
panic(err)
}
for _, v := range resp {
fmt.Println(string(v))
break
}
case "getmulticastinterfaces":
var resp multicast.GetMulticastInterfacesResponse
if err := json.Unmarshal(recv.Response, &resp); err != nil {
panic(err)
}
fmtBool := func(b bool) string {
if b {
return "Yes"
}
return "-"
}
table.SetHeader([]string{"Name", "Listen Address", "Beacon", "Listen", "Password"})
for _, p := range resp.Interfaces {
table.Append([]string{
p.Name,
p.Address,
fmtBool(p.Beacon),
fmtBool(p.Listen),
fmtBool(p.Password),
})
}
table.Render()
case "gettun":
var resp tun.GetTUNResponse
if err := json.Unmarshal(recv.Response, &resp); err != nil {
panic(err)
}
table.Append([]string{"TUN enabled:", fmt.Sprintf("%#v", resp.Enabled)})
if resp.Enabled {
table.Append([]string{"Interface name:", resp.Name})
table.Append([]string{"Interface MTU:", fmt.Sprintf("%d", resp.MTU)})
}
table.Render()
case "addpeer", "removepeer":
default:
fmt.Println(string(recv.Response))
}
os.Exit(0)
return 0
}

BIN
contrib/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -1,19 +1,18 @@
/*
This file generates crypto keys for [ansible-yggdrasil](https://github.com/jcgruenhage/ansible-yggdrasil/)
*/
package main
import (
"crypto/ed25519"
"encoding/hex"
"flag"
"fmt"
"net"
"os"
"github.com/cheggaaa/pb/v3"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
)
var numHosts = flag.Int("hosts", 1, "number of host vars to generate")
@ -22,36 +21,29 @@ var keyTries = flag.Int("tries", 1000, "number of tries before taking the best k
type keySet struct {
priv []byte
pub []byte
id []byte
ip string
}
func main() {
flag.Parse()
bar := pb.StartNew(*keyTries*2 + *numHosts)
if *numHosts > *keyTries {
println("Can't generate less keys than hosts.")
return
}
var encryptionKeys []keySet
var keys []keySet
for i := 0; i < *numHosts+1; i++ {
encryptionKeys = append(encryptionKeys, newBoxKey())
keys = append(keys, newKey())
bar.Increment()
}
encryptionKeys = sortKeySetArray(encryptionKeys)
keys = sortKeySetArray(keys)
for i := 0; i < *keyTries-*numHosts-1; i++ {
encryptionKeys[0] = newBoxKey()
encryptionKeys = bubbleUpTo(encryptionKeys, 0)
}
var signatureKeys []keySet
for i := 0; i < *numHosts+1; i++ {
signatureKeys = append(signatureKeys, newSigKey())
}
signatureKeys = sortKeySetArray(signatureKeys)
for i := 0; i < *keyTries-*numHosts-1; i++ {
signatureKeys[0] = newSigKey()
signatureKeys = bubbleUpTo(signatureKeys, 0)
keys[0] = newKey()
keys = bubbleUpTo(keys, 0)
bar.Increment()
}
os.MkdirAll("host_vars", 0755)
@ -63,41 +55,36 @@ func main() {
return
}
defer file.Close()
file.WriteString(fmt.Sprintf("yggdrasil_encryption_public_key: %v\n", hex.EncodeToString(encryptionKeys[i].pub)))
file.WriteString("yggdrasil_encryption_private_key: \"{{ vault_yggdrasil_encryption_private_key }}\"\n")
file.WriteString(fmt.Sprintf("yggdrasil_signing_public_key: %v\n", hex.EncodeToString(signatureKeys[i].pub)))
file.WriteString("yggdrasil_signing_private_key: \"{{ vault_yggdrasil_signing_private_key }}\"\n")
file.WriteString(fmt.Sprintf("ansible_host: %v\n", encryptionKeys[i].ip))
file.WriteString(fmt.Sprintf("yggdrasil_public_key: %v\n", hex.EncodeToString(keys[i].pub)))
file.WriteString("yggdrasil_private_key: \"{{ vault_yggdrasil_private_key }}\"\n")
file.WriteString(fmt.Sprintf("ansible_host: %v\n", keys[i].ip))
file, err = os.Create(fmt.Sprintf("host_vars/%x/vault", i))
if err != nil {
return
}
defer file.Close()
file.WriteString(fmt.Sprintf("vault_yggdrasil_encryption_private_key: %v\n", hex.EncodeToString(encryptionKeys[i].priv)))
file.WriteString(fmt.Sprintf("vault_yggdrasil_signing_private_key: %v\n", hex.EncodeToString(signatureKeys[i].priv)))
file.WriteString(fmt.Sprintf("vault_yggdrasil_private_key: %v\n", hex.EncodeToString(keys[i].priv)))
bar.Increment()
}
bar.Finish()
}
func newBoxKey() keySet {
pub, priv := crypto.NewBoxKeys()
id := crypto.GetNodeID(pub)
ip := net.IP(address.AddrForNodeID(id)[:]).String()
return keySet{priv[:], pub[:], id[:], ip}
}
func newSigKey() keySet {
pub, priv := crypto.NewSigKeys()
id := crypto.GetTreeID(pub)
return keySet{priv[:], pub[:], id[:], ""}
func newKey() keySet {
pub, priv, err := ed25519.GenerateKey(nil)
if err != nil {
panic(err)
}
ip := net.IP(address.AddrForKey(pub)[:]).String()
return keySet{priv[:], pub[:], ip}
}
func isBetter(oldID, newID []byte) bool {
for idx := range oldID {
if newID[idx] > oldID[idx] {
if newID[idx] < oldID[idx] {
return true
}
if newID[idx] < oldID[idx] {
if newID[idx] > oldID[idx] {
return false
}
}
@ -113,7 +100,7 @@ func sortKeySetArray(sets []keySet) []keySet {
func bubbleUpTo(sets []keySet, num int) []keySet {
for i := 0; i < len(sets)-num-1; i++ {
if isBetter(sets[i+1].id, sets[i].id) {
if isBetter(sets[i+1].pub, sets[i].pub) {
var tmp = sets[i]
sets[i] = sets[i+1]
sets[i+1] = tmp

View file

@ -1,23 +1,17 @@
# Last Modified: Sat Mar 9 06:08:02 2019
# Last Modified: Fri Oct 30 11:33:31 2020
#include <tunables/global>
/usr/bin/yggdrasil {
#include <abstractions/base>
#include <abstractions/nameservice>
capability net_admin,
capability net_raw,
network inet stream,
network inet dgram,
network inet6 dgram,
network inet6 stream,
network netlink raw,
/lib/@{multiarch}/ld-*.so mr,
/proc/sys/net/core/somaxconn r,
/dev/net/tun rw,
/proc/sys/net/core/somaxconn r,
/sys/kernel/mm/transparent_hugepage/hpage_pmd_size r,
/usr/bin/yggdrasil mr,
/etc/yggdrasil.conf rw,
/run/yggdrasil.sock rw,
}

View file

@ -0,0 +1,11 @@
# Last Modified: Mon Feb 3 22:19:45 2025
include <tunables/global>
/usr/bin/yggdrasilctl {
include <abstractions/base>
/etc/yggdrasil.conf rw,
/run/yggdrasil.sock rw,
owner /sys/kernel/mm/transparent_hugepage/hpage_pmd_size r,
}

View file

@ -1,97 +0,0 @@
package main
/*
This is a small utility that is designed to accompany the vyatta-yggdrasil
package. It takes a HJSON configuration file, makes changes to it based on
the command line arguments, and then spits out an updated file.
*/
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"strconv"
"github.com/hjson/hjson-go"
"golang.org/x/text/encoding/unicode"
"github.com/yggdrasil-network/yggdrasil-go/src/config"
)
type nodeConfig = config.NodeConfig
func main() {
useconffile := flag.String("useconffile", "/etc/yggdrasil.conf", "update config at specified file path")
flag.Parse()
cfg := nodeConfig{}
var config []byte
var err error
config, err = ioutil.ReadFile(*useconffile)
if err != nil {
panic(err)
}
if bytes.Compare(config[0:2], []byte{0xFF, 0xFE}) == 0 ||
bytes.Compare(config[0:2], []byte{0xFE, 0xFF}) == 0 {
utf := unicode.UTF16(unicode.BigEndian, unicode.UseBOM)
decoder := utf.NewDecoder()
config, err = decoder.Bytes(config)
if err != nil {
panic(err)
}
}
var dat map[string]interface{}
if err := hjson.Unmarshal(config, &dat); err != nil {
panic(err)
}
confJson, err := json.Marshal(dat)
if err != nil {
panic(err)
}
json.Unmarshal(confJson, &cfg)
switch flag.Arg(0) {
case "setMTU":
cfg.IfMTU, err = strconv.Atoi(flag.Arg(1))
if err != nil {
cfg.IfMTU = 1280
}
if mtu, _ := strconv.Atoi(flag.Arg(1)); mtu < 1280 {
cfg.IfMTU = 1280
}
case "setIfName":
cfg.IfName = flag.Arg(1)
case "setListen":
cfg.Listen = flag.Arg(1)
case "setAdminListen":
cfg.AdminListen = flag.Arg(1)
case "setIfTapMode":
if flag.Arg(1) == "true" {
cfg.IfTAPMode = true
} else {
cfg.IfTAPMode = false
}
case "addPeer":
found := false
for _, v := range cfg.Peers {
if v == flag.Arg(1) {
found = true
}
}
if !found {
cfg.Peers = append(cfg.Peers, flag.Arg(1))
}
case "removePeer":
for k, v := range cfg.Peers {
if v == flag.Arg(1) {
cfg.Peers = append(cfg.Peers[:k], cfg.Peers[k+1:]...)
}
}
}
bs, err := hjson.Marshal(cfg)
if err != nil {
panic(err)
}
fmt.Println(string(bs))
return
}

View file

@ -21,14 +21,18 @@ if [ $PKGBRANCH = "master" ]; then
PKGREPLACES=yggdrasil-develop
fi
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
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"
echo "Specify PKGARCH=amd64,i386,mips,mipsel,armhf,arm64,armel"
exit 1
fi
@ -37,7 +41,7 @@ echo "Building $PKGFILE"
mkdir -p /tmp/$PKGNAME/
mkdir -p /tmp/$PKGNAME/debian/
mkdir -p /tmp/$PKGNAME/usr/bin/
mkdir -p /tmp/$PKGNAME/etc/systemd/system/
mkdir -p /tmp/$PKGNAME/lib/systemd/system/
cat > /tmp/$PKGNAME/debian/changelog << EOF
Please see https://github.com/yggdrasil-network/yggdrasil-go/
@ -46,11 +50,12 @@ echo 9 > /tmp/$PKGNAME/debian/compat
cat > /tmp/$PKGNAME/debian/control << EOF
Package: $PKGNAME
Version: $PKGVERSION
Section: contrib/net
Priority: extra
Section: golang
Priority: optional
Architecture: $PKGARCH
Replaces: $PKGREPLACES
Conflicts: $PKGREPLACES
Depends: systemd
Maintainer: Neil Alexander <neilalexander@users.noreply.github.com>
Description: Yggdrasil Network
Yggdrasil is an early-stage implementation of a fully end-to-end encrypted IPv6
@ -67,35 +72,52 @@ EOF
cat > /tmp/$PKGNAME/debian/install << EOF
usr/bin/yggdrasil usr/bin
usr/bin/yggdrasilctl usr/bin
etc/systemd/system/*.service etc/systemd/system
lib/systemd/system/*.service lib/systemd/system
EOF
cat > /tmp/$PKGNAME/debian/postinst << EOF
#!/bin/sh
systemctl daemon-reload
if ! getent group yggdrasil 2>&1 > /dev/null; then
groupadd --system --force yggdrasil || echo "Failed to create group 'yggdrasil' - please create it manually and reinstall"
groupadd --system --force yggdrasil
fi
if [ -f /etc/yggdrasil.conf ];
if [ ! -d /etc/yggdrasil ];
then
mkdir -p /etc/yggdrasil
chown root:yggdrasil /etc/yggdrasil
chmod 750 /etc/yggdrasil
fi
if [ ! -f /etc/yggdrasil/yggdrasil.conf ];
then
test -f /etc/yggdrasil.conf && mv /etc/yggdrasil.conf /etc/yggdrasil/yggdrasil.conf
fi
if [ -f /etc/yggdrasil/yggdrasil.conf ];
then
mkdir -p /var/backups
echo "Backing up configuration file to /var/backups/yggdrasil.conf.`date +%Y%m%d`"
cp /etc/yggdrasil.conf /var/backups/yggdrasil.conf.`date +%Y%m%d`
echo "Normalising and updating /etc/yggdrasil.conf"
/usr/bin/yggdrasil -useconffile /var/backups/yggdrasil.conf.`date +%Y%m%d` -normaliseconf > /etc/yggdrasil.conf
chgrp yggdrasil /etc/yggdrasil.conf
cp /etc/yggdrasil/yggdrasil.conf /var/backups/yggdrasil.conf.`date +%Y%m%d`
if command -v systemctl >/dev/null; then
systemctl daemon-reload >/dev/null || true
systemctl enable yggdrasil || true
systemctl start yggdrasil || true
fi
echo "Normalising and updating /etc/yggdrasil/yggdrasil.conf"
/usr/bin/yggdrasil -useconf -normaliseconf < /var/backups/yggdrasil.conf.`date +%Y%m%d` > /etc/yggdrasil/yggdrasil.conf
chown root:yggdrasil /etc/yggdrasil/yggdrasil.conf
chmod 640 /etc/yggdrasil/yggdrasil.conf
else
echo "Generating initial configuration file /etc/yggdrasil.conf"
echo "Please familiarise yourself with this file before starting Yggdrasil"
/usr/bin/yggdrasil -genconf > /etc/yggdrasil.conf
chgrp yggdrasil /etc/yggdrasil.conf
echo "Generating initial configuration file /etc/yggdrasil/yggdrasil.conf"
/usr/bin/yggdrasil -genconf > /etc/yggdrasil/yggdrasil.conf
chown root:yggdrasil /etc/yggdrasil/yggdrasil.conf
chmod 640 /etc/yggdrasil/yggdrasil.conf
fi
systemctl enable yggdrasil
systemctl restart yggdrasil
exit 0
EOF
cat > /tmp/$PKGNAME/debian/prerm << EOF
#!/bin/sh
@ -109,12 +131,14 @@ 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-default-config.service.debian /tmp/$PKGNAME/lib/systemd/system/yggdrasil-default-config.service
cp contrib/systemd/yggdrasil.service.debian /tmp/$PKGNAME/lib/systemd/system/yggdrasil.service
tar -czvf /tmp/$PKGNAME/data.tar.gz -C /tmp/$PKGNAME/ \
tar --no-xattrs -czvf /tmp/$PKGNAME/data.tar.gz -C /tmp/$PKGNAME/ \
usr/bin/yggdrasil usr/bin/yggdrasilctl \
etc/systemd/system/yggdrasil.service
tar -czvf /tmp/$PKGNAME/control.tar.gz -C /tmp/$PKGNAME/debian .
lib/systemd/system/yggdrasil.service \
lib/systemd/system/yggdrasil-default-config.service
tar --no-xattrs -czvf /tmp/$PKGNAME/control.tar.gz -C /tmp/$PKGNAME/debian .
echo 2.0 > /tmp/$PKGNAME/debian-binary
ar -r $PKGFILE \

View file

@ -5,13 +5,13 @@ WORKDIR /src
ENV CGO_ENABLED=0
RUN apk add git && ./build
RUN apk add git && ./build && go build -o /src/genkeys cmd/genkeys/main.go
FROM docker.io/alpine
LABEL maintainer="Christer Waren/CWINFO <christer.waren@cwinfo.org>"
COPY --from=builder /src/yggdrasil /usr/bin/yggdrasil
COPY --from=builder /src/yggdrasilctl /usr/bin/yggdrasilctl
COPY --from=builder /src/genkeys /usr/bin/genkeys
COPY contrib/docker/entrypoint.sh /usr/bin/entrypoint.sh
# RUN addgroup -g 1000 -S yggdrasil-network \

View file

@ -15,6 +15,10 @@ command -v mkbom >/dev/null 2>&1 || (
sudo make install || (echo "Failed to build mkbom"; exit 1)
)
# Build Yggdrasil
echo "running GO111MODULE=on GOOS=darwin GOARCH=${PKGARCH-amd64} ./build"
GO111MODULE=on GOOS=darwin GOARCH=${PKGARCH-amd64} ./build
# Check if we can find the files we need - they should
# exist if you are running this script from the root of
# the yggdrasil-go repo and you have ran ./build
@ -75,6 +79,7 @@ PKGNAME=$(sh contrib/semver/name.sh)
PKGVERSION=$(sh contrib/semver/version.sh --bare)
PKGARCH=${PKGARCH-amd64}
PAYLOADSIZE=$(( $(wc -c pkgbuild/flat/base.pkg/Payload | awk '{ print $1 }') / 1024 ))
[ "$PKGARCH" = "amd64" ] && PKGHOSTARCH="x86_64" || PKGHOSTARCH=${PKGARCH}
# Create the PackageInfo file
cat > pkgbuild/flat/base.pkg/PackageInfo << EOF
@ -94,7 +99,7 @@ cat > pkgbuild/flat/Distribution << EOF
<?xml version="1.0" encoding="utf-8"?>
<installer-script minSpecVersion="1.000000" authoringTool="com.apple.PackageMaker" authoringToolVersion="3.0.3" authoringToolBuild="174">
<title>Yggdrasil (${PKGNAME}-${PKGVERSION})</title>
<options customize="never" allow-external-scripts="no"/>
<options customize="never" allow-external-scripts="no" hostArchitectures="${PKGHOSTARCH}" />
<domains enable_anywhere="true"/>
<installation-check script="pm_install_check();"/>
<script>

62
contrib/mobile/build Executable file
View file

@ -0,0 +1,62 @@
#!/bin/sh
set -ef
[ ! -d contrib/mobile ] && (echo "Must run ./contrib/mobile/build [-i] [-a] from the repository top level folder"; exit 1)
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)}
GOVER=$(go version | { read _ _ version _; echo ${version#go}; })
LDFLAGS="-X $PKGSRC.buildName=$PKGNAME -X $PKGSRC.buildVersion=$PKGVER"
ARGS="-v"
while getopts "aitc:l:d" option
do
case "$option"
in
i) IOS=true;;
a) ANDROID=true;;
t) TABLES=true;;
c) GCFLAGS="$GCFLAGS $OPTARG";;
l) LDFLAGS="$LDFLAGS $OPTARG";;
d) ARGS="$ARGS -tags debug" DEBUG=true;;
esac
done
if [ -z $TABLES ] && [ -z $DEBUG ]; then
LDFLAGS="$LDFLAGS -s -w"
fi
if [ ! $IOS ] && [ ! $ANDROID ]; then
echo "Must specify -a (Android), -i (iOS) or both"
exit 1
fi
ver_le() {
printf "$1\n$2\n" | sort -VC
}
if [ $ANDROID ] && ver_le 1.23.0 $GOVER ; then
# github.com/wlynxg/anet library relies on //go:linkname
LDFLAGS="$LDFLAGS -checklinkname=0"
fi
if [ $IOS ]; then
echo "Building framework for iOS"
go get golang.org/x/mobile/bind
gomobile bind \
-target ios,macos -tags mobile -o Yggdrasil.xcframework \
-ldflags="$LDFLAGS $STRIP" -gcflags="$GCFLAGS" \
./contrib/mobile ./src/config;
fi
if [ $ANDROID ]; then
echo "Building aar for Android"
go get golang.org/x/mobile/bind
gomobile bind \
-target android -tags mobile -o yggdrasil.aar \
-ldflags="$LDFLAGS $STRIP" -gcflags="$GCFLAGS" \
./contrib/mobile ./src/config;
fi

301
contrib/mobile/mobile.go Normal file
View file

@ -0,0 +1,301 @@
package mobile
import (
"crypto/ed25519"
"encoding/hex"
"encoding/json"
"net"
"regexp"
"github.com/gologme/log"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
"github.com/yggdrasil-network/yggdrasil-go/src/config"
"github.com/yggdrasil-network/yggdrasil-go/src/core"
"github.com/yggdrasil-network/yggdrasil-go/src/ipv6rwc"
"github.com/yggdrasil-network/yggdrasil-go/src/multicast"
"github.com/yggdrasil-network/yggdrasil-go/src/tun"
"github.com/yggdrasil-network/yggdrasil-go/src/version"
)
// Yggdrasil mobile package is meant to "plug the gap" for mobile support, as
// Gomobile will not create headers for Swift/Obj-C etc if they have complex
// (non-native) types. Therefore for iOS we will expose some nice simple
// functions. Note that in the case of iOS we handle reading/writing to/from TUN
// in Swift therefore we use the "dummy" TUN interface instead.
type Yggdrasil struct {
core *core.Core
iprwc *ipv6rwc.ReadWriteCloser
config *config.NodeConfig
multicast *multicast.Multicast
tun *tun.TunAdapter // optional
log MobileLogger
logger *log.Logger
}
// StartAutoconfigure starts a node with a randomly generated config
func (m *Yggdrasil) StartAutoconfigure() error {
return m.StartJSON([]byte("{}"))
}
// StartJSON starts a node with the given JSON config. You can get JSON config
// (rather than HJSON) by using the GenerateConfigJSON() function
func (m *Yggdrasil) StartJSON(configjson []byte) error {
setMemLimitIfPossible()
logger := log.New(m.log, "", 0)
logger.EnableLevel("error")
logger.EnableLevel("warn")
logger.EnableLevel("info")
m.logger = logger
m.config = config.GenerateConfig()
if err := m.config.UnmarshalHJSON(configjson); err != nil {
return err
}
// Set up the Yggdrasil node itself.
{
iprange := net.IPNet{
IP: net.ParseIP("200::"),
Mask: net.CIDRMask(7, 128),
}
options := []core.SetupOption{
core.PeerFilter(func(ip net.IP) bool {
return !iprange.Contains(ip)
}),
}
for _, peer := range m.config.Peers {
options = append(options, core.Peer{URI: peer})
}
for intf, peers := range m.config.InterfacePeers {
for _, peer := range peers {
options = append(options, core.Peer{URI: peer, SourceInterface: intf})
}
}
for _, allowed := range m.config.AllowedPublicKeys {
k, err := hex.DecodeString(allowed)
if err != nil {
panic(err)
}
options = append(options, core.AllowedPublicKey(k[:]))
}
for _, lAddr := range m.config.Listen {
options = append(options, core.ListenAddress(lAddr))
}
var err error
m.core, err = core.New(m.config.Certificate, logger, options...)
if err != nil {
panic(err)
}
address, subnet := m.core.Address(), m.core.Subnet()
logger.Infof("Your public key is %s", hex.EncodeToString(m.core.PublicKey()))
logger.Infof("Your IPv6 address is %s", address.String())
logger.Infof("Your IPv6 subnet is %s", subnet.String())
}
// Set up the multicast module.
if len(m.config.MulticastInterfaces) > 0 {
var err error
logger.Infof("Initializing multicast %s", "")
options := []multicast.SetupOption{}
for _, intf := range m.config.MulticastInterfaces {
options = append(options, multicast.MulticastInterface{
Regex: regexp.MustCompile(intf.Regex),
Beacon: intf.Beacon,
Listen: intf.Listen,
Port: intf.Port,
Priority: uint8(intf.Priority),
Password: intf.Password,
})
}
logger.Infof("Starting multicast %s", "")
m.multicast, err = multicast.New(m.core, m.logger, options...)
if err != nil {
logger.Errorln("An error occurred starting multicast:", err)
}
}
mtu := m.config.IfMTU
m.iprwc = ipv6rwc.NewReadWriteCloser(m.core)
if m.iprwc.MaxMTU() < mtu {
mtu = m.iprwc.MaxMTU()
}
m.iprwc.SetMTU(mtu)
return nil
}
// Send sends a packet to Yggdrasil. It should be a fully formed
// IPv6 packet
func (m *Yggdrasil) Send(p []byte) error {
if m.iprwc == nil {
return nil
}
_, _ = m.iprwc.Write(p)
return nil
}
// Send sends a packet from given buffer to Yggdrasil. From first byte up to length.
func (m *Yggdrasil) SendBuffer(p []byte, length int) error {
if m.iprwc == nil {
return nil
}
if len(p) < length {
return nil
}
_, _ = m.iprwc.Write(p[:length])
return nil
}
// Recv waits for and reads a packet coming from Yggdrasil. It
// will be a fully formed IPv6 packet
func (m *Yggdrasil) Recv() ([]byte, error) {
if m.iprwc == nil {
return nil, nil
}
var buf [65535]byte
n, _ := m.iprwc.Read(buf[:])
return buf[:n], nil
}
// Recv waits for and reads a packet coming from Yggdrasil to given buffer, returning size of packet
func (m *Yggdrasil) RecvBuffer(buf []byte) (int, error) {
if m.iprwc == nil {
return 0, nil
}
n, _ := m.iprwc.Read(buf)
return n, nil
}
// Stop the mobile Yggdrasil instance
func (m *Yggdrasil) Stop() error {
logger := log.New(m.log, "", 0)
logger.EnableLevel("info")
logger.Infof("Stopping the mobile Yggdrasil instance %s", "")
if m.multicast != nil {
logger.Infof("Stopping multicast %s", "")
if err := m.multicast.Stop(); err != nil {
return err
}
}
logger.Infof("Stopping TUN device %s", "")
if m.tun != nil {
if err := m.tun.Stop(); err != nil {
return err
}
}
logger.Infof("Stopping Yggdrasil core %s", "")
m.core.Stop()
return nil
}
// Retry resets the peer connection timer and tries to dial them immediately.
func (m *Yggdrasil) RetryPeersNow() {
m.core.RetryPeersNow()
}
// GenerateConfigJSON generates mobile-friendly configuration in JSON format
func GenerateConfigJSON() []byte {
nc := config.GenerateConfig()
nc.IfName = "none"
if json, err := json.Marshal(nc); err == nil {
return json
}
return nil
}
// GetAddressString gets the node's IPv6 address
func (m *Yggdrasil) GetAddressString() string {
ip := m.core.Address()
return ip.String()
}
// GetSubnetString gets the node's IPv6 subnet in CIDR notation
func (m *Yggdrasil) GetSubnetString() string {
subnet := m.core.Subnet()
return subnet.String()
}
// GetPublicKeyString gets the node's public key in hex form
func (m *Yggdrasil) GetPublicKeyString() string {
return hex.EncodeToString(m.core.GetSelf().Key)
}
// GetRoutingEntries gets the number of entries in the routing table
func (m *Yggdrasil) GetRoutingEntries() int {
return int(m.core.GetSelf().RoutingEntries)
}
func (m *Yggdrasil) GetPeersJSON() (result string) {
peers := []struct {
core.PeerInfo
IP string
}{}
for _, v := range m.core.GetPeers() {
var ip string
if v.Key != nil {
a := address.AddrForKey(v.Key)
ip = net.IP(a[:]).String()
}
peers = append(peers, struct {
core.PeerInfo
IP string
}{
PeerInfo: v,
IP: ip,
})
}
if res, err := json.Marshal(peers); err == nil {
return string(res)
} else {
return "{}"
}
}
func (m *Yggdrasil) GetPathsJSON() (result string) {
if res, err := json.Marshal(m.core.GetPaths()); err == nil {
return string(res)
} else {
return "{}"
}
}
func (m *Yggdrasil) GetTreeJSON() (result string) {
if res, err := json.Marshal(m.core.GetTree()); err == nil {
return string(res)
} else {
return "{}"
}
}
// GetMTU returns the configured node MTU. This must be called AFTER Start.
func (m *Yggdrasil) GetMTU() int {
return int(m.core.MTU())
}
func GetVersion() string {
return version.BuildVersion()
}
type ConfigSummary struct {
PublicKey string
IPv6Address string
IPv6Subnet string
}
func SummaryForConfig(b []byte) *ConfigSummary {
cfg := config.GenerateConfig()
if err := cfg.UnmarshalHJSON(b); err != nil {
return nil
}
pub := ed25519.PrivateKey(cfg.PrivateKey).Public().(ed25519.PublicKey)
hpub := hex.EncodeToString(pub)
addr := net.IP(address.AddrForKey(pub)[:])
snet := net.IPNet{
IP: append(address.SubnetForKey(pub)[:], 0, 0, 0, 0, 0, 0, 0, 0),
Mask: net.CIDRMask(64, 128),
}
return &ConfigSummary{
PublicKey: hpub,
IPv6Address: addr.String(),
IPv6Subnet: snet.String(),
}
}

View file

@ -1,6 +1,7 @@
//go:build android
// +build android
package yggdrasil
package mobile
import "log"

View file

@ -0,0 +1,40 @@
//go:build ios || darwin
// +build ios darwin
package mobile
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation
#import <Foundation/Foundation.h>
void Log(const char *text) {
NSString *nss = [NSString stringWithUTF8String:text];
NSLog(@"%@", nss);
}
*/
import "C"
import (
"unsafe"
"github.com/yggdrasil-network/yggdrasil-go/src/tun"
)
type MobileLogger struct {
}
func (nsl MobileLogger) Write(p []byte) (n int, err error) {
p = append(p, 0)
cstr := (*C.char)(unsafe.Pointer(&p[0]))
C.Log(cstr)
return len(p), nil
}
func (m *Yggdrasil) TakeOverTUN(fd int32) error {
options := []tun.SetupOption{
tun.FileDescriptor(fd),
tun.InterfaceMTU(m.iprwc.MTU()),
}
var err error
m.tun, err = tun.New(m.iprwc, m.logger, options...)
return err
}

View file

@ -0,0 +1,10 @@
//go:build go1.20
// +build go1.20
package mobile
import "runtime/debug"
func setMemLimitIfPossible() {
debug.SetMemoryLimit(1024 * 1024 * 40)
}

View file

@ -0,0 +1,8 @@
//go:build !go1.20
// +build !go1.20
package mobile
func setMemLimitIfPossible() {
// not supported by this Go version
}

View file

@ -0,0 +1,14 @@
//go:build !android && !ios && !darwin
// +build !android,!ios,!darwin
package mobile
import "fmt"
type MobileLogger struct {
}
func (nsl MobileLogger) Write(p []byte) (n int, err error) {
fmt.Print(string(p))
return len(p), nil
}

View file

@ -0,0 +1,28 @@
package mobile
import (
"os"
"testing"
"github.com/gologme/log"
)
func TestStartYggdrasil(t *testing.T) {
logger := log.New(os.Stdout, "", 0)
logger.EnableLevel("error")
logger.EnableLevel("warn")
logger.EnableLevel("info")
ygg := &Yggdrasil{
logger: logger,
}
if err := ygg.StartAutoconfigure(); err != nil {
t.Fatalf("Failed to start Yggdrasil: %s", err)
}
t.Log("Address:", ygg.GetAddressString())
t.Log("Subnet:", ygg.GetSubnetString())
t.Log("Routing entries:", ygg.GetRoutingEntries())
if err := ygg.Stop(); err != nil {
t.Fatalf("Failed to stop Yggdrasil: %s", err)
}
}

201
contrib/msi/build-msi.sh Normal file
View file

@ -0,0 +1,201 @@
#!/bin/sh
# This script generates an MSI file for Yggdrasil for a given architecture. It
# needs to run on Windows within MSYS2 and Go 1.21 or later must be installed on
# the system and within the PATH. This is ran currently by GitHub Actions (see
# the workflows in the repository).
#
# Author: Neil Alexander <neilalexander@users.noreply.github.com>
# Get arch from command line if given
PKGARCH=$1
if [ "${PKGARCH}" == "" ];
then
echo "tell me the architecture: x86, x64, arm or arm64"
exit 1
fi
# Download the wix tools!
dotnet tool install --global wix --version 5.0.0
# Build Yggdrasil!
[ "${PKGARCH}" == "x64" ] && GOOS=windows GOARCH=amd64 CGO_ENABLED=0 ./build
[ "${PKGARCH}" == "x86" ] && GOOS=windows GOARCH=386 CGO_ENABLED=0 ./build
[ "${PKGARCH}" == "arm" ] && GOOS=windows GOARCH=arm CGO_ENABLED=0 ./build
[ "${PKGARCH}" == "arm64" ] && GOOS=windows GOARCH=arm64 CGO_ENABLED=0 ./build
# Create the postinstall script
cat > updateconfig.bat << EOF
if not exist %ALLUSERSPROFILE%\\Yggdrasil (
mkdir %ALLUSERSPROFILE%\\Yggdrasil
)
if not exist %ALLUSERSPROFILE%\\Yggdrasil\\yggdrasil.conf (
if exist yggdrasil.exe (
yggdrasil.exe -genconf > %ALLUSERSPROFILE%\\Yggdrasil\\yggdrasil.conf
)
)
EOF
# Work out metadata for the package info
PKGNAME=$(sh contrib/semver/name.sh)
PKGVERSION=$(sh contrib/msi/msversion.sh --bare)
PKGVERSIONMS=$(echo $PKGVERSION | tr - .)
([ "${PKGARCH}" == "x64" ] || [ "${PKGARCH}" == "arm64" ]) && \
PKGGUID="77757838-1a23-40a5-a720-c3b43e0260cc" PKGINSTFOLDER="ProgramFiles64Folder" || \
PKGGUID="54a3294e-a441-4322-aefb-3bb40dd022bb" PKGINSTFOLDER="ProgramFilesFolder"
# Download the Wintun driver
if [ ! -d wintun ];
then
curl -o wintun.zip https://www.wintun.net/builds/wintun-0.14.1.zip
if [ `sha256sum wintun.zip | cut -f 1 -d " "` != "07c256185d6ee3652e09fa55c0b673e2624b565e02c4b9091c79ca7d2f24ef51" ];
then
echo "wintun package didn't match expected checksum"
exit 1
fi
unzip wintun.zip
fi
if [ $PKGARCH = "x64" ]; then
PKGWINTUNDLL=wintun/bin/amd64/wintun.dll
elif [ $PKGARCH = "x86" ]; then
PKGWINTUNDLL=wintun/bin/x86/wintun.dll
elif [ $PKGARCH = "arm" ]; then
PKGWINTUNDLL=wintun/bin/arm/wintun.dll
elif [ $PKGARCH = "arm64" ]; then
PKGWINTUNDLL=wintun/bin/arm64/wintun.dll
else
echo "wasn't sure which architecture to get wintun for"
exit 1
fi
if [ $PKGNAME != "master" ]; then
PKGDISPLAYNAME="Yggdrasil Network (${PKGNAME} branch)"
else
PKGDISPLAYNAME="Yggdrasil Network"
fi
# Generate the wix.xml file
cat > wix.xml << EOF
<?xml version="1.0" encoding="windows-1252"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product
Name="${PKGDISPLAYNAME}"
Id="*"
UpgradeCode="${PKGGUID}"
Language="1033"
Codepage="1252"
Version="${PKGVERSIONMS}"
Manufacturer="github.com/yggdrasil-network">
<Package
Id="*"
Keywords="Installer"
Description="Yggdrasil Network Installer"
Comments="Yggdrasil Network standalone router for Windows."
Manufacturer="github.com/yggdrasil-network"
InstallerVersion="500"
InstallScope="perMachine"
Languages="1033"
Compressed="yes"
SummaryCodepage="1252" />
<MajorUpgrade
AllowDowngrades="yes" />
<Media
Id="1"
Cabinet="Media.cab"
EmbedCab="yes"
CompressionLevel="high" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="${PKGINSTFOLDER}" Name="PFiles">
<Directory Id="YggdrasilInstallFolder" Name="Yggdrasil">
<Component Id="MainExecutable" Guid="c2119231-2aa3-4962-867a-9759c87beb24">
<File
Id="Yggdrasil"
Name="yggdrasil.exe"
DiskId="1"
Source="yggdrasil.exe"
KeyPath="yes" />
<File
Id="Wintun"
Name="wintun.dll"
DiskId="1"
Source="${PKGWINTUNDLL}" />
<ServiceInstall
Id="ServiceInstaller"
Account="LocalSystem"
Description="Yggdrasil Network router process"
DisplayName="Yggdrasil Service"
ErrorControl="normal"
LoadOrderGroup="NetworkProvider"
Name="Yggdrasil"
Start="auto"
Type="ownProcess"
Arguments='-useconffile "%ALLUSERSPROFILE%\\Yggdrasil\\yggdrasil.conf" -logto "%ALLUSERSPROFILE%\\Yggdrasil\\yggdrasil.log"'
Vital="yes" />
<ServiceControl
Id="ServiceControl"
Name="yggdrasil"
Start="install"
Stop="both"
Remove="uninstall" />
</Component>
<Component Id="CtrlExecutable" Guid="a916b730-974d-42a1-b687-d9d504cbb86a">
<File
Id="Yggdrasilctl"
Name="yggdrasilctl.exe"
DiskId="1"
Source="yggdrasilctl.exe"
KeyPath="yes"/>
</Component>
<Component Id="ConfigScript" Guid="64a3733b-c98a-4732-85f3-20cd7da1a785">
<File
Id="Configbat"
Name="updateconfig.bat"
DiskId="1"
Source="updateconfig.bat"
KeyPath="yes"/>
</Component>
</Directory>
</Directory>
</Directory>
<Feature Id="YggdrasilFeature" Title="Yggdrasil" Level="1">
<ComponentRef Id="MainExecutable" />
<ComponentRef Id="CtrlExecutable" />
<ComponentRef Id="ConfigScript" />
</Feature>
<CustomAction
Id="UpdateGenerateConfig"
Directory="YggdrasilInstallFolder"
ExeCommand="cmd.exe /c updateconfig.bat"
Execute="deferred"
Return="check"
Impersonate="yes" />
<InstallExecuteSequence>
<Custom
Action="UpdateGenerateConfig"
Before="StartServices">
NOT Installed AND NOT REMOVE
</Custom>
</InstallExecuteSequence>
</Product>
</Wix>
EOF
# Generate the MSI
CANDLEFLAGS="-nologo"
LIGHTFLAGS="-nologo -spdb -sice:ICE71 -sice:ICE61"
candle $CANDLEFLAGS -out ${PKGNAME}-${PKGVERSION}-${PKGARCH}.wixobj -arch ${PKGARCH} wix.xml && \
light $LIGHTFLAGS -ext WixUtilExtension.dll -out ${PKGNAME}-${PKGVERSION}-${PKGARCH}.msi ${PKGNAME}-${PKGVERSION}-${PKGARCH}.wixobj

46
contrib/msi/msversion.sh Normal file
View file

@ -0,0 +1,46 @@
#!/bin/sh
# Get the last tag
TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" 2>/dev/null)
# Did getting the tag succeed?
if [ $? != 0 ] || [ -z "$TAG" ]; then
printf -- "unknown"
exit 0
fi
# Get the current branch
BRANCH=$(git symbolic-ref -q HEAD --short 2>/dev/null)
# Did getting the branch succeed?
if [ $? != 0 ] || [ -z "$BRANCH" ]; then
BRANCH="master"
fi
# Split out into major, minor and patch numbers
MAJOR=$(echo $TAG | cut -c 2- | cut -d "." -f 1)
MINOR=$(echo $TAG | cut -c 2- | cut -d "." -f 2)
PATCH=$(echo $TAG | cut -c 2- | cut -d "." -f 3 | awk -F"rc" '{print $1}')
# Output in the desired format
if [ $((PATCH)) -eq 0 ]; then
printf '%s%d.%d' "$PREPEND" "$((MAJOR))" "$((MINOR))"
else
printf '%s%d.%d.%d' "$PREPEND" "$((MAJOR))" "$((MINOR))" "$((PATCH))"
fi
# Add the build tag on non-master branches
if [ "$BRANCH" != "master" ]; then
BUILD=$(git rev-list --count $TAG..HEAD 2>/dev/null)
# Did getting the count of commits since the tag succeed?
if [ $? != 0 ] || [ -z "$BUILD" ]; then
printf -- "-unknown"
exit 0
fi
# Is the build greater than zero?
if [ $((BUILD)) -gt 0 ]; then
printf -- "-%04d" "$((BUILD))"
fi
fi

View file

@ -6,7 +6,6 @@ CONFFILE="/etc/yggdrasil.conf"
pidfile="/run/${RC_SVCNAME}.pid"
command="/usr/bin/yggdrasil"
extra_started_commands="reload"
depend() {
use net dns logger
@ -42,12 +41,6 @@ start() {
eend $?
}
reload() {
ebegin "Reloading ${RC_SVCNAME}"
start-stop-daemon --signal HUP --pidfile "${pidfile}"
eend $?
}
stop() {
ebegin "Stopping ${RC_SVCNAME}"
start-stop-daemon --stop --pidfile "${pidfile}" --exec "${command}"

View file

@ -1,47 +0,0 @@
Name: yggdrasil
Version: 0.3.0
Release: 1%{?dist}
Summary: End-to-end encrypted IPv6 networking
License: GPLv3
URL: https://yggdrasil-network.github.io
Source0: https://codeload.github.com/yggdrasil-network/yggdrasil-go/tar.gz/v0.3.0
%{?systemd_requires}
BuildRequires: systemd golang >= 1.11
%description
Yggdrasil is a proof-of-concept to explore a wholly different approach to
network routing. Whereas current computer networks depend heavily on very
centralised design and configuration, Yggdrasil breaks this mould by making
use of a global spanning tree to form a scalable IPv6 encrypted mesh network.
%prep
%setup -qn yggdrasil-go-%{version}
%build
./build -t -l "-linkmode=external"
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}/%{_bindir}
mkdir -p %{buildroot}/%{_sysconfdir}/systemd/system
install -m 0755 yggdrasil %{buildroot}/%{_bindir}/yggdrasil
install -m 0755 yggdrasilctl %{buildroot}/%{_bindir}/yggdrasilctl
install -m 0755 contrib/systemd/yggdrasil.service %{buildroot}/%{_sysconfdir}/systemd/system/yggdrasil.service
install -m 0755 contrib/systemd/yggdrasil-resume.service %{buildroot}/%{_sysconfdir}/systemd/system/yggdrasil-resume.service
%files
%{_bindir}/yggdrasil
%{_bindir}/yggdrasilctl
%{_sysconfdir}/systemd/system/yggdrasil.service
%{_sysconfdir}/systemd/system/yggdrasil-resume.service
%post
%systemd_post yggdrasil.service
%preun
%systemd_preun yggdrasil.service
%postun
%systemd_postun_with_restart yggdrasil.service

View file

@ -1,12 +1,14 @@
#!/bin/sh
# Get the current branch name
BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null)
BRANCH="$GITHUB_REF_NAME"
if [ -z "$BRANCH" ]; then
BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null)
fi
# Complain if the git history is not available
if [ $? != 0 ] || [ -z "$BRANCH" ]; then
printf "yggdrasil"
exit 1
exit 0
fi
# Remove "/" characters from the branch name if present

View file

@ -1,46 +1,11 @@
#!/bin/sh
# Get the last tag
TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" 2>/dev/null)
# Did getting the tag succeed?
if [ $? != 0 ] || [ -z "$TAG" ]; then
printf -- "unknown"
exit 1
fi
# Get the current branch
BRANCH=$(git symbolic-ref -q HEAD --short 2>/dev/null)
# Did getting the branch succeed?
if [ $? != 0 ] || [ -z "$BRANCH" ]; then
BRANCH="master"
fi
# Split out into major, minor and patch numbers
MAJOR=$(echo $TAG | cut -c 2- | cut -d "." -f 1)
MINOR=$(echo $TAG | cut -c 2- | cut -d "." -f 2)
PATCH=$(echo $TAG | cut -c 2- | cut -d "." -f 3)
# Output in the desired format
if [ $((PATCH)) -eq 0 ]; then
printf '%s%d.%d' "$PREPEND" "$((MAJOR))" "$((MINOR))"
else
printf '%s%d.%d.%d' "$PREPEND" "$((MAJOR))" "$((MINOR))" "$((PATCH))"
fi
# Add the build tag on non-master branches
if [ "$BRANCH" != "master" ]; then
BUILD=$(git rev-list --count $TAG..HEAD 2>/dev/null)
# Did getting the count of commits since the tag succeed?
if [ $? != 0 ] || [ -z "$BUILD" ]; then
printf -- "-unknown"
exit 1
fi
# Is the build greater than zero?
if [ $((BUILD)) -gt 0 ]; then
printf -- "-%04d" "$((BUILD))"
fi
fi
case "$*" in
*--bare*)
# Remove the "v" prefix
git describe --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" | cut -c 2-
;;
*)
git describe --tags --match="v[0-9]*\.[0-9]*\.[0-9]*"
;;
esac

View file

@ -0,0 +1,13 @@
[Unit]
Description=yggdrasil default config generator
ConditionPathExists=|!/etc/yggdrasil.conf
ConditionFileNotEmpty=|!/etc/yggdrasil.conf
Wants=local-fs.target
After=local-fs.target
[Service]
Type=oneshot
Group=yggdrasil
StandardOutput=file:/etc/yggdrasil.conf
ExecStart=/usr/bin/yggdrasil -genconf
ExecStartPost=/usr/bin/chmod 0640 /etc/yggdrasil.conf

View file

@ -0,0 +1,13 @@
[Unit]
Description=Yggdrasil default config generator
ConditionPathExists=|!/etc/yggdrasil/yggdrasil.conf
ConditionFileNotEmpty=|!/etc/yggdrasil/yggdrasil.conf
Wants=local-fs.target
After=local-fs.target
[Service]
Type=oneshot
Group=yggdrasil
ExecStartPre=/usr/bin/mkdir -p /etc/yggdrasil
ExecStart=/usr/bin/yggdrasil -genconf > /etc/yggdrasil/yggdrasil.conf
ExecStartPost=/usr/bin/chmod -R 0640 /etc/yggdrasil

View file

@ -1,21 +1,21 @@
[Unit]
Description=yggdrasil
Wants=network.target
After=network.target
Wants=network-online.target
Wants=yggdrasil-default-config.service
After=network-online.target
After=yggdrasil-default-config.service
[Service]
Group=yggdrasil
ProtectHome=true
ProtectSystem=true
SyslogIdentifier=yggdrasil
ExecStartPre=/bin/sh -ec "if ! test -s /etc/yggdrasil.conf; \
then umask 077; \
yggdrasil -genconf > /etc/yggdrasil.conf; \
echo 'WARNING: A new /etc/yggdrasil.conf file has been generated.'; \
fi"
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
ExecStartPre=+-/sbin/modprobe tun
ExecStart=/usr/bin/yggdrasil -useconffile /etc/yggdrasil.conf
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
TimeoutStopSec=5
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,25 @@
[Unit]
Description=Yggdrasil Network
Wants=network-online.target
Wants=yggdrasil-default-config.service
After=network-online.target
After=yggdrasil-default-config.service
[Service]
Group=yggdrasil
ProtectHome=true
ProtectSystem=strict
NoNewPrivileges=true
RuntimeDirectory=yggdrasil
ReadWritePaths=/var/run/yggdrasil/ /run/yggdrasil/
SyslogIdentifier=yggdrasil
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
ExecStartPre=+-/sbin/modprobe tun
ExecStart=/usr/bin/yggdrasil -useconffile /etc/yggdrasil/yggdrasil.conf
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
TimeoutStopSec=5
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,150 @@
This software is released into the public domain. As such, it can be
used under the Unlicense or CC0 public domain dedications.
The Unlicense
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
CC0 1.0 Universal
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator and
subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for the
purpose of contributing to a commons of creative, cultural and scientific
works ("Commons") that the public can reliably and without fear of later
claims of infringement build upon, modify, incorporate in other works, reuse
and redistribute as freely as possible in any form whatsoever and for any
purposes, including without limitation commercial purposes. These owners may
contribute to the Commons to promote the ideal of a free culture and the
further production of creative, cultural and scientific works, or to gain
reputation or greater distribution for their Work in part through the use and
efforts of others.
For these and/or other purposes and motivations, and without any expectation
of additional consideration or compensation, the person associating CC0 with a
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
and publicly distribute the Work under its terms, with knowledge of his or her
Copyright and Related Rights in the Work and the meaning and intended legal
effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not limited
to, the following:
i. the right to reproduce, adapt, distribute, perform, display, communicate,
and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or likeness
depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data in
a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation thereof,
including any amended or successor version of such directive); and
vii. other similar, equivalent or corresponding rights throughout the world
based on applicable law or treaty, and any national implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention of,
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
and Related Rights and associated claims and causes of action, whether now
known or unknown (including existing as well as future claims and causes of
action), in the Work (i) in all territories worldwide, (ii) for the maximum
duration provided by applicable law or treaty (including future time
extensions), (iii) in any current or future medium and for any number of
copies, and (iv) for any purpose whatsoever, including without limitation
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
the Waiver for the benefit of each member of the public at large and to the
detriment of Affirmer's heirs and successors, fully intending that such Waiver
shall not be subject to revocation, rescission, cancellation, termination, or
any other legal or equitable action to disrupt the quiet enjoyment of the Work
by the public as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason be
judged legally invalid or ineffective under applicable law, then the Waiver
shall be preserved to the maximum extent permitted taking into account
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
is so judged Affirmer hereby grants to each affected person a royalty-free,
non transferable, non sublicensable, non exclusive, irrevocable and
unconditional license to exercise Affirmer's Copyright and Related Rights in
the Work (i) in all territories worldwide, (ii) for the maximum duration
provided by applicable law or treaty (including future time extensions), (iii)
in any current or future medium and for any number of copies, and (iv) for any
purpose whatsoever, including without limitation commercial, advertising or
promotional purposes (the "License"). The License shall be deemed effective as
of the date CC0 was applied by Affirmer to the Work. Should any part of the
License for any reason be judged legally invalid or ineffective under
applicable law, such partial invalidity or ineffectiveness shall not
invalidate the remainder of the License, and in such case Affirmer hereby
affirms that he or she will not (i) exercise any of his or her remaining
Copyright and Related Rights in the Work or (ii) assert any associated claims
and causes of action with respect to the Work, in either case contrary to
Affirmer's express Statement of Purpose.
4. Limitations and Disclaimers.
a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or warranties
of any kind concerning the Work, express, implied, statutory or otherwise,
including without limitation warranties of title, merchantability, fitness
for a particular purpose, non infringement, or the absence of latent or
other defects, accuracy, or the present or absence of errors, whether or not
discoverable, all to the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without limitation
any person's Copyright and Related Rights in the Work. Further, Affirmer
disclaims responsibility for obtaining any necessary consents, permissions
or other rights required for any use of the Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to this
CC0 or use of the Work.
For more information, please see
<http://creativecommons.org/publicdomain/zero/1.0/>

View file

@ -0,0 +1,12 @@
.PHONY: all
all: util yggdrasil-brute-multi-curve25519 yggdrasil-brute-multi-ed25519
util: util.c
gcc -Wall -std=c89 -O3 -c -o util.o util.c
yggdrasil-brute-multi-ed25519: yggdrasil-brute-multi-ed25519.c util.o
gcc -Wall -std=c89 -O3 -o yggdrasil-brute-multi-ed25519 -lsodium yggdrasil-brute-multi-ed25519.c util.o
yggdrasil-brute-multi-curve25519: yggdrasil-brute-multi-curve25519.c util.o
gcc -Wall -std=c89 -O3 -o yggdrasil-brute-multi-curve25519 -lsodium yggdrasil-brute-multi-curve25519.c util.o

View file

@ -0,0 +1,8 @@
# yggdrasil-brute-simple
Simple program for finding curve25519 and ed25519 public keys whose sha512 hash has many leading ones.
Because ed25519 private keys consist of a seed that is hashed to find the secret part of the keypair,
this program is near optimal for finding ed25519 keypairs. Curve25519 key generation, on the other hand,
could be further optimized with elliptic curve magic.
Depends on libsodium.

View file

@ -0,0 +1,62 @@
#include "yggdrasil-brute.h"
int find_where(unsigned char hash[64], unsigned char besthashlist[NUMKEYS][64]) {
/* Where to insert hash into sorted hashlist */
int j;
int where = -1;
for (j = 0; j < NUMKEYS; ++j) {
if (memcmp(hash, besthashlist[j], 64) > 0) ++where;
else break;
}
return where;
}
void insert_64(unsigned char itemlist[NUMKEYS][64], unsigned char item[64], int where) {
int j;
for (j = 0; j < where; ++j) {
memcpy(itemlist[j], itemlist[j+1], 64);
}
memcpy(itemlist[where], item, 64);
}
void insert_32(unsigned char itemlist[NUMKEYS][32], unsigned char item[32], int where) {
int j;
for (j = 0; j < where; ++j) {
memcpy(itemlist[j], itemlist[j+1], 32);
}
memcpy(itemlist[where], item, 32);
}
void make_addr(unsigned char addr[32], unsigned char hash[64]) {
/* Public key hash to yggdrasil ipv6 address */
int i;
int offset;
unsigned char mask;
unsigned char c;
int ones = 0;
unsigned char br = 0; /* false */
for (i = 0; i < 64 && !br; ++i) {
mask = 128;
c = hash[i];
while (mask) {
if (c & mask) {
++ones;
} else {
br = 1; /* true */
break;
}
mask >>= 1;
}
}
addr[0] = 2;
addr[1] = ones;
offset = ones + 1;
for (i = 0; i < 14; ++i) {
c = hash[offset/8] << (offset%8);
c |= hash[offset/8 + 1] >> (8 - offset%8);
addr[i + 2] = c;
offset += 8;
}
}

View file

@ -0,0 +1,105 @@
/*
sk: 32 random bytes
sk[0] &= 248;
sk[31] &= 127;
sk[31] |= 64;
increment sk
pk = curve25519_scalarmult_base(mysecret)
hash = sha512(pk)
if besthash:
bestsk = sk
besthash = hash
*/
#include "yggdrasil-brute.h"
void seed(unsigned char sk[32]) {
randombytes_buf(sk, 32);
sk[0] &= 248;
sk[31] &= 127;
sk[31] |= 64;
}
int main(int argc, char **argv) {
int i;
int j;
unsigned char addr[16];
time_t starttime;
time_t requestedtime;
unsigned char bestsklist[NUMKEYS][32];
unsigned char bestpklist[NUMKEYS][32];
unsigned char besthashlist[NUMKEYS][64];
unsigned char sk[32];
unsigned char pk[32];
unsigned char hash[64];
unsigned int runs = 0;
int where;
if (argc != 2) {
fprintf(stderr, "usage: ./yggdrasil-brute-multi-curve25519 <seconds>\n");
return 1;
}
if (sodium_init() < 0) {
/* panic! the library couldn't be initialized, it is not safe to use */
printf("sodium init failed!\n");
return 1;
}
starttime = time(NULL);
requestedtime = atoi(argv[1]);
if (requestedtime < 0) requestedtime = 0;
fprintf(stderr, "Searching for yggdrasil curve25519 keys (this will take slightly longer than %ld seconds)\n", requestedtime);
sodium_memzero(bestsklist, NUMKEYS * 32);
sodium_memzero(bestpklist, NUMKEYS * 32);
sodium_memzero(besthashlist, NUMKEYS * 64);
seed(sk);
do {
/* generate pubkey, hash, compare, increment secret.
* this loop should take 4 seconds on modern hardware */
for (i = 0; i < (1 << 16); ++i) {
++runs;
if (crypto_scalarmult_curve25519_base(pk, sk) != 0) {
printf("scalarmult to create pub failed!\n");
return 1;
}
crypto_hash_sha512(hash, pk, 32);
where = find_where(hash, besthashlist);
if (where >= 0) {
insert_32(bestsklist, sk, where);
insert_32(bestpklist, pk, where);
insert_64(besthashlist, hash, where);
seed(sk);
}
for (j = 1; j < 31; ++j) if (++sk[j]) break;
}
} while (time(NULL) - starttime < requestedtime || runs < NUMKEYS);
fprintf(stderr, "--------------addr-------------- -----------------------------secret----------------------------- -----------------------------public-----------------------------\n");
for (i = 0; i < NUMKEYS; ++i) {
make_addr(addr, besthashlist[i]);
for (j = 0; j < 16; ++j) printf("%02x", addr[j]);
printf(" ");
for (j = 0; j < 32; ++j) printf("%02x", bestsklist[i][j]);
printf(" ");
for (j = 0; j < 32; ++j) printf("%02x", bestpklist[i][j]);
printf("\n");
}
sodium_memzero(bestsklist, NUMKEYS * 32);
sodium_memzero(sk, 32);
return 0;
}

View file

@ -0,0 +1,106 @@
/*
seed: 32 random bytes
sk: sha512(seed)
sk[0] &= 248
sk[31] &= 127
sk[31] |= 64
pk: scalarmult_ed25519_base(sk)
increment seed
generate sk
generate pk
hash = sha512(mypub)
if besthash:
bestseed = seed
bestseckey = sk
bestpubkey = pk
besthash = hash
*/
#include "yggdrasil-brute.h"
int main(int argc, char **argv) {
int i;
int j;
time_t starttime;
time_t requestedtime;
unsigned char bestsklist[NUMKEYS][64]; /* sk contains pk */
unsigned char besthashlist[NUMKEYS][64];
unsigned char seed[32];
unsigned char sk[64];
unsigned char pk[32];
unsigned char hash[64];
unsigned int runs = 0;
int where;
if (argc != 2) {
fprintf(stderr, "usage: ./yggdrasil-brute-multi-curve25519 <seconds>\n");
return 1;
}
if (sodium_init() < 0) {
/* panic! the library couldn't be initialized, it is not safe to use */
printf("sodium init failed!\n");
return 1;
}
starttime = time(NULL);
requestedtime = atoi(argv[1]);
if (requestedtime < 0) requestedtime = 0;
fprintf(stderr, "Searching for yggdrasil ed25519 keys (this will take slightly longer than %ld seconds)\n", requestedtime);
sodium_memzero(bestsklist, NUMKEYS * 64);
sodium_memzero(besthashlist, NUMKEYS * 64);
randombytes_buf(seed, 32);
do {
/* generate pubkey, hash, compare, increment secret.
* this loop should take 4 seconds on modern hardware */
for (i = 0; i < (1 << 17); ++i) {
++runs;
crypto_hash_sha512(sk, seed, 32);
if (crypto_scalarmult_ed25519_base(pk, sk) != 0) {
printf("scalarmult to create pub failed!\n");
return 1;
}
memcpy(sk + 32, pk, 32);
crypto_hash_sha512(hash, pk, 32);
/* insert into local list of good key */
where = find_where(hash, besthashlist);
if (where >= 0) {
insert_64(bestsklist, sk, where);
insert_64(besthashlist, hash, where);
randombytes_buf(seed, 32);
}
for (j = 1; j < 31; ++j) if (++seed[j]) break;
}
} while (time(NULL) - starttime < requestedtime || runs < NUMKEYS);
fprintf(stderr, "!! Secret key is seed concatenated with public !!\n");
fprintf(stderr, "---hash--- ------------------------------seed------------------------------ -----------------------------public-----------------------------\n");
for (i = 0; i < NUMKEYS; ++i) {
for (j = 0; j < 5; ++j) printf("%02x", besthashlist[i][j]);
printf(" ");
for (j = 0; j < 32; ++j) printf("%02x", bestsklist[i][j]);
printf(" ");
for (j = 32; j < 64; ++j) printf("%02x", bestsklist[i][j]);
printf("\n");
}
sodium_memzero(bestsklist, NUMKEYS * 64);
sodium_memzero(sk, 64);
sodium_memzero(seed, 32);
return 0;
}

View file

@ -0,0 +1,12 @@
#include <sodium.h>
#include <stdio.h> /* printf */
#include <string.h> /* memcpy */
#include <stdlib.h> /* atoi */
#include <time.h> /* time */
#define NUMKEYS 10
void make_addr(unsigned char addr[32], unsigned char hash[64]);
int find_where(unsigned char hash[64], unsigned char besthashlist[NUMKEYS][64]);
void insert_64(unsigned char itemlist[NUMKEYS][64], unsigned char item[64], int where);
void insert_32(unsigned char itemlist[NUMKEYS][32], unsigned char item[32], int where);

View file

@ -1,148 +0,0 @@
# Yggdasil
Note: This is a very rough early draft.
Yggdrasil is an encrypted IPv6 network running in the [`200::/7` address range](https://en.wikipedia.org/wiki/Unique_local_address).
It is an experimental/toy network, so failure is acceptable, as long as it's instructive to see how it breaks if/when everything falls apart.
IP addresses are derived from cryptographic keys, to reduce the need for public key infrastructure.
A form of locator/identifier separation (similar in goal to [LISP](https://en.wikipedia.org/wiki/Locator/Identifier_Separation_Protocol)) is used to map static identifiers (IP addresses) onto dynamic routing information (locators), using a [distributed hash table](https://en.wikipedia.org/wiki/Distributed_hash_table) (DHT).
Locators are used to approximate the distance between nodes in the network, where the approximate distance is the length of a real worst-case-scenario path through the network.
This is (arguably) easier to secure and requires less information about the network than commonly used routing schemes.
While not technically a [compact routing scheme](https://arxiv.org/abs/0708.2309), tests on real-world networks suggest that routing in this style incurs stretch comparable to the name-dependent compact routing schemes designed for static networks.
Compared to compact routing schemes, Yggdrasil appears to have smaller average routing table sizes, works on dynamic networks, and is name-independent.
It currently lacks the provable bounds of compact routing schemes, and there's a serious argument to be made that it cheats by stretching the definition of some of the above terms, but the main point to be emphasized is that there are trade-offs between different concerns when trying to route traffic, and we'd rather make every part *good* than try to make any one part *perfect*.
In that sense, Yggdrasil seems to be competitive, on what are supposedly realistic networks, with compact routing schemes.
## Addressing
Yggdrasil uses a truncated version of a `NodeID` to assign addresses.
An address is assigned from the `200::/7` prefix, according to the following:
1. Begin with `0x02` as the first byte of the address, or `0x03` if it's a `/64` prefix.
2. Count the number of leading `1` bits in the NodeID.
3. Set the second byte of the address to the number of leading `1` bits in the NodeID (8 bit unsigned integer, at most 255).
4. Append the NodeID to the remaining bits of the address, truncating the leading `1` bits and the first `0` bit, to a total address size of 128 bits.
The last bit of the first byte is used to flag if an address is for a router (`200::/8`), or part of an advertised prefix (`300::/8`), where each router owns a `/64` that matches their address (except with the eight bit set to 1 instead of 0).
This allows the prefix to be advertised to the router's LAN, so unsupported devices can still connect to the network (e.g. network printers).
The NodeID is a [sha512sum](https://en.wikipedia.org/wiki/SHA-512) of a node's public encryption key.
Addresses are checked that they match NodeID, to prevent address spoofing.
As such, while a 128 bit IPv6 address is likely too short to be considered secure by cryptographer standards, there is a significant cost in attempting to cause an address collision.
Addresses can be made more secure by brute force generating a large number of leading `1` bits in the NodeID.
When connecting to a node, the IP address is unpacked into the known bits of the NodeID and a matching bitmask to track which bits are significant.
A node is only communicated with if its `NodeID` matches its public key and the known `NodeID` bits from the address.
It is important to note that only `NodeID` is used internally for routing, so the addressing scheme could in theory be changed without breaking compatibility with intermediate routers.
This has been done once, when moving the address range from the `fd00::/8` ULA range to the reserved-but-[deprecated](https://tools.ietf.org/html/rfc4048) `200::/7` range.
Further addressing scheme changes could occur if, for example, an IPv7 format ever emerges.
### Cryptography
Public key encryption is done using the `golang.org/x/crypto/nacl/box`, which uses [Curve25519](https://en.wikipedia.org/wiki/Curve25519), [XSalsa20](https://en.wikipedia.org/wiki/Salsa20), and [Poly1305](https://en.wikipedia.org/wiki/Poly1305) for key exchange, encryption, and authentication (interoperable with [NaCl](https://en.wikipedia.org/wiki/NaCl_(software))).
Permanent keys are used only for protocol traffic, with random nonces generated on a per-packet basis using `crypto/rand` from Go's standard library.
Ephemeral session keys (for [forward secrecy](https://en.wikipedia.org/wiki/Forward_secrecy)) are generated for encapsulated IPv6 traffic, using the same set of primitives, with random initial nonces that are subsequently incremented.
A list of recently received session nonces is kept (as a bitmask) and checked to reject duplicated packets, in an effort to block duplicate packets and replay attacks.
A separate set of keys are generated and used for signing with [Ed25519](https://en.wikipedia.org/wiki/Ed25519), which is used by the routing layer to secure construction of a spanning tree.
### Prefixes
Recall that each node's address is in the lower half of the address range, I.e. `200::/8`. A `/64` prefix is made available to each node under `300::/8`, where the remaining bits of the prefix match the node's address under `200::/8`.
A node may optionally advertise a prefix on their local area network, which allows unsupported or legacy devices with IPv6 support to connect to the network.
Note that there are 64 fewer bits of `NodeID` available to check in each address from a routing prefix, so it makes sense to brute force a `NodeID` with more significant bits in the address if this approach is to be used.
Running `genkeys.go` will do this by default.
## Locators and Routing
Locators are generated using information from a spanning tree (described below).
The result is that each node has a set of [coordinates in a greedy metric space](https://en.wikipedia.org/wiki/Greedy_embedding).
These coordinates are used as a distance label.
Given the coordinates of any two nodes, it is possible to calculate the length of some real path through the network between the two nodes.
Traffic is forwarded using a [greedy routing](https://en.wikipedia.org/wiki/Small-world_routing#Greedy_routing) scheme, where each node forwards the packet to a one-hop neighbor that is closer to the destination (according to this distance metric) than the current node.
In particular, when a packet needs to be forwarded, a node will forward it to whatever peer is closest to the destination in the greedy [metric space](https://en.wikipedia.org/wiki/Metric_space) used by the network, provided that the peer is closer to the destination than the current node.
If no closer peers are idle, then the packet is queued in FIFO order, with separate queues per destination coords (currently, as a bit of a hack, IPv6 flow labels are embedeed after the end of the significant part of the coords, so queues distinguish between different traffic streams with the same destination).
Whenever the node finishes forwarding a packet to a peer, it checks the queues, and will forward the first packet from the queue with the maximum `<age of first packet>/<queue size in bytes>`, i.e. the bandwidth the queue is attempting to use, subject to the constraint that the peer is a valid next hop (i.e. closer to the destination than the current node).
If no non-empty queue is available, then the peer is added to the idle set, forward packets when the need arises.
This acts as a crude approximation of backpressure routing, where the remote queue sizes are assumed to be equal to the distance of a node from a destination (rather than communicating queue size information), and packets are never forwarded "backwards" through the network, but congestion on a local link is routed around when possible.
The queue selection strategy behaves similar to shortest-queue-first, in that a larger fration of available bandwith to sessions that attempt to use less bandwidth, and is loosely based on the rationale behind some proposed solutions to the [cake-cutting](https://en.wikipedia.org/wiki/Fair_cake-cutting) problem.
The queue size is limited to 4 MB. If a packet is added to a queue and the total size of all queues is larger than this threshold, then a random queue is selected (with odds proportional to relative queue sizes), and the first packet from that queue is dropped, with the process repeated until the total queue size drops below the allowed threshold.
Note that this forwarding procedure generalizes to nodes that are not one-hop neighbors, but the current implementation omits the use of more distant neighbors, as this is expected to be a minor optimization (it would add per-link control traffic to pass path-vector-like information about a subset of the network, which is a lot of overhead compared to the current setup).
### Spanning Tree
A [spanning tree](https://en.wikipedia.org/wiki/Spanning_tree) is constructed with the tree rooted at the highest TreeID, where TreeID is equal to a sha512sum of a node's public [Ed25519](https://en.wikipedia.org/wiki/Ed25519) key (used for signing).
A node sends periodic advertisement messages to each neighbor.
The advertisement contains the coords that match the path from the root through the node, plus one additional hop from the node to the neighbor being advertised to.
Each hop in this advertisement includes a matching ed25519 signature.
These signatures prevent nodes from forging arbitrary routing advertisements.
The first hop, from the root, also includes a sequence number, which must be updated periodically.
A node will blacklist the current root (keeping a record of the last sequence number observed) if the root fails to update for longer than some timeout (currently hard coded at 1 minute).
Normally, a root node will update their sequence number for frequently than this (once every 30 seconds).
Nodes are throttled to ignore updates with a new sequence number for some period after updating their most recently seen sequence number (currently this cooldown is 15 seconds).
The implementation chooses to set the sequence number equal to the unix time on the root's clock, so that a new (higher) sequence number will be selected if the root is restarted and the clock is not set back.
Other than the root node, every other node in the network must select one of its neighbors to use as their parent.
This selection is done by tracking when each neighbor first sends us a message with a new timestamp from the root, to determine the ordering of the latency of each path from the root, to each neighbor, and then to the node that's searching for a parent.
These relative latencies are tracked by, for each neighbor, keeping a score vs each other neighbor.
If a neighbor sends a message with an updated timestamp before another neighbor, then the faster neighbor's score is increased by 1.
If the neighbor sends a message slower, then the score is decreased by 2, to make sure that a node must be reliably faster (at least 2/3 of the time) to see a net score increase over time.
If a node begins to advertise new coordinates, then its score vs all other nodes is reset to 0.
A node switches to a new parent if a neighbor's score (vs the current parent) reaches some threshold, currently 240, which corresponds to about 2 hours of being a reliably faster path.
The intended outcome of this process is that stable connections from fixed infrastructure near the "core" of the network should (eventually) select parents that minimize latency from the root to themselves, while the more dynamic parts of the network, presumably more towards the edges, will try to favor reliability when selecting a parent.
The distance metric between nodes is simply the distance between the nodes if they routed on the spanning tree.
This is equal to the sum of the distance from each node to the last common ancestor of the two nodes being compared.
The locator then consists of a root's key, timestamp, and coordinates representing each hop in the path from the root to the node.
In practice, only the coords are used for routing, while the root and timestamp, along with all the per-hop signatures, are needed to securely construct the spanning tree.
## Name-independent routing
A [Chord](https://en.wikipedia.org/wiki/Chord_(peer-to-peer))-like Distributed Hash Table (DHT) is used as a distributed database that maps NodeIDs onto coordinates in the spanning tree metric space.
The DHT is Chord-like in that it uses a successor/predecessor structure to do lookups in `O(n)` time with `O(1)` entries, then augments this with some additional information, adding roughly `O(logn)` additional entries, to reduce the lookup time to something around `O(logn)`.
In the long term, the idea is to favor spending our bandwidth making sure the minimum `O(1)` part is right, to prioritize correctness, and then try to conserve bandwidth (and power) by being a bit lazy about checking the remaining `O(logn)` portion when it's not in use.
To be specific, the DHT stores the immediate successor of a node, plus the next node it manages to find which is strictly closer (by the tree hop-count metric) than all previous nodes.
The same process is repeated for predecessor nodes, and lookups walk the network in the predecessor direction, with each key being owned by its successor (to make sure defaulting to 0 for unknown bits of a `NodeID` doesn't cause us to overshoot the target during a lookup).
In addition, all of a node's one-hop neighbors are included in the DHT, since we get this information "for free", and we must include it in our DHT to ensure that the network doesn't diverge to a broken state (though I suspect that only adding parents or parent-child relationships may be sufficient -- worth trying to prove or disprove, if somebody's bored).
The DHT differs from Chord in that there are no values in the key:value store -- it only stores information about DHT peers -- and that it uses a [Kademlia](https://en.wikipedia.org/wiki/Kademlia)-inspired iterative-parallel lookup process.
To summarize the entire routing procedure, when given only a node's IP address, the goal is to find a route to the destination.
That happens through 3 steps:
1. The address is unpacked into the known bits of a NodeID and a bitmask to signal which bits of the NodeID are known (the unknown bits are ignored).
2. A DHT search is performed, which normally results in a response from the node closest in the DHT keyspace to the target `NodeID`. The response contains the node's curve25519 public key, which is checked to match the `NodeID` (and therefore the address), as well as the node's coordinates.
3. Using the keys and coords from the above step, an ephemeral key exchange occurs between the source and destination nodes. These ephemeral session keys are used to encrypt any ordinary IPv6 traffic that may be encapsulated and sent between the nodes.
From that point, the session keys and coords are cached and used to encrypt and send traffic between nodes. This is *mostly* transparent to the user: the initial DHT lookup and key exchange takes at least 2 round trips, so there's some delay before session setup completes and normal IPv6 traffic can flow. This is similar to the delay caused by a DNS lookup, although it generally takes longer, as a DHT lookup requires multiple iterations to reach the destination.
## Project Status and Plans
The current (Go) implementation is considered alpha, so compatibility with future versions is neither guaranteed nor expected.
While users are discouraged from running anything truly critical on top of it, as of writing, it seems reliable enough for day-to-day use.
As an "alpha" quality release, Yggdrasil *should* at least be able to detect incompatible versions when it sees them, and warn the users that an update may be needed.
A "beta" quality release should know enough to be compatible in the face of wire format changes, and reasonably feature complete.
A "stable" 1.0 release, if it ever happens, would probably be feature complete, with no expectation of future wire format changes, and free of known critical bugs.
Roughly speaking, there are a few obvious ways the project could turn out:
1. The developers could lose interest before it goes anywhere.
2. The project could be reasonably complete (beta or stable), but never gain a significant number of users.
3. The network may grow large enough that fundamental (non-fixable) design problems appear, which is hopefully a learning experience, but the project may die as a result.
4. The network may grow large, but never hit any design problems, in which case we need to think about either moving the important parts into other projects ([cjdns](https://github.com/cjdelisle/cjdns)) or rewriting compatible implementations that are better optimized for the target platforms (e.g. a linux kernel module).
That last one is probably impossible, because the speed of light would *eventually* become a problem, for a sufficiently large network.
If the only thing limiting network growth turns out to be the underlying physics, then that arguably counts as a win.
Also, note that some design decisions were made for ease-of-programming or ease-of-testing reasons, and likely need to be reconsidered at some point.
In particular, Yggdrasil currently uses TCP for connections with one-hop neighbors, which introduces an additional layer of buffering that can lead to increased and/or unstable latency in congested areas of the network.

@ -1 +0,0 @@
Subproject commit 10672210f2fdce97dd5c301dfeed47284d4a28f2

56
go.mod
View file

@ -1,15 +1,49 @@
module github.com/yggdrasil-network/yggdrasil-go
go 1.22
require (
github.com/docker/libcontainer v2.2.1+incompatible
github.com/gologme/log v0.0.0-20181207131047-4e5d8ccb38e8
github.com/hjson/hjson-go v0.0.0-20181010104306-a25ecf6bd222
github.com/kardianos/minwinsvc v0.0.0-20151122163309-cad6b2b879b0
github.com/mitchellh/mapstructure v1.1.2
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
github.com/Arceliar/ironwood v0.0.0-20241213013129-743fe2fccbd3
github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d
github.com/cheggaaa/pb/v3 v3.1.5
github.com/coder/websocket v1.8.12
github.com/gologme/log v1.3.0
github.com/hashicorp/go-syslog v1.0.0
github.com/hjson/hjson-go/v4 v4.4.0
github.com/kardianos/minwinsvc v1.0.2
github.com/quic-go/quic-go v0.48.2
github.com/vishvananda/netlink v1.3.0
github.com/wlynxg/anet v0.0.5
golang.org/x/crypto v0.33.0
golang.org/x/net v0.35.0
golang.org/x/sys v0.30.0
golang.org/x/text v0.22.0
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173
golang.zx2c4.com/wireguard/windows v0.5.3
)
require (
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/bits-and-blooms/bloom/v3 v3.7.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/onsi/ginkgo/v2 v2.9.5 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
go.uber.org/mock v0.5.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/sync v0.11.0 // indirect
golang.org/x/tools v0.23.0 // indirect
)
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/olekukonko/tablewriter v0.0.5
github.com/vishvananda/netns v0.0.5 // indirect
suah.dev/protect v1.2.4
)

141
go.sum
View file

@ -1,22 +1,119 @@
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/gologme/log v0.0.0-20181207131047-4e5d8ccb38e8 h1:WD8iJ37bRNwvETMfVTusVSAi0WdXTpfNVGY2aHycNKY=
github.com/gologme/log v0.0.0-20181207131047-4e5d8ccb38e8/go.mod h1:gq31gQ8wEHkR+WekdWsqDuf8pXTUZA9BnnzTuPz1Y9U=
github.com/hjson/hjson-go v0.0.0-20181010104306-a25ecf6bd222 h1:xmvkbxXDeN1ffWq8kvrhyqVYAO2aXuRBsbpxVTR+JyU=
github.com/hjson/hjson-go v0.0.0-20181010104306-a25ecf6bd222/go.mod h1:qsetwF8NlsTsOTwZTApNlTCerV+b2GjYRRcIk4JMFio=
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/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=
github.com/Arceliar/ironwood v0.0.0-20241213013129-743fe2fccbd3 h1:d8N0z+udAnbU5PdjpLSNPTWlqeU/nnYsQ42B6+879aw=
github.com/Arceliar/ironwood v0.0.0-20241213013129-743fe2fccbd3/go.mod h1:SrrElc3FFMpYCODSr11jWbLFeOM8WsY+DbDY/l2AXF0=
github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d h1:UK9fsWbWqwIQkMCz1CP+v5pGbsGoWAw6g4AyvMpm1EM=
github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d/go.mod h1:BCnxhRf47C/dy/e/D2pmB8NkB3dQVIrkD98b220rx5Q=
github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
github.com/bits-and-blooms/bitset v1.13.0 h1:bAQ9OPNFYbGHV6Nez0tmNI0RiEu7/hxlYJRUA0wFAVE=
github.com/bits-and-blooms/bitset v1.13.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
github.com/bits-and-blooms/bloom/v3 v3.7.0 h1:VfknkqV4xI+PsaDIsoHueyxVDZrfvMn56jeWUzvzdls=
github.com/bits-and-blooms/bloom/v3 v3.7.0/go.mod h1:VKlUSvp0lFIYqxJjzdnSsZEw4iHb1kOL2tfHTgyJBHg=
github.com/cheggaaa/pb/v3 v3.1.5 h1:QuuUzeM2WsAqG2gMqtzaWithDJv0i+i6UlnwSCI4QLk=
github.com/cheggaaa/pb/v3 v3.1.5/go.mod h1:CrxkeghYTXi1lQBEI7jSn+3svI3cuc19haAj6jM60XI=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo=
github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/gologme/log v1.3.0 h1:l781G4dE+pbigClDSDzSaaYKtiueHCILUa/qSDsmHAo=
github.com/gologme/log v1.3.0/go.mod h1:yKT+DvIPdDdDoPtqFrFxheooyVmoqi0BAsw+erN3wA4=
github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/hashicorp/go-syslog v1.0.0 h1:KaodqZuhUoZereWVIYmpUgZysurB1kBLX2j0MwMrUAE=
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
github.com/hjson/hjson-go/v4 v4.4.0 h1:D/NPvqOCH6/eisTb5/ztuIS8GUvmpHaLOcNk1Bjr298=
github.com/hjson/hjson-go/v4 v4.4.0/go.mod h1:KaYt3bTw3zhBjYqnXkYywcYctk0A2nxeEFTse3rH13E=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/kardianos/minwinsvc v1.0.2 h1:JmZKFJQrmTGa/WiW+vkJXKmfzdjabuEW4Tirj5lLdR0=
github.com/kardianos/minwinsvc v1.0.2/go.mod h1:LUZNYhNmxujx2tR7FbdxqYJ9XDDoCd3MQcl1o//FWl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onsi/ginkgo/v2 v2.9.5 h1:+6Hr4uxzP4XIUyAkg61dWBw8lb/gc4/X5luuxN/EC+Q=
github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3RonqW57k=
github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/quic-go/quic-go v0.48.2 h1:wsKXZPeGWpMpCGSWqOcqpW2wZYic/8T3aqiOID0/KWE=
github.com/quic-go/quic-go v0.48.2/go.mod h1:yBgs3rWBOADpga7F+jJsb6Ybg1LSYiQvwWlLX+/6HMs=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/twmb/murmur3 v1.1.6 h1:mqrRot1BRxm+Yct+vavLMou2/iJt0tNVTTC0QoIjaZg=
github.com/twmb/murmur3 v1.1.6/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ=
github.com/vishvananda/netlink v1.3.0 h1:X7l42GfcV4S6E4vHTsw48qbrV+9PVojNfIhZcwQdrZk=
github.com/vishvananda/netlink v1.3.0/go.mod h1:i6NetklAujEcC6fK0JPjT8qSwWyO0HLn4UKG+hGqeJs=
github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
github.com/vishvananda/netns v0.0.5 h1:DfiHV+j8bA32MFM7bfEunvT8IAqQ/NzSJHtcmW5zdEY=
github.com/vishvananda/netns v0.0.5/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
github.com/wlynxg/anet v0.0.5 h1:J3VJGi1gvo0JwZ/P1/Yc/8p63SoW98B5dHkYDmpgvvU=
github.com/wlynxg/anet v0.0.5/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 h1:B82qJJgjvYKsXS9jeunTOisW56dUokqW/FOteYJJ/yg=
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2/go.mod h1:deeaetjYA+DHMHg+sMSMI58GrEteJUUzzw7en6TJQcI=
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173 h1:/jFs0duh4rdb8uIfPMv78iAJGcPKDeqAFnaLBropIC4=
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173/go.mod h1:tkCQ4FQXmpAgYVh++1cq16/dH4QJtmvpRv19DWGAHSA=
golang.zx2c4.com/wireguard/windows v0.5.3 h1:On6j2Rpn3OEMXqBq00QEDC7bWSZrPIHKIus8eIuExIE=
golang.zx2c4.com/wireguard/windows v0.5.3/go.mod h1:9TEe8TJmtwyQebdFwAkEWOPr3prrtqm+REGFifP60hI=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gvisor.dev/gvisor v0.0.0-20230927004350-cbd86285d259 h1:TbRPT0HtzFP3Cno1zZo7yPzEEnfu8EjLfl6IU9VfqkQ=
gvisor.dev/gvisor v0.0.0-20230927004350-cbd86285d259/go.mod h1:AVgIgHMwK63XvmAzWG9vLQ41YnVHN0du0tEC46fI7yY=
suah.dev/protect v1.2.4 h1:iVZG/zQB63FKNpITDYM/cXoAeCTIjCiXHuFVByJFDzg=
suah.dev/protect v1.2.4/go.mod h1:vVrquYO3u1Ep9Ez2z8x+6N6/czm+TBmWKZfiXU2tb54=

View file

@ -1,131 +0,0 @@
/*
This file generates crypto keys.
It prints out a new set of keys each time if finds a "better" one.
By default, "better" means a higher NodeID (-> higher IP address).
This is because the IP address format can compress leading 1s in the address, to incrase the number of ID bits in the address.
If run with the "-sig" flag, it generates signing keys instead.
A "better" signing key means one with a higher TreeID.
This only matters if it's high enough to make you the root of the tree.
*/
package main
import (
"encoding/hex"
"flag"
"fmt"
"net"
"runtime"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
)
var doSig = flag.Bool("sig", false, "generate new signing keys instead")
type keySet struct {
priv []byte
pub []byte
id []byte
ip string
}
func main() {
threads := runtime.GOMAXPROCS(0)
var threadChannels []chan []byte
var currentBest []byte
newKeys := make(chan keySet, threads)
flag.Parse()
for i := 0; i < threads; i++ {
threadChannels = append(threadChannels, make(chan []byte, threads))
switch {
case *doSig:
go doSigKeys(newKeys, threadChannels[i])
default:
go doBoxKeys(newKeys, threadChannels[i])
}
}
for {
newKey := <-newKeys
if isBetter(currentBest[:], newKey.id[:]) || len(currentBest) == 0 {
currentBest = newKey.id
for _, channel := range threadChannels {
select {
case channel <- newKey.id:
}
}
fmt.Println("--------------------------------------------------------------------------------")
switch {
case *doSig:
fmt.Println("sigPriv:", hex.EncodeToString(newKey.priv[:]))
fmt.Println("sigPub:", hex.EncodeToString(newKey.pub[:]))
fmt.Println("TreeID:", hex.EncodeToString(newKey.id[:]))
default:
fmt.Println("boxPriv:", hex.EncodeToString(newKey.priv[:]))
fmt.Println("boxPub:", hex.EncodeToString(newKey.pub[:]))
fmt.Println("NodeID:", hex.EncodeToString(newKey.id[:]))
fmt.Println("IP:", newKey.ip)
}
}
}
}
func isBetter(oldID, newID []byte) bool {
for idx := range oldID {
if newID[idx] > oldID[idx] {
return true
}
if newID[idx] < oldID[idx] {
return false
}
}
return false
}
func doBoxKeys(out chan<- keySet, in <-chan []byte) {
var bestID crypto.NodeID
for {
select {
case newBestID := <-in:
if isBetter(bestID[:], newBestID) {
copy(bestID[:], newBestID)
}
default:
pub, priv := crypto.NewBoxKeys()
id := crypto.GetNodeID(pub)
if !isBetter(bestID[:], id[:]) {
continue
}
bestID = *id
ip := net.IP(address.AddrForNodeID(id)[:]).String()
out <- keySet{priv[:], pub[:], id[:], ip}
}
}
}
func doSigKeys(out chan<- keySet, in <-chan []byte) {
var bestID crypto.TreeID
for idx := range bestID {
bestID[idx] = 0
}
for {
select {
case newBestID := <-in:
if isBetter(bestID[:], newBestID) {
copy(bestID[:], newBestID)
}
default:
}
pub, priv := crypto.NewSigKeys()
id := crypto.GetTreeID(pub)
if !isBetter(bestID[:], id[:]) {
continue
}
bestID = *id
out <- keySet{priv[:], pub[:], id[:], ""}
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,62 +0,0 @@
import glob
import sys
inputDirPath = sys.argv[1]
inputFilePaths = glob.glob(inputDirPath+"/*")
inputFilePaths.sort()
merged = dict()
stretches = []
total = 0
for inputFilePath in inputFilePaths:
print "Processing file {}".format(inputFilePath)
with open(inputFilePath, 'r') as f:
inData = f.readlines()
pathsChecked = 0.
avgStretch = 0.
for line in inData:
dat = line.rstrip('\n').split(' ')
eHops = int(dat[0])
nHops = int(dat[1])
count = int(dat[2])
if eHops not in merged: merged[eHops] = dict()
if nHops not in merged[eHops]: merged[eHops][nHops] = 0
merged[eHops][nHops] += count
total += count
pathsChecked += count
stretch = float(nHops)/eHops
avgStretch += stretch*count
finStretch = avgStretch / max(1, pathsChecked)
stretches.append(str(finStretch))
hopsUsed = 0.
hopsNeeded = 0.
avgStretch = 0.
results = []
for eHops in sorted(merged.keys()):
for nHops in sorted(merged[eHops].keys()):
count = merged[eHops][nHops]
result = "{} {} {}".format(eHops, nHops, count)
results.append(result)
hopsUsed += nHops*count
hopsNeeded += eHops*count
stretch = float(nHops)/eHops
avgStretch += stretch*count
print result
bandwidthUsage = hopsUsed/max(1, hopsNeeded)
avgStretch /= max(1, total)
with open("results.txt", "w") as f:
f.write('\n'.join(results))
with open("stretches.txt", "w") as f:
f.write('\n'.join(stretches))
print "Total files processed: {}".format(len(inputFilePaths))
print "Total paths found: {}".format(total)
print "Bandwidth usage: {}".format(bandwidthUsage)
print "Average stretch: {}".format(avgStretch)

View file

@ -1,2 +0,0 @@
#!/bin/bash
go run -tags debug misc/sim/treesim.go "$@"

View file

@ -1,901 +0,0 @@
# Tree routing scheme (named Yggdrasil, after the world tree from Norse mythology)
# Steps:
# 1: Pick any node, here I'm using highest nodeID
# 2: Build spanning tree, each node stores path back to root
# Optionally with weights for each hop
# Ties broken by preferring a parent with higher degree
# 3: Distance metric: self->peer + (via tree) peer->dest
# 4: Perform (modified) greedy lookup via this metric for each direction (A->B and B->A)
# 5: Source-route traffic using the better of those two paths
# Note: This makes no attempt to simulate a dynamic network
# E.g. A node's peers cannot be disconnected
# TODO:
# Make better use of drop?
# In particular, we should be ignoring *all* recently dropped *paths* to the root
# To minimize route flapping
# Not really an issue in the sim, but probably needed for a real network
import array
import gc
import glob
import gzip
import heapq
import os
import random
import time
#############
# Constants #
#############
# Reminder of where link cost comes in
LINK_COST = 1
# Timeout before dropping something, in simulated seconds
TIMEOUT = 60
###########
# Classes #
###########
class PathInfo:
def __init__(self, nodeID):
self.nodeID = nodeID # e.g. IP
self.coords = [] # Position in tree
self.tstamp = 0 # Timestamp from sender, to keep track of old vs new info
self.degree = 0 # Number of peers the sender has, used to break ties
# The above should be signed
self.path = [nodeID] # Path to node (in path-vector route)
self.time = 0 # Time info was updated, to keep track of e.g. timeouts
self.treeID = nodeID # Hack, let tree use different ID than IP, used so we can dijkstra once and test many roots
def clone(self):
# Return a deep-enough copy of the path
clone = PathInfo(None)
clone.nodeID = self.nodeID
clone.coords = self.coords[:]
clone.tstamp = self.tstamp
clone.degree = self.degree
clone.path = self.path[:]
clone.time = self.time
clone.treeID = self.treeID
return clone
# End class PathInfo
class Node:
def __init__(self, nodeID):
self.info = PathInfo(nodeID) # Self NodeInfo
self.root = None # PathInfo to node at root of tree
self.drop = dict() # PathInfo to nodes from clus that have timed out
self.peers = dict() # PathInfo to peers
self.links = dict() # Links to peers (to pass messages)
self.msgs = [] # Said messages
self.table = dict() # Pre-computed lookup table of peer info
def tick(self):
# Do periodic maintenance stuff, including push updates
self.info.time += 1
if self.info.time > self.info.tstamp + TIMEOUT/4:
# Update timestamp at least once every 1/4 timeout period
# This should probably be randomized in a real implementation
self.info.tstamp = self.info.time
self.info.degree = 0# TODO decide if degree should be used, len(self.peers)
changed = False # Used to track when the network has converged
changed |= self.cleanRoot()
self.cleanDropped()
# Should probably send messages infrequently if there's nothing new to report
if self.info.tstamp == self.info.time:
msg = self.createMessage()
self.sendMessage(msg)
return changed
def cleanRoot(self):
changed = False
if self.root and self.info.time - self.root.time > TIMEOUT:
print "DEBUG: clean root,", self.root.path
self.drop[self.root.treeID] = self.root
self.root = None
changed = True
if not self.root or self.root.treeID < self.info.treeID:
# No need to drop someone who'se worse than us
self.info.coords = [self.info.nodeID]
self.root = self.info.clone()
changed = True
elif self.root.treeID == self.info.treeID:
self.root = self.info.clone()
return changed
def cleanDropped(self):
# May actually be a treeID... better to iterate over keys explicitly
nodeIDs = sorted(self.drop.keys())
for nodeID in nodeIDs:
node = self.drop[nodeID]
if self.info.time - node.time > 4*TIMEOUT:
del self.drop[nodeID]
return None
def createMessage(self):
# Message is just a tuple
# First element is the sender
# Second element is the root
# We will .clone() everything during the send operation
msg = (self.info, self.root)
return msg
def sendMessage(self, msg):
for link in self.links.values():
newMsg = (msg[0].clone(), msg[1].clone())
link.msgs.append(newMsg)
return None
def handleMessages(self):
changed = False
while self.msgs:
changed |= self.handleMessage(self.msgs.pop())
return changed
def handleMessage(self, msg):
changed = False
for node in msg:
# Update the path and timestamp for the sender and root info
node.path.append(self.info.nodeID)
node.time = self.info.time
# Update the sender's info in our list of peers
sender = msg[0]
self.peers[sender.nodeID] = sender
# Decide if we want to update the root
root = msg[1]
updateRoot = False
isSameParent = False
isBetterParent = False
if len(self.root.path) > 1 and len(root.path) > 1:
parent = self.peers[self.root.path[-2]]
if parent.nodeID == sender.nodeID: isSameParent = True
if sender.degree > parent.degree:
# This would also be where you check path uptime/reliability/whatever
# All else being equal, we prefer parents with high degree
# We are trusting peers to report degree correctly in this case
# So expect some performance reduction if your peers aren't trustworthy
# (Lies can increase average stretch by a few %)
isBetterParent = True
if self.info.nodeID in root.path[:-1]: pass # No loopy routes allowed
elif root.treeID in self.drop and self.drop[root.treeID].tstamp >= root.tstamp: pass
elif not self.root: updateRoot = True
elif self.root.treeID < root.treeID: updateRoot = True
elif self.root.treeID != root.treeID: pass
elif self.root.tstamp > root.tstamp: pass
elif len(root.path) < len(self.root.path): updateRoot = True
elif isBetterParent and len(root.path) == len(self.root.path): updateRoot = True
elif isSameParent and self.root.tstamp < root.tstamp: updateRoot = True
if updateRoot:
if not self.root or self.root.path != root.path: changed = True
self.root = root
self.info.coords = self.root.path
return changed
def lookup(self, dest):
# Note: Can loop in an unconverged network
# The person looking up the route is responsible for checking for loops
best = None
bestDist = 0
for node in self.peers.itervalues():
# dist = distance to node + dist (on tree) from node to dest
dist = len(node.path)-1 + treeDist(node.coords, dest.coords)
if not best or dist < bestDist:
best = node
bestDist = dist
if best:
next = best.path[-2]
assert next in self.peers
return next
else:
# We failed to look something up
# TODO some way to signal this which doesn't crash
assert False
def initTable(self):
# Pre-computes a lookup table for destination coords
# Insert parent first so you prefer them as a next-hop
self.table.clear()
parent = self.info.nodeID
if len(self.info.coords) >= 2: parent = self.info.coords[-2]
for peer in self.peers.itervalues():
current = self.table
for coord in peer.coords:
if coord not in current: current[coord] = (peer.nodeID, dict())
old = current[coord]
next = old[1]
oldPeer = self.peers[old[0]]
oldDist = len(oldPeer.coords)
oldDeg = oldPeer.degree
newDist = len(peer.coords)
newDeg = peer.degree
# Prefer parent
# Else prefer short distance from root
# If equal distance, prefer high degree
if peer.nodeID == parent: current[coord] = (peer.nodeID, next)
elif newDist < oldDist: current[coord] = (peer.nodeID, next)
elif newDist == oldDist and newDeg > oldDeg: current[coord] = (peer.nodeID, next)
current = next
return None
def lookup_new(self, dest):
# Use pre-computed lookup table to look up next hop for dest coords
assert self.table
if len(self.info.coords) >= 2: parent = self.info.coords[-2]
else: parent = None
current = (parent, self.table)
c = None
for coord in dest.coords:
c = coord
if coord not in current[1]: break
current = current[1][coord]
next = current[0]
if c in self.peers: next = c
if next not in self.peers:
assert next == None
# You're the root of a different connected component
# You'd drop the packet in this case
# To make the path cache not die, need to return a valid next hop...
# Returning self for that reason
next = self.info.nodeID
return next
# End class Node
####################
# Helper Functions #
####################
def getIndexOfLCA(source, dest):
# Return index of last common ancestor in source/dest coords
# -1 if no common ancestor (e.g. different roots)
lcaIdx = -1
minLen = min(len(source), len(dest))
for idx in xrange(minLen):
if source[idx] == dest[idx]: lcaIdx = idx
else: break
return lcaIdx
def treePath(source, dest):
# Return path with source at head and dest at tail
lastMatch = getIndexOfLCA(source, dest)
path = dest[-1:lastMatch:-1] + source[lastMatch:]
assert path[0] == dest[-1]
assert path[-1] == source[-1]
return path
def treeDist(source, dest):
dist = len(source) + len(dest)
lcaIdx = getIndexOfLCA(source, dest)
dist -= 2*(lcaIdx+1)
return dist
def dijkstra(nodestore, startingNodeID):
# Idea to use heapq and basic implementation taken from stackexchange post
# http://codereview.stackexchange.com/questions/79025/dijkstras-algorithm-in-python
nodeIDs = sorted(nodestore.keys())
nNodes = len(nodeIDs)
idxs = dict()
for nodeIdx in xrange(nNodes):
nodeID = nodeIDs[nodeIdx]
idxs[nodeID] = nodeIdx
dists = array.array("H", [0]*nNodes)
queue = [(0, startingNodeID)]
while queue:
dist, nodeID = heapq.heappop(queue)
idx = idxs[nodeID]
if not dists[idx]: # Unvisited, otherwise we skip it
dists[idx] = dist
for peer in nodestore[nodeID].links:
if not dists[idxs[peer]]:
# Peer is also unvisited, so add to queue
heapq.heappush(queue, (dist+LINK_COST, peer))
return dists
def dijkstrall(nodestore):
# Idea to use heapq and basic implementation taken from stackexchange post
# http://codereview.stackexchange.com/questions/79025/dijkstras-algorithm-in-python
nodeIDs = sorted(nodestore.keys())
nNodes = len(nodeIDs)
idxs = dict()
for nodeIdx in xrange(nNodes):
nodeID = nodeIDs[nodeIdx]
idxs[nodeID] = nodeIdx
dists = array.array("H", [0]*nNodes*nNodes) # use GetCacheIndex(nNodes, start, end)
for sourceIdx in xrange(nNodes):
print "Finding shortest paths for node {} / {} ({})".format(sourceIdx+1, nNodes, nodeIDs[sourceIdx])
queue = [(0, sourceIdx)]
while queue:
dist, nodeIdx = heapq.heappop(queue)
distIdx = getCacheIndex(nNodes, sourceIdx, nodeIdx)
if not dists[distIdx]: # Unvisited, otherwise we skip it
dists[distIdx] = dist
for peer in nodestore[nodeIDs[nodeIdx]].links:
pIdx = idxs[peer]
pdIdx = getCacheIndex(nNodes, sourceIdx, pIdx)
if not dists[pdIdx]:
# Peer is also unvisited, so add to queue
heapq.heappush(queue, (dist+LINK_COST, pIdx))
return dists
def linkNodes(node1, node2):
node1.links[node2.info.nodeID] = node2
node2.links[node1.info.nodeID] = node1
############################
# Store topology functions #
############################
def makeStoreSquareGrid(sideLength, randomize=True):
# Simple grid in a sideLength*sideLength square
# Just used to validate that the code runs
store = dict()
nodeIDs = list(range(sideLength*sideLength))
if randomize: random.shuffle(nodeIDs)
for nodeID in nodeIDs:
store[nodeID] = Node(nodeID)
for index in xrange(len(nodeIDs)):
if (index % sideLength != 0): linkNodes(store[nodeIDs[index]], store[nodeIDs[index-1]])
if (index >= sideLength): linkNodes(store[nodeIDs[index]], store[nodeIDs[index-sideLength]])
print "Grid store created, size {}".format(len(store))
return store
def makeStoreASRelGraph(pathToGraph):
#Existing network graphs, in caida.org's asrel format (ASx|ASy|z per line, z denotes relationship type)
with open(pathToGraph, "r") as f:
inData = f.readlines()
store = dict()
for line in inData:
if line.strip()[0] == "#": continue # Skip comment lines
line = line.replace('|'," ")
nodes = map(int, line.split()[0:2])
if nodes[0] not in store: store[nodes[0]] = Node(nodes[0])
if nodes[1] not in store: store[nodes[1]] = Node(nodes[1])
linkNodes(store[nodes[0]], store[nodes[1]])
print "CAIDA AS-relation graph successfully imported, size {}".format(len(store))
return store
def makeStoreASRelGraphMaxDeg(pathToGraph, degIdx=0):
with open(pathToGraph, "r") as f:
inData = f.readlines()
store = dict()
nodeDeg = dict()
for line in inData:
if line.strip()[0] == "#": continue # Skip comment lines
line = line.replace('|'," ")
nodes = map(int, line.split()[0:2])
if nodes[0] not in nodeDeg: nodeDeg[nodes[0]] = 0
if nodes[1] not in nodeDeg: nodeDeg[nodes[1]] = 0
nodeDeg[nodes[0]] += 1
nodeDeg[nodes[1]] += 1
sortedNodes = sorted(nodeDeg.keys(), \
key=lambda x: (nodeDeg[x], x), \
reverse=True)
maxDegNodeID = sortedNodes[degIdx]
return makeStoreASRelGraphFixedRoot(pathToGraph, maxDegNodeID)
def makeStoreASRelGraphFixedRoot(pathToGraph, rootNodeID):
with open(pathToGraph, "r") as f:
inData = f.readlines()
store = dict()
for line in inData:
if line.strip()[0] == "#": continue # Skip comment lines
line = line.replace('|'," ")
nodes = map(int, line.split()[0:2])
if nodes[0] not in store:
store[nodes[0]] = Node(nodes[0])
if nodes[0] == rootNodeID: store[nodes[0]].info.treeID += 1000000000
if nodes[1] not in store:
store[nodes[1]] = Node(nodes[1])
if nodes[1] == rootNodeID: store[nodes[1]].info.treeID += 1000000000
linkNodes(store[nodes[0]], store[nodes[1]])
print "CAIDA AS-relation graph successfully imported, size {}".format(len(store))
return store
def makeStoreDimesEdges(pathToGraph, rootNodeID=None):
# Read from a DIMES csv-formatted graph from a gzip file
store = dict()
with gzip.open(pathToGraph, "r") as f:
inData = f.readlines()
size = len(inData)
index = 0
for edge in inData:
if not index % 1000:
pct = 100.0*index/size
print "Processing edge {}, {:.2f}%".format(index, pct)
index += 1
dat = edge.rstrip().split(',')
node1 = "N" + str(dat[0].strip())
node2 = "N" + str(dat[1].strip())
if '?' in node1 or '?' in node2: continue #Unknown node
if node1 == rootNodeID: node1 = "R" + str(dat[0].strip())
if node2 == rootNodeID: node2 = "R" + str(dat[1].strip())
if node1 not in store: store[node1] = Node(node1)
if node2 not in store: store[node2] = Node(node2)
if node1 != node2: linkNodes(store[node1], store[node2])
print "DIMES graph successfully imported, size {}".format(len(store))
return store
def makeStoreGeneratedGraph(pathToGraph, root=None):
with open(pathToGraph, "r") as f:
inData = f.readlines()
store = dict()
for line in inData:
if line.strip()[0] == "#": continue # Skip comment lines
nodes = map(int, line.strip().split(' ')[0:2])
node1 = nodes[0]
node2 = nodes[1]
if node1 == root: node1 += 1000000
if node2 == root: node2 += 1000000
if node1 not in store: store[node1] = Node(node1)
if node2 not in store: store[node2] = Node(node2)
linkNodes(store[node1], store[node2])
print "Generated graph successfully imported, size {}".format(len(store))
return store
############################################
# Functions used as parts of network tests #
############################################
def idleUntilConverged(store):
nodeIDs = sorted(store.keys())
timeOfLastChange = 0
step = 0
# Idle until the network has converged
while step - timeOfLastChange < 4*TIMEOUT:
step += 1
print "Step: {}, last change: {}".format(step, timeOfLastChange)
changed = False
for nodeID in nodeIDs:
# Update node status, send messages
changed |= store[nodeID].tick()
for nodeID in nodeIDs:
# Process messages
changed |= store[nodeID].handleMessages()
if changed: timeOfLastChange = step
initTables(store)
return store
def getCacheIndex(nodes, sourceIndex, destIndex):
return sourceIndex*nodes + destIndex
def initTables(store):
nodeIDs = sorted(store.keys())
nNodes = len(nodeIDs)
print "Initializing routing tables for {} nodes".format(nNodes)
for idx in xrange(nNodes):
nodeID = nodeIDs[idx]
store[nodeID].initTable()
print "Routing tables initialized"
return None
def getCache(store):
nodeIDs = sorted(store.keys())
nNodes = len(nodeIDs)
nodeIdxs = dict()
for nodeIdx in xrange(nNodes):
nodeIdxs[nodeIDs[nodeIdx]] = nodeIdx
cache = array.array("H", [0]*nNodes*nNodes)
for sourceIdx in xrange(nNodes):
sourceID = nodeIDs[sourceIdx]
print "Building fast lookup table for node {} / {} ({})".format(sourceIdx+1, nNodes, sourceID)
for destIdx in xrange(nNodes):
destID = nodeIDs[destIdx]
if sourceID == destID: nextHop = destID # lookup would fail
else: nextHop = store[sourceID].lookup(store[destID].info)
nextHopIdx = nodeIdxs[nextHop]
cache[getCacheIndex(nNodes, sourceIdx, destIdx)] = nextHopIdx
return cache
def testPaths(store, dists):
cache = getCache(store)
nodeIDs = sorted(store.keys())
nNodes = len(nodeIDs)
idxs = dict()
for nodeIdx in xrange(nNodes):
nodeID = nodeIDs[nodeIdx]
idxs[nodeID] = nodeIdx
results = dict()
for sourceIdx in xrange(nNodes):
sourceID = nodeIDs[sourceIdx]
print "Testing paths from node {} / {} ({})".format(sourceIdx+1, len(nodeIDs), sourceID)
#dists = dijkstra(store, sourceID)
for destIdx in xrange(nNodes):
destID = nodeIDs[destIdx]
if destID == sourceID: continue # Skip self
distIdx = getCacheIndex(nNodes, sourceIdx, destIdx)
eHops = dists[distIdx]
if not eHops: continue # The network is split, no path exists
hops = 0
for pair in ((sourceIdx, destIdx),):
nHops = 0
locIdx = pair[0]
dIdx = pair[1]
while locIdx != dIdx:
locIdx = cache[getCacheIndex(nNodes, locIdx, dIdx)]
nHops += 1
if not hops or nHops < hops: hops = nHops
if eHops not in results: results[eHops] = dict()
if hops not in results[eHops]: results[eHops][hops] = 0
results[eHops][hops] += 1
return results
def getAvgStretch(pathMatrix):
avgStretch = 0.
checked = 0.
for eHops in sorted(pathMatrix.keys()):
for nHops in sorted(pathMatrix[eHops].keys()):
count = pathMatrix[eHops][nHops]
stretch = float(nHops)/float(max(1, eHops))
avgStretch += stretch*count
checked += count
avgStretch /= max(1, checked)
return avgStretch
def getMaxStretch(pathMatrix):
maxStretch = 0.
for eHops in sorted(pathMatrix.keys()):
for nHops in sorted(pathMatrix[eHops].keys()):
stretch = float(nHops)/float(max(1, eHops))
maxStretch = max(maxStretch, stretch)
return maxStretch
def getCertSizes(store):
# Returns nCerts frequency distribution
# De-duplicates common certs (for shared prefixes in the path)
sizes = dict()
for node in store.values():
certs = set()
for peer in node.peers.values():
pCerts = set()
assert len(peer.path) == 2
assert peer.coords[-1] == peer.path[0]
hops = peer.coords + peer.path[1:]
for hopIdx in xrange(len(hops)-1):
send = hops[hopIdx]
if send == node.info.nodeID: continue # We created it, already have it
path = hops[0:hopIdx+2]
# Each cert is signed by the sender
# Includes information about the path from the sender to the next hop
# Next hop is at hopIdx+1, so the path to next hop is hops[0:hopIdx+2]
cert = "{}:{}".format(send, path)
certs.add(cert)
size = len(certs)
if size not in sizes: sizes[size] = 0
sizes[size] += 1
return sizes
def getMinLinkCertSizes(store):
# Returns nCerts frequency distribution
# De-duplicates common certs (for shared prefixes in the path)
# Based on the minimum number of certs that must be traded through a particular link
# Handled per link
sizes = dict()
for node in store.values():
peerCerts = dict()
for peer in node.peers.values():
pCerts = set()
assert len(peer.path) == 2
assert peer.coords[-1] == peer.path[0]
hops = peer.coords + peer.path[1:]
for hopIdx in xrange(len(hops)-1):
send = hops[hopIdx]
if send == node.info.nodeID: continue # We created it, already have it
path = hops[0:hopIdx+2]
# Each cert is signed by the sender
# Includes information about the path from the sender to the next hop
# Next hop is at hopIdx+1, so the path to next hop is hops[0:hopIdx+2]
cert = "{}:{}".format(send, path)
pCerts.add(cert)
peerCerts[peer.nodeID] = pCerts
for peer in peerCerts:
size = 0
pCerts = peerCerts[peer]
for cert in pCerts:
required = True
for p2 in peerCerts:
if p2 == peer: continue
p2Certs = peerCerts[p2]
if cert in p2Certs: required = False
if required: size += 1
if size not in sizes: sizes[size] = 0
sizes[size] += 1
return sizes
def getPathSizes(store):
# Returns frequency distribution of the total number of hops the routing table
# I.e. a node with 3 peers, each with 5 hop coord+path, would count as 3x5=15
sizes = dict()
for node in store.values():
size = 0
for peer in node.peers.values():
assert len(peer.path) == 2
assert peer.coords[-1] == peer.path[0]
peerSize = len(peer.coords) + len(peer.path) - 1 # double-counts peer, -1
size += peerSize
if size not in sizes: sizes[size] = 0
sizes[size] += 1
return sizes
def getPeerSizes(store):
# Returns frequency distribution of the number of peers each node has
sizes = dict()
for node in store.values():
nPeers = len(node.peers)
if nPeers not in sizes: sizes[nPeers] = 0
sizes[nPeers] += 1
return sizes
def getAvgSize(sizes):
sumSizes = 0
nNodes = 0
for size in sizes:
count = sizes[size]
sumSizes += size*count
nNodes += count
avgSize = float(sumSizes)/max(1, nNodes)
return avgSize
def getMaxSize(sizes):
return max(sizes.keys())
def getMinSize(sizes):
return min(sizes.keys())
def getResults(pathMatrix):
results = []
for eHops in sorted(pathMatrix.keys()):
for nHops in sorted(pathMatrix[eHops].keys()):
count = pathMatrix[eHops][nHops]
results.append("{} {} {}".format(eHops, nHops, count))
return '\n'.join(results)
####################################
# Functions to run different tests #
####################################
def runTest(store):
# Runs the usual set of tests on the store
# Does not save results, so only meant for quick tests
# To e.g. check the code works, maybe warm up the pypy jit
for node in store.values():
node.info.time = random.randint(0, TIMEOUT)
node.info.tstamp = TIMEOUT
print "Begin testing network"
dists = None
if not dists: dists = dijkstrall(store)
idleUntilConverged(store)
pathMatrix = testPaths(store, dists)
avgStretch = getAvgStretch(pathMatrix)
maxStretch = getMaxStretch(pathMatrix)
peers = getPeerSizes(store)
certs = getCertSizes(store)
paths = getPathSizes(store)
linkCerts = getMinLinkCertSizes(store)
avgPeerSize = getAvgSize(peers)
maxPeerSize = getMaxSize(peers)
avgCertSize = getAvgSize(certs)
maxCertSize = getMaxSize(certs)
avgPathSize = getAvgSize(paths)
maxPathSize = getMaxSize(paths)
avgLinkCert = getAvgSize(linkCerts)
maxLinkCert = getMaxSize(linkCerts)
totalCerts = sum(map(lambda x: x*certs[x], certs.keys()))
totalLinks = sum(map(lambda x: x*peers[x], peers.keys())) # one-way links
avgCertsPerLink = float(totalCerts)/max(1, totalLinks)
print "Finished testing network"
print "Avg / Max stretch: {} / {}".format(avgStretch, maxStretch)
print "Avg / Max nPeers size: {} / {}".format(avgPeerSize, maxPeerSize)
print "Avg / Max nCerts size: {} / {}".format(avgCertSize, maxCertSize)
print "Avg / Max total hops in any node's routing table: {} / {}".format(avgPathSize, maxPathSize)
print "Avg / Max lower bound cert requests per link (one-way): {} / {}".format(avgLinkCert, maxLinkCert)
print "Avg certs per link (one-way): {}".format(avgCertsPerLink)
return # End of function
def rootNodeASTest(path, outDir="output-treesim-AS", dists=None, proc = 1):
# Checks performance for every possible choice of root node
# Saves output for each root node to a separate file on disk
# path = input path to some caida.org formatted AS-relationship graph
if not os.path.exists(outDir): os.makedirs(outDir)
assert os.path.exists(outDir)
store = makeStoreASRelGraph(path)
nodes = sorted(store.keys())
for nodeIdx in xrange(len(nodes)):
if nodeIdx % proc != 0: continue # Work belongs to someone else
rootNodeID = nodes[nodeIdx]
outpath = outDir+"/{}".format(rootNodeID)
if os.path.exists(outpath):
print "Skipping {}, already processed".format(rootNodeID)
continue
store = makeStoreASRelGraphFixedRoot(path, rootNodeID)
for node in store.values():
node.info.time = random.randint(0, TIMEOUT)
node.info.tstamp = TIMEOUT
print "Beginning {}, size {}".format(nodeIdx, len(store))
if not dists: dists = dijkstrall(store)
idleUntilConverged(store)
pathMatrix = testPaths(store, dists)
avgStretch = getAvgStretch(pathMatrix)
maxStretch = getMaxStretch(pathMatrix)
results = getResults(pathMatrix)
with open(outpath, "w") as f:
f.write(results)
print "Finished test for root AS {} ({} / {})".format(rootNodeID, nodeIdx+1, len(store))
print "Avg / Max stretch: {} / {}".format(avgStretch, maxStretch)
#break # Stop after 1, because they can take forever
return # End of function
def timelineASTest():
# Meant to study the performance of the network as a function of network size
# Loops over a set of AS-relationship graphs
# Runs a test on each graph, selecting highest-degree node as the root
# Saves results for each graph to a separate file on disk
outDir = "output-treesim-timeline-AS"
if not os.path.exists(outDir): os.makedirs(outDir)
assert os.path.exists(outDir)
paths = sorted(glob.glob("asrel/datasets/*"))
for path in paths:
date = os.path.basename(path).split(".")[0]
outpath = outDir+"/{}".format(date)
if os.path.exists(outpath):
print "Skipping {}, already processed".format(date)
continue
store = makeStoreASRelGraphMaxDeg(path)
dists = None
for node in store.values():
node.info.time = random.randint(0, TIMEOUT)
node.info.tstamp = TIMEOUT
print "Beginning {}, size {}".format(date, len(store))
if not dists: dists = dijkstrall(store)
idleUntilConverged(store)
pathMatrix = testPaths(store, dists)
avgStretch = getAvgStretch(pathMatrix)
maxStretch = getMaxStretch(pathMatrix)
results = getResults(pathMatrix)
with open(outpath, "w") as f:
f.write(results)
print "Finished {} with {} nodes".format(date, len(store))
print "Avg / Max stretch: {} / {}".format(avgStretch, maxStretch)
#break # Stop after 1, because they can take forever
return # End of function
def timelineDimesTest():
# Meant to study the performance of the network as a function of network size
# Loops over a set of AS-relationship graphs
# Runs a test on each graph, selecting highest-degree node as the root
# Saves results for each graph to a separate file on disk
outDir = "output-treesim-timeline-dimes"
if not os.path.exists(outDir): os.makedirs(outDir)
assert os.path.exists(outDir)
# Input files are named ASEdgesX_Y where X = month (no leading 0), Y = year
paths = sorted(glob.glob("DIMES/ASEdges/*.gz"))
exists = set(glob.glob(outDir+"/*"))
for path in paths:
date = os.path.basename(path).split(".")[0]
outpath = outDir+"/{}".format(date)
if outpath in exists:
print "Skipping {}, already processed".format(date)
continue
store = makeStoreDimesEdges(path)
# Get the highest degree node and make it root
# Sorted by nodeID just to make it stable in the event of a tie
nodeIDs = sorted(store.keys())
bestRoot = ""
bestDeg = 0
for nodeID in nodeIDs:
node = store[nodeID]
if len(node.links) > bestDeg:
bestRoot = nodeID
bestDeg = len(node.links)
assert bestRoot
store = makeStoreDimesEdges(path, bestRoot)
rootID = "R" + bestRoot[1:]
assert rootID in store
# Don't forget to set random seed before setitng times
# To make results reproducible
nodeIDs = sorted(store.keys())
random.seed(12345)
for nodeID in nodeIDs:
node = store[nodeID]
node.info.time = random.randint(0, TIMEOUT)
node.info.tstamp = TIMEOUT
print "Beginning {}, size {}".format(date, len(store))
if not dists: dists = dijkstrall(store)
idleUntilConverged(store)
pathMatrix = testPaths(store, dists)
avgStretch = getAvgStretch(pathMatrix)
maxStretch = getMaxStretch(pathMatrix)
results = getResults(pathMatrix)
with open(outpath, "w") as f:
f.write(results)
print "Finished {} with {} nodes".format(date, len(store))
print "Avg / Max stretch: {} / {}".format(avgStretch, maxStretch)
break # Stop after 1, because they can take forever
return # End of function
def scalingTest(maxTests=None, inputDir="graphs"):
# Meant to study the performance of the network as a function of network size
# Loops over a set of nodes in a previously generated graph
# Runs a test on each graph, testing each node as the root
# if maxTests is set, tests only that number of roots (highest degree first)
# Saves results for each graph to a separate file on disk
outDir = "output-treesim-{}".format(inputDir)
if not os.path.exists(outDir): os.makedirs(outDir)
assert os.path.exists(outDir)
paths = sorted(glob.glob("{}/*".format(inputDir)))
exists = set(glob.glob(outDir+"/*"))
for path in paths:
gc.collect() # pypy waits for gc to close files
graph = os.path.basename(path).split(".")[0]
store = makeStoreGeneratedGraph(path)
# Get the highest degree node and make it root
# Sorted by nodeID just to make it stable in the event of a tie
nodeIDs = sorted(store.keys(), key=lambda x: len(store[x].links), reverse=True)
dists = None
if maxTests: nodeIDs = nodeIDs[:maxTests]
for nodeID in nodeIDs:
nodeIDStr = str(nodeID).zfill(len(str(len(store)-1)))
outpath = outDir+"/{}-{}".format(graph, nodeIDStr)
if outpath in exists:
print "Skipping {}-{}, already processed".format(graph, nodeIDStr)
continue
store = makeStoreGeneratedGraph(path, nodeID)
# Don't forget to set random seed before setting times
random.seed(12345) # To make results reproducible
nIDs = sorted(store.keys())
for nID in nIDs:
node = store[nID]
node.info.time = random.randint(0, TIMEOUT)
node.info.tstamp = TIMEOUT
print "Beginning {}, size {}".format(graph, len(store))
if not dists: dists = dijkstrall(store)
idleUntilConverged(store)
pathMatrix = testPaths(store, dists)
avgStretch = getAvgStretch(pathMatrix)
maxStretch = getMaxStretch(pathMatrix)
results = getResults(pathMatrix)
with open(outpath, "w") as f:
f.write(results)
print "Finished {} with {} nodes for root {}".format(graph, len(store), nodeID)
print "Avg / Max stretch: {} / {}".format(avgStretch, maxStretch)
return # End of function
##################
# Main Execution #
##################
if __name__ == "__main__":
if True: # Run a quick test
random.seed(12345) # DEBUG
store = makeStoreSquareGrid(4)
runTest(store) # Quick test
store = None
# Do some real work
#runTest(makeStoreDimesEdges("DIMES/ASEdges/ASEdges1_2007.csv.gz"))
#timelineDimesTest()
#rootNodeASTest("asrel/datasets/19980101.as-rel.txt")
#timelineASTest()
#rootNodeASTest("hype-2016-09-19.list", "output-treesim-hype")
#scalingTest(None, "graphs-20") # First argument 1 to only test 1 root per graph
#store = makeStoreGeneratedGraph("bgp_tables")
#store = makeStoreGeneratedGraph("skitter")
#store = makeStoreASRelGraphMaxDeg("hype-2016-09-19.list") #http://hia.cjdns.ca/watchlist/c/walk.peers.20160919
#store = makeStoreGeneratedGraph("fc00-2017-08-12.txt")
if store: runTest(store)
#rootNodeASTest("skitter", "output-treesim-skitter", None, 0, 1)
#scalingTest(1, "graphs-20") # First argument 1 to only test 1 root per graph
#scalingTest(1, "graphs-21") # First argument 1 to only test 1 root per graph
#scalingTest(1, "graphs-22") # First argument 1 to only test 1 root per graph
#scalingTest(1, "graphs-23") # First argument 1 to only test 1 root per graph
if not store:
import sys
args = sys.argv
if len(args) == 2:
job_number = int(sys.argv[1])
rootNodeASTest("fc00-2017-08-12.txt", "fc00", None, job_number)
else:
print "Usage: {} job_number".format(args[0])
print "job_number = which job set to run on this node (1-indexed)"

View file

@ -1,455 +0,0 @@
package main
import "fmt"
import "bufio"
import "os"
import "strings"
import "strconv"
import "time"
import "runtime"
import "runtime/pprof"
import "flag"
import "github.com/gologme/log"
import . "github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil"
import . "github.com/yggdrasil-network/yggdrasil-go/src/crypto"
////////////////////////////////////////////////////////////////////////////////
type Node struct {
index int
core Core
send chan<- []byte
recv <-chan []byte
}
func (n *Node) init(index int) {
n.index = index
n.core.Init()
n.send = n.core.DEBUG_getSend()
n.recv = n.core.DEBUG_getRecv()
n.core.DEBUG_simFixMTU()
}
func (n *Node) printTraffic() {
for {
packet := <-n.recv
fmt.Println(n.index, packet)
//panic("Got a packet")
}
}
func (n *Node) startPeers() {
//for _, p := range n.core.Peers.Ports {
// go p.MainLoop()
//}
//go n.printTraffic()
//n.core.Peers.DEBUG_startPeers()
}
func linkNodes(m, n *Node) {
// Don't allow duplicates
if m.core.DEBUG_getPeers().DEBUG_hasPeer(n.core.DEBUG_getSigningPublicKey()) {
return
}
// Create peers
// Buffering reduces packet loss in the sim
// This slightly speeds up testing (fewer delays before retrying a ping)
pLinkPub, pLinkPriv := m.core.DEBUG_newBoxKeys()
qLinkPub, qLinkPriv := m.core.DEBUG_newBoxKeys()
p := m.core.DEBUG_getPeers().DEBUG_newPeer(n.core.DEBUG_getEncryptionPublicKey(),
n.core.DEBUG_getSigningPublicKey(), *m.core.DEBUG_getSharedKey(pLinkPriv, qLinkPub))
q := n.core.DEBUG_getPeers().DEBUG_newPeer(m.core.DEBUG_getEncryptionPublicKey(),
m.core.DEBUG_getSigningPublicKey(), *n.core.DEBUG_getSharedKey(qLinkPriv, pLinkPub))
DEBUG_simLinkPeers(p, q)
return
}
func makeStoreSquareGrid(sideLength int) map[int]*Node {
store := make(map[int]*Node)
nNodes := sideLength * sideLength
idxs := make([]int, 0, nNodes)
// TODO shuffle nodeIDs
for idx := 1; idx <= nNodes; idx++ {
idxs = append(idxs, idx)
}
for _, idx := range idxs {
node := &Node{}
node.init(idx)
store[idx] = node
}
for idx := 0; idx < nNodes; idx++ {
if (idx % sideLength) != 0 {
linkNodes(store[idxs[idx]], store[idxs[idx-1]])
}
if idx >= sideLength {
linkNodes(store[idxs[idx]], store[idxs[idx-sideLength]])
}
}
//for _, node := range store { node.initPorts() }
return store
}
func makeStoreStar(nNodes int) map[int]*Node {
store := make(map[int]*Node)
center := &Node{}
center.init(0)
store[0] = center
for idx := 1; idx < nNodes; idx++ {
node := &Node{}
node.init(idx)
store[idx] = node
linkNodes(center, node)
}
return store
}
func loadGraph(path string) map[int]*Node {
f, err := os.Open(path)
if err != nil {
panic(err)
}
defer f.Close()
store := make(map[int]*Node)
s := bufio.NewScanner(f)
for s.Scan() {
line := s.Text()
nodeIdxstrs := strings.Split(line, " ")
nodeIdx0, _ := strconv.Atoi(nodeIdxstrs[0])
nodeIdx1, _ := strconv.Atoi(nodeIdxstrs[1])
if store[nodeIdx0] == nil {
node := &Node{}
node.init(nodeIdx0)
store[nodeIdx0] = node
}
if store[nodeIdx1] == nil {
node := &Node{}
node.init(nodeIdx1)
store[nodeIdx1] = node
}
linkNodes(store[nodeIdx0], store[nodeIdx1])
}
//for _, node := range store { node.initPorts() }
return store
}
////////////////////////////////////////////////////////////////////////////////
func startNetwork(store map[[32]byte]*Node) {
for _, node := range store {
node.startPeers()
}
}
func getKeyedStore(store map[int]*Node) map[[32]byte]*Node {
newStore := make(map[[32]byte]*Node)
for _, node := range store {
newStore[node.core.DEBUG_getSigningPublicKey()] = node
}
return newStore
}
func testPaths(store map[[32]byte]*Node) bool {
nNodes := len(store)
count := 0
for _, source := range store {
count++
fmt.Printf("Testing paths from node %d / %d (%d)\n", count, nNodes, source.index)
for _, dest := range store {
//if source == dest { continue }
destLoc := dest.core.DEBUG_getLocator()
coords := destLoc.DEBUG_getCoords()
temp := 0
ttl := ^uint64(0)
oldTTL := ttl
for here := source; here != dest; {
temp++
if temp > 4096 {
fmt.Println("Loop?")
time.Sleep(time.Second)
return false
}
nextPort := here.core.DEBUG_switchLookup(coords)
// First check if "here" is accepting packets from the previous node
// TODO explain how this works
ports := here.core.DEBUG_getPeers().DEBUG_getPorts()
nextPeer := ports[nextPort]
if nextPeer == nil {
fmt.Println("Peer associated with next port is nil")
return false
}
next := store[nextPeer.DEBUG_getSigKey()]
/*
if next == here {
//for idx, link := range here.links {
// fmt.Println("DUMP:", idx, link.nodeID)
//}
if nextPort != 0 { panic("This should not be") }
fmt.Println("Failed to route:", source.index, here.index, dest.index, oldTTL, ttl)
//here.table.DEBUG_dumpTable()
//fmt.Println("Ports:", here.nodeID, here.ports)
return false
panic(fmt.Sprintln("Routing Loop:",
source.index,
here.index,
dest.index))
}
*/
if temp > 4090 {
fmt.Println("DEBUG:",
source.index, source.core.DEBUG_getLocator(),
here.index, here.core.DEBUG_getLocator(),
dest.index, dest.core.DEBUG_getLocator())
//here.core.DEBUG_getSwitchTable().DEBUG_dumpTable()
}
if here != source {
// This is sufficient to check for routing loops or blackholes
//break
}
if here == next {
fmt.Println("Drop:", source.index, here.index, dest.index, oldTTL)
return false
}
here = next
}
}
}
return true
}
func stressTest(store map[[32]byte]*Node) {
fmt.Println("Stress testing network...")
nNodes := len(store)
dests := make([][]byte, 0, nNodes)
for _, dest := range store {
loc := dest.core.DEBUG_getLocator()
coords := loc.DEBUG_getCoords()
dests = append(dests, coords)
}
lookups := 0
start := time.Now()
for _, source := range store {
for _, coords := range dests {
source.core.DEBUG_switchLookup(coords)
lookups++
}
}
timed := time.Since(start)
fmt.Printf("%d lookups in %s (%f lookups per second)\n",
lookups,
timed,
float64(lookups)/timed.Seconds())
}
func pingNodes(store map[[32]byte]*Node) {
fmt.Println("Sending pings...")
nNodes := len(store)
count := 0
equiv := func(a []byte, b []byte) bool {
if len(a) != len(b) {
return false
}
for idx := 0; idx < len(a); idx++ {
if a[idx] != b[idx] {
return false
}
}
return true
}
for _, source := range store {
count++
//if count > 16 { break }
fmt.Printf("Sending packets from node %d/%d (%d)\n", count, nNodes, source.index)
sourceKey := source.core.DEBUG_getEncryptionPublicKey()
payload := sourceKey[:]
sourceAddr := source.core.DEBUG_getAddr()[:]
sendTo := func(bs []byte, destAddr []byte) {
packet := make([]byte, 40+len(bs))
copy(packet[8:24], sourceAddr)
copy(packet[24:40], destAddr)
copy(packet[40:], bs)
packet[0] = 6 << 4
source.send <- packet
}
destCount := 0
for _, dest := range store {
destCount += 1
fmt.Printf("%d Nodes, %d Send, %d Recv\n", nNodes, count, destCount)
if dest == source {
fmt.Println("Skipping self")
continue
}
destAddr := dest.core.DEBUG_getAddr()[:]
ticker := time.NewTicker(150 * time.Millisecond)
sendTo(payload, destAddr)
for loop := true; loop; {
select {
case packet := <-dest.recv:
{
if equiv(payload, packet[len(packet)-len(payload):]) {
loop = false
}
}
case <-ticker.C:
sendTo(payload, destAddr)
//dumpDHTSize(store) // note that this uses racey functions to read things...
}
}
ticker.Stop()
}
//break // Only try sending pings from 1 node
// This is because, for some reason, stopTun() doesn't always close it
// And if two tuns are up, bad things happen (sends via wrong interface)
}
fmt.Println("Finished pinging nodes")
}
func pingBench(store map[[32]byte]*Node) {
fmt.Println("Benchmarking pings...")
nPings := 0
payload := make([]byte, 1280+40) // MTU + ipv6 header
var timed time.Duration
//nNodes := len(store)
count := 0
for _, source := range store {
count++
//fmt.Printf("Sending packets from node %d/%d (%d)\n", count, nNodes, source.index)
getPing := func(key [32]byte, decodedCoords []byte) []byte {
// TODO write some function to do this the right way, put... somewhere...
coords := DEBUG_wire_encode_coords(decodedCoords)
packet := make([]byte, 0, len(key)+len(coords)+len(payload))
packet = append(packet, key[:]...)
packet = append(packet, coords...)
packet = append(packet, payload[:]...)
return packet
}
for _, dest := range store {
key := dest.core.DEBUG_getEncryptionPublicKey()
loc := dest.core.DEBUG_getLocator()
coords := loc.DEBUG_getCoords()
ping := getPing(key, coords)
// TODO make sure the session is open first
start := time.Now()
for i := 0; i < 1000000; i++ {
source.send <- ping
nPings++
}
timed += time.Since(start)
break
}
break
}
fmt.Printf("Sent %d pings in %s (%f per second)\n",
nPings,
timed,
float64(nPings)/timed.Seconds())
}
func dumpStore(store map[NodeID]*Node) {
for _, node := range store {
fmt.Println("DUMPSTORE:", node.index, node.core.DEBUG_getLocator())
node.core.DEBUG_getSwitchTable().DEBUG_dumpTable()
}
}
func dumpDHTSize(store map[[32]byte]*Node) {
var min, max, sum int
for _, node := range store {
num := node.core.DEBUG_getDHTSize()
min = num
max = num
break
}
for _, node := range store {
num := node.core.DEBUG_getDHTSize()
if num < min {
min = num
}
if num > max {
max = num
}
sum += num
}
avg := float64(sum) / float64(len(store))
fmt.Printf("DHT min %d / avg %f / max %d\n", min, avg, max)
}
func (n *Node) startTCP(listen string) {
n.core.DEBUG_setupAndStartGlobalTCPInterface(listen)
}
func (n *Node) connectTCP(remoteAddr string) {
n.core.AddPeer(remoteAddr, remoteAddr)
}
////////////////////////////////////////////////////////////////////////////////
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile `file`")
var memprofile = flag.String("memprofile", "", "write memory profile to this file")
func main() {
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
panic(fmt.Sprintf("could not create CPU profile: ", err))
}
if err := pprof.StartCPUProfile(f); err != nil {
panic(fmt.Sprintf("could not start CPU profile: ", err))
}
defer pprof.StopCPUProfile()
}
if *memprofile != "" {
f, err := os.Create(*memprofile)
if err != nil {
panic(fmt.Sprintf("could not create memory profile: ", err))
}
defer func() { pprof.WriteHeapProfile(f); f.Close() }()
}
fmt.Println("Test")
Util_testAddrIDMask()
idxstore := makeStoreSquareGrid(4)
//idxstore := makeStoreStar(256)
//idxstore := loadGraph("misc/sim/hype-2016-09-19.list")
//idxstore := loadGraph("misc/sim/fc00-2017-08-12.txt")
//idxstore := loadGraph("skitter")
kstore := getKeyedStore(idxstore)
//*
logger := log.New(os.Stderr, "", log.Flags())
for _, n := range kstore {
n.core.DEBUG_setLogger(logger)
}
//*/
startNetwork(kstore)
//time.Sleep(10*time.Second)
// Note that testPaths only works if pressure is turend off
// Otherwise congestion can lead to routing loops?
for finished := false; !finished; {
finished = testPaths(kstore)
}
pingNodes(kstore)
//pingBench(kstore) // Only after disabling debug output
//stressTest(kstore)
//time.Sleep(120 * time.Second)
dumpDHTSize(kstore) // note that this uses racey functions to read things...
if false {
// This connects the sim to the local network
for _, node := range kstore {
node.startTCP("localhost:0")
node.connectTCP("localhost:12345")
break // just 1
}
for _, node := range kstore {
go func() {
// Just dump any packets sent to this node
for range node.recv {
}
}()
}
var block chan struct{}
<-block
}
runtime.GC()
}

View file

@ -1,22 +1,26 @@
// Package address contains the types used by yggdrasil to represent IPv6 addresses or prefixes, as well as functions for working with these types.
// Of particular importance are the functions used to derive addresses or subnets from a NodeID, or to get the NodeID and bitmask of the bits visible from an address, which is needed for DHT searches.
package address
import "github.com/yggdrasil-network/yggdrasil-go/src/crypto"
import (
"crypto/ed25519"
)
// address represents an IPv6 address in the yggdrasil address range.
// Address represents an IPv6 address in the yggdrasil address range.
type Address [16]byte
// subnet represents an IPv6 /64 subnet in the yggdrasil subnet range.
// Subnet represents an IPv6 /64 subnet in the yggdrasil subnet range.
type Subnet [8]byte
// address_prefix is the prefix used for all addresses and subnets in the network.
// The current implementation requires this to be a muliple of 8 bits + 7 bits.
// GetPrefix returns the address prefix used by yggdrasil.
// The current implementation requires this to be a multiple of 8 bits + 7 bits.
// The 8th bit of the last byte is used to signal nodes (0) or /64 prefixes (1).
// Nodes that configure this differently will be unable to communicate with eachother, though routing and the DHT machinery *should* still work.
// Nodes that configure this differently will be unable to communicate with each other using IP packets, though routing and the DHT machinery *should* still work.
func GetPrefix() [1]byte {
return [...]byte{0x02}
}
// isValid returns true if an address falls within the range used by nodes in the network.
// IsValid returns true if an address falls within the range used by nodes in the network.
func (a *Address) IsValid() bool {
prefix := GetPrefix()
for idx := range prefix {
@ -27,7 +31,7 @@ func (a *Address) IsValid() bool {
return true
}
// isValid returns true if a prefix falls within the range usable by the network.
// IsValid returns true if a prefix falls within the range usable by the network.
func (s *Subnet) IsValid() bool {
prefix := GetPrefix()
l := len(prefix)
@ -39,25 +43,34 @@ func (s *Subnet) IsValid() bool {
return (*s)[l-1] == prefix[l-1]|0x01
}
// address_addrForNodeID takes a *NodeID as an argument and returns an *address.
// This subnet begins with the address prefix, with the last bit set to 0 to indicate an address.
// The following 8 bits are set to the number of leading 1 bits in the NodeID.
// The NodeID, excluding the leading 1 bits and the first leading 0 bit, is truncated to the appropriate length and makes up the remainder of the address.
func AddrForNodeID(nid *crypto.NodeID) *Address {
// AddrForKey takes an ed25519.PublicKey as an argument and returns an *Address.
// This function returns nil if the key length is not ed25519.PublicKeySize.
// This address begins with the contents of GetPrefix(), with the last bit set to 0 to indicate an address.
// The following 8 bits are set to the number of leading 1 bits in the bitwise inverse of the public key.
// The bitwise inverse of the key, excluding the leading 1 bits and the first leading 0 bit, is truncated to the appropriate length and makes up the remainder of the address.
func AddrForKey(publicKey ed25519.PublicKey) *Address {
// 128 bit address
// Begins with prefix
// Next bit is a 0
// Next 7 bits, interpreted as a uint, are # of leading 1s in the NodeID
// Leading 1s and first leading 0 of the NodeID are truncated off
// The rest is appended to the IPv6 address (truncated to 128 bits total)
if len(publicKey) != ed25519.PublicKeySize {
return nil
}
var buf [ed25519.PublicKeySize]byte
copy(buf[:], publicKey)
for idx := range buf {
buf[idx] = ^buf[idx]
}
var addr Address
var temp []byte
var temp = make([]byte, 0, 32)
done := false
ones := byte(0)
bits := byte(0)
nBits := 0
for idx := 0; idx < 8*len(nid); idx++ {
bit := (nid[idx/8] & (0x80 >> byte(idx%8))) >> byte(7-(idx%8))
for idx := 0; idx < 8*len(buf); idx++ {
bit := (buf[idx/8] & (0x80 >> byte(idx%8))) >> byte(7-(idx%8))
if !done && bit != 0 {
ones++
continue
@ -80,77 +93,58 @@ func AddrForNodeID(nid *crypto.NodeID) *Address {
return &addr
}
// address_subnetForNodeID takes a *NodeID as an argument and returns a *subnet.
// This subnet begins with the address prefix, with the last bit set to 1 to indicate a prefix.
// The following 8 bits are set to the number of leading 1 bits in the NodeID.
// The NodeID, excluding the leading 1 bits and the first leading 0 bit, is truncated to the appropriate length and makes up the remainder of the subnet.
func SubnetForNodeID(nid *crypto.NodeID) *Subnet {
// SubnetForKey takes an ed25519.PublicKey as an argument and returns a *Subnet.
// This function returns nil if the key length is not ed25519.PublicKeySize.
// The subnet begins with the address prefix, with the last bit set to 1 to indicate a prefix.
// The following 8 bits are set to the number of leading 1 bits in the bitwise inverse of the key.
// The bitwise inverse of the key, excluding the leading 1 bits and the first leading 0 bit, is truncated to the appropriate length and makes up the remainder of the subnet.
func SubnetForKey(publicKey ed25519.PublicKey) *Subnet {
// Exactly as the address version, with two exceptions:
// 1) The first bit after the fixed prefix is a 1 instead of a 0
// 2) It's truncated to a subnet prefix length instead of 128 bits
addr := *AddrForNodeID(nid)
addr := AddrForKey(publicKey)
if addr == nil {
return nil
}
var snet Subnet
copy(snet[:], addr[:])
prefix := GetPrefix()
prefix := GetPrefix() // nolint:staticcheck
snet[len(prefix)-1] |= 0x01
return &snet
}
// getNodeIDandMask returns two *NodeID.
// The first is a NodeID with all the bits known from the address set to their correct values.
// The second is a bitmask with 1 bit set for each bit that was known from the address.
// This is used to look up NodeIDs in the DHT and tell if they match an address.
func (a *Address) GetNodeIDandMask() (*crypto.NodeID, *crypto.NodeID) {
// Mask is a bitmask to mark the bits visible from the address
// This means truncated leading 1s, first leading 0, and visible part of addr
var nid crypto.NodeID
var mask crypto.NodeID
prefix := GetPrefix()
// GetKey returns the partial ed25519.PublicKey for the Address.
// This is used for key lookup.
func (a *Address) GetKey() ed25519.PublicKey {
var key [ed25519.PublicKeySize]byte
prefix := GetPrefix() // nolint:staticcheck
ones := int(a[len(prefix)])
for idx := 0; idx < ones; idx++ {
nid[idx/8] |= 0x80 >> byte(idx%8)
key[idx/8] |= 0x80 >> byte(idx%8)
}
nidOffset := ones + 1
keyOffset := ones + 1
addrOffset := 8*len(prefix) + 8
for idx := addrOffset; idx < 8*len(a); idx++ {
bits := a[idx/8] & (0x80 >> byte(idx%8))
bits <<= byte(idx % 8)
nidIdx := nidOffset + (idx - addrOffset)
bits >>= byte(nidIdx % 8)
nid[nidIdx/8] |= bits
keyIdx := keyOffset + (idx - addrOffset)
bits >>= byte(keyIdx % 8)
idx := keyIdx / 8
if idx >= len(key) {
break
}
key[idx] |= bits
}
maxMask := 8*(len(a)-len(prefix)-1) + ones + 1
for idx := 0; idx < maxMask; idx++ {
mask[idx/8] |= 0x80 >> byte(idx%8)
for idx := range key {
key[idx] = ^key[idx]
}
return &nid, &mask
return ed25519.PublicKey(key[:])
}
// getNodeIDandMask returns two *NodeID.
// The first is a NodeID with all the bits known from the address set to their correct values.
// The second is a bitmask with 1 bit set for each bit that was known from the subnet.
// This is used to look up NodeIDs in the DHT and tell if they match a subnet.
func (s *Subnet) GetNodeIDandMask() (*crypto.NodeID, *crypto.NodeID) {
// As with the address version, but visible parts of the subnet prefix instead
var nid crypto.NodeID
var mask crypto.NodeID
prefix := GetPrefix()
ones := int(s[len(prefix)])
for idx := 0; idx < ones; idx++ {
nid[idx/8] |= 0x80 >> byte(idx%8)
}
nidOffset := ones + 1
addrOffset := 8*len(prefix) + 8
for idx := addrOffset; idx < 8*len(s); idx++ {
bits := s[idx/8] & (0x80 >> byte(idx%8))
bits <<= byte(idx % 8)
nidIdx := nidOffset + (idx - addrOffset)
bits >>= byte(nidIdx % 8)
nid[nidIdx/8] |= bits
}
maxMask := 8*(len(s)-len(prefix)-1) + ones + 1
for idx := 0; idx < maxMask; idx++ {
mask[idx/8] |= 0x80 >> byte(idx%8)
}
return &nid, &mask
// GetKey returns the partial ed25519.PublicKey for the Subnet.
// This is used for key lookup.
func (s *Subnet) GetKey() ed25519.PublicKey {
var addr Address
copy(addr[:], s[:])
return addr.GetKey()
}

114
src/address/address_test.go Normal file
View file

@ -0,0 +1,114 @@
package address
import (
"bytes"
"crypto/ed25519"
"crypto/rand"
"testing"
)
func TestAddress_Address_IsValid(t *testing.T) {
var address Address
_, _ = rand.Read(address[:])
address[0] = 0
if address.IsValid() {
t.Fatal("invalid address marked as valid")
}
address[0] = 0x03
if address.IsValid() {
t.Fatal("invalid address marked as valid")
}
address[0] = 0x02
if !address.IsValid() {
t.Fatal("valid address marked as invalid")
}
}
func TestAddress_Subnet_IsValid(t *testing.T) {
var subnet Subnet
_, _ = rand.Read(subnet[:])
subnet[0] = 0
if subnet.IsValid() {
t.Fatal("invalid subnet marked as valid")
}
subnet[0] = 0x02
if subnet.IsValid() {
t.Fatal("invalid subnet marked as valid")
}
subnet[0] = 0x03
if !subnet.IsValid() {
t.Fatal("valid subnet marked as invalid")
}
}
func TestAddress_AddrForKey(t *testing.T) {
publicKey := ed25519.PublicKey{
189, 186, 207, 216, 34, 64, 222, 61, 205, 18, 57, 36, 203, 181, 82, 86,
251, 141, 171, 8, 170, 152, 227, 5, 82, 138, 184, 79, 65, 158, 110, 251,
}
expectedAddress := Address{
2, 0, 132, 138, 96, 79, 187, 126, 67, 132, 101, 219, 141, 182, 104, 149,
}
if *AddrForKey(publicKey) != expectedAddress {
t.Fatal("invalid address returned")
}
}
func TestAddress_SubnetForKey(t *testing.T) {
publicKey := ed25519.PublicKey{
189, 186, 207, 216, 34, 64, 222, 61, 205, 18, 57, 36, 203, 181, 82, 86,
251, 141, 171, 8, 170, 152, 227, 5, 82, 138, 184, 79, 65, 158, 110, 251,
}
expectedSubnet := Subnet{3, 0, 132, 138, 96, 79, 187, 126}
if *SubnetForKey(publicKey) != expectedSubnet {
t.Fatal("invalid subnet returned")
}
}
func TestAddress_Address_GetKey(t *testing.T) {
address := Address{
2, 0, 132, 138, 96, 79, 187, 126, 67, 132, 101, 219, 141, 182, 104, 149,
}
expectedPublicKey := ed25519.PublicKey{
189, 186, 207, 216, 34, 64, 222, 61,
205, 18, 57, 36, 203, 181, 127, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
}
if !bytes.Equal(address.GetKey(), expectedPublicKey) {
t.Fatal("invalid public key returned")
}
}
func TestAddress_Subnet_GetKey(t *testing.T) {
subnet := Subnet{3, 0, 132, 138, 96, 79, 187, 126}
expectedPublicKey := ed25519.PublicKey{
189, 186, 207, 216, 34, 64, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
}
if !bytes.Equal(subnet.GetKey(), expectedPublicKey) {
t.Fatal("invalid public key returned")
}
}

21
src/admin/addpeer.go Normal file
View file

@ -0,0 +1,21 @@
package admin
import (
"fmt"
"net/url"
)
type AddPeerRequest struct {
Uri string `json:"uri"`
Sintf string `json:"interface,omitempty"`
}
type AddPeerResponse struct{}
func (a *AdminSocket) addPeerHandler(req *AddPeerRequest, _ *AddPeerResponse) error {
u, err := url.Parse(req.Uri)
if err != nil {
return fmt.Errorf("unable to parse peering URI: %w", err)
}
return a.core.AddPeer(u, req.Sintf)
}

370
src/admin/admin.go Normal file
View file

@ -0,0 +1,370 @@
package admin
import (
"encoding/json"
"errors"
"fmt"
"net"
"net/url"
"os"
"sort"
"strings"
"time"
"github.com/yggdrasil-network/yggdrasil-go/src/core"
)
// TODO: Add authentication
type AdminSocket struct {
core *core.Core
log core.Logger
listener net.Listener
handlers map[string]handler
done chan struct{}
config struct {
listenaddr ListenAddress
}
}
type AdminSocketRequest struct {
Name string `json:"request"`
Arguments json.RawMessage `json:"arguments,omitempty"`
KeepAlive bool `json:"keepalive,omitempty"`
}
type AdminSocketResponse struct {
Status string `json:"status"`
Error string `json:"error,omitempty"`
Request AdminSocketRequest `json:"request"`
Response json.RawMessage `json:"response"`
}
type handler struct {
desc string // What does the endpoint do?
args []string // List of human-readable argument names
handler core.AddHandlerFunc // First is input map, second is output
}
type ListResponse struct {
List []ListEntry `json:"list"`
}
type ListEntry struct {
Command string `json:"command"`
Description string `json:"description"`
Fields []string `json:"fields,omitempty"`
}
// AddHandler is called for each admin function to add the handler and help documentation to the API.
func (a *AdminSocket) AddHandler(name, desc string, args []string, handlerfunc core.AddHandlerFunc) error {
if _, ok := a.handlers[strings.ToLower(name)]; ok {
return errors.New("handler already exists")
}
a.handlers[strings.ToLower(name)] = handler{
desc: desc,
args: args,
handler: handlerfunc,
}
return nil
}
// Init runs the initial admin setup.
func New(c *core.Core, log core.Logger, opts ...SetupOption) (*AdminSocket, error) {
a := &AdminSocket{
core: c,
log: log,
handlers: make(map[string]handler),
}
for _, opt := range opts {
a._applyOption(opt)
}
if a.config.listenaddr == "none" || a.config.listenaddr == "" {
return nil, nil
}
listenaddr := string(a.config.listenaddr)
u, err := url.Parse(listenaddr)
if err == nil {
switch strings.ToLower(u.Scheme) {
case "unix":
if _, err := os.Stat(u.Path); err == nil {
a.log.Debugln("Admin socket", u.Path, "already exists, trying to clean up")
if _, err := net.DialTimeout("unix", u.Path, time.Second*2); err == nil || err.(net.Error).Timeout() {
a.log.Errorln("Admin socket", u.Path, "already exists and is in use by another process")
os.Exit(1)
} else {
if err := os.Remove(u.Path); err == nil {
a.log.Debugln(u.Path, "was cleaned up")
} else {
a.log.Errorln(u.Path, "already exists and was not cleaned up:", err)
os.Exit(1)
}
}
}
a.listener, err = net.Listen("unix", u.Path)
if err == nil {
switch u.Path[:1] {
case "@": // maybe abstract namespace
default:
if err := os.Chmod(u.Path, 0660); err != nil {
a.log.Warnln("WARNING:", u.Path, "may have unsafe permissions!")
}
}
}
case "tcp":
a.listener, err = net.Listen("tcp", u.Host)
default:
a.listener, err = net.Listen("tcp", listenaddr)
}
} else {
a.listener, err = net.Listen("tcp", listenaddr)
}
if err != nil {
a.log.Errorf("Admin socket failed to listen: %v", err)
os.Exit(1)
}
a.log.Infof("%s admin socket listening on %s",
strings.ToUpper(a.listener.Addr().Network()),
a.listener.Addr().String())
_ = a.AddHandler("list", "List available commands", []string{}, func(_ json.RawMessage) (interface{}, error) {
res := &ListResponse{}
for name, handler := range a.handlers {
res.List = append(res.List, ListEntry{
Command: name,
Description: handler.desc,
Fields: handler.args,
})
}
sort.SliceStable(res.List, func(i, j int) bool {
return strings.Compare(res.List[i].Command, res.List[j].Command) < 0
})
return res, nil
})
a.done = make(chan struct{})
go a.listen()
return a, a.core.SetAdmin(a)
}
func (a *AdminSocket) SetupAdminHandlers() {
_ = a.AddHandler(
"getSelf", "Show details about this node", []string{},
func(in json.RawMessage) (interface{}, error) {
req := &GetSelfRequest{}
res := &GetSelfResponse{}
if err := json.Unmarshal(in, &req); err != nil {
return nil, err
}
if err := a.getSelfHandler(req, res); err != nil {
return nil, err
}
return res, nil
},
)
_ = a.AddHandler(
"getPeers", "Show directly connected peers", []string{},
func(in json.RawMessage) (interface{}, error) {
req := &GetPeersRequest{}
res := &GetPeersResponse{}
if err := json.Unmarshal(in, &req); err != nil {
return nil, err
}
if err := a.getPeersHandler(req, res); err != nil {
return nil, err
}
return res, nil
},
)
_ = a.AddHandler(
"getTree", "Show known Tree entries", []string{},
func(in json.RawMessage) (interface{}, error) {
req := &GetTreeRequest{}
res := &GetTreeResponse{}
if err := json.Unmarshal(in, &req); err != nil {
return nil, err
}
if err := a.getTreeHandler(req, res); err != nil {
return nil, err
}
return res, nil
},
)
_ = a.AddHandler(
"getPaths", "Show established paths through this node", []string{},
func(in json.RawMessage) (interface{}, error) {
req := &GetPathsRequest{}
res := &GetPathsResponse{}
if err := json.Unmarshal(in, &req); err != nil {
return nil, err
}
if err := a.getPathsHandler(req, res); err != nil {
return nil, err
}
return res, nil
},
)
_ = a.AddHandler(
"getSessions", "Show established traffic sessions with remote nodes", []string{},
func(in json.RawMessage) (interface{}, error) {
req := &GetSessionsRequest{}
res := &GetSessionsResponse{}
if err := json.Unmarshal(in, &req); err != nil {
return nil, err
}
if err := a.getSessionsHandler(req, res); err != nil {
return nil, err
}
return res, nil
},
)
_ = a.AddHandler(
"addPeer", "Add a peer to the peer list", []string{"uri", "interface"},
func(in json.RawMessage) (interface{}, error) {
req := &AddPeerRequest{}
res := &AddPeerResponse{}
if err := json.Unmarshal(in, &req); err != nil {
return nil, err
}
if err := a.addPeerHandler(req, res); err != nil {
return nil, err
}
return res, nil
},
)
_ = a.AddHandler(
"removePeer", "Remove a peer from the peer list", []string{"uri", "interface"},
func(in json.RawMessage) (interface{}, error) {
req := &RemovePeerRequest{}
res := &RemovePeerResponse{}
if err := json.Unmarshal(in, &req); err != nil {
return nil, err
}
if err := a.removePeerHandler(req, res); err != nil {
return nil, err
}
return res, nil
},
)
}
// IsStarted returns true if the module has been started.
func (a *AdminSocket) IsStarted() bool {
select {
case <-a.done:
// Not blocking, so we're not currently running
return false
default:
// Blocked, so we must have started
return true
}
}
// Stop will stop the admin API and close the socket.
func (a *AdminSocket) Stop() error {
if a == nil {
return nil
}
if a.listener != nil {
select {
case <-a.done:
default:
close(a.done)
}
return a.listener.Close()
}
return nil
}
// listen is run by start and manages API connections.
func (a *AdminSocket) listen() {
defer a.listener.Close()
for {
conn, err := a.listener.Accept()
if err == nil {
go a.handleRequest(conn)
} else {
select {
case <-a.done:
// Not blocked, so we havent started or already stopped
return
default:
// Blocked, so we're supposed to keep running
}
}
}
}
// handleRequest calls the request handler for each request sent to the admin API.
func (a *AdminSocket) handleRequest(conn net.Conn) {
decoder := json.NewDecoder(conn)
decoder.DisallowUnknownFields()
encoder := json.NewEncoder(conn)
encoder.SetIndent("", " ")
defer conn.Close()
for {
var err error
var buf json.RawMessage
var req AdminSocketRequest
var resp AdminSocketResponse
req.Arguments = []byte("{}")
if err := func() error {
if err = decoder.Decode(&buf); err != nil {
return fmt.Errorf("Failed to find request")
}
if err = json.Unmarshal(buf, &req); err != nil {
return fmt.Errorf("Failed to unmarshal request")
}
resp.Request = req
if req.Name == "" {
return fmt.Errorf("No request specified")
}
reqname := strings.ToLower(req.Name)
handler, ok := a.handlers[reqname]
if !ok {
return fmt.Errorf("Unknown action '%s', try 'list' for help", reqname)
}
res, err := handler.handler(req.Arguments)
if err != nil {
return err
}
if resp.Response, err = json.Marshal(res); err != nil {
return fmt.Errorf("Failed to marshal response: %w", err)
}
resp.Status = "success"
return nil
}(); err != nil {
resp.Status = "error"
resp.Error = err.Error()
}
if err = encoder.Encode(resp); err != nil {
a.log.Debugln("Encode error:", err)
}
if !req.KeepAlive {
break
} else {
continue
}
}
}
type DataUnit uint64
func (d DataUnit) String() string {
switch {
case d >= 1024*1024*1024*1024:
return fmt.Sprintf("%2.1fTB", float64(d)/1024/1024/1024/1024)
case d >= 1024*1024*1024:
return fmt.Sprintf("%2.1fGB", float64(d)/1024/1024/1024)
case d >= 1024*1024:
return fmt.Sprintf("%2.1fMB", float64(d)/1024/1024)
case d >= 100:
return fmt.Sprintf("%2.1fKB", float64(d)/1024)
default:
return fmt.Sprintf("%dB", d)
}
}

5
src/admin/error.go Normal file
View file

@ -0,0 +1,5 @@
package admin
type ErrorResponse struct {
Error string `json:"error"`
}

42
src/admin/getpaths.go Normal file
View file

@ -0,0 +1,42 @@
package admin
import (
"encoding/hex"
"net"
"slices"
"strings"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
)
type GetPathsRequest struct {
}
type GetPathsResponse struct {
Paths []PathEntry `json:"paths"`
}
type PathEntry struct {
IPAddress string `json:"address"`
PublicKey string `json:"key"`
Path []uint64 `json:"path"`
Sequence uint64 `json:"sequence"`
}
func (a *AdminSocket) getPathsHandler(_ *GetPathsRequest, res *GetPathsResponse) error {
paths := a.core.GetPaths()
res.Paths = make([]PathEntry, 0, len(paths))
for _, p := range paths {
addr := address.AddrForKey(p.Key)
res.Paths = append(res.Paths, PathEntry{
IPAddress: net.IP(addr[:]).String(),
PublicKey: hex.EncodeToString(p.Key),
Path: p.Path,
Sequence: p.Sequence,
})
}
slices.SortStableFunc(res.Paths, func(a, b PathEntry) int {
return strings.Compare(a.PublicKey, b.PublicKey)
})
return nil
}

91
src/admin/getpeers.go Normal file
View file

@ -0,0 +1,91 @@
package admin
import (
"encoding/hex"
"net"
"slices"
"strings"
"time"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
)
type GetPeersRequest struct {
}
type GetPeersResponse struct {
Peers []PeerEntry `json:"peers"`
}
type PeerEntry struct {
URI string `json:"remote,omitempty"`
Up bool `json:"up"`
Inbound bool `json:"inbound"`
IPAddress string `json:"address,omitempty"`
PublicKey string `json:"key"`
Port uint64 `json:"port"`
Priority uint64 `json:"priority"`
Cost uint64 `json:"cost"`
RXBytes DataUnit `json:"bytes_recvd,omitempty"`
TXBytes DataUnit `json:"bytes_sent,omitempty"`
RXRate DataUnit `json:"rate_recvd,omitempty"`
TXRate DataUnit `json:"rate_sent,omitempty"`
Uptime float64 `json:"uptime,omitempty"`
Latency time.Duration `json:"latency,omitempty"`
LastErrorTime time.Duration `json:"last_error_time,omitempty"`
LastError string `json:"last_error,omitempty"`
}
func (a *AdminSocket) getPeersHandler(_ *GetPeersRequest, res *GetPeersResponse) error {
peers := a.core.GetPeers()
res.Peers = make([]PeerEntry, 0, len(peers))
for _, p := range peers {
peer := PeerEntry{
Port: p.Port,
Up: p.Up,
Inbound: p.Inbound,
Priority: uint64(p.Priority), // can't be uint8 thanks to gobind
Cost: p.Cost,
URI: p.URI,
RXBytes: DataUnit(p.RXBytes),
TXBytes: DataUnit(p.TXBytes),
RXRate: DataUnit(p.RXRate),
TXRate: DataUnit(p.TXRate),
Uptime: p.Uptime.Seconds(),
}
if p.Latency > 0 {
peer.Latency = p.Latency
}
if addr := address.AddrForKey(p.Key); addr != nil {
peer.PublicKey = hex.EncodeToString(p.Key)
peer.IPAddress = net.IP(addr[:]).String()
}
if p.LastError != nil {
peer.LastError = p.LastError.Error()
peer.LastErrorTime = time.Since(p.LastErrorTime)
}
res.Peers = append(res.Peers, peer)
}
slices.SortStableFunc(res.Peers, func(a, b PeerEntry) int {
if !a.Inbound && b.Inbound {
return -1
}
if a.Inbound && !b.Inbound {
return 1
}
if d := strings.Compare(a.PublicKey, b.PublicKey); d != 0 {
return d
}
if d := a.Priority - b.Priority; d != 0 {
return int(d)
}
if d := a.Cost - b.Cost; d != 0 {
return int(d)
}
if d := a.Uptime - b.Uptime; d != 0 {
return int(d)
}
return 0
})
return nil
}

30
src/admin/getself.go Normal file
View file

@ -0,0 +1,30 @@
package admin
import (
"encoding/hex"
"github.com/yggdrasil-network/yggdrasil-go/src/version"
)
type GetSelfRequest struct{}
type GetSelfResponse struct {
BuildName string `json:"build_name"`
BuildVersion string `json:"build_version"`
PublicKey string `json:"key"`
IPAddress string `json:"address"`
RoutingEntries uint64 `json:"routing_entries"`
Subnet string `json:"subnet"`
}
func (a *AdminSocket) getSelfHandler(_ *GetSelfRequest, res *GetSelfResponse) error {
self := a.core.GetSelf()
snet := a.core.Subnet()
res.BuildName = version.BuildName()
res.BuildVersion = version.BuildVersion()
res.PublicKey = hex.EncodeToString(self.Key[:])
res.IPAddress = a.core.Address().String()
res.Subnet = snet.String()
res.RoutingEntries = self.RoutingEntries
return nil
}

43
src/admin/getsessions.go Normal file
View file

@ -0,0 +1,43 @@
package admin
import (
"encoding/hex"
"net"
"slices"
"strings"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
)
type GetSessionsRequest struct{}
type GetSessionsResponse struct {
Sessions []SessionEntry `json:"sessions"`
}
type SessionEntry struct {
IPAddress string `json:"address"`
PublicKey string `json:"key"`
RXBytes DataUnit `json:"bytes_recvd"`
TXBytes DataUnit `json:"bytes_sent"`
Uptime float64 `json:"uptime"`
}
func (a *AdminSocket) getSessionsHandler(_ *GetSessionsRequest, res *GetSessionsResponse) error {
sessions := a.core.GetSessions()
res.Sessions = make([]SessionEntry, 0, len(sessions))
for _, s := range sessions {
addr := address.AddrForKey(s.Key)
res.Sessions = append(res.Sessions, SessionEntry{
IPAddress: net.IP(addr[:]).String(),
PublicKey: hex.EncodeToString(s.Key[:]),
RXBytes: DataUnit(s.RXBytes),
TXBytes: DataUnit(s.TXBytes),
Uptime: s.Uptime.Seconds(),
})
}
slices.SortStableFunc(res.Sessions, func(a, b SessionEntry) int {
return strings.Compare(a.PublicKey, b.PublicKey)
})
return nil
}

41
src/admin/gettree.go Normal file
View file

@ -0,0 +1,41 @@
package admin
import (
"encoding/hex"
"net"
"slices"
"strings"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
)
type GetTreeRequest struct{}
type GetTreeResponse struct {
Tree []TreeEntry `json:"tree"`
}
type TreeEntry struct {
IPAddress string `json:"address"`
PublicKey string `json:"key"`
Parent string `json:"parent"`
Sequence uint64 `json:"sequence"`
}
func (a *AdminSocket) getTreeHandler(_ *GetTreeRequest, res *GetTreeResponse) error {
tree := a.core.GetTree()
res.Tree = make([]TreeEntry, 0, len(tree))
for _, d := range tree {
addr := address.AddrForKey(d.Key)
res.Tree = append(res.Tree, TreeEntry{
IPAddress: net.IP(addr[:]).String(),
PublicKey: hex.EncodeToString(d.Key[:]),
Parent: hex.EncodeToString(d.Parent[:]),
Sequence: d.Sequence,
})
}
slices.SortStableFunc(res.Tree, func(a, b TreeEntry) int {
return strings.Compare(a.PublicKey, b.PublicKey)
})
return nil
}

79
src/admin/options.go Normal file
View file

@ -0,0 +1,79 @@
package admin
import (
"crypto/ed25519"
"encoding/hex"
"encoding/json"
"net"
"sync"
"time"
"github.com/Arceliar/ironwood/network"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
)
func (c *AdminSocket) _applyOption(opt SetupOption) {
switch v := opt.(type) {
case ListenAddress:
c.config.listenaddr = v
case LogLookups:
c.logLookups()
}
}
type SetupOption interface {
isSetupOption()
}
type ListenAddress string
func (a ListenAddress) isSetupOption() {}
type LogLookups struct{}
func (l LogLookups) isSetupOption() {}
func (a *AdminSocket) logLookups() {
type resi struct {
Address string `json:"addr"`
Key string `json:"key"`
Path []uint64 `json:"path"`
Time int64 `json:"time"`
}
type res struct {
Infos []resi `json:"infos"`
}
type info struct {
path []uint64
time time.Time
}
type edk [ed25519.PublicKeySize]byte
infos := make(map[edk]info)
var m sync.Mutex
a.core.PacketConn.PacketConn.Debug.SetDebugLookupLogger(func(l network.DebugLookupInfo) {
var k edk
copy(k[:], l.Key[:])
m.Lock()
infos[k] = info{path: l.Path, time: time.Now()}
m.Unlock()
})
_ = a.AddHandler(
"lookups", "Dump a record of lookups received in the past hour", []string{},
func(in json.RawMessage) (interface{}, error) {
m.Lock()
rs := make([]resi, 0, len(infos))
for k, v := range infos {
if time.Since(v.time) > 24*time.Hour {
// TODO? automatic cleanup, so we don't need to call lookups periodically to prevent leaks
delete(infos, k)
}
a := address.AddrForKey(ed25519.PublicKey(k[:]))
addr := net.IP(a[:]).String()
rs = append(rs, resi{Address: addr, Key: hex.EncodeToString(k[:]), Path: v.path, Time: v.time.Unix()})
}
m.Unlock()
return &res{Infos: rs}, nil
},
)
}

21
src/admin/removepeer.go Normal file
View file

@ -0,0 +1,21 @@
package admin
import (
"fmt"
"net/url"
)
type RemovePeerRequest struct {
Uri string `json:"uri"`
Sintf string `json:"interface,omitempty"`
}
type RemovePeerResponse struct{}
func (a *AdminSocket) removePeerHandler(req *RemovePeerRequest, _ *RemovePeerResponse) error {
u, err := url.Parse(req.Uri)
if err != nil {
return fmt.Errorf("unable to parse peering URI: %w", err)
}
return a.core.RemovePeer(u, req.Sintf)
}

View file

@ -1,91 +1,260 @@
/*
The config package contains structures related to the configuration of an
Yggdrasil node.
The configuration contains, amongst other things, encryption keys which are used
to derive a node's identity, information about peerings and node information
that is shared with the network. There are also some module-specific options
related to TUN, multicast and the admin socket.
In order for a node to maintain the same identity across restarts, you should
persist the configuration onto the filesystem or into some configuration storage
so that the encryption keys (and therefore the node ID) do not change.
Note that Yggdrasil will automatically populate sane defaults for any
configuration option that is not provided.
*/
package config
import (
"bytes"
"crypto/ed25519"
"crypto/rand"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"encoding/hex"
"encoding/json"
"encoding/pem"
"fmt"
"io"
"math/big"
"os"
"time"
"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
"github.com/yggdrasil-network/yggdrasil-go/src/defaults"
"github.com/hjson/hjson-go/v4"
"golang.org/x/text/encoding/unicode"
)
// NodeConfig defines all configuration values needed to run a signle yggdrasil node
// NodeConfig is the main configuration structure, containing configuration
// options that are necessary for an Yggdrasil node to run. You will need to
// supply one of these structs to the Yggdrasil core when starting a node.
type NodeConfig struct {
Peers []string `comment:"List of connection strings for outbound peer connections in URI format,\ne.g. tcp://a.b.c.d:e or socks://a.b.c.d:e/f.g.h.i:j. These connections\nwill obey the operating system routing table, therefore you should\nuse this section when you may connect via different interfaces."`
InterfacePeers map[string][]string `comment:"List of connection strings for outbound peer connections in URI format,\narranged by source interface, e.g. { \"eth0\": [ tcp://a.b.c.d:e ] }.\nNote that SOCKS peerings will NOT be affected by this option and should\ngo in the \"Peers\" section instead."`
Listen []string `comment:"Listen addresses for incoming connections. You will need to add\nlisteners in order to accept incoming peerings from non-local nodes.\nMulticast peer discovery will work regardless of any listeners set\nhere. Each listener should be specified in URI format as above, e.g.\ntcp://0.0.0.0:0 or tcp://[::]:0 to listen on all interfaces."`
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."`
MulticastInterfaces []string `comment:"Regular expressions for which interfaces multicast peer discovery\nshould be enabled on. If none specified, multicast peer discovery is\ndisabled. The default value is .* which uses all interfaces."`
AllowedEncryptionPublicKeys []string `comment:"List of peer encryption public keys to allow incoming TCP peering\nconnections from. If left empty/undefined then all connections will\nbe allowed by default. This does not affect outgoing peerings, nor\ndoes it affect link-local peers discovered via multicast."`
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!"`
SigningPublicKey string `comment:"Your public signing key. You should not ordinarily need to share\nthis with anyone."`
SigningPrivateKey string `comment:"Your private signing key. DO NOT share this with anyone!"`
LinkLocalTCPPort uint16 `comment:"The port number to be used for the link-local TCP listeners for the\nconfigured MulticastInterfaces. This option does not affect listeners\nspecified in the Listen option. Unless you plan to firewall link-local\ntraffic, it is best to leave this as the default value of 0. This\noption cannot currently be changed by reloading config during runtime."`
IfName string `comment:"Local network interface name for TUN/TAP adapter, or \"auto\" to select\nan interface automatically, or \"none\" to run without TUN/TAP."`
IfTAPMode bool `comment:"Set local network interface to TAP mode rather than TUN mode if\nsupported by your platform - option will be ignored if not."`
IfMTU int `comment:"Maximux Transmission Unit (MTU) size for your local TUN/TAP interface.\nDefault is the largest supported size for your platform. The lowest\npossible value is 1280."`
SessionFirewall SessionFirewall `comment:"The session firewall controls who can send/receive network traffic\nto/from. This is useful if you want to protect this node without\nresorting to using a real firewall. This does not affect traffic\nbeing routed via this node to somewhere else. Rules are prioritised as\nfollows: blacklist, whitelist, always allow outgoing, direct, remote."`
TunnelRouting TunnelRouting `comment:"Allow tunneling non-Yggdrasil traffic over Yggdrasil. This effectively\nallows you to use Yggdrasil to route to, or to bridge other networks,\nsimilar to a VPN tunnel. Tunnelling works between any two nodes and\ndoes not require them to be directly peered."`
SwitchOptions SwitchOptions `comment:"Advanced options for tuning the switch. Normally you will not need\nto edit these options."`
NodeInfoPrivacy bool `comment:"By default, nodeinfo contains some defaults including the platform,\narchitecture and Yggdrasil version. These can help when surveying\nthe network and diagnosing network routing problems. Enabling\nnodeinfo privacy prevents this, so that only items specified in\n\"NodeInfo\" are sent back if specified."`
NodeInfo map[string]interface{} `comment:"Optional node info. This must be a { \"key\": \"value\", ... } map\nor set as null. This is entirely optional but, if set, is visible\nto the whole network on request."`
PrivateKey KeyBytes `json:",omitempty" comment:"Your private key. DO NOT share this with anyone!"`
PrivateKeyPath string `json:",omitempty" comment:"The path to your private key file in PEM format."`
Certificate *tls.Certificate `json:"-"`
Peers []string `comment:"List of outbound peer connection strings (e.g. tls://a.b.c.d:e or\nsocks://a.b.c.d:e/f.g.h.i:j). Connection strings can contain options,\nsee https://yggdrasil-network.github.io/configurationref.html#peers.\nYggdrasil has no concept of bootstrap nodes - all network traffic\nwill transit peer connections. Therefore make sure to only peer with\nnearby nodes that have good connectivity and low latency. Avoid adding\npeers to this list from distant countries as this will worsen your\nnode's connectivity and performance considerably."`
InterfacePeers map[string][]string `comment:"List of connection strings for outbound peer connections in URI format,\narranged by source interface, e.g. { \"eth0\": [ \"tls://a.b.c.d:e\" ] }.\nYou should only use this option if your machine is multi-homed and you\nwant to establish outbound peer connections on different interfaces.\nOtherwise you should use \"Peers\"."`
Listen []string `comment:"Listen addresses for incoming connections. You will need to add\nlisteners in order to accept incoming peerings from non-local nodes.\nThis is not required if you wish to establish outbound peerings only.\nMulticast peer discovery will work regardless of any listeners set\nhere. Each listener should be specified in URI format as above, e.g.\ntls://0.0.0.0:0 or tls://[::]:0 to listen on all interfaces."`
AdminListen string `json:",omitempty" 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."`
MulticastInterfaces []MulticastInterfaceConfig `comment:"Configuration for which interfaces multicast peer discovery should be\nenabled on. Regex is a regular expression which is matched against an\ninterface name, and interfaces use the first configuration that they\nmatch against. Beacon controls whether or not your node advertises its\npresence to others, whereas Listen controls whether or not your node\nlistens out for and tries to connect to other advertising nodes. See\nhttps://yggdrasil-network.github.io/configurationref.html#multicastinterfaces\nfor more supported options."`
AllowedPublicKeys []string `comment:"List of peer public keys to allow incoming peering connections\nfrom. If left empty/undefined then all connections will be allowed\nby default. This does not affect outgoing peerings, nor does it\naffect link-local peers discovered via multicast.\nWARNING: THIS IS NOT A FIREWALL and DOES NOT limit who can reach\nopen ports or services running on your machine!"`
IfName string `comment:"Local network interface name for TUN adapter, or \"auto\" to select\nan interface automatically, or \"none\" to run without TUN."`
IfMTU uint64 `comment:"Maximum Transmission Unit (MTU) size for your local TUN interface.\nDefault is the largest supported size for your platform. The lowest\npossible value is 1280."`
LogLookups bool `json:",omitempty"`
NodeInfoPrivacy bool `comment:"By default, nodeinfo contains some defaults including the platform,\narchitecture and Yggdrasil version. These can help when surveying\nthe network and diagnosing network routing problems. Enabling\nnodeinfo privacy prevents this, so that only items specified in\n\"NodeInfo\" are sent back if specified."`
NodeInfo map[string]interface{} `comment:"Optional nodeinfo. This must be a { \"key\": \"value\", ... } map\nor set as null. This is entirely optional but, if set, is visible\nto the whole network on request."`
}
// SessionFirewall controls the session firewall configuration
type SessionFirewall struct {
Enable bool `comment:"Enable or disable the session firewall. If disabled, network traffic\nfrom any node will be allowed. If enabled, the below rules apply."`
AllowFromDirect bool `comment:"Allow network traffic from directly connected peers."`
AllowFromRemote bool `comment:"Allow network traffic from remote nodes on the network that you are\nnot directly peered with."`
AlwaysAllowOutbound bool `comment:"Allow outbound network traffic regardless of AllowFromDirect or\nAllowFromRemote. This does allow a remote node to send unsolicited\ntraffic back to you for the length of the session."`
WhitelistEncryptionPublicKeys []string `comment:"List of public keys from which network traffic is always accepted,\nregardless of AllowFromDirect or AllowFromRemote."`
BlacklistEncryptionPublicKeys []string `comment:"List of public keys from which network traffic is always rejected,\nregardless of the whitelist, AllowFromDirect or AllowFromRemote."`
type MulticastInterfaceConfig struct {
Regex string
Beacon bool
Listen bool
Port uint16 `json:",omitempty"`
Priority uint64 `json:",omitempty"` // really uint8, but gobind won't export it
Password string
}
// TunnelRouting contains the crypto-key routing tables for tunneling
type TunnelRouting struct {
Enable bool `comment:"Enable or disable tunnel routing."`
IPv6Destinations map[string]string `comment:"IPv6 CIDR subnets, mapped to the EncryptionPublicKey to which they\nshould be routed, e.g. { \"aaaa:bbbb:cccc::/e\": \"boxpubkey\", ... }"`
IPv6Sources []string `comment:"Optional IPv6 source subnets which are allowed to be tunnelled in\naddition to this node's Yggdrasil address/subnet. If not\nspecified, only traffic originating from this node's Yggdrasil\naddress or subnet will be tunnelled."`
IPv4Destinations map[string]string `comment:"IPv4 CIDR subnets, mapped to the EncryptionPublicKey to which they\nshould be routed, e.g. { \"a.b.c.d/e\": \"boxpubkey\", ... }"`
IPv4Sources []string `comment:"IPv4 source subnets which are allowed to be tunnelled. Unlike for\nIPv6, this option is required for bridging IPv4 traffic. Only\ntraffic with a source matching these subnets will be tunnelled."`
}
// SwitchOptions contains tuning options for the switch
type SwitchOptions struct {
MaxTotalQueueSize uint64 `comment:"Maximum size of all switch queues combined (in bytes)."`
}
// Generates default configuration. This is used when outputting the -genconf
// parameter and also when using -autoconf. The isAutoconf flag is used to
// determine whether the operating system should select a free port by itself
// (which guarantees that there will not be a conflict with any other services)
// or whether to generate a random port number. The only side effect of setting
// isAutoconf is that the TCP and UDP ports will likely end up with different
// port numbers.
// Generates default configuration and returns a pointer to the resulting
// NodeConfig. This is used when outputting the -genconf parameter and also when
// using -autoconf.
func GenerateConfig() *NodeConfig {
// Generate encryption keys.
bpub, bpriv := crypto.NewBoxKeys()
spub, spriv := crypto.NewSigKeys()
// Get the defaults for the platform.
defaults := GetDefaults()
// Create a node configuration and populate it.
cfg := NodeConfig{}
cfg := new(NodeConfig)
cfg.NewPrivateKey()
cfg.Listen = []string{}
cfg.AdminListen = defaults.GetDefaults().DefaultAdminListen
cfg.EncryptionPublicKey = hex.EncodeToString(bpub[:])
cfg.EncryptionPrivateKey = hex.EncodeToString(bpriv[:])
cfg.SigningPublicKey = hex.EncodeToString(spub[:])
cfg.SigningPrivateKey = hex.EncodeToString(spriv[:])
cfg.AdminListen = defaults.DefaultAdminListen
cfg.Peers = []string{}
cfg.InterfacePeers = map[string][]string{}
cfg.AllowedEncryptionPublicKeys = []string{}
cfg.MulticastInterfaces = []string{".*"}
cfg.IfName = defaults.GetDefaults().DefaultIfName
cfg.IfMTU = defaults.GetDefaults().DefaultIfMTU
cfg.IfTAPMode = defaults.GetDefaults().DefaultIfTAPMode
cfg.SessionFirewall.Enable = false
cfg.SessionFirewall.AllowFromDirect = true
cfg.SessionFirewall.AllowFromRemote = true
cfg.SessionFirewall.AlwaysAllowOutbound = true
cfg.SwitchOptions.MaxTotalQueueSize = 4 * 1024 * 1024
cfg.AllowedPublicKeys = []string{}
cfg.MulticastInterfaces = defaults.DefaultMulticastInterfaces
cfg.IfName = defaults.DefaultIfName
cfg.IfMTU = defaults.DefaultIfMTU
cfg.NodeInfoPrivacy = false
return &cfg
if err := cfg.postprocessConfig(); err != nil {
panic(err)
}
return cfg
}
func (cfg *NodeConfig) ReadFrom(r io.Reader) (int64, error) {
conf, err := io.ReadAll(r)
if err != nil {
return 0, err
}
n := int64(len(conf))
// If there's a byte order mark - which Windows 10 is now incredibly fond of
// throwing everywhere when it's converting things into UTF-16 for the hell
// of it - remove it and decode back down into UTF-8. This is necessary
// because hjson doesn't know what to do with UTF-16 and will panic
if bytes.Equal(conf[0:2], []byte{0xFF, 0xFE}) ||
bytes.Equal(conf[0:2], []byte{0xFE, 0xFF}) {
utf := unicode.UTF16(unicode.BigEndian, unicode.UseBOM)
decoder := utf.NewDecoder()
conf, err = decoder.Bytes(conf)
if err != nil {
return n, err
}
}
// Generate a new configuration - this gives us a set of sane defaults -
// then parse the configuration we loaded above on top of it. The effect
// of this is that any configuration item that is missing from the provided
// configuration will use a sane default.
*cfg = *GenerateConfig()
if err := cfg.UnmarshalHJSON(conf); err != nil {
return n, err
}
return n, nil
}
func (cfg *NodeConfig) UnmarshalHJSON(b []byte) error {
if err := hjson.Unmarshal(b, cfg); err != nil {
return err
}
return cfg.postprocessConfig()
}
func (cfg *NodeConfig) postprocessConfig() error {
if cfg.PrivateKeyPath != "" {
cfg.PrivateKey = nil
f, err := os.ReadFile(cfg.PrivateKeyPath)
if err != nil {
return err
}
if err := cfg.UnmarshalPEMPrivateKey(f); err != nil {
return err
}
}
switch {
case cfg.Certificate == nil:
// No self-signed certificate has been generated yet.
fallthrough
case !bytes.Equal(cfg.Certificate.PrivateKey.(ed25519.PrivateKey), cfg.PrivateKey):
// A self-signed certificate was generated but the private
// key has changed since then, possibly because a new config
// was parsed.
if err := cfg.GenerateSelfSignedCertificate(); err != nil {
return err
}
}
return nil
}
// RFC5280 section 4.1.2.5
var notAfterNeverExpires = time.Date(9999, time.December, 31, 23, 59, 59, 0, time.UTC)
func (cfg *NodeConfig) GenerateSelfSignedCertificate() error {
key, err := cfg.MarshalPEMPrivateKey()
if err != nil {
return err
}
cert, err := cfg.MarshalPEMCertificate()
if err != nil {
return err
}
tlsCert, err := tls.X509KeyPair(cert, key)
if err != nil {
return err
}
cfg.Certificate = &tlsCert
return nil
}
func (cfg *NodeConfig) MarshalPEMCertificate() ([]byte, error) {
privateKey := ed25519.PrivateKey(cfg.PrivateKey)
publicKey := privateKey.Public().(ed25519.PublicKey)
cert := &x509.Certificate{
SerialNumber: big.NewInt(1),
Subject: pkix.Name{
CommonName: hex.EncodeToString(publicKey),
},
NotBefore: time.Now(),
NotAfter: notAfterNeverExpires,
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
}
certbytes, err := x509.CreateCertificate(rand.Reader, cert, cert, publicKey, privateKey)
if err != nil {
return nil, err
}
block := &pem.Block{
Type: "CERTIFICATE",
Bytes: certbytes,
}
return pem.EncodeToMemory(block), nil
}
func (cfg *NodeConfig) NewPrivateKey() {
_, spriv, err := ed25519.GenerateKey(nil)
if err != nil {
panic(err)
}
cfg.PrivateKey = KeyBytes(spriv)
}
func (cfg *NodeConfig) MarshalPEMPrivateKey() ([]byte, error) {
b, err := x509.MarshalPKCS8PrivateKey(ed25519.PrivateKey(cfg.PrivateKey))
if err != nil {
return nil, fmt.Errorf("failed to marshal PKCS8 key: %w", err)
}
block := &pem.Block{
Type: "PRIVATE KEY",
Bytes: b,
}
return pem.EncodeToMemory(block), nil
}
func (cfg *NodeConfig) UnmarshalPEMPrivateKey(b []byte) error {
p, _ := pem.Decode(b)
if p == nil {
return fmt.Errorf("failed to parse PEM file")
}
if p.Type != "PRIVATE KEY" {
return fmt.Errorf("unexpected PEM type %q", p.Type)
}
k, err := x509.ParsePKCS8PrivateKey(p.Bytes)
if err != nil {
return fmt.Errorf("failed to unmarshal PKCS8 key: %w", err)
}
key, ok := k.(ed25519.PrivateKey)
if !ok {
return fmt.Errorf("private key must be ed25519 key")
}
if len(key) != ed25519.PrivateKeySize {
return fmt.Errorf("unexpected ed25519 private key length")
}
cfg.PrivateKey = KeyBytes(key)
return nil
}
type KeyBytes []byte
func (k KeyBytes) MarshalJSON() ([]byte, error) {
return json.Marshal(hex.EncodeToString(k))
}
func (k *KeyBytes) UnmarshalJSON(b []byte) error {
var s string
var err error
if err = json.Unmarshal(b, &s); err != nil {
return err
}
*k, err = hex.DecodeString(s)
return err
}

54
src/config/config_test.go Normal file
View file

@ -0,0 +1,54 @@
package config
import (
"testing"
)
func TestConfig_Keys(t *testing.T) {
/*
var nodeConfig NodeConfig
nodeConfig.NewKeys()
publicKey1, err := hex.DecodeString(nodeConfig.PublicKey)
if err != nil {
t.Fatal("can not decode generated public key")
}
if len(publicKey1) == 0 {
t.Fatal("empty public key generated")
}
privateKey1, err := hex.DecodeString(nodeConfig.PrivateKey)
if err != nil {
t.Fatal("can not decode generated private key")
}
if len(privateKey1) == 0 {
t.Fatal("empty private key generated")
}
nodeConfig.NewKeys()
publicKey2, err := hex.DecodeString(nodeConfig.PublicKey)
if err != nil {
t.Fatal("can not decode generated public key")
}
if bytes.Equal(publicKey2, publicKey1) {
t.Fatal("same public key generated")
}
privateKey2, err := hex.DecodeString(nodeConfig.PrivateKey)
if err != nil {
t.Fatal("can not decode generated private key")
}
if bytes.Equal(privateKey2, privateKey1) {
t.Fatal("same private key generated")
}
*/
}

34
src/config/defaults.go Normal file
View file

@ -0,0 +1,34 @@
package config
var defaultConfig = "" // LDFLAGS='-X github.com/yggdrasil-network/yggdrasil-go/src/config.defaultConfig=/path/to/config
var defaultAdminListen = "" // LDFLAGS='-X github.com/yggdrasil-network/yggdrasil-go/src/config.defaultAdminListen=unix://path/to/sock'
// Defines which parameters are expected by default for configuration on a
// specific platform. These values are populated in the relevant defaults_*.go
// for the platform being targeted. They must be set.
type platformDefaultParameters struct {
// Admin socket
DefaultAdminListen string
// Configuration (used for yggdrasilctl)
DefaultConfigFile string
// Multicast interfaces
DefaultMulticastInterfaces []MulticastInterfaceConfig
// TUN
MaximumIfMTU uint64
DefaultIfMTU uint64
DefaultIfName string
}
func GetDefaults() platformDefaultParameters {
defaults := getDefaults()
if defaultConfig != "" {
defaults.DefaultConfigFile = defaultConfig
}
if defaultAdminListen != "" {
defaults.DefaultAdminListen = defaultAdminListen
}
return defaults
}

View file

@ -0,0 +1,28 @@
//go:build darwin
// +build darwin
package config
// Sane defaults for the macOS/Darwin platform. The "default" options may be
// may be replaced by the running configuration.
func getDefaults() platformDefaultParameters {
return platformDefaultParameters{
// Admin
DefaultAdminListen: "unix:///var/run/yggdrasil.sock",
// Configuration (used for yggdrasilctl)
DefaultConfigFile: "/etc/yggdrasil.conf",
// Multicast interfaces
DefaultMulticastInterfaces: []MulticastInterfaceConfig{
{Regex: "en.*", Beacon: true, Listen: true},
{Regex: "bridge.*", Beacon: true, Listen: true},
{Regex: "awdl0", Beacon: false, Listen: false},
},
// TUN
MaximumIfMTU: 65535,
DefaultIfMTU: 65535,
DefaultIfName: "auto",
}
}

View file

@ -0,0 +1,26 @@
//go:build freebsd
// +build freebsd
package config
// Sane defaults for the BSD platforms. The "default" options may be
// may be replaced by the running configuration.
func getDefaults() platformDefaultParameters {
return platformDefaultParameters{
// Admin
DefaultAdminListen: "unix:///var/run/yggdrasil.sock",
// Configuration (used for yggdrasilctl)
DefaultConfigFile: "/usr/local/etc/yggdrasil.conf",
// Multicast interfaces
DefaultMulticastInterfaces: []MulticastInterfaceConfig{
{Regex: ".*", Beacon: true, Listen: true},
},
// TUN
MaximumIfMTU: 32767,
DefaultIfMTU: 32767,
DefaultIfName: "/dev/tun0",
}
}

View file

@ -1,10 +1,11 @@
//go:build linux
// +build linux
package defaults
package config
// Sane defaults for the Linux platform. The "default" options may be
// may be replaced by the running configuration.
func GetDefaults() platformDefaultParameters {
func getDefaults() platformDefaultParameters {
return platformDefaultParameters{
// Admin
DefaultAdminListen: "unix:///var/run/yggdrasil.sock",
@ -12,10 +13,14 @@ func GetDefaults() platformDefaultParameters {
// Configuration (used for yggdrasilctl)
DefaultConfigFile: "/etc/yggdrasil.conf",
// TUN/TAP
MaximumIfMTU: 65535,
DefaultIfMTU: 65535,
DefaultIfName: "auto",
DefaultIfTAPMode: false,
// Multicast interfaces
DefaultMulticastInterfaces: []MulticastInterfaceConfig{
{Regex: ".*", Beacon: true, Listen: true},
},
// TUN
MaximumIfMTU: 65535,
DefaultIfMTU: 65535,
DefaultIfName: "auto",
}
}

View file

@ -1,10 +1,11 @@
//go:build openbsd
// +build openbsd
package defaults
package config
// Sane defaults for the BSD platforms. The "default" options may be
// may be replaced by the running configuration.
func GetDefaults() platformDefaultParameters {
func getDefaults() platformDefaultParameters {
return platformDefaultParameters{
// Admin
DefaultAdminListen: "unix:///var/run/yggdrasil.sock",
@ -12,10 +13,14 @@ func GetDefaults() platformDefaultParameters {
// Configuration (used for yggdrasilctl)
DefaultConfigFile: "/etc/yggdrasil.conf",
// TUN/TAP
MaximumIfMTU: 16384,
DefaultIfMTU: 16384,
DefaultIfName: "/dev/tap0",
DefaultIfTAPMode: true,
// Multicast interfaces
DefaultMulticastInterfaces: []MulticastInterfaceConfig{
{Regex: ".*", Beacon: true, Listen: true},
},
// TUN
MaximumIfMTU: 16384,
DefaultIfMTU: 16384,
DefaultIfName: "tun0",
}
}

View file

@ -0,0 +1,26 @@
//go:build !linux && !darwin && !windows && !openbsd && !freebsd
// +build !linux,!darwin,!windows,!openbsd,!freebsd
package config
// Sane defaults for the other platforms. The "default" options may be
// may be replaced by the running configuration.
func getDefaults() platformDefaultParameters {
return platformDefaultParameters{
// Admin
DefaultAdminListen: "tcp://localhost:9001",
// Configuration (used for yggdrasilctl)
DefaultConfigFile: "/etc/yggdrasil.conf",
// Multicast interfaces
DefaultMulticastInterfaces: []MulticastInterfaceConfig{
{Regex: ".*", Beacon: true, Listen: true},
},
// TUN
MaximumIfMTU: 65535,
DefaultIfMTU: 65535,
DefaultIfName: "none",
}
}

View file

@ -1,10 +1,11 @@
//go:build windows
// +build windows
package defaults
package config
// Sane defaults for the Windows platform. The "default" options may be
// may be replaced by the running configuration.
func GetDefaults() platformDefaultParameters {
func getDefaults() platformDefaultParameters {
return platformDefaultParameters{
// Admin
DefaultAdminListen: "tcp://localhost:9001",
@ -12,10 +13,14 @@ func GetDefaults() platformDefaultParameters {
// Configuration (used for yggdrasilctl)
DefaultConfigFile: "C:\\Program Files\\Yggdrasil\\yggdrasil.conf",
// TUN/TAP
MaximumIfMTU: 65535,
DefaultIfMTU: 65535,
DefaultIfName: "auto",
DefaultIfTAPMode: true,
// Multicast interfaces
DefaultMulticastInterfaces: []MulticastInterfaceConfig{
{Regex: ".*", Beacon: true, Listen: true},
},
// TUN
MaximumIfMTU: 65535,
DefaultIfMTU: 65535,
DefaultIfName: "Yggdrasil",
}
}

265
src/core/api.go Normal file
View file

@ -0,0 +1,265 @@
package core
import (
"crypto/ed25519"
"encoding/json"
"net"
"net/url"
"sync/atomic"
"time"
"github.com/Arceliar/phony"
"github.com/Arceliar/ironwood/network"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
)
type SelfInfo struct {
Key ed25519.PublicKey
RoutingEntries uint64
}
type PeerInfo struct {
URI string
Up bool
Inbound bool
LastError error
LastErrorTime time.Time
Key ed25519.PublicKey
Root ed25519.PublicKey
Coords []uint64
Port uint64
Priority uint8
Cost uint64
RXBytes uint64
TXBytes uint64
RXRate uint64
TXRate uint64
Uptime time.Duration
Latency time.Duration
}
type TreeEntryInfo struct {
Key ed25519.PublicKey
Parent ed25519.PublicKey
Sequence uint64
//Port uint64
//Rest uint64
}
type PathEntryInfo struct {
Key ed25519.PublicKey
Path []uint64
Sequence uint64
}
type SessionInfo struct {
Key ed25519.PublicKey
RXBytes uint64
TXBytes uint64
Uptime time.Duration
}
func (c *Core) GetSelf() SelfInfo {
var self SelfInfo
s := c.PacketConn.PacketConn.Debug.GetSelf()
self.Key = s.Key
self.RoutingEntries = s.RoutingEntries
return self
}
func (c *Core) GetPeers() []PeerInfo {
peers := []PeerInfo{}
conns := map[net.Conn]network.DebugPeerInfo{}
iwpeers := c.PacketConn.PacketConn.Debug.GetPeers()
for _, p := range iwpeers {
conns[p.Conn] = p
}
phony.Block(&c.links, func() {
for info, state := range c.links._links {
var peerinfo PeerInfo
var conn net.Conn
peerinfo.URI = info.uri
peerinfo.LastError = state._err
peerinfo.LastErrorTime = state._errtime
if c := state._conn; c != nil {
conn = c
peerinfo.Up = true
peerinfo.Inbound = state.linkType == linkTypeIncoming
peerinfo.RXBytes = atomic.LoadUint64(&c.rx)
peerinfo.TXBytes = atomic.LoadUint64(&c.tx)
peerinfo.RXRate = atomic.LoadUint64(&c.rxrate)
peerinfo.TXRate = atomic.LoadUint64(&c.txrate)
peerinfo.Uptime = time.Since(c.up)
}
if p, ok := conns[conn]; ok {
peerinfo.Key = p.Key
peerinfo.Root = p.Root
peerinfo.Port = p.Port
peerinfo.Priority = p.Priority
peerinfo.Latency = p.Latency
peerinfo.Cost = p.Cost
}
peers = append(peers, peerinfo)
}
})
return peers
}
func (c *Core) GetTree() []TreeEntryInfo {
var trees []TreeEntryInfo
ts := c.PacketConn.PacketConn.Debug.GetTree()
for _, t := range ts {
var info TreeEntryInfo
info.Key = t.Key
info.Parent = t.Parent
info.Sequence = t.Sequence
//info.Port = d.Port
//info.Rest = d.Rest
trees = append(trees, info)
}
return trees
}
func (c *Core) GetPaths() []PathEntryInfo {
var paths []PathEntryInfo
ps := c.PacketConn.PacketConn.Debug.GetPaths()
for _, p := range ps {
var info PathEntryInfo
info.Key = p.Key
info.Sequence = p.Sequence
info.Path = p.Path
paths = append(paths, info)
}
return paths
}
func (c *Core) GetSessions() []SessionInfo {
var sessions []SessionInfo
ss := c.PacketConn.Debug.GetSessions()
for _, s := range ss {
var info SessionInfo
info.Key = s.Key
info.RXBytes = s.RX
info.TXBytes = s.TX
info.Uptime = s.Uptime
sessions = append(sessions, info)
}
return sessions
}
// Listen starts a new listener (either TCP or TLS). The input should be a url.URL
// parsed from a string of the form e.g. "tcp://a.b.c.d:e". In the case of a
// link-local address, the interface should be provided as the second argument.
func (c *Core) Listen(u *url.URL, sintf string) (*Listener, error) {
return c.links.listen(u, sintf, false)
}
// ListenLocal starts a listener, like the Listen function, but is used for
// more trustworthy situations where you want to ignore AllowedPublicKeys, i.e.
// with multicast listeners.
func (c *Core) ListenLocal(u *url.URL, sintf string) (*Listener, error) {
return c.links.listen(u, sintf, true)
}
// Address gets the IPv6 address of the Yggdrasil node. This is always a /128
// address. The IPv6 address is only relevant when the node is operating as an
// IP router and often is meaningless when embedded into an application, unless
// that application also implements either VPN functionality or deals with IP
// packets specifically.
func (c *Core) Address() net.IP {
addr := net.IP(address.AddrForKey(c.public)[:])
return addr
}
// Subnet gets the routed IPv6 subnet of the Yggdrasil node. This is always a
// /64 subnet. The IPv6 subnet is only relevant when the node is operating as an
// IP router and often is meaningless when embedded into an application, unless
// that application also implements either VPN functionality or deals with IP
// packets specifically.
func (c *Core) Subnet() net.IPNet {
subnet := address.SubnetForKey(c.public)[:]
subnet = append(subnet, 0, 0, 0, 0, 0, 0, 0, 0)
return net.IPNet{IP: subnet, Mask: net.CIDRMask(64, 128)}
}
// SetLogger sets the output logger of the Yggdrasil node after startup. This
// may be useful if you want to redirect the output later. Note that this
// expects a Logger from the github.com/gologme/log package and not from Go's
// built-in log package.
func (c *Core) SetLogger(log Logger) {
c.log = log
}
// AddPeer adds a peer. This should be specified in the peer URI format, e.g.:
//
// tcp://a.b.c.d:e
// socks://a.b.c.d:e/f.g.h.i:j
//
// This adds the peer to the peer list, so that they will be called again if the
// connection drops.
func (c *Core) AddPeer(u *url.URL, sintf string) error {
return c.links.add(u, sintf, linkTypePersistent)
}
// RemovePeer removes a peer. The peer should be specified in URI format, see AddPeer.
// The peer is not disconnected immediately.
func (c *Core) RemovePeer(u *url.URL, sintf string) error {
return c.links.remove(u, sintf, linkTypePersistent)
}
// CallPeer calls a peer once. This should be specified in the peer URI format,
// e.g.:
//
// tcp://a.b.c.d:e
// socks://a.b.c.d:e/f.g.h.i:j
//
// This does not add the peer to the peer list, so if the connection drops, the
// peer will not be called again automatically.
func (c *Core) CallPeer(u *url.URL, sintf string) error {
return c.links.add(u, sintf, linkTypeEphemeral)
}
func (c *Core) PublicKey() ed25519.PublicKey {
return c.public
}
// Hack to get the admin stuff working, TODO something cleaner
type AddHandler interface {
AddHandler(name, desc string, args []string, handlerfunc AddHandlerFunc) error
}
type AddHandlerFunc func(json.RawMessage) (interface{}, error)
// SetAdmin must be called after Init and before Start.
// It sets the admin handler for NodeInfo and the Debug admin functions.
func (c *Core) SetAdmin(a AddHandler) error {
if err := a.AddHandler(
"getNodeInfo", "Request nodeinfo from a remote node by its public key", []string{"key"},
c.proto.nodeinfo.nodeInfoAdminHandler,
); err != nil {
return err
}
if err := a.AddHandler(
"debug_remoteGetSelf", "Debug use only", []string{"key"},
c.proto.getSelfHandler,
); err != nil {
return err
}
if err := a.AddHandler(
"debug_remoteGetPeers", "Debug use only", []string{"key"},
c.proto.getPeersHandler,
); err != nil {
return err
}
if err := a.AddHandler(
"debug_remoteGetTree", "Debug use only", []string{"key"},
c.proto.getTreeHandler,
); err != nil {
return err
}
return nil
}

252
src/core/core.go Normal file
View file

@ -0,0 +1,252 @@
package core
import (
"context"
"crypto/ed25519"
"crypto/tls"
"fmt"
"io"
"net"
"net/url"
"time"
iwe "github.com/Arceliar/ironwood/encrypted"
iwn "github.com/Arceliar/ironwood/network"
iwt "github.com/Arceliar/ironwood/types"
"github.com/Arceliar/phony"
"github.com/gologme/log"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
"github.com/yggdrasil-network/yggdrasil-go/src/version"
)
// The Core object represents the Yggdrasil node. You should create a Core
// object for each Yggdrasil node you plan to run.
type Core struct {
// This is the main data structure that holds everything else for a node
// We're going to keep our own copy of the provided config - that way we can
// guarantee that it will be covered by the mutex
phony.Inbox
*iwe.PacketConn
ctx context.Context
cancel context.CancelFunc
secret ed25519.PrivateKey
public ed25519.PublicKey
links links
proto protoHandler
log Logger
addPeerTimer *time.Timer
config struct {
tls *tls.Config // immutable after startup
//_peers map[Peer]*linkInfo // configurable after startup
_listeners map[ListenAddress]struct{} // configurable after startup
peerFilter func(ip net.IP) bool // immutable after startup
nodeinfo NodeInfo // immutable after startup
nodeinfoPrivacy NodeInfoPrivacy // immutable after startup
_allowedPublicKeys map[[32]byte]struct{} // configurable after startup
}
pathNotify func(ed25519.PublicKey)
}
func New(cert *tls.Certificate, logger Logger, opts ...SetupOption) (*Core, error) {
c := &Core{
log: logger,
}
c.ctx, c.cancel = context.WithCancel(context.Background())
if c.log == nil {
c.log = log.New(io.Discard, "", 0)
}
if name := version.BuildName(); name != "unknown" {
c.log.Infoln("Build name:", name)
}
if version := version.BuildVersion(); version != "unknown" {
c.log.Infoln("Build version:", version)
}
var err error
c.config._listeners = map[ListenAddress]struct{}{}
c.config._allowedPublicKeys = map[[32]byte]struct{}{}
for _, opt := range opts {
switch opt.(type) {
case Peer, ListenAddress:
// We can't do peers yet as the links aren't set up.
continue
default:
if err = c._applyOption(opt); err != nil {
return nil, fmt.Errorf("failed to apply configuration option %T: %w", opt, err)
}
}
}
if cert == nil || cert.PrivateKey == nil {
return nil, fmt.Errorf("no private key supplied")
}
var ok bool
if c.secret, ok = cert.PrivateKey.(ed25519.PrivateKey); !ok {
return nil, fmt.Errorf("private key must be ed25519")
}
if len(c.secret) != ed25519.PrivateKeySize {
return nil, fmt.Errorf("private key is incorrect length")
}
c.public = c.secret.Public().(ed25519.PublicKey)
if c.config.tls, err = c.generateTLSConfig(cert); err != nil {
return nil, fmt.Errorf("error generating TLS config: %w", err)
}
keyXform := func(key ed25519.PublicKey) ed25519.PublicKey {
return address.SubnetForKey(key).GetKey()
}
if c.PacketConn, err = iwe.NewPacketConn(
c.secret,
iwn.WithBloomTransform(keyXform),
iwn.WithPeerMaxMessageSize(65535*2),
iwn.WithPathNotify(c.doPathNotify),
); err != nil {
return nil, fmt.Errorf("error creating encryption: %w", err)
}
c.proto.init(c)
if err := c.links.init(c); err != nil {
return nil, fmt.Errorf("error initialising links: %w", err)
}
for _, opt := range opts {
switch opt.(type) {
case Peer, ListenAddress:
// Now do the peers and listeners.
if err = c._applyOption(opt); err != nil {
return nil, fmt.Errorf("failed to apply configuration option %T: %w", opt, err)
}
default:
continue
}
}
if err := c.proto.nodeinfo.setNodeInfo(c.config.nodeinfo, bool(c.config.nodeinfoPrivacy)); err != nil {
return nil, fmt.Errorf("error setting node info: %w", err)
}
for listenaddr := range c.config._listeners {
u, err := url.Parse(string(listenaddr))
if err != nil {
c.log.Errorf("Invalid listener URI %q specified, ignoring\n", listenaddr)
continue
}
if _, err = c.links.listen(u, "", false); err != nil {
c.log.Errorf("Failed to start listener %q: %s\n", listenaddr, err)
}
}
return c, nil
}
func (c *Core) RetryPeersNow() {
phony.Block(&c.links, func() {
for _, l := range c.links._links {
select {
case l.kick <- struct{}{}:
default:
}
}
})
}
// Stop shuts down the Yggdrasil node.
func (c *Core) Stop() {
phony.Block(c, func() {
c.log.Infoln("Stopping...")
_ = c._close()
c.log.Infoln("Stopped")
})
}
// This function is unsafe and should only be ran by the core actor.
func (c *Core) _close() error {
c.cancel()
c.links.shutdown()
err := c.PacketConn.Close()
if c.addPeerTimer != nil {
c.addPeerTimer.Stop()
c.addPeerTimer = nil
}
return err
}
func (c *Core) MTU() uint64 {
const sessionTypeOverhead = 1
MTU := c.PacketConn.MTU() - sessionTypeOverhead
if MTU > 65535 {
MTU = 65535
}
return MTU
}
func (c *Core) ReadFrom(p []byte) (n int, from net.Addr, err error) {
buf := allocBytes(int(c.PacketConn.MTU()))
defer freeBytes(buf)
for {
bs := buf
n, from, err = c.PacketConn.ReadFrom(bs)
if err != nil {
return 0, from, err
}
if n == 0 {
continue
}
switch bs[0] {
case typeSessionTraffic:
// This is what we want to handle here
case typeSessionProto:
var key keyArray
copy(key[:], from.(iwt.Addr))
data := append([]byte(nil), bs[1:n]...)
c.proto.handleProto(nil, key, data)
continue
default:
continue
}
bs = bs[1:n]
copy(p, bs)
if len(p) < len(bs) {
n = len(p)
} else {
n = len(bs)
}
return
}
}
func (c *Core) WriteTo(p []byte, addr net.Addr) (n int, err error) {
buf := allocBytes(0)
defer func() { freeBytes(buf) }()
buf = append(buf, typeSessionTraffic)
buf = append(buf, p...)
n, err = c.PacketConn.WriteTo(buf, addr)
if n > 0 {
n -= 1
}
return
}
func (c *Core) doPathNotify(key ed25519.PublicKey) {
c.Act(nil, func() {
if c.pathNotify != nil {
c.pathNotify(key)
}
})
}
func (c *Core) SetPathNotify(notify func(ed25519.PublicKey)) {
c.Act(nil, func() {
c.pathNotify = notify
})
}
type Logger interface {
Printf(string, ...interface{})
Println(...interface{})
Infof(string, ...interface{})
Infoln(...interface{})
Warnf(string, ...interface{})
Warnln(...interface{})
Errorf(string, ...interface{})
Errorln(...interface{})
Debugf(string, ...interface{})
Debugln(...interface{})
Traceln(...interface{})
}

290
src/core/core_test.go Normal file
View file

@ -0,0 +1,290 @@
package core
import (
"bytes"
"crypto/rand"
"net/url"
"os"
"testing"
"time"
"github.com/gologme/log"
"github.com/yggdrasil-network/yggdrasil-go/src/config"
)
// GetLoggerWithPrefix creates a new logger instance with prefix.
// If verbose is set to true, three log levels are enabled: "info", "warn", "error".
func GetLoggerWithPrefix(prefix string, verbose bool) *log.Logger {
l := log.New(os.Stderr, prefix, log.Flags())
if !verbose {
return l
}
l.EnableLevel("info")
l.EnableLevel("warn")
l.EnableLevel("error")
return l
}
func require_NoError(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Fatal(err)
}
}
func require_Equal[T comparable](t *testing.T, a, b T) {
t.Helper()
if a != b {
t.Fatalf("%v != %v", a, b)
}
}
func require_True(t *testing.T, a bool) {
t.Helper()
if !a {
t.Fatal("expected true")
}
}
// CreateAndConnectTwo creates two nodes. nodeB connects to nodeA.
// Verbosity flag is passed to logger.
func CreateAndConnectTwo(t testing.TB, verbose bool) (nodeA *Core, nodeB *Core) {
var err error
cfgA, cfgB := config.GenerateConfig(), config.GenerateConfig()
if err = cfgA.GenerateSelfSignedCertificate(); err != nil {
t.Fatal(err)
}
if err = cfgB.GenerateSelfSignedCertificate(); err != nil {
t.Fatal(err)
}
logger := GetLoggerWithPrefix("", false)
logger.EnableLevel("debug")
if nodeA, err = New(cfgA.Certificate, logger); err != nil {
t.Fatal(err)
}
if nodeB, err = New(cfgB.Certificate, logger); err != nil {
t.Fatal(err)
}
nodeAListenURL, err := url.Parse("tcp://localhost:0")
if err != nil {
t.Fatal(err)
}
nodeAListener, err := nodeA.Listen(nodeAListenURL, "")
if err != nil {
t.Fatal(err)
}
nodeAURL, err := url.Parse("tcp://" + nodeAListener.Addr().String())
if err != nil {
t.Fatal(err)
}
if err = nodeB.CallPeer(nodeAURL, ""); err != nil {
t.Fatal(err)
}
time.Sleep(100 * time.Millisecond)
if l := len(nodeA.GetPeers()); l != 1 {
t.Fatal("unexpected number of peers", l)
}
if l := len(nodeB.GetPeers()); l != 1 {
t.Fatal("unexpected number of peers", l)
}
return nodeA, nodeB
}
// WaitConnected blocks until either nodes negotiated DHT or 5 seconds passed.
func WaitConnected(nodeA, nodeB *Core) bool {
// It may take up to 3 seconds, but let's wait 5.
for i := 0; i < 50; i++ {
time.Sleep(100 * time.Millisecond)
/*
if len(nodeA.GetPeers()) > 0 && len(nodeB.GetPeers()) > 0 {
return true
}
*/
if len(nodeA.GetTree()) > 1 && len(nodeB.GetTree()) > 1 {
time.Sleep(3 * time.Second) // FIXME hack, there's still stuff happening internally
return true
}
}
return false
}
// CreateEchoListener creates a routine listening on nodeA. It expects repeats messages of length bufLen.
// It returns a channel used to synchronize the routine with caller.
func CreateEchoListener(t testing.TB, nodeA *Core, bufLen int, repeats int) chan struct{} {
// Start routine
done := make(chan struct{})
go func() {
buf := make([]byte, bufLen)
res := make([]byte, bufLen)
for i := 0; i < repeats; i++ {
n, from, err := nodeA.ReadFrom(buf)
if err != nil {
t.Error(err)
return
}
if n != bufLen {
t.Error("missing data")
return
}
copy(res, buf)
copy(res[8:24], buf[24:40])
copy(res[24:40], buf[8:24])
_, err = nodeA.WriteTo(res, from)
if err != nil {
t.Error(err)
}
}
done <- struct{}{}
}()
return done
}
// TestCore_Start_Connect checks if two nodes can connect together.
func TestCore_Start_Connect(t *testing.T) {
CreateAndConnectTwo(t, true)
}
// TestCore_Start_Transfer checks that messages can be passed between nodes (in both directions).
func TestCore_Start_Transfer(t *testing.T) {
nodeA, nodeB := CreateAndConnectTwo(t, true)
defer nodeA.Stop()
defer nodeB.Stop()
msgLen := 1500
done := CreateEchoListener(t, nodeA, msgLen, 1)
if !WaitConnected(nodeA, nodeB) {
t.Fatal("nodes did not connect")
}
// Send
msg := make([]byte, msgLen)
_, _ = rand.Read(msg[40:])
msg[0] = 0x60
copy(msg[8:24], nodeB.Address())
copy(msg[24:40], nodeA.Address())
_, err := nodeB.WriteTo(msg, nodeA.LocalAddr())
if err != nil {
t.Fatal(err)
}
buf := make([]byte, msgLen)
_, _, err = nodeB.ReadFrom(buf)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(msg[40:], buf[40:]) {
t.Fatal("expected echo")
}
<-done
}
// BenchmarkCore_Start_Transfer estimates the possible transfer between nodes (in MB/s).
func BenchmarkCore_Start_Transfer(b *testing.B) {
nodeA, nodeB := CreateAndConnectTwo(b, false)
msgLen := 1500 // typical MTU
done := CreateEchoListener(b, nodeA, msgLen, b.N)
if !WaitConnected(nodeA, nodeB) {
b.Fatal("nodes did not connect")
}
// Send
msg := make([]byte, msgLen)
_, _ = rand.Read(msg[40:])
msg[0] = 0x60
copy(msg[8:24], nodeB.Address())
copy(msg[24:40], nodeA.Address())
buf := make([]byte, msgLen)
b.SetBytes(int64(msgLen))
b.ResetTimer()
addr := nodeA.LocalAddr()
for i := 0; i < b.N; i++ {
_, err := nodeB.WriteTo(msg, addr)
if err != nil {
b.Fatal(err)
}
_, _, err = nodeB.ReadFrom(buf)
if err != nil {
b.Fatal(err)
}
}
<-done
}
func TestAllowedPublicKeys(t *testing.T) {
logger := GetLoggerWithPrefix("", false)
cfgA, cfgB := config.GenerateConfig(), config.GenerateConfig()
require_NoError(t, cfgA.GenerateSelfSignedCertificate())
require_NoError(t, cfgB.GenerateSelfSignedCertificate())
nodeA, err := New(cfgA.Certificate, logger, AllowedPublicKey("abcdef"))
require_NoError(t, err)
defer nodeA.Stop()
nodeB, err := New(cfgB.Certificate, logger)
require_NoError(t, err)
defer nodeB.Stop()
u, err := url.Parse("tcp://localhost:0")
require_NoError(t, err)
l, err := nodeA.Listen(u, "")
require_NoError(t, err)
u, err = url.Parse("tcp://" + l.Addr().String())
require_NoError(t, err)
require_NoError(t, nodeB.AddPeer(u, ""))
time.Sleep(time.Second)
peers := nodeB.GetPeers()
require_Equal(t, len(peers), 1)
require_True(t, !peers[0].Up)
require_True(t, peers[0].LastError != nil)
}
func TestAllowedPublicKeysLocal(t *testing.T) {
logger := GetLoggerWithPrefix("", false)
cfgA, cfgB := config.GenerateConfig(), config.GenerateConfig()
require_NoError(t, cfgA.GenerateSelfSignedCertificate())
require_NoError(t, cfgB.GenerateSelfSignedCertificate())
nodeA, err := New(cfgA.Certificate, logger, AllowedPublicKey("abcdef"))
require_NoError(t, err)
defer nodeA.Stop()
nodeB, err := New(cfgB.Certificate, logger)
require_NoError(t, err)
defer nodeB.Stop()
u, err := url.Parse("tcp://localhost:0")
require_NoError(t, err)
l, err := nodeA.ListenLocal(u, "")
require_NoError(t, err)
u, err = url.Parse("tcp://" + l.Addr().String())
require_NoError(t, err)
require_NoError(t, nodeB.AddPeer(u, ""))
time.Sleep(time.Second)
peers := nodeB.GetPeers()
require_Equal(t, len(peers), 1)
require_True(t, peers[0].Up)
require_True(t, peers[0].LastError == nil)
}

19
src/core/debug.go Normal file
View file

@ -0,0 +1,19 @@
package core
import (
"fmt"
"net/http"
_ "net/http/pprof"
"os"
)
// Start the profiler if the required environment variable is set.
func init() {
envVarName := "PPROFLISTEN"
if hostPort := os.Getenv(envVarName); hostPort != "" {
fmt.Fprintf(os.Stderr, "DEBUG: Starting pprof on %s\n", hostPort)
go func() {
fmt.Fprintf(os.Stderr, "DEBUG: %s", http.ListenAndServe(hostPort, nil))
}()
}
}

767
src/core/link.go Normal file
View file

@ -0,0 +1,767 @@
package core
import (
"bytes"
"context"
"encoding/hex"
"errors"
"fmt"
"io"
"net"
"net/url"
"strconv"
"strings"
"sync/atomic"
"time"
"github.com/Arceliar/phony"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
"golang.org/x/crypto/blake2b"
)
type linkType int
const (
linkTypePersistent linkType = iota // Statically configured
linkTypeEphemeral // Multicast discovered
linkTypeIncoming // Incoming connection
)
const defaultBackoffLimit = time.Second << 12 // 1h8m16s
const minimumBackoffLimit = time.Second * 30
type links struct {
phony.Inbox
core *Core
tcp *linkTCP // TCP interface support
tls *linkTLS // TLS interface support
unix *linkUNIX // UNIX interface support
socks *linkSOCKS // SOCKS interface support
quic *linkQUIC // QUIC interface support
ws *linkWS // WS interface support
wss *linkWSS // WSS interface support
// _links can only be modified safely from within the links actor
_links map[linkInfo]*link // *link is nil if connection in progress
_listeners map[*Listener]context.CancelFunc
}
type linkProtocol interface {
dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error)
listen(ctx context.Context, url *url.URL, sintf string) (net.Listener, error)
}
// linkInfo is used as a map key
type linkInfo struct {
uri string // Peering URI in complete form
sintf string // Peering source interface (i.e. from InterfacePeers)
}
// link tracks the state of a connection, either persistent or non-persistent
type link struct {
ctx context.Context // Connection context
cancel context.CancelFunc // Stop future redial attempts (when peer removed)
kick chan struct{} // Attempt to reconnect now, if backing off
linkType linkType // Type of link, i.e. outbound/inbound, persistent/ephemeral
linkProto string // Protocol carrier of link, e.g. TCP, AWDL
// The remaining fields can only be modified safely from within the links actor
_conn *linkConn // Connected link, if any, nil if not connected
_err error // Last error on the connection, if any
_errtime time.Time // Last time an error occurred
}
type linkOptions struct {
pinnedEd25519Keys map[keyArray]struct{}
priority uint8
tlsSNI string
password []byte
maxBackoff time.Duration
}
type Listener struct {
listener net.Listener
ctx context.Context
Cancel context.CancelFunc
}
func (l *Listener) Addr() net.Addr {
return l.listener.Addr()
}
func (l *links) init(c *Core) error {
l.core = c
l.tcp = l.newLinkTCP()
l.tls = l.newLinkTLS(l.tcp)
l.unix = l.newLinkUNIX()
l.socks = l.newLinkSOCKS()
l.quic = l.newLinkQUIC()
l.ws = l.newLinkWS()
l.wss = l.newLinkWSS()
l._links = make(map[linkInfo]*link)
l._listeners = make(map[*Listener]context.CancelFunc)
l.Act(nil, l._updateAverages)
return nil
}
func (l *links) _updateAverages() {
select {
case <-l.core.ctx.Done():
return
default:
}
for _, l := range l._links {
if l._conn == nil {
continue
}
rx := atomic.LoadUint64(&l._conn.rx)
tx := atomic.LoadUint64(&l._conn.tx)
lastrx := atomic.LoadUint64(&l._conn.lastrx)
lasttx := atomic.LoadUint64(&l._conn.lasttx)
atomic.StoreUint64(&l._conn.rxrate, rx-lastrx)
atomic.StoreUint64(&l._conn.txrate, tx-lasttx)
atomic.StoreUint64(&l._conn.lastrx, rx)
atomic.StoreUint64(&l._conn.lasttx, tx)
}
time.AfterFunc(time.Second, func() {
l.Act(nil, l._updateAverages)
})
}
func (l *links) shutdown() {
phony.Block(l, func() {
for _, cancel := range l._listeners {
cancel()
}
for _, link := range l._links {
if link._conn != nil {
_ = link._conn.Close()
}
}
})
}
type linkError string
func (e linkError) Error() string { return string(e) }
const ErrLinkAlreadyConfigured = linkError("peer is already configured")
const ErrLinkNotConfigured = linkError("peer is not configured")
const ErrLinkPriorityInvalid = linkError("priority value is invalid")
const ErrLinkPinnedKeyInvalid = linkError("pinned public key is invalid")
const ErrLinkPasswordInvalid = linkError("invalid password supplied")
const ErrLinkUnrecognisedSchema = linkError("link schema unknown")
const ErrLinkMaxBackoffInvalid = linkError("max backoff duration invalid")
const ErrLinkSNINotSupported = linkError("SNI not supported on this link type")
const ErrLinkNoSuitableIPs = linkError("peer has no suitable addresses")
func (l *links) add(u *url.URL, sintf string, linkType linkType) error {
var retErr error
phony.Block(l, func() {
// Generate the link info and see whether we think we already
// have an open peering to this peer.
lu := urlForLinkInfo(*u)
info := linkInfo{
uri: lu.String(),
sintf: sintf,
}
// Collect together the link options, these are global options
// that are not specific to any given protocol.
options := linkOptions{
maxBackoff: defaultBackoffLimit,
}
for _, pubkey := range u.Query()["key"] {
sigPub, err := hex.DecodeString(pubkey)
if err != nil {
retErr = ErrLinkPinnedKeyInvalid
return
}
var sigPubKey keyArray
copy(sigPubKey[:], sigPub)
if options.pinnedEd25519Keys == nil {
options.pinnedEd25519Keys = map[keyArray]struct{}{}
}
options.pinnedEd25519Keys[sigPubKey] = struct{}{}
}
if p := u.Query().Get("priority"); p != "" {
pi, err := strconv.ParseUint(p, 10, 8)
if err != nil {
retErr = ErrLinkPriorityInvalid
return
}
options.priority = uint8(pi)
}
if p := u.Query().Get("password"); p != "" {
if len(p) > blake2b.Size {
retErr = ErrLinkPasswordInvalid
return
}
options.password = []byte(p)
}
if p := u.Query().Get("maxbackoff"); p != "" {
d, err := time.ParseDuration(p)
if err != nil || d < minimumBackoffLimit {
retErr = ErrLinkMaxBackoffInvalid
return
}
options.maxBackoff = d
}
// SNI headers must contain hostnames and not IP addresses, so we must make sure
// that we do not populate the SNI with an IP literal. We do this by splitting
// the host-port combo from the query option and then seeing if it parses to an
// IP address successfully or not.
if sni := u.Query().Get("sni"); sni != "" {
if net.ParseIP(sni) == nil {
options.tlsSNI = sni
}
}
// If the SNI is not configured still because the above failed then we'll try
// again but this time we'll use the host part of the peering URI instead.
if options.tlsSNI == "" {
if host, _, err := net.SplitHostPort(u.Host); err == nil && net.ParseIP(host) == nil {
options.tlsSNI = host
}
}
// If we think we're already connected to this peer, load up
// the existing peer state. Try to kick the peer if possible,
// which will cause an immediate connection attempt if it is
// backing off for some reason.
state, ok := l._links[info]
if ok && state != nil {
select {
case state.kick <- struct{}{}:
default:
}
retErr = ErrLinkAlreadyConfigured
return
}
// Create the link entry. This will contain the connection
// in progress (if any), any error details and a context that
// lets the link be cancelled later.
state = &link{
linkType: linkType,
linkProto: strings.ToUpper(u.Scheme),
kick: make(chan struct{}),
}
state.ctx, state.cancel = context.WithCancel(l.core.ctx)
// Store the state of the link so that it can be queried later.
l._links[info] = state
// Track how many consecutive connection failures we have had,
// as we will back off exponentially rather than hammering the
// remote node endlessly.
var backoff int
// backoffNow is called when there's a connection error. It
// will wait for the specified amount of time and then return
// true, unless the peering context was cancelled (due to a
// peer removal most likely), in which case it returns false.
// The caller should check the return value to decide whether
// or not to give up trying.
backoffNow := func() bool {
if backoff < 32 {
backoff++
}
duration := time.Second << backoff
if duration > options.maxBackoff {
duration = options.maxBackoff
}
select {
case <-state.kick:
return true
case <-state.ctx.Done():
return false
case <-l.core.ctx.Done():
return false
case <-time.After(duration):
return true
}
}
// resetBackoff is called by the connection handler when the
// handshake has successfully completed.
resetBackoff := func() {
backoff = 0
}
// The goroutine is responsible for attempting the connection
// and then running the handler. If the connection is persistent
// then the loop will run endlessly, using backoffs as needed.
// Otherwise the loop will end, cleaning up the link entry.
go func() {
defer phony.Block(l, func() {
if l._links[info] == state {
delete(l._links, info)
}
})
// This loop will run each and every time we want to attempt
// a connection to this peer.
// TODO get rid of this loop, this is *exactly* what time.AfterFunc is for, we should just send a signal to the links actor to kick off a goroutine as needed
for {
select {
case <-state.ctx.Done():
// The peering context has been cancelled, so don't try
// to dial again.
return
default:
}
conn, err := l.connect(state.ctx, u, info, options)
if err != nil || conn == nil {
if err == nil && conn == nil {
l.core.log.Warnf("Link %q reached inconsistent error state", u.String())
}
if linkType == linkTypePersistent {
// If the link is a persistent configured peering,
// store information about the connection error so
// that we can report it through the admin socket.
phony.Block(l, func() {
state._conn = nil
state._err = err
state._errtime = time.Now()
})
// Back off for a bit. If true is returned here, we
// can continue onto the next loop iteration to try
// the next connection.
if backoffNow() {
continue
}
return
}
// Ephemeral and incoming connections don't remain
// after a connection failure, so exit out of the
// loop and clean up the link entry.
break
}
// The linkConn wrapper allows us to track the number of
// bytes written to and read from this connection without
// the help of ironwood.
lc := &linkConn{
Conn: conn,
up: time.Now(),
}
// Update the link state with our newly wrapped connection.
// Clear the error state.
var doRet bool
phony.Block(l, func() {
if state._conn != nil {
// If a peering has come up in this time, abort this one.
doRet = true
}
state._conn = lc
})
if doRet {
return
}
// Give the connection to the handler. The handler will block
// for the lifetime of the connection.
switch err = l.handler(linkType, options, lc, resetBackoff, false); {
case err == nil:
case errors.Is(err, io.EOF):
case errors.Is(err, net.ErrClosed):
default:
l.core.log.Debugf("Link %s error: %s\n", u.Host, err)
}
// The handler has stopped running so the connection is dead,
// try to close the underlying socket just in case and then
// update the link state.
_ = lc.Close()
phony.Block(l, func() {
state._conn = nil
if err == nil {
err = fmt.Errorf("remote side closed the connection")
}
state._err = err
state._errtime = time.Now()
})
// If the link is persistently configured, back off if needed
// and then try reconnecting. Otherwise, exit out.
if linkType == linkTypePersistent {
if backoffNow() {
continue
}
}
// Ephemeral or incoming connections don't reconnect.
return
}
}()
})
return retErr
}
func (l *links) remove(u *url.URL, sintf string, _ linkType) error {
var retErr error
phony.Block(l, func() {
// Generate the link info and see whether we think we already
// have an open peering to this peer.
lu := urlForLinkInfo(*u)
info := linkInfo{
uri: lu.String(),
sintf: sintf,
}
// If this peer is already configured then we will close the
// connection and stop it from retrying.
state, ok := l._links[info]
if ok && state != nil {
state.cancel()
if conn := state._conn; conn != nil {
retErr = conn.Close()
}
return
}
retErr = ErrLinkNotConfigured
})
return retErr
}
func (l *links) listen(u *url.URL, sintf string, local bool) (*Listener, error) {
ctx, ctxcancel := context.WithCancel(l.core.ctx)
var protocol linkProtocol
switch strings.ToLower(u.Scheme) {
case "tcp":
protocol = l.tcp
case "tls":
protocol = l.tls
case "unix":
protocol = l.unix
case "quic":
protocol = l.quic
case "ws":
protocol = l.ws
case "wss":
protocol = l.wss
default:
ctxcancel()
return nil, ErrLinkUnrecognisedSchema
}
listener, err := protocol.listen(ctx, u, sintf)
if err != nil {
ctxcancel()
return nil, err
}
addr := listener.Addr()
cancel := func() {
ctxcancel()
if err := listener.Close(); err != nil && !errors.Is(err, net.ErrClosed) {
l.core.log.Warnf("Error closing %s listener %s: %s", strings.ToUpper(u.Scheme), addr, err)
}
}
li := &Listener{
listener: listener,
ctx: ctx,
Cancel: cancel,
}
var options linkOptions
if p := u.Query().Get("priority"); p != "" {
pi, err := strconv.ParseUint(p, 10, 8)
if err != nil {
return nil, ErrLinkPriorityInvalid
}
options.priority = uint8(pi)
}
if p := u.Query().Get("password"); p != "" {
if len(p) > blake2b.Size {
return nil, ErrLinkPasswordInvalid
}
options.password = []byte(p)
}
phony.Block(l, func() {
l._listeners[li] = cancel
})
go func() {
l.core.log.Infof("%s listener started on %s", strings.ToUpper(u.Scheme), addr)
defer phony.Block(l, func() {
cancel()
delete(l._listeners, li)
l.core.log.Infof("%s listener stopped on %s", strings.ToUpper(u.Scheme), addr)
})
for {
conn, err := li.listener.Accept()
if err != nil {
return
}
go func(conn net.Conn) {
defer conn.Close()
// In order to populate a somewhat sane looking connection
// URI in the admin socket, we need to replace the host in
// the listener URL with the remote address.
pu := *u
pu.Host = conn.RemoteAddr().String()
lu := urlForLinkInfo(pu)
info := linkInfo{
uri: lu.String(),
sintf: sintf,
}
// If there's an existing link state for this link, get it.
// If this node is already connected to us, just drop the
// connection. This prevents duplicate peerings.
var lc *linkConn
var state *link
phony.Block(l, func() {
var ok bool
state, ok = l._links[info]
if !ok || state == nil {
state = &link{
linkType: linkTypeIncoming,
linkProto: strings.ToUpper(u.Scheme),
kick: make(chan struct{}),
}
}
if state._conn != nil {
// If a connection has come up in this time, abort
// this one.
return
}
// The linkConn wrapper allows us to track the number of
// bytes written to and read from this connection without
// the help of ironwood.
lc = &linkConn{
Conn: conn,
up: time.Now(),
}
// Update the link state with our newly wrapped connection.
// Clear the error state.
state._conn = lc
state._err = nil
state._errtime = time.Time{}
// Store the state of the link so that it can be queried later.
l._links[info] = state
})
defer phony.Block(l, func() {
if l._links[info] == state {
delete(l._links, info)
}
})
if lc == nil {
return
}
// Give the connection to the handler. The handler will block
// for the lifetime of the connection.
switch err = l.handler(linkTypeIncoming, options, lc, nil, local); {
case err == nil:
case errors.Is(err, io.EOF):
case errors.Is(err, net.ErrClosed):
default:
l.core.log.Debugf("Link %s error: %s\n", u.Host, err)
}
// The handler has stopped running so the connection is dead,
// try to close the underlying socket just in case and then
// drop the link state.
_ = lc.Close()
}(conn)
}
}()
return li, nil
}
func (l *links) connect(ctx context.Context, u *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
var dialer linkProtocol
switch strings.ToLower(u.Scheme) {
case "tcp":
dialer = l.tcp
case "tls":
dialer = l.tls
case "socks", "sockstls":
dialer = l.socks
case "unix":
dialer = l.unix
case "quic":
dialer = l.quic
case "ws":
dialer = l.ws
case "wss":
dialer = l.wss
default:
return nil, ErrLinkUnrecognisedSchema
}
return dialer.dial(ctx, u, info, options)
}
func (l *links) handler(linkType linkType, options linkOptions, conn net.Conn, success func(), local bool) error {
meta := version_getBaseMetadata()
meta.publicKey = l.core.public
meta.priority = options.priority
metaBytes, err := meta.encode(l.core.secret, options.password)
if err != nil {
return fmt.Errorf("failed to generate handshake: %w", err)
}
if err := conn.SetDeadline(time.Now().Add(time.Second * 6)); err != nil {
return fmt.Errorf("failed to set handshake deadline: %w", err)
}
n, err := conn.Write(metaBytes)
switch {
case err != nil:
return fmt.Errorf("write handshake: %w", err)
case n != len(metaBytes):
return fmt.Errorf("incomplete handshake send")
}
meta = version_metadata{}
base := version_getBaseMetadata()
if err := meta.decode(conn, options.password); err != nil {
_ = conn.Close()
return err
}
if !meta.check() {
return fmt.Errorf("remote node incompatible version (local %s, remote %s)",
fmt.Sprintf("%d.%d", base.majorVer, base.minorVer),
fmt.Sprintf("%d.%d", meta.majorVer, meta.minorVer),
)
}
if err = conn.SetDeadline(time.Time{}); err != nil {
return fmt.Errorf("failed to clear handshake deadline: %w", err)
}
// Check if the remote side matches the keys we expected. This is a bit of a weak
// check - in future versions we really should check a signature or something like that.
if pinned := options.pinnedEd25519Keys; len(pinned) > 0 {
var key keyArray
copy(key[:], meta.publicKey)
if _, allowed := pinned[key]; !allowed {
return fmt.Errorf("node public key that does not match pinned keys")
}
}
// Check if we're authorized to connect to this key / IP
if !local {
var allowed map[[32]byte]struct{}
phony.Block(l.core, func() {
allowed = l.core.config._allowedPublicKeys
})
isallowed := len(allowed) == 0
for k := range allowed {
if bytes.Equal(k[:], meta.publicKey) {
isallowed = true
break
}
}
if linkType == linkTypeIncoming && !isallowed {
return fmt.Errorf("node public key %q is not in AllowedPublicKeys", hex.EncodeToString(meta.publicKey))
}
}
dir := "outbound"
if linkType == linkTypeIncoming {
dir = "inbound"
}
remoteAddr := net.IP(address.AddrForKey(meta.publicKey)[:]).String()
remoteStr := fmt.Sprintf("%s@%s", remoteAddr, conn.RemoteAddr())
localStr := conn.LocalAddr()
priority := options.priority
if meta.priority > priority {
priority = meta.priority
}
l.core.log.Infof("Connected %s: %s, source %s",
dir, remoteStr, localStr)
if success != nil {
success()
}
err = l.core.HandleConn(meta.publicKey, conn, priority)
switch err {
case io.EOF, net.ErrClosed, nil:
l.core.log.Infof("Disconnected %s: %s, source %s",
dir, remoteStr, localStr)
default:
l.core.log.Infof("Disconnected %s: %s, source %s; error: %s",
dir, remoteStr, localStr, err)
}
return err
}
func (l *links) findSuitableIP(url *url.URL, fn func(hostname string, ip net.IP, port int) (net.Conn, error)) (net.Conn, error) {
host, p, err := net.SplitHostPort(url.Host)
if err != nil {
return nil, err
}
port, err := strconv.Atoi(p)
if err != nil {
return nil, err
}
resp, err := net.LookupIP(host)
if err != nil {
return nil, err
}
var _ips [64]net.IP
ips := _ips[:0]
for _, ip := range resp {
switch {
case ip.IsUnspecified():
continue
case ip.IsMulticast():
continue
case ip.IsLinkLocalMulticast():
continue
case ip.IsInterfaceLocalMulticast():
continue
case l.core.config.peerFilter != nil && !l.core.config.peerFilter(ip):
continue
}
ips = append(ips, ip)
}
if len(ips) == 0 {
return nil, ErrLinkNoSuitableIPs
}
for _, ip := range ips {
var conn net.Conn
if conn, err = fn(host, ip, port); err != nil {
url := *url
url.RawQuery = ""
l.core.log.Debugln("Dialling", url.Redacted(), "reported error:", err)
continue
}
return conn, nil
}
return nil, err
}
func urlForLinkInfo(u url.URL) url.URL {
u.RawQuery = ""
return u
}
type linkConn struct {
// tx and rx are at the beginning of the struct to ensure 64-bit alignment
// on 32-bit platforms, see https://pkg.go.dev/sync/atomic#pkg-note-BUG
rx uint64
tx uint64
rxrate uint64
txrate uint64
lastrx uint64
lasttx uint64
up time.Time
net.Conn
}
func (c *linkConn) Read(p []byte) (n int, err error) {
n, err = c.Conn.Read(p)
atomic.AddUint64(&c.rx, uint64(n))
return
}
func (c *linkConn) Write(p []byte) (n int, err error) {
n, err = c.Conn.Write(p)
atomic.AddUint64(&c.tx, uint64(n))
return
}

108
src/core/link_quic.go Normal file
View file

@ -0,0 +1,108 @@
package core
import (
"context"
"crypto/tls"
"fmt"
"net"
"net/url"
"time"
"github.com/Arceliar/phony"
"github.com/quic-go/quic-go"
)
type linkQUIC struct {
phony.Inbox
*links
tlsconfig *tls.Config
quicconfig *quic.Config
}
type linkQUICStream struct {
quic.Connection
quic.Stream
}
type linkQUICListener struct {
*quic.Listener
ch <-chan *linkQUICStream
}
func (l *linkQUICListener) Accept() (net.Conn, error) {
qs := <-l.ch
if qs == nil {
return nil, context.Canceled
}
return qs, nil
}
func (l *links) newLinkQUIC() *linkQUIC {
lt := &linkQUIC{
links: l,
tlsconfig: l.core.config.tls.Clone(),
quicconfig: &quic.Config{
MaxIdleTimeout: time.Minute,
KeepAlivePeriod: time.Second * 20,
TokenStore: quic.NewLRUTokenStore(255, 255),
},
}
return lt
}
func (l *linkQUIC) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
tlsconfig := l.tlsconfig.Clone()
return l.links.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) {
tlsconfig.ServerName = hostname
tlsconfig.MinVersion = tls.VersionTLS12
tlsconfig.MaxVersion = tls.VersionTLS13
hostport := net.JoinHostPort(ip.String(), fmt.Sprintf("%d", port))
qc, err := quic.DialAddr(ctx, hostport, l.tlsconfig, l.quicconfig)
if err != nil {
return nil, err
}
qs, err := qc.OpenStreamSync(ctx)
if err != nil {
return nil, err
}
return &linkQUICStream{
Connection: qc,
Stream: qs,
}, nil
})
}
func (l *linkQUIC) listen(ctx context.Context, url *url.URL, _ string) (net.Listener, error) {
ql, err := quic.ListenAddr(url.Host, l.tlsconfig, l.quicconfig)
if err != nil {
return nil, err
}
ch := make(chan *linkQUICStream)
lql := &linkQUICListener{
Listener: ql,
ch: ch,
}
go func() {
for {
qc, err := ql.Accept(ctx)
switch err {
case context.Canceled, context.DeadlineExceeded:
ql.Close()
fallthrough
case quic.ErrServerClosed:
return
case nil:
qs, err := qc.AcceptStream(ctx)
if err != nil {
_ = qc.CloseWithError(1, fmt.Sprintf("stream error: %s", err))
continue
}
ch <- &linkQUICStream{
Connection: qc,
Stream: qs,
}
}
}
}()
return lql, nil
}

67
src/core/link_socks.go Normal file
View file

@ -0,0 +1,67 @@
package core
import (
"context"
"crypto/tls"
"fmt"
"net"
"net/url"
"strings"
"golang.org/x/net/proxy"
)
type linkSOCKS struct {
*links
}
func (l *links) newLinkSOCKS() *linkSOCKS {
lt := &linkSOCKS{
links: l,
}
return lt
}
func (l *linkSOCKS) dial(_ context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
var proxyAuth *proxy.Auth
if url.User != nil && url.User.Username() != "" {
proxyAuth = &proxy.Auth{
User: url.User.Username(),
}
proxyAuth.Password, _ = url.User.Password()
}
tlsconfig := l.tls.config.Clone()
return l.links.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) {
hostport := net.JoinHostPort(ip.String(), fmt.Sprintf("%d", port))
dialer, err := l.tcp.dialerFor(&net.TCPAddr{
IP: ip,
Port: port,
}, info.sintf)
if err != nil {
return nil, err
}
proxy, err := proxy.SOCKS5("tcp", hostport, proxyAuth, dialer)
if err != nil {
return nil, err
}
pathtokens := strings.Split(strings.Trim(url.Path, "/"), "/")
conn, err := proxy.Dial("tcp", pathtokens[0])
if err != nil {
return nil, err
}
if url.Scheme == "sockstls" {
tlsconfig.ServerName = hostname
tlsconfig.MinVersion = tls.VersionTLS12
tlsconfig.MaxVersion = tls.VersionTLS13
if sni := options.tlsSNI; sni != "" {
tlsconfig.ServerName = sni
}
conn = tls.Client(conn, tlsconfig)
}
return conn, nil
})
}
func (l *linkSOCKS) listen(ctx context.Context, url *url.URL, _ string) (net.Listener, error) {
return nil, fmt.Errorf("SOCKS listener not supported")
}

111
src/core/link_tcp.go Normal file
View file

@ -0,0 +1,111 @@
package core
import (
"context"
"fmt"
"net"
"net/url"
"time"
"github.com/Arceliar/phony"
)
type linkTCP struct {
phony.Inbox
*links
listenconfig *net.ListenConfig
}
func (l *links) newLinkTCP() *linkTCP {
lt := &linkTCP{
links: l,
listenconfig: &net.ListenConfig{
KeepAlive: -1,
},
}
lt.listenconfig.Control = lt.tcpContext
return lt
}
func (l *linkTCP) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
return l.links.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) {
addr := &net.TCPAddr{
IP: ip,
Port: port,
}
dialer, err := l.tcp.dialerFor(addr, info.sintf)
if err != nil {
return nil, err
}
return dialer.DialContext(ctx, "tcp", addr.String())
})
}
func (l *linkTCP) listen(ctx context.Context, url *url.URL, sintf string) (net.Listener, error) {
hostport := url.Host
if sintf != "" {
if host, port, err := net.SplitHostPort(hostport); err == nil {
hostport = fmt.Sprintf("[%s%%%s]:%s", host, sintf, port)
}
}
return l.listenconfig.Listen(ctx, "tcp", hostport)
}
func (l *linkTCP) dialerFor(dst *net.TCPAddr, sintf string) (*net.Dialer, error) {
if dst.IP.IsLinkLocalUnicast() {
if sintf != "" {
dst.Zone = sintf
}
if dst.Zone == "" {
return nil, fmt.Errorf("link-local address requires a zone")
}
}
dialer := &net.Dialer{
Timeout: time.Second * 5,
KeepAlive: -1,
Control: l.tcpContext,
}
if sintf != "" {
dialer.Control = l.getControl(sintf)
ief, err := net.InterfaceByName(sintf)
if err != nil {
return nil, fmt.Errorf("interface %q not found", sintf)
}
if ief.Flags&net.FlagUp == 0 {
return nil, fmt.Errorf("interface %q is not up", sintf)
}
addrs, err := ief.Addrs()
if err != nil {
return nil, fmt.Errorf("interface %q addresses not available: %w", sintf, err)
}
for addrindex, addr := range addrs {
src, _, err := net.ParseCIDR(addr.String())
if err != nil {
continue
}
if !src.IsGlobalUnicast() && !src.IsLinkLocalUnicast() {
continue
}
bothglobal := src.IsGlobalUnicast() == dst.IP.IsGlobalUnicast()
bothlinklocal := src.IsLinkLocalUnicast() == dst.IP.IsLinkLocalUnicast()
if !bothglobal && !bothlinklocal {
continue
}
if (src.To4() != nil) != (dst.IP.To4() != nil) {
continue
}
if bothglobal || bothlinklocal || addrindex == len(addrs)-1 {
dialer.LocalAddr = &net.TCPAddr{
IP: src,
Port: 0,
Zone: sintf,
}
break
}
}
if dialer.LocalAddr == nil {
return nil, fmt.Errorf("no suitable source address found on interface %q", sintf)
}
}
return dialer, nil
}

View file

@ -1,6 +1,7 @@
//go:build darwin
// +build darwin
package yggdrasil
package core
import (
"syscall"
@ -10,7 +11,7 @@ import (
// WARNING: This context is used both by net.Dialer and net.Listen in tcp.go
func (t *tcp) tcpContext(network, address string, c syscall.RawConn) error {
func (t *linkTCP) tcpContext(network, address string, c syscall.RawConn) error {
var control error
var recvanyif error
@ -26,3 +27,7 @@ func (t *tcp) tcpContext(network, address string, c syscall.RawConn) error {
return control
}
}
func (t *linkTCP) getControl(_ string) func(string, string, syscall.RawConn) error {
return t.tcpContext
}

View file

@ -0,0 +1,30 @@
//go:build linux
// +build linux
package core
import (
"syscall"
"golang.org/x/sys/unix"
)
// WARNING: This context is used both by net.Dialer and net.Listen in tcp.go
func (t *linkTCP) tcpContext(network, address string, c syscall.RawConn) error {
return nil
}
func (t *linkTCP) getControl(sintf string) func(string, string, syscall.RawConn) error {
return func(network, address string, c syscall.RawConn) error {
var err error
btd := func(fd uintptr) {
err = unix.BindToDevice(int(fd), sintf)
}
_ = c.Control(btd)
if err != nil {
t.links.core.log.Debugln("Failed to set SO_BINDTODEVICE:", sintf)
}
return t.tcpContext(network, address, c)
}
}

View file

@ -0,0 +1,18 @@
//go:build !darwin && !linux
// +build !darwin,!linux
package core
import (
"syscall"
)
// WARNING: This context is used both by net.Dialer and net.Listen in tcp.go
func (t *linkTCP) tcpContext(network, address string, c syscall.RawConn) error {
return nil
}
func (t *linkTCP) getControl(sintf string) func(string, string, syscall.RawConn) error {
return t.tcpContext
}

72
src/core/link_tls.go Normal file
View file

@ -0,0 +1,72 @@
package core
import (
"context"
"crypto/tls"
"fmt"
"net"
"net/url"
"github.com/Arceliar/phony"
)
type linkTLS struct {
phony.Inbox
*links
tcp *linkTCP
listener *net.ListenConfig
config *tls.Config
}
func (l *links) newLinkTLS(tcp *linkTCP) *linkTLS {
lt := &linkTLS{
links: l,
tcp: tcp,
listener: &net.ListenConfig{
Control: tcp.tcpContext,
KeepAlive: -1,
},
config: l.core.config.tls.Clone(),
}
return lt
}
func (l *linkTLS) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
tlsconfig := l.config.Clone()
return l.links.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) {
tlsconfig.ServerName = hostname
tlsconfig.MinVersion = tls.VersionTLS12
tlsconfig.MaxVersion = tls.VersionTLS13
if sni := options.tlsSNI; sni != "" {
tlsconfig.ServerName = sni
}
addr := &net.TCPAddr{
IP: ip,
Port: port,
}
dialer, err := l.tcp.dialerFor(addr, info.sintf)
if err != nil {
return nil, err
}
tlsdialer := &tls.Dialer{
NetDialer: dialer,
Config: tlsconfig,
}
return tlsdialer.DialContext(ctx, "tcp", addr.String())
})
}
func (l *linkTLS) listen(ctx context.Context, url *url.URL, sintf string) (net.Listener, error) {
hostport := url.Host
if sintf != "" {
if host, port, err := net.SplitHostPort(hostport); err == nil {
hostport = fmt.Sprintf("[%s%%%s]:%s", host, sintf, port)
}
}
listener, err := l.listener.Listen(ctx, "tcp", hostport)
if err != nil {
return nil, err
}
tlslistener := tls.NewListener(listener, l.config)
return tlslistener, nil
}

43
src/core/link_unix.go Normal file
View file

@ -0,0 +1,43 @@
package core
import (
"context"
"net"
"net/url"
"time"
"github.com/Arceliar/phony"
)
type linkUNIX struct {
phony.Inbox
*links
dialer *net.Dialer
listener *net.ListenConfig
}
func (l *links) newLinkUNIX() *linkUNIX {
lt := &linkUNIX{
links: l,
dialer: &net.Dialer{
Timeout: time.Second * 5,
KeepAlive: -1,
},
listener: &net.ListenConfig{
KeepAlive: -1,
},
}
return lt
}
func (l *linkUNIX) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
addr, err := net.ResolveUnixAddr("unix", url.Path)
if err != nil {
return nil, err
}
return l.dialer.DialContext(ctx, "unix", addr.String())
}
func (l *linkUNIX) listen(ctx context.Context, url *url.URL, _ string) (net.Listener, error) {
return l.listener.Listen(ctx, "unix", url.Path)
}

148
src/core/link_ws.go Normal file
View file

@ -0,0 +1,148 @@
package core
import (
"context"
"fmt"
"net"
"net/http"
"net/url"
"time"
"github.com/Arceliar/phony"
"github.com/coder/websocket"
)
type linkWS struct {
phony.Inbox
*links
listenconfig *net.ListenConfig
}
type linkWSConn struct {
net.Conn
}
type linkWSListener struct {
ch chan *linkWSConn
ctx context.Context
httpServer *http.Server
listener net.Listener
}
type wsServer struct {
ch chan *linkWSConn
ctx context.Context
}
func (l *linkWSListener) Accept() (net.Conn, error) {
qs := <-l.ch
if qs == nil {
return nil, context.Canceled
}
return qs, nil
}
func (l *linkWSListener) Addr() net.Addr {
return l.listener.Addr()
}
func (l *linkWSListener) Close() error {
if err := l.httpServer.Shutdown(l.ctx); err != nil {
return err
}
return l.listener.Close()
}
func (s *wsServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/health" || r.URL.Path == "/healthz" {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("OK"))
return
}
c, err := websocket.Accept(w, r, &websocket.AcceptOptions{
Subprotocols: []string{"ygg-ws"},
})
if err != nil {
return
}
if c.Subprotocol() != "ygg-ws" {
c.Close(websocket.StatusPolicyViolation, "client must speak the ygg-ws subprotocol")
return
}
s.ch <- &linkWSConn{
Conn: websocket.NetConn(s.ctx, c, websocket.MessageBinary),
}
}
func (l *links) newLinkWS() *linkWS {
lt := &linkWS{
links: l,
listenconfig: &net.ListenConfig{
KeepAlive: -1,
},
}
return lt
}
func (l *linkWS) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
return l.links.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) {
u := *url
u.Host = net.JoinHostPort(ip.String(), fmt.Sprintf("%d", port))
addr := &net.TCPAddr{
IP: ip,
Port: port,
}
dialer, err := l.tcp.dialerFor(addr, info.sintf)
if err != nil {
return nil, err
}
wsconn, _, err := websocket.Dial(ctx, u.String(), &websocket.DialOptions{
HTTPClient: &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: dialer.Dial,
DialContext: dialer.DialContext,
},
},
Subprotocols: []string{"ygg-ws"},
Host: hostname,
})
if err != nil {
return nil, err
}
return &linkWSConn{
Conn: websocket.NetConn(ctx, wsconn, websocket.MessageBinary),
}, nil
})
}
func (l *linkWS) listen(ctx context.Context, url *url.URL, _ string) (net.Listener, error) {
nl, err := l.listenconfig.Listen(ctx, "tcp", url.Host)
if err != nil {
return nil, err
}
ch := make(chan *linkWSConn)
httpServer := &http.Server{
Handler: &wsServer{
ch: ch,
ctx: ctx,
},
BaseContext: func(_ net.Listener) context.Context { return ctx },
ReadTimeout: time.Second * 10,
WriteTimeout: time.Second * 10,
}
lwl := &linkWSListener{
ch: ch,
ctx: ctx,
httpServer: httpServer,
listener: nl,
}
go lwl.httpServer.Serve(nl) // nolint:errcheck
return lwl, nil
}

72
src/core/link_wss.go Normal file
View file

@ -0,0 +1,72 @@
package core
import (
"context"
"crypto/tls"
"fmt"
"net"
"net/http"
"net/url"
"github.com/Arceliar/phony"
"github.com/coder/websocket"
)
type linkWSS struct {
phony.Inbox
*links
tlsconfig *tls.Config
}
type linkWSSConn struct {
net.Conn
}
func (l *links) newLinkWSS() *linkWSS {
lwss := &linkWSS{
links: l,
tlsconfig: l.core.config.tls.Clone(),
}
return lwss
}
func (l *linkWSS) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
tlsconfig := l.tlsconfig.Clone()
return l.links.findSuitableIP(url, func(hostname string, ip net.IP, port int) (net.Conn, error) {
tlsconfig.ServerName = hostname
tlsconfig.MinVersion = tls.VersionTLS12
tlsconfig.MaxVersion = tls.VersionTLS13
u := *url
u.Host = net.JoinHostPort(ip.String(), fmt.Sprintf("%d", port))
addr := &net.TCPAddr{
IP: ip,
Port: port,
}
dialer, err := l.tcp.dialerFor(addr, info.sintf)
if err != nil {
return nil, err
}
wsconn, _, err := websocket.Dial(ctx, u.String(), &websocket.DialOptions{
HTTPClient: &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: dialer.Dial,
DialContext: dialer.DialContext,
TLSClientConfig: tlsconfig,
},
},
Subprotocols: []string{"ygg-ws"},
Host: hostname,
})
if err != nil {
return nil, err
}
return &linkWSSConn{
Conn: websocket.NetConn(ctx, wsconn, websocket.MessageBinary),
}, nil
})
}
func (l *linkWSS) listen(ctx context.Context, url *url.URL, _ string) (net.Listener, error) {
return nil, fmt.Errorf("WSS listener not supported, use WS listener behind reverse proxy instead")
}

173
src/core/nodeinfo.go Normal file
View file

@ -0,0 +1,173 @@
package core
import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"runtime"
"time"
iwt "github.com/Arceliar/ironwood/types"
"github.com/Arceliar/phony"
"github.com/yggdrasil-network/yggdrasil-go/src/version"
)
type nodeinfo struct {
phony.Inbox
proto *protoHandler
myNodeInfo json.RawMessage
callbacks map[keyArray]nodeinfoCallback
}
type nodeinfoCallback struct {
call func(nodeinfo json.RawMessage)
created time.Time
}
// Initialises the nodeinfo cache/callback maps, and starts a goroutine to keep
// the cache/callback maps clean of stale entries
func (m *nodeinfo) init(proto *protoHandler) {
m.Act(nil, func() {
m._init(proto)
})
}
func (m *nodeinfo) _init(proto *protoHandler) {
m.proto = proto
m.callbacks = make(map[keyArray]nodeinfoCallback)
m._cleanup()
}
func (m *nodeinfo) _cleanup() {
for boxPubKey, callback := range m.callbacks {
if time.Since(callback.created) > time.Minute {
delete(m.callbacks, boxPubKey)
}
}
time.AfterFunc(time.Second*30, func() {
m.Act(nil, m._cleanup)
})
}
func (m *nodeinfo) _addCallback(sender keyArray, call func(nodeinfo json.RawMessage)) {
m.callbacks[sender] = nodeinfoCallback{
created: time.Now(),
call: call,
}
}
// Handles the callback, if there is one
func (m *nodeinfo) _callback(sender keyArray, nodeinfo json.RawMessage) {
if callback, ok := m.callbacks[sender]; ok {
callback.call(nodeinfo)
delete(m.callbacks, sender)
}
}
func (m *nodeinfo) _getNodeInfo() json.RawMessage {
return m.myNodeInfo
}
// Set the current node's nodeinfo
func (m *nodeinfo) setNodeInfo(given map[string]interface{}, privacy bool) (err error) {
phony.Block(m, func() {
err = m._setNodeInfo(given, privacy)
})
return
}
func (m *nodeinfo) _setNodeInfo(given map[string]interface{}, privacy bool) error {
newnodeinfo := make(map[string]interface{}, len(given))
for k, v := range given {
newnodeinfo[k] = v
}
if !privacy {
newnodeinfo["buildname"] = version.BuildName()
newnodeinfo["buildversion"] = version.BuildVersion()
newnodeinfo["buildplatform"] = runtime.GOOS
newnodeinfo["buildarch"] = runtime.GOARCH
}
newjson, err := json.Marshal(newnodeinfo)
switch {
case err != nil:
return fmt.Errorf("NodeInfo marshalling failed: %w", err)
case len(newjson) > 16384:
return fmt.Errorf("NodeInfo exceeds max length of 16384 bytes")
default:
m.myNodeInfo = newjson
return nil
}
}
func (m *nodeinfo) sendReq(from phony.Actor, key keyArray, callback func(nodeinfo json.RawMessage)) {
m.Act(from, func() {
m._sendReq(key, callback)
})
}
func (m *nodeinfo) _sendReq(key keyArray, callback func(nodeinfo json.RawMessage)) {
if callback != nil {
m._addCallback(key, callback)
}
_, _ = m.proto.core.PacketConn.WriteTo([]byte{typeSessionProto, typeProtoNodeInfoRequest}, iwt.Addr(key[:]))
}
func (m *nodeinfo) handleReq(from phony.Actor, key keyArray) {
m.Act(from, func() {
m._sendRes(key)
})
}
func (m *nodeinfo) handleRes(from phony.Actor, key keyArray, info json.RawMessage) {
m.Act(from, func() {
m._callback(key, info)
})
}
func (m *nodeinfo) _sendRes(key keyArray) {
bs := append([]byte{typeSessionProto, typeProtoNodeInfoResponse}, m._getNodeInfo()...)
_, _ = m.proto.core.PacketConn.WriteTo(bs, iwt.Addr(key[:]))
}
// Admin socket stuff
type GetNodeInfoRequest struct {
Key string `json:"key"`
}
type GetNodeInfoResponse map[string]json.RawMessage
func (m *nodeinfo) nodeInfoAdminHandler(in json.RawMessage) (interface{}, error) {
var req GetNodeInfoRequest
if err := json.Unmarshal(in, &req); err != nil {
return nil, err
}
if req.Key == "" {
return nil, fmt.Errorf("No remote public key supplied")
}
var key keyArray
var kbs []byte
var err error
if kbs, err = hex.DecodeString(req.Key); err != nil {
return nil, fmt.Errorf("Failed to decode public key: %w", err)
}
copy(key[:], kbs)
ch := make(chan []byte, 1)
m.sendReq(nil, key, func(info json.RawMessage) {
ch <- info
})
timer := time.NewTimer(6 * time.Second)
defer timer.Stop()
select {
case <-timer.C:
return nil, errors.New("Timed out waiting for response")
case info := <-ch:
var msg json.RawMessage
if err := msg.UnmarshalJSON(info); err != nil {
return nil, err
}
key := hex.EncodeToString(kbs[:])
res := GetNodeInfoResponse{key: msg}
return res, nil
}
}

61
src/core/options.go Normal file
View file

@ -0,0 +1,61 @@
package core
import (
"crypto/ed25519"
"fmt"
"net"
"net/url"
)
func (c *Core) _applyOption(opt SetupOption) (err error) {
switch v := opt.(type) {
case Peer:
u, err := url.Parse(v.URI)
if err != nil {
return fmt.Errorf("unable to parse peering URI: %w", err)
}
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 PeerFilter:
c.config.peerFilter = v
case NodeInfo:
c.config.nodeinfo = v
case NodeInfoPrivacy:
c.config.nodeinfoPrivacy = v
case AllowedPublicKey:
pk := [32]byte{}
copy(pk[:], v)
c.config._allowedPublicKeys[pk] = struct{}{}
}
return
}
type SetupOption interface {
isSetupOption()
}
type ListenAddress string
type Peer struct {
URI string
SourceInterface string
}
type NodeInfo map[string]interface{}
type NodeInfoPrivacy bool
type AllowedPublicKey ed25519.PublicKey
type PeerFilter func(net.IP) bool
func (a ListenAddress) isSetupOption() {}
func (a Peer) isSetupOption() {}
func (a NodeInfo) isSetupOption() {}
func (a NodeInfoPrivacy) isSetupOption() {}
func (a AllowedPublicKey) isSetupOption() {}
func (a PeerFilter) isSetupOption() {}

41
src/core/options_test.go Normal file
View file

@ -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")
}
}

17
src/core/pool.go Normal file
View file

@ -0,0 +1,17 @@
package core
import "sync"
var bytePool = sync.Pool{New: func() interface{} { return []byte(nil) }}
func allocBytes(size int) []byte {
bs := bytePool.Get().([]byte)
if cap(bs) < size {
bs = make([]byte, size)
}
return bs[:size]
}
func freeBytes(bs []byte) {
bytePool.Put(bs[:0]) //nolint:staticcheck
}

376
src/core/proto.go Normal file
View file

@ -0,0 +1,376 @@
package core
import (
"crypto/ed25519"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"net"
"time"
iwt "github.com/Arceliar/ironwood/types"
"github.com/Arceliar/phony"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
)
const (
typeDebugDummy = iota
typeDebugGetSelfRequest
typeDebugGetSelfResponse
typeDebugGetPeersRequest
typeDebugGetPeersResponse
typeDebugGetTreeRequest
typeDebugGetTreeResponse
)
type reqInfo struct {
callback func([]byte)
timer *time.Timer // time.AfterFunc cleanup
}
type keyArray [ed25519.PublicKeySize]byte
type protoHandler struct {
phony.Inbox
core *Core
nodeinfo nodeinfo
selfRequests map[keyArray]*reqInfo
peersRequests map[keyArray]*reqInfo
treeRequests map[keyArray]*reqInfo
}
func (p *protoHandler) init(core *Core) {
p.core = core
p.nodeinfo.init(p)
p.selfRequests = make(map[keyArray]*reqInfo)
p.peersRequests = make(map[keyArray]*reqInfo)
p.treeRequests = make(map[keyArray]*reqInfo)
}
// Common functions
func (p *protoHandler) handleProto(from phony.Actor, key keyArray, bs []byte) {
if len(bs) == 0 {
return
}
switch bs[0] {
case typeProtoDummy:
case typeProtoNodeInfoRequest:
p.nodeinfo.handleReq(p, key)
case typeProtoNodeInfoResponse:
p.nodeinfo.handleRes(p, key, bs[1:])
case typeProtoDebug:
p.handleDebug(from, key, bs[1:])
}
}
func (p *protoHandler) handleDebug(from phony.Actor, key keyArray, bs []byte) {
p.Act(from, func() {
p._handleDebug(key, bs)
})
}
func (p *protoHandler) _handleDebug(key keyArray, bs []byte) {
if len(bs) == 0 {
return
}
switch bs[0] {
case typeDebugDummy:
case typeDebugGetSelfRequest:
p._handleGetSelfRequest(key)
case typeDebugGetSelfResponse:
p._handleGetSelfResponse(key, bs[1:])
case typeDebugGetPeersRequest:
p._handleGetPeersRequest(key)
case typeDebugGetPeersResponse:
p._handleGetPeersResponse(key, bs[1:])
case typeDebugGetTreeRequest:
p._handleGetTreeRequest(key)
case typeDebugGetTreeResponse:
p._handleGetTreeResponse(key, bs[1:])
}
}
func (p *protoHandler) _sendDebug(key keyArray, dType uint8, data []byte) {
bs := append([]byte{typeSessionProto, typeProtoDebug, dType}, data...)
_, _ = p.core.PacketConn.WriteTo(bs, iwt.Addr(key[:]))
}
// Get self
func (p *protoHandler) sendGetSelfRequest(key keyArray, callback func([]byte)) {
p.Act(nil, func() {
if info := p.selfRequests[key]; info != nil {
info.timer.Stop()
delete(p.selfRequests, key)
}
info := new(reqInfo)
info.callback = callback
info.timer = time.AfterFunc(time.Minute, func() {
p.Act(nil, func() {
if p.selfRequests[key] == info {
delete(p.selfRequests, key)
}
})
})
p.selfRequests[key] = info
p._sendDebug(key, typeDebugGetSelfRequest, nil)
})
}
func (p *protoHandler) _handleGetSelfRequest(key keyArray) {
self := p.core.GetSelf()
res := map[string]string{
"key": hex.EncodeToString(self.Key[:]),
"routing_entries": fmt.Sprintf("%v", self.RoutingEntries),
}
bs, err := json.Marshal(res) // FIXME this puts keys in base64, not hex
if err != nil {
return
}
p._sendDebug(key, typeDebugGetSelfResponse, bs)
}
func (p *protoHandler) _handleGetSelfResponse(key keyArray, bs []byte) {
if info := p.selfRequests[key]; info != nil {
info.timer.Stop()
info.callback(bs)
delete(p.selfRequests, key)
}
}
// Get peers
func (p *protoHandler) sendGetPeersRequest(key keyArray, callback func([]byte)) {
p.Act(nil, func() {
if info := p.peersRequests[key]; info != nil {
info.timer.Stop()
delete(p.peersRequests, key)
}
info := new(reqInfo)
info.callback = callback
info.timer = time.AfterFunc(time.Minute, func() {
p.Act(nil, func() {
if p.peersRequests[key] == info {
delete(p.peersRequests, key)
}
})
})
p.peersRequests[key] = info
p._sendDebug(key, typeDebugGetPeersRequest, nil)
})
}
func (p *protoHandler) _handleGetPeersRequest(key keyArray) {
peers := p.core.GetPeers()
var bs []byte
for _, pinfo := range peers {
tmp := append(bs, pinfo.Key[:]...)
const responseOverhead = 2 // 1 debug type, 1 getpeers type
if uint64(len(tmp))+responseOverhead > p.core.MTU() {
break
}
bs = tmp
}
p._sendDebug(key, typeDebugGetPeersResponse, bs)
}
func (p *protoHandler) _handleGetPeersResponse(key keyArray, bs []byte) {
if info := p.peersRequests[key]; info != nil {
info.timer.Stop()
info.callback(bs)
delete(p.peersRequests, key)
}
}
// Get Tree
func (p *protoHandler) sendGetTreeRequest(key keyArray, callback func([]byte)) {
p.Act(nil, func() {
if info := p.treeRequests[key]; info != nil {
info.timer.Stop()
delete(p.treeRequests, key)
}
info := new(reqInfo)
info.callback = callback
info.timer = time.AfterFunc(time.Minute, func() {
p.Act(nil, func() {
if p.treeRequests[key] == info {
delete(p.treeRequests, key)
}
})
})
p.treeRequests[key] = info
p._sendDebug(key, typeDebugGetTreeRequest, nil)
})
}
func (p *protoHandler) _handleGetTreeRequest(key keyArray) {
dinfos := p.core.GetTree()
var bs []byte
for _, dinfo := range dinfos {
tmp := append(bs, dinfo.Key[:]...)
const responseOverhead = 2 // 1 debug type, 1 gettree type
if uint64(len(tmp))+responseOverhead > p.core.MTU() {
break
}
bs = tmp
}
p._sendDebug(key, typeDebugGetTreeResponse, bs)
}
func (p *protoHandler) _handleGetTreeResponse(key keyArray, bs []byte) {
if info := p.treeRequests[key]; info != nil {
info.timer.Stop()
info.callback(bs)
delete(p.treeRequests, key)
}
}
// Admin socket stuff for "Get self"
type DebugGetSelfRequest struct {
Key string `json:"key"`
}
type DebugGetSelfResponse map[string]interface{}
func (p *protoHandler) getSelfHandler(in json.RawMessage) (interface{}, error) {
var req DebugGetSelfRequest
if err := json.Unmarshal(in, &req); err != nil {
return nil, err
}
var key keyArray
var kbs []byte
var err error
if kbs, err = hex.DecodeString(req.Key); err != nil {
return nil, err
}
if len(kbs) != ed25519.PublicKeySize {
return nil, fmt.Errorf("invalid public key length")
}
copy(key[:], kbs)
ch := make(chan []byte, 1)
p.sendGetSelfRequest(key, func(info []byte) {
ch <- info
})
select {
case <-time.After(6 * time.Second):
return nil, errors.New("timeout")
case info := <-ch:
var msg json.RawMessage
if err := msg.UnmarshalJSON(info); err != nil {
return nil, err
}
ip := net.IP(address.AddrForKey(kbs)[:])
res := DebugGetSelfResponse{ip.String(): msg}
return res, nil
}
}
// Admin socket stuff for "Get peers"
type DebugGetPeersRequest struct {
Key string `json:"key"`
}
type DebugGetPeersResponse map[string]interface{}
func (p *protoHandler) getPeersHandler(in json.RawMessage) (interface{}, error) {
var req DebugGetPeersRequest
if err := json.Unmarshal(in, &req); err != nil {
return nil, err
}
var key keyArray
var kbs []byte
var err error
if kbs, err = hex.DecodeString(req.Key); err != nil {
return nil, err
}
if len(kbs) != ed25519.PublicKeySize {
return nil, fmt.Errorf("invalid public key length")
}
copy(key[:], kbs)
ch := make(chan []byte, 1)
p.sendGetPeersRequest(key, func(info []byte) {
ch <- info
})
select {
case <-time.After(6 * time.Second):
return nil, errors.New("timeout")
case info := <-ch:
ks := make(map[string][]string)
bs := info
for len(bs) >= len(key) {
ks["keys"] = append(ks["keys"], hex.EncodeToString(bs[:len(key)]))
bs = bs[len(key):]
}
js, err := json.Marshal(ks)
if err != nil {
return nil, err
}
var msg json.RawMessage
if err := msg.UnmarshalJSON(js); err != nil {
return nil, err
}
ip := net.IP(address.AddrForKey(kbs)[:])
res := DebugGetPeersResponse{ip.String(): msg}
return res, nil
}
}
// Admin socket stuff for "Get Tree"
type DebugGetTreeRequest struct {
Key string `json:"key"`
}
type DebugGetTreeResponse map[string]interface{}
func (p *protoHandler) getTreeHandler(in json.RawMessage) (interface{}, error) {
var req DebugGetTreeRequest
if err := json.Unmarshal(in, &req); err != nil {
return nil, err
}
var key keyArray
var kbs []byte
var err error
if kbs, err = hex.DecodeString(req.Key); err != nil {
return nil, err
}
if len(kbs) != ed25519.PublicKeySize {
return nil, fmt.Errorf("invalid public key length")
}
copy(key[:], kbs)
ch := make(chan []byte, 1)
p.sendGetTreeRequest(key, func(info []byte) {
ch <- info
})
select {
case <-time.After(6 * time.Second):
return nil, errors.New("timeout")
case info := <-ch:
ks := make(map[string][]string)
bs := info
for len(bs) >= len(key) {
ks["keys"] = append(ks["keys"], hex.EncodeToString(bs[:len(key)]))
bs = bs[len(key):]
}
js, err := json.Marshal(ks)
if err != nil {
return nil, err
}
var msg json.RawMessage
if err := msg.UnmarshalJSON(js); err != nil {
return nil, err
}
ip := net.IP(address.AddrForKey(kbs)[:])
res := DebugGetTreeResponse{ip.String(): msg}
return res, nil
}
}

29
src/core/tls.go Normal file
View file

@ -0,0 +1,29 @@
package core
import (
"crypto/tls"
"crypto/x509"
)
func (c *Core) generateTLSConfig(cert *tls.Certificate) (*tls.Config, error) {
config := &tls.Config{
Certificates: []tls.Certificate{*cert},
ClientAuth: tls.NoClientCert,
GetClientCertificate: func(cri *tls.CertificateRequestInfo) (*tls.Certificate, error) {
return cert, nil
},
VerifyPeerCertificate: c.verifyTLSCertificate,
VerifyConnection: c.verifyTLSConnection,
InsecureSkipVerify: true,
MinVersion: tls.VersionTLS13,
}
return config, nil
}
func (c *Core) verifyTLSCertificate(_ [][]byte, _ [][]*x509.Certificate) error {
return nil
}
func (c *Core) verifyTLSConnection(_ tls.ConnectionState) error {
return nil
}

Some files were not shown because too many files have changed in this diff Show more