This commit is contained in:
jdl
2026-06-15 20:15:06 +02:00
parent b86b43f1de
commit fe9f15bec9
2 changed files with 12 additions and 2 deletions

View File

@@ -28,8 +28,12 @@ func (a *App) onStateTick() {
switch p.State { switch p.State {
case StateRelayed: case StateRelayed:
// If we have an ep to probe, add it. if p.DirectAlive() {
if ep := p.PreferredEndpoint(); ep.IsValid() { // We may already have a valid direct endpoint due to wireguard
// roaming.
a.devPromote(p)
} else if ep := p.PreferredEndpoint(); ep.IsValid() {
// If we have an ep to probe, add it.
a.devAddProbe(p, ep) a.devAddProbe(p, ep)
} }

View File

@@ -7,6 +7,7 @@ import (
"golang.zx2c4.com/wireguard/wgctrl/wgtypes" "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"vppn/peer/control" "vppn/peer/control"
"vppn/peer/wginterface"
) )
type PeerState string type PeerState string
@@ -61,6 +62,11 @@ func (p *Peer) Up() bool {
return time.Since(p.LastPing) < 3*PingInterval return time.Since(p.LastPing) < 3*PingInterval
} }
func (p *Peer) DirectAlive() bool {
return p.WGEndpoint().IsValid() &&
time.Since(p.LastHandshakeTime()) < 2*wginterface.ProbeKeepalive
}
func (p *Peer) CanRelay() bool { func (p *Peer) CanRelay() bool {
return p.IsRelay && p.Up() return p.IsRelay && p.Up()
} }