mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-12-22 22:15:46 +00:00
Measure RTT, report in getPeers
(#1143)
Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
This commit is contained in:
parent
fcefb20993
commit
f788a18bef
@ -174,11 +174,13 @@ func run() int {
|
|||||||
if err := json.Unmarshal(recv.Response, &resp); err != nil {
|
if err := json.Unmarshal(recv.Response, &resp); err != nil {
|
||||||
panic(err)
|
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 {
|
for _, peer := range resp.Peers {
|
||||||
state, lasterr, dir := "Up", "-", "Out"
|
state, lasterr, dir, rtt := "Up", "-", "Out", "-"
|
||||||
if !peer.Up {
|
if !peer.Up {
|
||||||
state, lasterr = "Down", fmt.Sprintf("%s ago: %s", peer.LastErrorTime.Round(time.Second), peer.LastError)
|
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 {
|
if peer.Inbound {
|
||||||
dir = "In"
|
dir = "In"
|
||||||
@ -194,6 +196,7 @@ func run() int {
|
|||||||
dir,
|
dir,
|
||||||
peer.IPAddress,
|
peer.IPAddress,
|
||||||
(time.Duration(peer.Uptime) * time.Second).String(),
|
(time.Duration(peer.Uptime) * time.Second).String(),
|
||||||
|
rtt,
|
||||||
peer.RXBytes.String(),
|
peer.RXBytes.String(),
|
||||||
peer.TXBytes.String(),
|
peer.TXBytes.String(),
|
||||||
fmt.Sprintf("%d", peer.Priority),
|
fmt.Sprintf("%d", peer.Priority),
|
||||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/yggdrasil-network/yggdrasil-go
|
|||||||
go 1.21
|
go 1.21
|
||||||
|
|
||||||
require (
|
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/Arceliar/phony v0.0.0-20220903101357-530938a4b13d
|
||||||
github.com/cheggaaa/pb/v3 v3.1.4
|
github.com/cheggaaa/pb/v3 v3.1.4
|
||||||
github.com/gologme/log v1.3.0
|
github.com/gologme/log v1.3.0
|
||||||
|
4
go.sum
4
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-20240529054413-b8e59574e2b2 h1:SBdYBKeXYUUFef5wi2CMhYmXFVGiYaRpTvbki0Bu+JQ=
|
||||||
github.com/Arceliar/ironwood v0.0.0-20240525111224-8b482710326e/go.mod h1:6WP4799FX0OuWdENGQAh+0RXp9FLh0y7NZ7tM9cJyXk=
|
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 h1:UK9fsWbWqwIQkMCz1CP+v5pGbsGoWAw6g4AyvMpm1EM=
|
||||||
github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d/go.mod h1:BCnxhRf47C/dy/e/D2pmB8NkB3dQVIrkD98b220rx5Q=
|
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 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
|
||||||
|
@ -27,6 +27,7 @@ type PeerEntry struct {
|
|||||||
RXBytes DataUnit `json:"bytes_recvd,omitempty"`
|
RXBytes DataUnit `json:"bytes_recvd,omitempty"`
|
||||||
TXBytes DataUnit `json:"bytes_sent,omitempty"`
|
TXBytes DataUnit `json:"bytes_sent,omitempty"`
|
||||||
Uptime float64 `json:"uptime,omitempty"`
|
Uptime float64 `json:"uptime,omitempty"`
|
||||||
|
Latency time.Duration `json:"latency_ms,omitempty"`
|
||||||
LastErrorTime time.Duration `json:"last_error_time,omitempty"`
|
LastErrorTime time.Duration `json:"last_error_time,omitempty"`
|
||||||
LastError string `json:"last_error,omitempty"`
|
LastError string `json:"last_error,omitempty"`
|
||||||
}
|
}
|
||||||
@ -45,6 +46,9 @@ func (a *AdminSocket) getPeersHandler(req *GetPeersRequest, res *GetPeersRespons
|
|||||||
TXBytes: DataUnit(p.TXBytes),
|
TXBytes: DataUnit(p.TXBytes),
|
||||||
Uptime: p.Uptime.Seconds(),
|
Uptime: p.Uptime.Seconds(),
|
||||||
}
|
}
|
||||||
|
if p.Latency > 0 {
|
||||||
|
peer.Latency = p.Latency
|
||||||
|
}
|
||||||
if addr := address.AddrForKey(p.Key); addr != nil {
|
if addr := address.AddrForKey(p.Key); addr != nil {
|
||||||
peer.PublicKey = hex.EncodeToString(p.Key)
|
peer.PublicKey = hex.EncodeToString(p.Key)
|
||||||
peer.IPAddress = net.IP(addr[:]).String()
|
peer.IPAddress = net.IP(addr[:]).String()
|
||||||
|
@ -33,6 +33,7 @@ type PeerInfo struct {
|
|||||||
RXBytes uint64
|
RXBytes uint64
|
||||||
TXBytes uint64
|
TXBytes uint64
|
||||||
Uptime time.Duration
|
Uptime time.Duration
|
||||||
|
Latency time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
type TreeEntryInfo struct {
|
type TreeEntryInfo struct {
|
||||||
@ -92,6 +93,7 @@ func (c *Core) GetPeers() []PeerInfo {
|
|||||||
peerinfo.Root = p.Root
|
peerinfo.Root = p.Root
|
||||||
peerinfo.Port = p.Port
|
peerinfo.Port = p.Port
|
||||||
peerinfo.Priority = p.Priority
|
peerinfo.Priority = p.Priority
|
||||||
|
peerinfo.Latency = p.Latency
|
||||||
}
|
}
|
||||||
peers = append(peers, peerinfo)
|
peers = append(peers, peerinfo)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user