mirror of
https://github.com/fosrl/newt.git
synced 2026-02-08 05:56:40 +00:00
Dont ping if there is just 1
This commit is contained in:
26
main.go
26
main.go
@@ -488,6 +488,32 @@ persistent_keepalive_interval=5`, fixKey(privateKey.String()), fixKey(wgData.Pub
|
||||
return
|
||||
}
|
||||
|
||||
// If there is just one exit node, we can skip pinging it and use it directly
|
||||
if len(exitNodes) == 1 {
|
||||
logger.Debug("Only one exit node available, using it directly: %s", exitNodes[0].Endpoint)
|
||||
|
||||
// Prepare data to send to the cloud for selection
|
||||
pingResults := []ExitNodePingResult{
|
||||
{
|
||||
ExitNodeID: exitNodes[0].ID,
|
||||
LatencyMs: 0, // No ping latency since we are using it directly
|
||||
Weight: exitNodes[0].Weight,
|
||||
Error: "",
|
||||
Name: exitNodes[0].Name,
|
||||
Endpoint: exitNodes[0].Endpoint,
|
||||
WasPreviouslyConnected: exitNodes[0].WasPreviouslyConnected,
|
||||
},
|
||||
}
|
||||
|
||||
stopFunc = client.SendMessageInterval("newt/wg/register", map[string]interface{}{
|
||||
"publicKey": publicKey.String(),
|
||||
"pingResults": pingResults,
|
||||
"newtVersion": newtVersion,
|
||||
}, 1*time.Second)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type nodeResult struct {
|
||||
Node ExitNode
|
||||
Latency time.Duration
|
||||
|
||||
Reference in New Issue
Block a user