mirror of
https://github.com/h44z/wg-portal.git
synced 2025-10-04 15:36:18 +00:00
wip: ping handler per backend (#426)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package domain
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type PeerStatus struct {
|
||||
PeerId PeerIdentifier `gorm:"primaryKey;column:identifier"`
|
||||
@@ -35,3 +37,25 @@ type InterfaceStatus struct {
|
||||
BytesReceived uint64 `gorm:"column:received"`
|
||||
BytesTransmitted uint64 `gorm:"column:transmitted"`
|
||||
}
|
||||
|
||||
type PingerResult struct {
|
||||
PacketsRecv int
|
||||
PacketsSent int
|
||||
Rtts []time.Duration
|
||||
}
|
||||
|
||||
func (r PingerResult) IsPingable() bool {
|
||||
return r.PacketsRecv > 0 && r.PacketsSent > 0 && len(r.Rtts) > 0
|
||||
}
|
||||
|
||||
func (r PingerResult) AverageRtt() time.Duration {
|
||||
if len(r.Rtts) == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
var total time.Duration
|
||||
for _, rtt := range r.Rtts {
|
||||
total += rtt
|
||||
}
|
||||
return total / time.Duration(len(r.Rtts))
|
||||
}
|
||||
|
Reference in New Issue
Block a user