peer online count in report

This commit is contained in:
Callan Bryant 2020-03-07 21:57:00 +00:00
parent 1fd9e03509
commit 17b0ad74ae
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
4 changed files with 19 additions and 14 deletions

2
add.go
View File

@ -3,8 +3,8 @@ package dsnet
import (
"fmt"
"os"
"time"
"text/template"
"time"
)
func Add() {

View File

@ -60,12 +60,15 @@ type DsnetReport struct {
Network JSONIPNet
DNS net.IP
Peers []PeerReport
PeersOnline int
PeersTotal int
}
func GenerateReport(dev *wgtypes.Device, conf *DsnetConfig, oldReport *DsnetReport) DsnetReport {
wgPeerIndex := make(map[wgtypes.Key]wgtypes.Peer)
peerReports := make([]PeerReport, len(conf.Peers))
oldPeerReportIndex := make(map[string]PeerReport)
peersOnline := 0
for _, peer := range dev.Peers {
wgPeerIndex[peer.PublicKey] = peer
@ -86,6 +89,7 @@ func GenerateReport(dev *wgtypes.Device, conf *DsnetConfig, oldReport *DsnetRepo
status = StatusSyncRequired
} else if time.Since(wgPeer.LastHandshakeTime) < TIMEOUT {
status = StatusOnline
peersOnline += 1
// TODO same test but with rx byte data from last report (otherwise
// peer can fake online status by disabling handshake)
} else if !wgPeer.LastHandshakeTime.IsZero() && time.Since(wgPeer.LastHandshakeTime) > EXPIRY {
@ -118,6 +122,8 @@ func GenerateReport(dev *wgtypes.Device, conf *DsnetConfig, oldReport *DsnetRepo
Network: conf.Network,
DNS: conf.DNS,
Peers: peerReports,
PeersOnline: peersOnline,
PeersTotal: len(peerReports),
}
}

View File

@ -54,7 +54,6 @@ func ConfigureDevice(conf *DsnetConfig) {
Peers: peers,
}
err = wg.ConfigureDevice(conf.InterfaceName, wgConfig)
if err != nil {