Audit changes.

This commit is contained in:
jdl
2026-06-13 19:30:03 +02:00
parent c4a81cf553
commit c325180a1b
2 changed files with 43 additions and 2 deletions

View File

@@ -1,9 +1,12 @@
package peer
import (
"fmt"
"log"
"net/netip"
"os"
"os/signal"
"strings"
"syscall"
"time"
@@ -82,6 +85,8 @@ func (a *App) Run() error {
signal.Notify(sig, syscall.SIGTERM, syscall.SIGINT)
defer signal.Stop(sig)
tickCount := 0
for {
select {
case p := <-a.hubAddCh:
@@ -94,6 +99,11 @@ func (a *App) Run() error {
a.onMulticastDiscovery(e)
case <-ticker.C:
a.onTick()
tickCount++
if tickCount%8 == 0 {
a.logNetworkState()
}
case <-sig:
return a.onShutdown()
}
@@ -103,3 +113,27 @@ func (a *App) Run() error {
func (a *App) onShutdown() error {
return wginterface.Delete(a.dev.Name())
}
func (a *App) logNetworkState() {
var b strings.Builder
fmt.Fprintf(&b, "Network state (self: %s public=%v):\n", a.vpnIP, a.isPublic)
fmt.Fprintf(&b, " IPv4: %v\n", a.selfV4)
fmt.Fprintf(&b, " IPv6: %v\n", a.selfV6)
b.WriteString("Peers:\n")
for _, p := range a.peersByIP {
switch p.State {
case StateDirect:
fmt.Fprintf(&b, " %24s %s DIRECT @ %s rtt=%s\n",
p.Name, p.VPNIP, p.WGEndpoint(), p.RTT.Round(time.Millisecond))
case StateProbing:
fmt.Fprintf(&b, " %24s %s PROBING @ %s\n",
p.Name, p.VPNIP, p.PreferredEndpoint())
case StateRelayed:
fmt.Fprintf(&b, " %24s %s RELAYED\n", p.Name, p.VPNIP)
}
}
log.Print(b.String())
}