Skip to content

Commit 705b0c9

Browse files
committed
update Identity struct to match runtime
1 parent dcb7709 commit 705b0c9

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/net.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,34 @@ use std::collections::BTreeMap;
1010
pub struct Identity {
1111
pub name: NodeId,
1212
pub networking_key: String,
13-
pub ws_routing: Option<(String, u16)>,
14-
pub allowed_routers: Vec<NodeId>,
13+
pub routing: NodeRouting,
14+
}
15+
16+
#[derive(Clone, Debug, Serialize, Deserialize)]
17+
pub enum NodeRouting {
18+
Routers(Vec<NodeId>),
19+
Direct {
20+
ip: String,
21+
ports: BTreeMap<String, u16>,
22+
},
23+
}
24+
25+
impl Identity {
26+
pub fn is_direct(&self) -> bool {
27+
matches!(&self.routing, NodeRouting::Direct { .. })
28+
}
29+
pub fn get_protocol_port(&self, protocol: &str) -> Option<u16> {
30+
match &self.routing {
31+
NodeRouting::Routers(_) => None,
32+
NodeRouting::Direct { ports, .. } => ports.get(protocol).cloned(),
33+
}
34+
}
35+
pub fn routers(&self) -> Option<&Vec<NodeId>> {
36+
match &self.routing {
37+
NodeRouting::Routers(routers) => Some(routers),
38+
NodeRouting::Direct { .. } => None,
39+
}
40+
}
1541
}
1642

1743
/// Must be parsed from message pack vector.

0 commit comments

Comments
 (0)