mirror of
https://github.com/fosrl/newt.git
synced 2026-04-02 16:06:40 +00:00
Add chain id to ping
This commit is contained in:
@@ -285,7 +285,11 @@ func startPingCheck(tnet *netstack.Net, serverIP string, client *websocket.Clien
|
|||||||
if tunnelID != "" {
|
if tunnelID != "" {
|
||||||
telemetry.IncReconnect(context.Background(), tunnelID, "client", telemetry.ReasonTimeout)
|
telemetry.IncReconnect(context.Background(), tunnelID, "client", telemetry.ReasonTimeout)
|
||||||
}
|
}
|
||||||
stopFunc = client.SendMessageInterval("newt/ping/request", map[string]interface{}{}, 3*time.Second)
|
pingChainId := generateChainId()
|
||||||
|
pendingPingChainId = pingChainId
|
||||||
|
stopFunc = client.SendMessageInterval("newt/ping/request", map[string]interface{}{
|
||||||
|
"chainId": pingChainId,
|
||||||
|
}, 3*time.Second)
|
||||||
// Send registration message to the server for backward compatibility
|
// Send registration message to the server for backward compatibility
|
||||||
bcChainId := generateChainId()
|
bcChainId := generateChainId()
|
||||||
pendingRegisterChainId = bcChainId
|
pendingRegisterChainId = bcChainId
|
||||||
|
|||||||
17
main.go
17
main.go
@@ -62,6 +62,7 @@ type TargetData struct {
|
|||||||
|
|
||||||
type ExitNodeData struct {
|
type ExitNodeData struct {
|
||||||
ExitNodes []ExitNode `json:"exitNodes"`
|
ExitNodes []ExitNode `json:"exitNodes"`
|
||||||
|
ChainId string `json:"chainId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExitNode represents an exit node with an ID, endpoint, and weight.
|
// ExitNode represents an exit node with an ID, endpoint, and weight.
|
||||||
@@ -132,6 +133,7 @@ var (
|
|||||||
pingStopChan chan struct{}
|
pingStopChan chan struct{}
|
||||||
stopFunc func()
|
stopFunc func()
|
||||||
pendingRegisterChainId string
|
pendingRegisterChainId string
|
||||||
|
pendingPingChainId string
|
||||||
healthFile string
|
healthFile string
|
||||||
useNativeInterface bool
|
useNativeInterface bool
|
||||||
authorizedKeysFile string
|
authorizedKeysFile string
|
||||||
@@ -919,8 +921,11 @@ persistent_keepalive_interval=5`, util.FixKey(privateKey.String()), util.FixKey(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Request exit nodes from the server
|
// Request exit nodes from the server
|
||||||
|
pingChainId := generateChainId()
|
||||||
|
pendingPingChainId = pingChainId
|
||||||
stopFunc = client.SendMessageInterval("newt/ping/request", map[string]interface{}{
|
stopFunc = client.SendMessageInterval("newt/ping/request", map[string]interface{}{
|
||||||
"noCloud": noCloud,
|
"noCloud": noCloud,
|
||||||
|
"chainId": pingChainId,
|
||||||
}, 3*time.Second)
|
}, 3*time.Second)
|
||||||
|
|
||||||
logger.Info("Tunnel destroyed, ready for reconnection")
|
logger.Info("Tunnel destroyed, ready for reconnection")
|
||||||
@@ -949,6 +954,7 @@ persistent_keepalive_interval=5`, util.FixKey(privateKey.String()), util.FixKey(
|
|||||||
|
|
||||||
client.RegisterHandler("newt/ping/exitNodes", func(msg websocket.WSMessage) {
|
client.RegisterHandler("newt/ping/exitNodes", func(msg websocket.WSMessage) {
|
||||||
logger.Debug("Received ping message")
|
logger.Debug("Received ping message")
|
||||||
|
|
||||||
if stopFunc != nil {
|
if stopFunc != nil {
|
||||||
stopFunc() // stop the ws from sending more requests
|
stopFunc() // stop the ws from sending more requests
|
||||||
stopFunc = nil // reset stopFunc to nil to avoid double stopping
|
stopFunc = nil // reset stopFunc to nil to avoid double stopping
|
||||||
@@ -968,6 +974,14 @@ persistent_keepalive_interval=5`, util.FixKey(privateKey.String()), util.FixKey(
|
|||||||
}
|
}
|
||||||
exitNodes := exitNodeData.ExitNodes
|
exitNodes := exitNodeData.ExitNodes
|
||||||
|
|
||||||
|
if exitNodeData.ChainId != "" {
|
||||||
|
if exitNodeData.ChainId != pendingPingChainId {
|
||||||
|
logger.Debug("Discarding duplicate/stale newt/ping/exitNodes (chainId=%s, expected=%s)", exitNodeData.ChainId, pendingPingChainId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pendingPingChainId = "" // consume – further duplicates with this id are rejected
|
||||||
|
}
|
||||||
|
|
||||||
if len(exitNodes) == 0 {
|
if len(exitNodes) == 0 {
|
||||||
logger.Info("No exit nodes provided")
|
logger.Info("No exit nodes provided")
|
||||||
return
|
return
|
||||||
@@ -1762,8 +1776,11 @@ persistent_keepalive_interval=5`, util.FixKey(privateKey.String()), util.FixKey(
|
|||||||
stopFunc()
|
stopFunc()
|
||||||
}
|
}
|
||||||
// request from the server the list of nodes to ping
|
// request from the server the list of nodes to ping
|
||||||
|
pingChainId := generateChainId()
|
||||||
|
pendingPingChainId = pingChainId
|
||||||
stopFunc = client.SendMessageInterval("newt/ping/request", map[string]interface{}{
|
stopFunc = client.SendMessageInterval("newt/ping/request", map[string]interface{}{
|
||||||
"noCloud": noCloud,
|
"noCloud": noCloud,
|
||||||
|
"chainId": pingChainId,
|
||||||
}, 3*time.Second)
|
}, 3*time.Second)
|
||||||
logger.Debug("Requesting exit nodes from server")
|
logger.Debug("Requesting exit nodes from server")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user