This commit is contained in:
jdl
2026-06-07 09:33:21 +02:00
parent 199f774ed3
commit cad200b9cc
16 changed files with 692 additions and 63 deletions

View File

@@ -5,6 +5,7 @@ import (
"time"
"vppn/peer/control"
"vppn/peer/wginterface"
)
func (a *App) onTick() {
@@ -13,38 +14,36 @@ func (a *App) onTick() {
a.nextPingID++
now := time.Now().UnixNano()
// Update Up values.
for _, p := range a.peersByKey {
p.Up = p.Alive()
}
for _, wgPeer := range wgPeers {
p, ok := a.peersByKey[wgPeer.PublicKey]
if !ok {
log.Fatalf("Wireguard peer not in index: %v", wgPeer)
}
p.wgPeer = wgPeer
// Send pings to peers where we're the client.
if p.Role == control.Client {
a.sendPing(p, a.nextPingID, now)
}
// Promote probing peers to direct once alive (direct path confirmed
// working).
if p.State == StateProbing && time.Since(wgPeer.LastHandshakeTime) < 2*PingInterval {
p.State = StateDirect
a.devAddDirect(p, p.WGEndpoint)
}
switch p.State() {
case StateProbing:
// Promote probing peers to direct once alive (direct path confirmed
// working).
if time.Since(p.LastHandshakeTime()) < wginterface.SessionTimeout {
a.devAddDirect(p, p.WGEndpoint())
}
// Demote stale non-public direct peers back to probing.
if p.State == StateDirect && !p.IsPublic && !p.Up {
p.State = StateProbing
a.devAddProbe(p, p.WGEndpoint)
case StateDirect:
// Demote stale non-public direct peers back to probing.
if !p.IsPublic && !p.Up() {
a.devAddProbe(p, p.WGEndpoint())
}
}
}
// Ensure we have a live relay.
if a.relay == nil || !a.relay.Up {
if a.relay == nil || !a.relay.Up() {
a.switchActiveRelay()
}
}