change key retrieval to use bond info

This commit is contained in:
Simon Wicky
2024-03-11 11:23:00 +01:00
committed by Simon Wicky
parent 30a1f5582a
commit a0e3610681
+23 -15
View File
@@ -191,25 +191,33 @@ impl NymTopology {
mix_host: SocketAddr,
) -> Result<Option<String>, NymTopologyError> {
for node in self.described_nodes.iter() {
let sphinx_key = match node {
DescribedNymNode::Gateway(g) => &g.bond.gateway.sphinx_key,
DescribedNymNode::Mixnode(m) => &m.bond.mix_node.sphinx_key,
let (sphinx_key, socket_addresses, description) = match node {
DescribedNymNode::Gateway(g) => {
let sphinx_key = &g.bond.gateway.sphinx_key;
let gateway_node: Option<gateway::Node> = (&g.bond).try_into().ok();
let mix_hosts = gateway_node.map(|node| node.mix_hosts);
let description = &g.self_described;
(sphinx_key, mix_hosts, description)
}
DescribedNymNode::Mixnode(m) => {
let sphinx_key = &m.bond.mix_node.sphinx_key;
let mix_node: Option<mix::Node> = (&m.bond).try_into().ok();
let mix_hosts = mix_node.map(|node| node.mix_hosts);
let description = &m.self_described;
(sphinx_key, mix_hosts, description)
}
};
if let Some(description) = match node {
DescribedNymNode::Gateway(g) => &g.self_described,
DescribedNymNode::Mixnode(m) => &m.self_described,
} {
if description
.host_information
.ip_address
.contains(&mix_host.ip())
{
if let Some(sock_addr) = socket_addresses {
let ip_addresses = sock_addr.iter().map(|addr| addr.ip()).collect::<Vec<_>>();
if ip_addresses.contains(&mix_host.ip()) {
//we have our node
if description.noise_information.supported {
if description.is_some()
&& description.as_ref().unwrap().noise_information.supported
//SAFETY: We checked that `description` wasn't None
{
return Ok(Some(sphinx_key.to_string()));
} else {
return Ok(None);
}
return Ok(None);
}
}
}