mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-11 07:59:08 +02:00
[client] Expose peer detail fields on the Android binding
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"slices"
|
"slices"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -299,6 +300,13 @@ func (c *Client) SetInfoLogLevel() {
|
|||||||
// PeersList return with the list of the PeerInfos
|
// PeersList return with the list of the PeerInfos
|
||||||
func (c *Client) PeersList() *PeerInfoArray {
|
func (c *Client) PeersList() *PeerInfoArray {
|
||||||
|
|
||||||
|
// The recorder only caches transfer counters and handshake times; nothing
|
||||||
|
// refreshes them on its own, so without this they read as zero. The desktop
|
||||||
|
// daemon does the same before serving a full peer status.
|
||||||
|
if err := c.recorder.RefreshWireGuardStats(); err != nil {
|
||||||
|
log.Debugf("failed to refresh WireGuard stats: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
fullStatus := c.recorder.GetFullStatus()
|
fullStatus := c.recorder.GetFullStatus()
|
||||||
|
|
||||||
peerInfos := make([]PeerInfo, len(fullStatus.Peers))
|
peerInfos := make([]PeerInfo, len(fullStatus.Peers))
|
||||||
@@ -309,6 +317,20 @@ func (c *Client) PeersList() *PeerInfoArray {
|
|||||||
FQDN: p.FQDN,
|
FQDN: p.FQDN,
|
||||||
ConnStatus: int(p.ConnStatus),
|
ConnStatus: int(p.ConnStatus),
|
||||||
Routes: PeerRoutes{routes: maps.Keys(p.GetRoutes())},
|
Routes: PeerRoutes{routes: maps.Keys(p.GetRoutes())},
|
||||||
|
|
||||||
|
PubKey: p.PubKey,
|
||||||
|
Latency: formatDuration(p.Latency),
|
||||||
|
LatencyMs: p.Latency.Milliseconds(),
|
||||||
|
BytesRx: p.BytesRx,
|
||||||
|
BytesTx: p.BytesTx,
|
||||||
|
ConnStatusUpdate: formatTime(p.ConnStatusUpdate),
|
||||||
|
Relayed: p.Relayed,
|
||||||
|
RosenpassEnabled: p.RosenpassEnabled,
|
||||||
|
LastWireguardHandshake: formatTime(p.LastWireguardHandshake),
|
||||||
|
LocalIceCandidateType: p.LocalIceCandidateType,
|
||||||
|
RemoteIceCandidateType: p.RemoteIceCandidateType,
|
||||||
|
LocalIceCandidateEndpoint: p.LocalIceCandidateEndpoint,
|
||||||
|
RemoteIceCandidateEndpoint: p.RemoteIceCandidateEndpoint,
|
||||||
}
|
}
|
||||||
peerInfos[n] = pi
|
peerInfos[n] = pi
|
||||||
}
|
}
|
||||||
@@ -512,3 +534,28 @@ func exportEnvList(list *EnvList) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// formatDuration renders a duration for display, trimming the fractional part
|
||||||
|
// to two digits so latencies read as "12.34ms" rather than "12.345678ms".
|
||||||
|
func formatDuration(d time.Duration) string {
|
||||||
|
ds := d.String()
|
||||||
|
dotIndex := strings.Index(ds, ".")
|
||||||
|
if dotIndex == -1 {
|
||||||
|
return ds
|
||||||
|
}
|
||||||
|
|
||||||
|
endIndex := min(dotIndex+3, len(ds))
|
||||||
|
|
||||||
|
// Skip the remaining digits so only the unit suffix is appended back.
|
||||||
|
unitStart := endIndex
|
||||||
|
for unitStart < len(ds) && ds[unitStart] >= '0' && ds[unitStart] <= '9' {
|
||||||
|
unitStart++
|
||||||
|
}
|
||||||
|
return ds[:endIndex] + ds[unitStart:]
|
||||||
|
}
|
||||||
|
|
||||||
|
// formatTime renders a timestamp in UTC using a fixed layout. The zero time is
|
||||||
|
// passed through as-is so the UI can recognise it and show "never" instead.
|
||||||
|
func formatTime(t time.Time) string {
|
||||||
|
return t.UTC().Format("2006-01-02 15:04:05")
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,12 +12,30 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// PeerInfo describe information about the peers. It designed for the UI usage
|
// PeerInfo describe information about the peers. It designed for the UI usage
|
||||||
|
//
|
||||||
|
// The fields below ConnStatus back the peer detail screen. Durations and times
|
||||||
|
// are pre-formatted into strings so the UI does not have to know Go's layouts;
|
||||||
|
// Latency is additionally exposed as LatencyMs for colour coding.
|
||||||
type PeerInfo struct {
|
type PeerInfo struct {
|
||||||
IP string
|
IP string
|
||||||
IPv6 string
|
IPv6 string
|
||||||
FQDN string
|
FQDN string
|
||||||
ConnStatus int
|
ConnStatus int
|
||||||
Routes PeerRoutes
|
Routes PeerRoutes
|
||||||
|
|
||||||
|
PubKey string
|
||||||
|
Latency string
|
||||||
|
LatencyMs int64
|
||||||
|
BytesRx int64
|
||||||
|
BytesTx int64
|
||||||
|
ConnStatusUpdate string
|
||||||
|
Relayed bool
|
||||||
|
RosenpassEnabled bool
|
||||||
|
LastWireguardHandshake string
|
||||||
|
LocalIceCandidateType string
|
||||||
|
RemoteIceCandidateType string
|
||||||
|
LocalIceCandidateEndpoint string
|
||||||
|
RemoteIceCandidateEndpoint string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PeerInfo) GetPeerRoutes() *PeerRoutes {
|
func (p *PeerInfo) GetPeerRoutes() *PeerRoutes {
|
||||||
|
|||||||
Reference in New Issue
Block a user