diff --git a/cmd/yggdrasilctl/main.go b/cmd/yggdrasilctl/main.go index db823417..2a1d70b1 100644 --- a/cmd/yggdrasilctl/main.go +++ b/cmd/yggdrasilctl/main.go @@ -174,11 +174,13 @@ func run() int { if err := json.Unmarshal(recv.Response, &resp); err != nil { panic(err) } - table.SetHeader([]string{"URI", "State", "Dir", "IP Address", "Uptime", "RX", "TX", "Pr", "Last Error"}) + table.SetHeader([]string{"URI", "State", "Dir", "IP Address", "Uptime", "RTT", "RX", "TX", "Pr", "Last Error"}) for _, peer := range resp.Peers { - state, lasterr, dir := "Up", "-", "Out" + state, lasterr, dir, rtt := "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" @@ -194,6 +196,7 @@ func run() int { dir, peer.IPAddress, (time.Duration(peer.Uptime) * time.Second).String(), + rtt, peer.RXBytes.String(), peer.TXBytes.String(), fmt.Sprintf("%d", peer.Priority), diff --git a/go.mod b/go.mod index 7b3b7cc9..3dd8c848 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/yggdrasil-network/yggdrasil-go go 1.21 require ( - github.com/Arceliar/ironwood v0.0.0-20240525111224-8b482710326e + github.com/Arceliar/ironwood v0.0.0-20240529054413-b8e59574e2b2 github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d github.com/cheggaaa/pb/v3 v3.1.4 github.com/gologme/log v1.3.0 diff --git a/go.sum b/go.sum index 137b5b8c..7ee76861 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/Arceliar/ironwood v0.0.0-20240525111224-8b482710326e h1:fBcasrsrE1kVlsAlyG7Rz5/wvGFKHO4z3GfHzEc0xwE= -github.com/Arceliar/ironwood v0.0.0-20240525111224-8b482710326e/go.mod h1:6WP4799FX0OuWdENGQAh+0RXp9FLh0y7NZ7tM9cJyXk= +github.com/Arceliar/ironwood v0.0.0-20240529054413-b8e59574e2b2 h1:SBdYBKeXYUUFef5wi2CMhYmXFVGiYaRpTvbki0Bu+JQ= +github.com/Arceliar/ironwood v0.0.0-20240529054413-b8e59574e2b2/go.mod h1:6WP4799FX0OuWdENGQAh+0RXp9FLh0y7NZ7tM9cJyXk= 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= diff --git a/src/admin/getpeers.go b/src/admin/getpeers.go index aad98294..f79877ca 100644 --- a/src/admin/getpeers.go +++ b/src/admin/getpeers.go @@ -27,6 +27,7 @@ type PeerEntry struct { RXBytes DataUnit `json:"bytes_recvd,omitempty"` TXBytes DataUnit `json:"bytes_sent,omitempty"` Uptime float64 `json:"uptime,omitempty"` + Latency time.Duration `json:"latency_ms,omitempty"` LastErrorTime time.Duration `json:"last_error_time,omitempty"` LastError string `json:"last_error,omitempty"` } @@ -45,6 +46,9 @@ func (a *AdminSocket) getPeersHandler(req *GetPeersRequest, res *GetPeersRespons TXBytes: DataUnit(p.TXBytes), 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() diff --git a/src/core/api.go b/src/core/api.go index b5fa93cb..875d7bf2 100644 --- a/src/core/api.go +++ b/src/core/api.go @@ -33,6 +33,7 @@ type PeerInfo struct { RXBytes uint64 TXBytes uint64 Uptime time.Duration + Latency time.Duration } type TreeEntryInfo struct { @@ -92,6 +93,7 @@ func (c *Core) GetPeers() []PeerInfo { peerinfo.Root = p.Root peerinfo.Port = p.Port peerinfo.Priority = p.Priority + peerinfo.Latency = p.Latency } peers = append(peers, peerinfo) }