From 69eb6f17c6ea4491f6796c0c685c7bad92a27faa Mon Sep 17 00:00:00 2001 From: Pascal Fischer Date: Fri, 3 May 2024 17:30:26 +0200 Subject: [PATCH 1/2] remove stacktrace --- management/server/peer.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/management/server/peer.go b/management/server/peer.go index afb5e5fbc..8a080eea3 100644 --- a/management/server/peer.go +++ b/management/server/peer.go @@ -3,7 +3,6 @@ package server import ( "fmt" "net" - "runtime/debug" "strings" "time" @@ -290,7 +289,6 @@ func (am *DefaultAccountManager) DeletePeer(accountID, peerID, userID string) er // GetNetworkMap returns Network map for a given peer (omits original peer from the Peers result) func (am *DefaultAccountManager) GetNetworkMap(peerID string) (*NetworkMap, error) { - log.Debugf("GetNetworkMap with trace: %s", string(debug.Stack())) account, err := am.Store.GetAccountByPeerID(peerID) if err != nil { return nil, err From 0dc050b354a9c7485c75fc80d9ed85f38daefe92 Mon Sep 17 00:00:00 2001 From: Pascal Fischer Date: Mon, 6 May 2024 13:25:46 +0200 Subject: [PATCH 2/2] update sqlite operations --- management/server/sqlite_store.go | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/management/server/sqlite_store.go b/management/server/sqlite_store.go index bdb889919..6215267f2 100644 --- a/management/server/sqlite_store.go +++ b/management/server/sqlite_store.go @@ -279,15 +279,11 @@ func (s *SqliteStore) GetInstallationID() string { } func (s *SqliteStore) SavePeerStatus(accountID, peerID string, peerStatus nbpeer.PeerStatus) error { - var peer nbpeer.Peer - result := s.db.Model(&peer). + var peerCopy nbpeer.Peer + peerCopy.Status = &peerStatus + result := s.db.Model(&nbpeer.Peer{}). Where("account_id = ? AND id = ?", accountID, peerID). - Updates(map[string]interface{}{ - "peer_status_last_seen": peerStatus.LastSeen, - "peer_status_connected": peerStatus.Connected, - "peer_status_login_expired": peerStatus.LoginExpired, - "peer_status_requires_approval": peerStatus.RequiresApproval, - }) + Updates(peerCopy) if result.Error != nil { return result.Error @@ -301,16 +297,15 @@ func (s *SqliteStore) SavePeerStatus(accountID, peerID string, peerStatus nbpeer } func (s *SqliteStore) SavePeerLocation(accountID string, peerWithLocation *nbpeer.Peer) error { - location := peerWithLocation.Location + // To maintain data integrity, we create a copy of the peer's location to prevent unintended updates to other fields. + var peerCopy nbpeer.Peer + // Since the location field has been migrated to JSON serialization, + // updating the struct ensures the correct data format is inserted into the database. + peerCopy.Location = peerWithLocation.Location - var peer nbpeer.Peer - result := s.db.Model(&peer).Where("account_id = ? and id = ?", accountID, peerWithLocation.ID). - Updates(map[string]interface{}{ - "location_connection_ip": location.ConnectionIP, - "location_country_code": location.CountryCode, - "location_city_name": location.CityName, - "location_geo_name_id": location.GeoNameID, - }) + result := s.db.Model(&nbpeer.Peer{}). + Where("account_id = ? and id = ?", accountID, peerWithLocation.ID). + Updates(peerCopy) if result.Error != nil { return result.Error