fix(go): check for overlapping ports on endpoint change;

This commit is contained in:
VishalDalwadi
2026-04-16 18:05:20 +05:30
parent 942120df5b
commit 16d2749df1
4 changed files with 15 additions and 5 deletions
+4 -1
View File
@@ -426,7 +426,10 @@ func handleHostRegister(w http.ResponseWriter, r *http.Request) {
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
return
}
logic.UpdateHostFromClient(&newHost, currHost)
endpointChanged, _ := logic.UpdateHostFromClient(&newHost, currHost)
if endpointChanged {
logic.CheckHostPorts(currHost)
}
if err = logic.UpsertHost(currHost); err != nil {
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
return
+5 -1
View File
@@ -521,7 +521,11 @@ func hostUpdateFallback(w http.ResponseWriter, r *http.Request) {
//remove old peer entry
replacePeers = true
}
sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
var endpointChanged bool
endpointChanged, sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
if endpointChanged {
logic.CheckHostPorts(currentHost)
}
err := logic.UpsertHost(currentHost)
if err != nil {
slog.Error("failed to update host", "id", currentHost.ID, "error", err)
+1 -2
View File
@@ -175,7 +175,7 @@ func UpdateHost(newHost, currentHost *schema.Host) {
}
// UpdateHostFromClient - used for updating host on server with update recieved from client
func UpdateHostFromClient(newHost, currHost *schema.Host) (sendPeerUpdate bool) {
func UpdateHostFromClient(newHost, currHost *schema.Host) (isEndpointChanged, sendPeerUpdate bool) {
if newHost.PublicKey != currHost.PublicKey {
currHost.PublicKey = newHost.PublicKey
sendPeerUpdate = true
@@ -189,7 +189,6 @@ func UpdateHostFromClient(newHost, currHost *schema.Host) (sendPeerUpdate bool)
currHost.WgPublicListenPort = newHost.WgPublicListenPort
sendPeerUpdate = true
}
isEndpointChanged := false
if !currHost.EndpointIP.Equal(newHost.EndpointIP) {
currHost.EndpointIP = newHost.EndpointIP
sendPeerUpdate = true
+5 -1
View File
@@ -140,7 +140,11 @@ func UpdateHost(client mqtt.Client, msg mqtt.Message) {
//remove old peer entry
replacePeers = true
}
sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
var endpointChanged bool
endpointChanged, sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
if endpointChanged {
logic.CheckHostPorts(currentHost)
}
err := logic.UpsertHost(currentHost)
if err != nil {
slog.Error("failed to update host", "id", currentHost.ID, "error", err)