package peer import ( "log" "time" "vppn/peer/control" ) func (a *App) onTick() { wgPeers := a.devPeers() 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) } // 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) } // 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) } } // Ensure we have a live relay. if a.relay == nil || !a.relay.Up { a.switchActiveRelay() } }