mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
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:
parent
9f5cc0eecb
commit
2d2ad4692b
3 changed files with 51 additions and 7 deletions
|
@ -14,6 +14,8 @@ import (
|
|||
//"sync/atomic"
|
||||
"time"
|
||||
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/address"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/util"
|
||||
"golang.org/x/net/proxy"
|
||||
|
@ -40,7 +42,7 @@ type linkInfo struct {
|
|||
type link struct {
|
||||
lname string
|
||||
links *links
|
||||
conn net.Conn
|
||||
conn *linkConn
|
||||
options linkOptions
|
||||
info linkInfo
|
||||
incoming bool
|
||||
|
@ -124,7 +126,10 @@ func (l *links) call(u *url.URL, sintf string) error {
|
|||
func (l *links) create(conn net.Conn, name, linkType, local, remote string, incoming, force bool, options linkOptions) (*link, error) {
|
||||
// Technically anything unique would work for names, but let's pick something human readable, just for debugging
|
||||
intf := link{
|
||||
conn: conn,
|
||||
conn: &linkConn{
|
||||
Conn: conn,
|
||||
up: time.Now(),
|
||||
},
|
||||
lname: name,
|
||||
links: l,
|
||||
options: options,
|
||||
|
@ -272,3 +277,24 @@ func (intf *link) close() {
|
|||
func (intf *link) name() string {
|
||||
return intf.lname
|
||||
}
|
||||
|
||||
type linkConn struct {
|
||||
// tx and rx are at the beginning of the struct to ensure 64-bit alignment
|
||||
// on 32-bit platforms, see https://pkg.go.dev/sync/atomic#pkg-note-BUG
|
||||
rx uint64
|
||||
tx uint64
|
||||
up time.Time
|
||||
net.Conn
|
||||
}
|
||||
|
||||
func (c *linkConn) Read(p []byte) (n int, err error) {
|
||||
n, err = c.Conn.Read(p)
|
||||
atomic.AddUint64(&c.rx, uint64(n))
|
||||
return
|
||||
}
|
||||
|
||||
func (c *linkConn) Write(p []byte) (n int, err error) {
|
||||
n, err = c.Conn.Write(p)
|
||||
atomic.AddUint64(&c.tx, uint64(n))
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue