WIP
This commit is contained in:
@@ -10,19 +10,16 @@ import (
|
||||
)
|
||||
|
||||
func (a *App) onAddPeer(p HubPeer) {
|
||||
if _, exists := a.peersByKey[p.PubKey]; exists {
|
||||
a.onRemovePeer(p.PubKey)
|
||||
}
|
||||
a.onRemovePeer(p.PubKey)
|
||||
|
||||
peer := &Peer{
|
||||
PubKey: p.PubKey,
|
||||
wgPeer: wgtypes.Peer{PublicKey: p.PubKey},
|
||||
VPNIP: p.VPNIP,
|
||||
IsRelay: p.IsRelay,
|
||||
IsPublic: p.IsPublic,
|
||||
Endpoint4: p.EndpointV4,
|
||||
Endpoint6: p.EndpointV6,
|
||||
Role: roleFor(a.isPublic, a.vpnIP, p),
|
||||
State: StateRelayed,
|
||||
}
|
||||
|
||||
endpoint := peer.PreferredEndpoint()
|
||||
@@ -36,11 +33,10 @@ func (a *App) onAddPeer(p HubPeer) {
|
||||
a.peersByIP[peer.VPNIP] = peer
|
||||
|
||||
if !peer.IsPublic {
|
||||
a.devAddPeer(peer)
|
||||
return
|
||||
}
|
||||
|
||||
peer.WGEndpoint = endpoint
|
||||
peer.State = StateDirect
|
||||
a.devAddDirect(peer, endpoint)
|
||||
}
|
||||
|
||||
@@ -62,7 +58,7 @@ func (a *App) onRemovePeer(key wgtypes.Key) {
|
||||
// switchActiveRelay promotes the lowest-latency relay peer to active.
|
||||
func (a *App) switchActiveRelay() {
|
||||
if a.relay != nil {
|
||||
a.devAddDirect(a.relay, a.relay.WGEndpoint)
|
||||
a.devAddDirect(a.relay, a.relay.WGEndpoint())
|
||||
a.relay = nil
|
||||
}
|
||||
|
||||
@@ -81,10 +77,11 @@ func (a *App) switchActiveRelay() {
|
||||
return
|
||||
}
|
||||
|
||||
a.devSetRelay(best, best.WGEndpoint)
|
||||
a.devSetRelay(best, best.WGEndpoint())
|
||||
a.relay = best
|
||||
}
|
||||
|
||||
// TODO: Why not < ??
|
||||
// betterRelay reports whether a is a better relay candidate than b.
|
||||
// Prefers lower RTT; treats zero RTT (no measurement yet) as worst case.
|
||||
func betterRelay(a, b *Peer) bool {
|
||||
|
||||
Reference in New Issue
Block a user