"strings"
"sync/atomic"
"syscall"
+ "time"
)
const (
if peer.endpoint != nil {
send("endpoint=" + peer.endpoint.String())
}
- send(fmt.Sprintf("tx_bytes=%d", peer.txBytes))
- send(fmt.Sprintf("rx_bytes=%d", peer.rxBytes))
+
+ nano := atomic.LoadInt64(&peer.stats.lastHandshakeNano)
+ secs := nano / time.Second.Nanoseconds()
+ nano %= time.Second.Nanoseconds()
+
+ send(fmt.Sprintf("last_handshake_time_sec=%d", secs))
+ send(fmt.Sprintf("last_handshake_time_nsec=%d", nano))
+ send(fmt.Sprintf("tx_bytes=%d", peer.stats.txBytes))
+ send(fmt.Sprintf("rx_bytes=%d", peer.stats.rxBytes))
send(fmt.Sprintf("persistent_keepalive_interval=%d",
atomic.LoadUint64(&peer.persistentKeepaliveInterval),
))
keyPairs KeyPairs
handshake Handshake
device *Device
- txBytes uint64
- rxBytes uint64
- time struct {
+ stats struct {
+ txBytes uint64 // bytes send to peer (endpoint)
+ rxBytes uint64 // bytes received from peer
+ lastHandshakeNano int64 // nano seconds since epoch
+ }
+ time struct {
mutex sync.RWMutex
lastSend time.Time // last send message
lastHandshake time.Time // last completed handshake
return
}
- atomic.AddUint64(&peer.rxBytes, uint64(len(elem.packet)))
+ atomic.AddUint64(&peer.stats.rxBytes, uint64(len(elem.packet)))
device.addToInboundQueue(device.queue.inbound, elem)
}()
}
if err != nil {
return
}
- atomic.AddUint64(&peer.txBytes, uint64(len(elem.packet)))
+
+ atomic.AddUint64(&peer.stats.txBytes, uint64(len(elem.packet)))
peer.TimerResetKeepalive()
}()
func (peer *Peer) EventHandshakeComplete() {
peer.device.log.Info.Println("Negotiated new handshake for", peer.String())
peer.timer.zeroAllKeys.Reset(RejectAfterTime * 3)
+ atomic.StoreInt64(
+ &peer.stats.lastHandshakeNano,
+ time.Now().UnixNano(),
+ )
signalSend(peer.signal.handshakeCompleted)
}