Handle server version and prevent backward issues with clients

This commit is contained in:
Owen
2025-12-08 11:48:14 -05:00
parent 87e2eb33db
commit 3bcafbf07a
3 changed files with 23 additions and 5 deletions

View File

@@ -1389,7 +1389,12 @@ persistent_keepalive_interval=5`, util.FixKey(privateKey.String()), util.FixKey(
"noCloud": noCloud, "noCloud": noCloud,
}, 3*time.Second) }, 3*time.Second)
logger.Debug("Requesting exit nodes from server") logger.Debug("Requesting exit nodes from server")
clientsOnConnect()
if client.GetServerVersion() != "" { // to prevent issues with running newt > 1.7 versions with older servers
clientsOnConnect()
} else {
logger.Warn("CLIENTS WILL NOT WORK ON THIS VERSION OF NEWT WITH THIS VERSION OF PANGOLIN, PLEASE UPDATE THE SERVER TO 1.13 OR HIGHER OR DOWNGRADE NEWT")
}
} }
// Send registration message to the server for backward compatibility // Send registration message to the server for backward compatibility

View File

@@ -46,6 +46,7 @@ type Client struct {
metricsCtxMu sync.RWMutex metricsCtxMu sync.RWMutex
metricsCtx context.Context metricsCtx context.Context
configNeedsSave bool // Flag to track if config needs to be saved configNeedsSave bool // Flag to track if config needs to be saved
serverVersion string
} }
type ClientOption func(*Client) type ClientOption func(*Client)
@@ -149,6 +150,10 @@ func (c *Client) GetConfig() *Config {
return c.config return c.config
} }
func (c *Client) GetServerVersion() string {
return c.serverVersion
}
// Connect establishes the WebSocket connection // Connect establishes the WebSocket connection
func (c *Client) Connect() error { func (c *Client) Connect() error {
go c.connectWithRetry() go c.connectWithRetry()
@@ -351,9 +356,11 @@ func (c *Client) getToken() (string, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
logger.Debug("Token response body: %s", string(body))
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body) logger.Error("Failed to get token with status code: %d", resp.StatusCode)
logger.Error("Failed to get token with status code: %d, body: %s", resp.StatusCode, string(body))
telemetry.IncConnAttempt(ctx, "auth", "failure") telemetry.IncConnAttempt(ctx, "auth", "failure")
etype := "io_error" etype := "io_error"
if resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden { if resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden {
@@ -368,7 +375,7 @@ func (c *Client) getToken() (string, error) {
} }
var tokenResp TokenResponse var tokenResp TokenResponse
if err := json.NewDecoder(resp.Body).Decode(&tokenResp); err != nil { if err := json.Unmarshal(body, &tokenResp); err != nil {
logger.Error("Failed to decode token response.") logger.Error("Failed to decode token response.")
return "", fmt.Errorf("failed to decode token response: %w", err) return "", fmt.Errorf("failed to decode token response: %w", err)
} }
@@ -381,6 +388,11 @@ func (c *Client) getToken() (string, error) {
return "", fmt.Errorf("received empty token from server") return "", fmt.Errorf("received empty token from server")
} }
// print server version
logger.Info("Server version: %s", tokenResp.Data.ServerVersion)
c.serverVersion = tokenResp.Data.ServerVersion
logger.Debug("Received token: %s", tokenResp.Data.Token) logger.Debug("Received token: %s", tokenResp.Data.Token)
telemetry.IncConnAttempt(ctx, "auth", "success") telemetry.IncConnAttempt(ctx, "auth", "success")

View File

@@ -9,7 +9,8 @@ type Config struct {
type TokenResponse struct { type TokenResponse struct {
Data struct { Data struct {
Token string `json:"token"` Token string `json:"token"`
ServerVersion string `json:"serverVersion"`
} `json:"data"` } `json:"data"`
Success bool `json:"success"` Success bool `json:"success"`
Message string `json:"message"` Message string `json:"message"`