diff --git a/controllers/hosts.go b/controllers/hosts.go index a1015cf95..e9c8d1a8a 100644 --- a/controllers/hosts.go +++ b/controllers/hosts.go @@ -319,6 +319,9 @@ func hostUpdateFallback(w http.ResponseWriter, r *http.Request) { switch hostUpdate.Action { case models.CheckIn: sendPeerUpdate = mq.HandleHostCheckin(&hostUpdate.Host, currentHost) + if sendPeerUpdate { + slog.Error("sendPeerUpdate from CheckIn", "Debug", sendPeerUpdate, &hostUpdate.Host.Name, &hostUpdate.Host.ID) + } case models.UpdateHost: if hostUpdate.Host.PublicKey != currentHost.PublicKey { @@ -326,6 +329,9 @@ func hostUpdateFallback(w http.ResponseWriter, r *http.Request) { replacePeers = true } sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost) + if sendPeerUpdate { + slog.Error("sendPeerUpdate from UpdateHost", "Debug", sendPeerUpdate, &hostUpdate.Host.Name, &hostUpdate.Host.ID) + } err := logic.UpsertHost(currentHost) if err != nil { slog.Error("failed to update host", "id", currentHost.ID, "error", err) diff --git a/logic/hosts.go b/logic/hosts.go index 8fd125c52..c182e68ba 100644 --- a/logic/hosts.go +++ b/logic/hosts.go @@ -243,25 +243,30 @@ func UpdateHost(newHost, currentHost *models.Host) { // UpdateHostFromClient - used for updating host on server with update recieved from client func UpdateHostFromClient(newHost, currHost *models.Host) (sendPeerUpdate bool) { if newHost.PublicKey != currHost.PublicKey { + slog.Error("PublicKey changed:", "Debug") currHost.PublicKey = newHost.PublicKey sendPeerUpdate = true } if newHost.ListenPort != 0 && currHost.ListenPort != newHost.ListenPort { + slog.Error("ListenPort changed:", "Debug", currHost.ListenPort, newHost.ListenPort) currHost.ListenPort = newHost.ListenPort sendPeerUpdate = true } if newHost.WgPublicListenPort != 0 && currHost.WgPublicListenPort != newHost.WgPublicListenPort { + slog.Error("WgPublicListenPort changed:", "Debug", currHost.WgPublicListenPort, newHost.WgPublicListenPort) currHost.WgPublicListenPort = newHost.WgPublicListenPort sendPeerUpdate = true } isEndpointChanged := false if currHost.EndpointIP.String() != newHost.EndpointIP.String() { + slog.Error("EndpointIP changed:", "Debug", currHost.EndpointIP, newHost.EndpointIP) currHost.EndpointIP = newHost.EndpointIP sendPeerUpdate = true isEndpointChanged = true } if currHost.EndpointIPv6.String() != newHost.EndpointIPv6.String() { + slog.Error("EndpointIPv6 changed:", "Debug", currHost.EndpointIPv6, newHost.EndpointIPv6) currHost.EndpointIPv6 = newHost.EndpointIPv6 sendPeerUpdate = true isEndpointChanged = true @@ -290,6 +295,7 @@ func UpdateHostFromClient(newHost, currHost *models.Host) (sendPeerUpdate bool) currHost.Name = newHost.Name if len(newHost.NatType) > 0 && newHost.NatType != currHost.NatType { + slog.Error("NatType changed:", "Debug", currHost.NatType, newHost.NatType) currHost.NatType = newHost.NatType sendPeerUpdate = true } diff --git a/mq/handlers.go b/mq/handlers.go index 129133268..3e23047a4 100644 --- a/mq/handlers.go +++ b/mq/handlers.go @@ -106,6 +106,10 @@ func UpdateHost(client mqtt.Client, msg mqtt.Message) { switch hostUpdate.Action { case models.CheckIn: sendPeerUpdate = HandleHostCheckin(&hostUpdate.Host, currentHost) + if sendPeerUpdate { + slog.Error("sendPeerUpdate from UpdateHost.CheckIn", "Debug", sendPeerUpdate, &hostUpdate.Host.Name, &hostUpdate.Host.ID) + } + case models.Acknowledgement: hu := hostactions.GetAction(currentHost.ID.String()) if hu != nil { @@ -129,6 +133,9 @@ func UpdateHost(client mqtt.Client, msg mqtt.Message) { replacePeers = true } sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost) + if sendPeerUpdate { + slog.Error("sendPeerUpdate from UpdateHost.UpdateHost", "Debug", sendPeerUpdate, &hostUpdate.Host.Name, &hostUpdate.Host.ID) + } err := logic.UpsertHost(currentHost) if err != nil { slog.Error("failed to update host", "id", currentHost.ID, "error", err) diff --git a/mq/publishers.go b/mq/publishers.go index 5aac351ef..91241e43a 100644 --- a/mq/publishers.go +++ b/mq/publishers.go @@ -18,16 +18,17 @@ import ( var batchSize = servercfg.GetPeerUpdateBatchSize() var batchUpdate = servercfg.GetBatchPeerUpdate() -var peerUpdateTS = time.Now().Unix() + +//var peerUpdateTS = time.Now().Unix() // PublishPeerUpdate --- determines and publishes a peer update to all the hosts func PublishPeerUpdate(replacePeers bool) error { slog.Error("entering PublishPeerUpdate", "Debug") t1 := time.Now().Unix() - if time.Now().Unix()-peerUpdateTS < 60 { - return nil - } - peerUpdateTS = time.Now().Unix() + //if time.Now().Unix()-peerUpdateTS < 60 { + // return nil + //} + //peerUpdateTS = time.Now().Unix() pc, file, no, ok := runtime.Caller(1) if ok {