| 40 | |
| 41 | impl AdminRpcHandler { |
| 42 | pub(crate) async fn status(self) -> Result<StatusResponse> { |
| 43 | let (base_domain, _port) = self |
| 44 | .state |
| 45 | .kv_store() |
| 46 | .get_best_zt_domain() |
| 47 | .unwrap_or_default(); |
| 48 | let mut state = self.state.lock(); |
| 49 | state.refresh_state()?; |
| 50 | let hosts = state |
| 51 | .state |
| 52 | .instances |
| 53 | .values() |
| 54 | .map(|instance| { |
| 55 | // Get global latest_handshake from KvStore (max across all nodes) |
| 56 | let latest_handshake = state |
| 57 | .get_instance_latest_handshake(&instance.id) |
| 58 | .unwrap_or(0); |
| 59 | HostInfo { |
| 60 | instance_id: instance.id.clone(), |
| 61 | ip: instance.ip.to_string(), |
| 62 | app_id: instance.app_id.clone(), |
| 63 | base_domain: base_domain.clone(), |
| 64 | latest_handshake, |
| 65 | num_connections: instance.num_connections(), |
| 66 | } |
| 67 | }) |
| 68 | .collect::<Vec<_>>(); |
| 69 | Ok(StatusResponse { |
| 70 | id: state.config.sync.node_id, |
| 71 | url: state.config.sync.my_url.clone(), |
| 72 | uuid: state.config.uuid(), |
| 73 | bootnode_url: state.config.sync.bootnode.clone(), |
| 74 | nodes: state.get_all_nodes(), |
| 75 | hosts, |
| 76 | num_connections: NUM_CONNECTIONS.load(Ordering::Relaxed), |
| 77 | }) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | impl AdminRpc for AdminRpcHandler { |