This commit is contained in:
jdl
2026-06-08 17:29:45 +02:00
parent 96e7916721
commit a2e43ba49f
6 changed files with 20 additions and 23 deletions

View File

@@ -39,10 +39,12 @@ func (a *App) devPeers() []wgtypes.Peer {
func (a *App) devAddPeer(p *Peer) {
devRetry(p.VPNIP, "AddPeer", func() error { return a.dev.AddPeer(p.PubKey()) })
p.State = StateRelayed
}
func (a *App) devAddDirect(p *Peer, endpoint netip.AddrPort) {
devRetry(p.VPNIP, "AddDirect", func() error { return a.dev.AddDirect(p.PubKey(), endpoint, p.VPNIP) })
p.State = StateDirect
}
func (a *App) devSetRelay(p *Peer, endpoint netip.AddrPort) {
@@ -51,10 +53,12 @@ func (a *App) devSetRelay(p *Peer, endpoint netip.AddrPort) {
func (a *App) devPromote(p *Peer) {
devRetry(p.VPNIP, "Promote", func() error { return a.dev.Promote(p.PubKey(), p.VPNIP) })
p.State = StateDirect
}
func (a *App) devAddProbe(p *Peer, endpoint netip.AddrPort) {
devRetry(p.VPNIP, "AddProbe", func() error { return a.dev.AddProbe(p.PubKey(), endpoint) })
p.State = StateProbing
}
func (a *App) devRemove(p *Peer) {

View File

@@ -41,8 +41,8 @@ func TestOnAddPeer(t *testing.T) {
if a.peersByIP[peerVPNIP] == nil {
t.Fatal("not in peersByIP")
}
if p.State() != StateRelayed {
t.Fatalf("state = %v, want StateRelayed", p.State())
if p.State != StateRelayed {
t.Fatalf("state = %v, want StateRelayed", p.State)
}
dev.AssertAddPeer(t, 0, key)
},

View File

@@ -28,7 +28,7 @@ func (a *App) onMulticastDiscovery(e MulticastEvent) {
return
}
if peer.IsPublic || peer.State() == StateDirect {
if peer.IsPublic || peer.State == StateDirect {
return
}

View File

@@ -34,7 +34,7 @@ func (a *App) onPing(e PingEvent) {
// We can only learn our own endpoint from directly-connected peers — Dst
// is the sender's observation of our WG handshake source.
if peer.State() == StateDirect {
if peer.State == StateDirect {
if dst := e.ping.Dst; dst.IsValid() {
if dst.Addr().Is4() {
a.selfV4 = dst

View File

@@ -27,7 +27,7 @@ func (a *App) onTick() {
a.sendPing(p, now)
}
switch p.State() {
switch p.State {
case StateProbing:
// Promote probing peers to direct once alive (direct path confirmed
// working).

View File

@@ -19,15 +19,17 @@ const (
)
type Peer struct {
wgPeer wgtypes.Peer
VPNIP netip.Addr // VPN IP address.
IsRelay bool // Peer is a relay.
IsPublic bool // Peer has a public IP.
Endpoint4 netip.AddrPort // Reported IPv4 endpoint.
Endpoint6 netip.AddrPort // Reported IPv6 endpoint.
RTT time.Duration // Round-trip time.
Role control.Role // Client initiates pings; server responds.
SignPubKey [32]byte // nacl/sign public key for verifying multicast beacons.
wgPeer wgtypes.Peer
VPNIP netip.Addr // VPN IP address.
IsRelay bool // Peer is a relay.
IsPublic bool // Peer has a public IP.
Endpoint4 netip.AddrPort // Reported IPv4 endpoint.
Endpoint6 netip.AddrPort // Reported IPv6 endpoint.
RTT time.Duration // Round-trip time.
Role control.Role // Client initiates pings; server responds.
SignPubKey [32]byte // nacl/sign public key for verifying multicast beacons.
State PeerState // Explicit state; set by devXxx helpers.
probeDeadline time.Time // Deadline for direct-path probe; zero if not probing.
}
// PubKey is the wireguard public key.
@@ -35,15 +37,6 @@ func (p *Peer) PubKey() wgtypes.Key {
return p.wgPeer.PublicKey
}
func (p *Peer) State() PeerState {
if len(p.wgPeer.AllowedIPs) > 0 {
return StateDirect
}
if p.wgPeer.Endpoint == nil {
return StateRelayed
}
return StateProbing
}
func (p *Peer) WGEndpoint() netip.AddrPort {
ep := p.wgPeer.Endpoint