2026-01-19 08:34:17 +01:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
2026-02-02 07:19:22 +01:00
|
|
|
use crate::env::{LocalDeployerEnv, Node};
|
2026-01-19 08:34:17 +01:00
|
|
|
|
2026-02-02 07:19:22 +01:00
|
|
|
pub(crate) struct LocalNodeManagerState<E: LocalDeployerEnv> {
|
2026-01-26 08:26:15 +01:00
|
|
|
pub(crate) node_count: usize,
|
2026-01-19 08:34:17 +01:00
|
|
|
pub(crate) peer_ports: Vec<u16>,
|
|
|
|
|
pub(crate) peer_ports_by_name: HashMap<String, u16>,
|
2026-02-02 07:19:22 +01:00
|
|
|
pub(crate) clients_by_name: HashMap<String, E::NodeClient>,
|
2026-02-05 08:23:14 +02:00
|
|
|
pub(crate) indices_by_name: HashMap<String, usize>,
|
2026-02-02 07:19:22 +01:00
|
|
|
pub(crate) nodes: Vec<Node<E>>,
|
2026-01-19 08:34:17 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-02 07:19:22 +01:00
|
|
|
impl<E: LocalDeployerEnv> LocalNodeManagerState<E> {
|
|
|
|
|
fn register_common(&mut self, node_name: &str, network_port: u16, client: E::NodeClient) {
|
2026-01-19 08:34:17 +01:00
|
|
|
self.peer_ports.push(network_port);
|
|
|
|
|
self.peer_ports_by_name
|
|
|
|
|
.insert(node_name.to_string(), network_port);
|
|
|
|
|
self.clients_by_name.insert(node_name.to_string(), client);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-26 08:26:15 +01:00
|
|
|
pub(super) fn register_node(
|
2026-01-19 08:34:17 +01:00
|
|
|
&mut self,
|
|
|
|
|
node_name: &str,
|
|
|
|
|
network_port: u16,
|
2026-02-02 07:19:22 +01:00
|
|
|
client: E::NodeClient,
|
|
|
|
|
node: Node<E>,
|
2026-01-19 08:34:17 +01:00
|
|
|
) {
|
|
|
|
|
self.register_common(node_name, network_port, client);
|
2026-02-05 08:23:14 +02:00
|
|
|
let index = self.nodes.len();
|
|
|
|
|
self.indices_by_name.insert(node_name.to_string(), index);
|
2026-01-26 08:26:15 +01:00
|
|
|
self.node_count += 1;
|
|
|
|
|
self.nodes.push(node);
|
2026-01-19 08:34:17 +01:00
|
|
|
}
|
|
|
|
|
}
|