mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-11-26 01:03:08 +01:00
Added last_handshake_time fields to UAPI
This commit is contained in:
parent
bd6027a4d5
commit
18714fc4a4
@ -10,6 +10,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -58,8 +59,15 @@ func ipcGetOperation(device *Device, socket *bufio.ReadWriter) *IPCError {
|
|||||||
if peer.endpoint != nil {
|
if peer.endpoint != nil {
|
||||||
send("endpoint=" + peer.endpoint.String())
|
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",
|
send(fmt.Sprintf("persistent_keepalive_interval=%d",
|
||||||
atomic.LoadUint64(&peer.persistentKeepaliveInterval),
|
atomic.LoadUint64(&peer.persistentKeepaliveInterval),
|
||||||
))
|
))
|
||||||
|
@ -19,9 +19,12 @@ type Peer struct {
|
|||||||
keyPairs KeyPairs
|
keyPairs KeyPairs
|
||||||
handshake Handshake
|
handshake Handshake
|
||||||
device *Device
|
device *Device
|
||||||
txBytes uint64
|
stats struct {
|
||||||
rxBytes uint64
|
txBytes uint64 // bytes send to peer (endpoint)
|
||||||
time struct {
|
rxBytes uint64 // bytes received from peer
|
||||||
|
lastHandshakeNano int64 // nano seconds since epoch
|
||||||
|
}
|
||||||
|
time struct {
|
||||||
mutex sync.RWMutex
|
mutex sync.RWMutex
|
||||||
lastSend time.Time // last send message
|
lastSend time.Time // last send message
|
||||||
lastHandshake time.Time // last completed handshake
|
lastHandshake time.Time // last completed handshake
|
||||||
|
@ -540,7 +540,7 @@ func (peer *Peer) RoutineSequentialReceiver() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic.AddUint64(&peer.rxBytes, uint64(len(elem.packet)))
|
atomic.AddUint64(&peer.stats.rxBytes, uint64(len(elem.packet)))
|
||||||
device.addToInboundQueue(device.queue.inbound, elem)
|
device.addToInboundQueue(device.queue.inbound, elem)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
@ -379,7 +379,8 @@ func (peer *Peer) RoutineSequentialSender() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
atomic.AddUint64(&peer.txBytes, uint64(len(elem.packet)))
|
|
||||||
|
atomic.AddUint64(&peer.stats.txBytes, uint64(len(elem.packet)))
|
||||||
peer.TimerResetKeepalive()
|
peer.TimerResetKeepalive()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -52,6 +52,10 @@ func (peer *Peer) KeepKeyFreshReceiving() {
|
|||||||
func (peer *Peer) EventHandshakeComplete() {
|
func (peer *Peer) EventHandshakeComplete() {
|
||||||
peer.device.log.Info.Println("Negotiated new handshake for", peer.String())
|
peer.device.log.Info.Println("Negotiated new handshake for", peer.String())
|
||||||
peer.timer.zeroAllKeys.Reset(RejectAfterTime * 3)
|
peer.timer.zeroAllKeys.Reset(RejectAfterTime * 3)
|
||||||
|
atomic.StoreInt64(
|
||||||
|
&peer.stats.lastHandshakeNano,
|
||||||
|
time.Now().UnixNano(),
|
||||||
|
)
|
||||||
signalSend(peer.signal.handshakeCompleted)
|
signalSend(peer.signal.handshakeCompleted)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user