Skip to content

Commit 5cdd45e

Browse files
committed
Link costing based on average RTT
1 parent 947b6ad commit 5cdd45e

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

cmd/yggdrasilctl/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ func run() int {
174174
if err := json.Unmarshal(recv.Response, &resp); err != nil {
175175
panic(err)
176176
}
177-
table.SetHeader([]string{"URI", "State", "Dir", "IP Address", "Uptime", "RTT", "RX", "TX", "Pr", "Last Error"})
177+
table.SetHeader([]string{"URI", "State", "Dir", "IP Address", "Uptime", "RTT", "RX", "TX", "Pr", "Cost", "Last Error"})
178178
for _, peer := range resp.Peers {
179-
state, lasterr, dir, rtt := "Up", "-", "Out", "-"
179+
state, lasterr, dir, rtt, cost := "Up", "-", "Out", "-", "-"
180180
if !peer.Up {
181181
state, lasterr = "Down", fmt.Sprintf("%s ago: %s", peer.LastErrorTime.Round(time.Second), peer.LastError)
182182
} else if rttms := float64(peer.Latency.Microseconds()) / 1000; rttms > 0 {
@@ -190,6 +190,9 @@ func run() int {
190190
uri.RawQuery = ""
191191
uristring = uri.String()
192192
}
193+
if peer.Cost < uint64(^uint32(0)) {
194+
cost = fmt.Sprintf("%d", peer.Cost)
195+
}
193196
table.Append([]string{
194197
uristring,
195198
state,
@@ -200,6 +203,7 @@ func run() int {
200203
peer.RXBytes.String(),
201204
peer.TXBytes.String(),
202205
fmt.Sprintf("%d", peer.Priority),
206+
cost,
203207
lasterr,
204208
})
205209
}

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module github.com/yggdrasil-network/yggdrasil-go
22

33
go 1.21
44

5+
replace github.com/Arceliar/ironwood => github.com/neilalexander/ironwood v0.0.0-20240921204201-4e4428b103ee
6+
57
require (
68
github.com/Arceliar/ironwood v0.0.0-20240529054413-b8e59574e2b2
79
github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d
@@ -14,10 +16,10 @@ require (
1416
github.com/vishvananda/netlink v1.1.0
1517
github.com/wlynxg/anet v0.0.4-0.20240806025826-e684438fc7c6
1618
golang.org/x/crypto v0.25.0
17-
golang.org/x/mobile v0.0.0-20240716161057-1ad2df20a8b6
1819
golang.org/x/net v0.27.0
1920
golang.org/x/sys v0.22.0
2021
golang.org/x/text v0.16.0
22+
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2
2123
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173
2224
golang.zx2c4.com/wireguard/windows v0.5.3
2325
nhooyr.io/websocket v1.8.11
@@ -36,7 +38,6 @@ require (
3638
golang.org/x/mod v0.19.0 // indirect
3739
golang.org/x/sync v0.7.0 // indirect
3840
golang.org/x/tools v0.23.0 // indirect
39-
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
4041
)
4142

4243
require (

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
github.com/Arceliar/ironwood v0.0.0-20240529054413-b8e59574e2b2 h1:SBdYBKeXYUUFef5wi2CMhYmXFVGiYaRpTvbki0Bu+JQ=
2-
github.com/Arceliar/ironwood v0.0.0-20240529054413-b8e59574e2b2/go.mod h1:6WP4799FX0OuWdENGQAh+0RXp9FLh0y7NZ7tM9cJyXk=
31
github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d h1:UK9fsWbWqwIQkMCz1CP+v5pGbsGoWAw6g4AyvMpm1EM=
42
github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d/go.mod h1:BCnxhRf47C/dy/e/D2pmB8NkB3dQVIrkD98b220rx5Q=
53
github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
@@ -48,6 +46,8 @@ github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
4846
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
4947
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
5048
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
49+
github.com/neilalexander/ironwood v0.0.0-20240921204201-4e4428b103ee h1:awS1+Bfe9EwcND8zciKNRqy1Q6uGE8WCw82C7+4ViLU=
50+
github.com/neilalexander/ironwood v0.0.0-20240921204201-4e4428b103ee/go.mod h1:6WP4799FX0OuWdENGQAh+0RXp9FLh0y7NZ7tM9cJyXk=
5151
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
5252
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
5353
github.com/onsi/ginkgo/v2 v2.9.5 h1:+6Hr4uxzP4XIUyAkg61dWBw8lb/gc4/X5luuxN/EC+Q=
@@ -83,8 +83,6 @@ golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
8383
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
8484
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
8585
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
86-
golang.org/x/mobile v0.0.0-20240716161057-1ad2df20a8b6 h1:/VlmIrkuLf2wzPjkZ8imSpckHoW7Y71h66dxbLHSpi8=
87-
golang.org/x/mobile v0.0.0-20240716161057-1ad2df20a8b6/go.mod h1:TCsc78+c4cqb8IKEosz2LwJ6YRNkIjMuAYeHYjchGDE=
8886
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
8987
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
9088
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=

src/admin/getpeers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type PeerEntry struct {
2424
PublicKey string `json:"key"`
2525
Port uint64 `json:"port"`
2626
Priority uint64 `json:"priority"`
27+
Cost uint64 `json:"cost"`
2728
RXBytes DataUnit `json:"bytes_recvd,omitempty"`
2829
TXBytes DataUnit `json:"bytes_sent,omitempty"`
2930
Uptime float64 `json:"uptime,omitempty"`
@@ -41,6 +42,7 @@ func (a *AdminSocket) getPeersHandler(_ *GetPeersRequest, res *GetPeersResponse)
4142
Up: p.Up,
4243
Inbound: p.Inbound,
4344
Priority: uint64(p.Priority), // can't be uint8 thanks to gobind
45+
Cost: p.Cost,
4446
URI: p.URI,
4547
RXBytes: DataUnit(p.RXBytes),
4648
TXBytes: DataUnit(p.TXBytes),

src/core/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type PeerInfo struct {
3030
Coords []uint64
3131
Port uint64
3232
Priority uint8
33+
Cost uint64
3334
RXBytes uint64
3435
TXBytes uint64
3536
Uptime time.Duration
@@ -94,6 +95,7 @@ func (c *Core) GetPeers() []PeerInfo {
9495
peerinfo.Port = p.Port
9596
peerinfo.Priority = p.Priority
9697
peerinfo.Latency = p.Latency
98+
peerinfo.Cost = p.Cost
9799
}
98100
peers = append(peers, peerinfo)
99101
}

0 commit comments

Comments
 (0)