(&mut self)
| 1308 | } |
| 1309 | |
| 1310 | pub(crate) fn refresh_state(&mut self) -> Result<()> { |
| 1311 | // Get local WG handshakes and sync to KvStore |
| 1312 | let handshakes = self.latest_handshakes(None)?; |
| 1313 | |
| 1314 | // Build a map from public_key to instance_id for lookup |
| 1315 | let pk_to_id: BTreeMap<&str, &str> = self |
| 1316 | .state |
| 1317 | .instances |
| 1318 | .iter() |
| 1319 | .map(|(id, info)| (info.public_key.as_str(), id.as_str())) |
| 1320 | .collect(); |
| 1321 | |
| 1322 | // Sync local handshake observations to KvStore |
| 1323 | for (pk, (ts, _)) in &handshakes { |
| 1324 | if let Some(&instance_id) = pk_to_id.get(pk.as_str()) { |
| 1325 | if let Err(err) = self.kv_store.sync_instance_handshake(instance_id, *ts) { |
| 1326 | debug!("failed to sync instance handshake: {err:?}"); |
| 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | // Update this node's last_seen in KvStore |
| 1332 | let now = SystemTime::now() |
| 1333 | .duration_since(UNIX_EPOCH) |
| 1334 | .map(|d| d.as_secs()) |
| 1335 | .unwrap_or(0); |
| 1336 | if let Err(err) = self |
| 1337 | .kv_store |
| 1338 | .sync_node_last_seen(self.config.sync.node_id, now) |
| 1339 | { |
| 1340 | debug!("failed to sync node last_seen: {err:?}"); |
| 1341 | } |
| 1342 | Ok(()) |
| 1343 | } |
| 1344 | |
| 1345 | /// Sync connection count for an instance to KvStore |
| 1346 | pub(crate) fn sync_connections(&self, instance_id: &str, count: u64) { |
no test coverage detected