Restore uptime, bytes_sent and bytes_recvd to getPeers (#888)

* Restore `uptime`, `bytes_sent` and `bytes_recvd` to the admin API for peers

* Wrap conn in Yggdrasil instead, so not necessary to do so in Ironwood

* Shuffle struct for alignment
This commit is contained in:
Neil Alexander 2022-02-01 13:37:45 +00:00 committed by GitHub
parent 9f5cc0eecb
commit 2d2ad4692b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 7 deletions

View file

@ -2,12 +2,16 @@ package core
import (
"crypto/ed25519"
"sync/atomic"
"time"
//"encoding/hex"
"encoding/json"
//"errors"
//"fmt"
"net"
"net/url"
//"sort"
//"time"
@ -24,11 +28,14 @@ type Self struct {
}
type Peer struct {
Key ed25519.PublicKey
Root ed25519.PublicKey
Coords []uint64
Port uint64
Remote string
Key ed25519.PublicKey
Root ed25519.PublicKey
Coords []uint64
Port uint64
Remote string
RXBytes uint64
TXBytes uint64
Uptime time.Duration
}
type DHTEntry struct {
@ -74,6 +81,11 @@ func (c *Core) GetPeers() []Peer {
if name := names[p.Conn]; name != "" {
info.Remote = name
}
if linkconn, ok := p.Conn.(*linkConn); ok {
info.RXBytes = atomic.LoadUint64(&linkconn.rx)
info.TXBytes = atomic.LoadUint64(&linkconn.tx)
info.Uptime = time.Since(linkconn.up)
}
peers = append(peers, info)
}
return peers