WIP
This commit is contained in:
@@ -39,10 +39,12 @@ func (a *App) devPeers() []wgtypes.Peer {
|
|||||||
|
|
||||||
func (a *App) devAddPeer(p *Peer) {
|
func (a *App) devAddPeer(p *Peer) {
|
||||||
devRetry(p.VPNIP, "AddPeer", func() error { return a.dev.AddPeer(p.PubKey()) })
|
devRetry(p.VPNIP, "AddPeer", func() error { return a.dev.AddPeer(p.PubKey()) })
|
||||||
|
p.State = StateRelayed
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) devAddDirect(p *Peer, endpoint netip.AddrPort) {
|
func (a *App) devAddDirect(p *Peer, endpoint netip.AddrPort) {
|
||||||
devRetry(p.VPNIP, "AddDirect", func() error { return a.dev.AddDirect(p.PubKey(), endpoint, p.VPNIP) })
|
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) {
|
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) {
|
func (a *App) devPromote(p *Peer) {
|
||||||
devRetry(p.VPNIP, "Promote", func() error { return a.dev.Promote(p.PubKey(), p.VPNIP) })
|
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) {
|
func (a *App) devAddProbe(p *Peer, endpoint netip.AddrPort) {
|
||||||
devRetry(p.VPNIP, "AddProbe", func() error { return a.dev.AddProbe(p.PubKey(), endpoint) })
|
devRetry(p.VPNIP, "AddProbe", func() error { return a.dev.AddProbe(p.PubKey(), endpoint) })
|
||||||
|
p.State = StateProbing
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) devRemove(p *Peer) {
|
func (a *App) devRemove(p *Peer) {
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ func TestOnAddPeer(t *testing.T) {
|
|||||||
if a.peersByIP[peerVPNIP] == nil {
|
if a.peersByIP[peerVPNIP] == nil {
|
||||||
t.Fatal("not in peersByIP")
|
t.Fatal("not in peersByIP")
|
||||||
}
|
}
|
||||||
if p.State() != StateRelayed {
|
if p.State != StateRelayed {
|
||||||
t.Fatalf("state = %v, want StateRelayed", p.State())
|
t.Fatalf("state = %v, want StateRelayed", p.State)
|
||||||
}
|
}
|
||||||
dev.AssertAddPeer(t, 0, key)
|
dev.AssertAddPeer(t, 0, key)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func (a *App) onMulticastDiscovery(e MulticastEvent) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if peer.IsPublic || peer.State() == StateDirect {
|
if peer.IsPublic || peer.State == StateDirect {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func (a *App) onPing(e PingEvent) {
|
|||||||
|
|
||||||
// We can only learn our own endpoint from directly-connected peers — Dst
|
// We can only learn our own endpoint from directly-connected peers — Dst
|
||||||
// is the sender's observation of our WG handshake source.
|
// 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 := e.ping.Dst; dst.IsValid() {
|
||||||
if dst.Addr().Is4() {
|
if dst.Addr().Is4() {
|
||||||
a.selfV4 = dst
|
a.selfV4 = dst
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func (a *App) onTick() {
|
|||||||
a.sendPing(p, now)
|
a.sendPing(p, now)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch p.State() {
|
switch p.State {
|
||||||
case StateProbing:
|
case StateProbing:
|
||||||
// Promote probing peers to direct once alive (direct path confirmed
|
// Promote probing peers to direct once alive (direct path confirmed
|
||||||
// working).
|
// working).
|
||||||
|
|||||||
@@ -19,15 +19,17 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Peer struct {
|
type Peer struct {
|
||||||
wgPeer wgtypes.Peer
|
wgPeer wgtypes.Peer
|
||||||
VPNIP netip.Addr // VPN IP address.
|
VPNIP netip.Addr // VPN IP address.
|
||||||
IsRelay bool // Peer is a relay.
|
IsRelay bool // Peer is a relay.
|
||||||
IsPublic bool // Peer has a public IP.
|
IsPublic bool // Peer has a public IP.
|
||||||
Endpoint4 netip.AddrPort // Reported IPv4 endpoint.
|
Endpoint4 netip.AddrPort // Reported IPv4 endpoint.
|
||||||
Endpoint6 netip.AddrPort // Reported IPv6 endpoint.
|
Endpoint6 netip.AddrPort // Reported IPv6 endpoint.
|
||||||
RTT time.Duration // Round-trip time.
|
RTT time.Duration // Round-trip time.
|
||||||
Role control.Role // Client initiates pings; server responds.
|
Role control.Role // Client initiates pings; server responds.
|
||||||
SignPubKey [32]byte // nacl/sign public key for verifying multicast beacons.
|
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.
|
// PubKey is the wireguard public key.
|
||||||
@@ -35,15 +37,6 @@ func (p *Peer) PubKey() wgtypes.Key {
|
|||||||
return p.wgPeer.PublicKey
|
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 {
|
func (p *Peer) WGEndpoint() netip.AddrPort {
|
||||||
ep := p.wgPeer.Endpoint
|
ep := p.wgPeer.Endpoint
|
||||||
|
|||||||
Reference in New Issue
Block a user