Skip to content

Commit 5fd8205

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

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

cmd/yggdrasilctl/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ 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 {
179179
state, lasterr, dir, rtt := "Up", "-", "Out", "-"
180180
if !peer.Up {
@@ -200,6 +200,7 @@ func run() int {
200200
peer.RXBytes.String(),
201201
peer.TXBytes.String(),
202202
fmt.Sprintf("%d", peer.Priority),
203+
fmt.Sprintf("%d", peer.Cost),
203204
lasterr,
204205
})
205206
}

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/yggdrasil-network/yggdrasil-go
33
go 1.21
44

55
require (
6-
github.com/Arceliar/ironwood v0.0.0-20240529054413-b8e59574e2b2
6+
github.com/Arceliar/ironwood v0.0.0-20240921214443-277f642d5db3
77
github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d
88
github.com/cheggaaa/pb/v3 v3.1.5
99
github.com/gologme/log v1.3.0
@@ -14,10 +14,10 @@ require (
1414
github.com/vishvananda/netlink v1.1.0
1515
github.com/wlynxg/anet v0.0.4-0.20240806025826-e684438fc7c6
1616
golang.org/x/crypto v0.25.0
17-
golang.org/x/mobile v0.0.0-20240716161057-1ad2df20a8b6
1817
golang.org/x/net v0.27.0
1918
golang.org/x/sys v0.22.0
2019
golang.org/x/text v0.16.0
20+
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2
2121
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173
2222
golang.zx2c4.com/wireguard/windows v0.5.3
2323
nhooyr.io/websocket v1.8.11
@@ -36,7 +36,6 @@ require (
3636
golang.org/x/mod v0.19.0 // indirect
3737
golang.org/x/sync v0.7.0 // indirect
3838
golang.org/x/tools v0.23.0 // indirect
39-
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
4039
)
4140

4241
require (

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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=
1+
github.com/Arceliar/ironwood v0.0.0-20240921214443-277f642d5db3 h1:OJ49qTfdw5MNkpnRraNEsVQbHahSvShh8Z9WYpZrYa0=
2+
github.com/Arceliar/ironwood v0.0.0-20240921214443-277f642d5db3/go.mod h1:6WP4799FX0OuWdENGQAh+0RXp9FLh0y7NZ7tM9cJyXk=
33
github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d h1:UK9fsWbWqwIQkMCz1CP+v5pGbsGoWAw6g4AyvMpm1EM=
44
github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d/go.mod h1:BCnxhRf47C/dy/e/D2pmB8NkB3dQVIrkD98b220rx5Q=
55
github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
@@ -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)