Extend getSessions admin call to include uptime/TX/RX

This commit is contained in:
Neil Alexander 2022-09-03 16:55:57 +01:00
parent 5477566fa9
commit dc9720e580
6 changed files with 23 additions and 97 deletions

View file

@ -16,8 +16,11 @@ type GetSessionsResponse struct {
}
type SessionEntry struct {
IPAddress string `json:"address"`
PublicKey string `json:"key"`
IPAddress string `json:"address"`
PublicKey string `json:"key"`
RXBytes DataUnit `json:"bytes_recvd"`
TXBytes DataUnit `json:"bytes_sent"`
Uptime float64 `json:"uptime"`
}
func (a *AdminSocket) getSessionsHandler(req *GetSessionsRequest, res *GetSessionsResponse) error {
@ -28,6 +31,9 @@ func (a *AdminSocket) getSessionsHandler(req *GetSessionsRequest, res *GetSessio
res.Sessions = append(res.Sessions, SessionEntry{
IPAddress: net.IP(addr[:]).String(),
PublicKey: hex.EncodeToString(s.Key[:]),
RXBytes: DataUnit(s.RXBytes),
TXBytes: DataUnit(s.TXBytes),
Uptime: s.Uptime.Seconds(),
})
}
sort.SliceStable(res.Sessions, func(i, j int) bool {

View file

@ -50,7 +50,10 @@ type PathEntryInfo struct {
}
type SessionInfo struct {
Key ed25519.PublicKey
Key ed25519.PublicKey
RXBytes uint64
TXBytes uint64
Uptime time.Duration
}
func (c *Core) GetSelf() SelfInfo {
@ -122,6 +125,9 @@ func (c *Core) GetSessions() []SessionInfo {
for _, s := range ss {
var info SessionInfo
info.Key = s.Key
info.RXBytes = s.RX
info.TXBytes = s.TX
info.Uptime = s.Uptime
sessions = append(sessions, info)
}
return sessions