|
|
@ -42,23 +42,36 @@ impl Tunnel { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn next(&self, me: &PublicKey, to: &PublicKey) -> Option<PublicKey> { |
|
|
|
fn index(&self, node: &PublicKey) -> Option<usize> { |
|
|
|
let my_index = self.nodes |
|
|
|
match self.nodes |
|
|
|
.iter() |
|
|
|
|
|
|
|
.enumerate() |
|
|
|
|
|
|
|
.find(|&node| node.1 == me).unwrap().0; |
|
|
|
|
|
|
|
let to_index = self.nodes |
|
|
|
|
|
|
|
.iter() |
|
|
|
.iter() |
|
|
|
.enumerate() |
|
|
|
.enumerate() |
|
|
|
.find(|&node| node.1 == to).unwrap().0; |
|
|
|
.find(|¤t_node| current_node.1 == node) { |
|
|
|
|
|
|
|
Some((index, _)) => Some(index), |
|
|
|
|
|
|
|
None => None |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_next(&self, me: &PublicKey, forward: bool) -> Option<PublicKey> { |
|
|
|
|
|
|
|
let my_index = self.index(me).unwrap(); |
|
|
|
|
|
|
|
if forward { |
|
|
|
|
|
|
|
if my_index + 1 < self.nodes.len() { |
|
|
|
|
|
|
|
Some(self.nodes[my_index + 1].clone()) |
|
|
|
|
|
|
|
} else {None} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if my_index > 0 { |
|
|
|
|
|
|
|
Some(self.nodes[my_index - 1].clone()) |
|
|
|
|
|
|
|
} else { None } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn next(&self, me: &PublicKey, to: &PublicKey) -> Option<PublicKey> { |
|
|
|
|
|
|
|
let my_index = self.index(me); |
|
|
|
|
|
|
|
let to_index = self.index(to); |
|
|
|
if to_index == my_index { |
|
|
|
if to_index == my_index { |
|
|
|
return None; |
|
|
|
return None; |
|
|
|
} |
|
|
|
} |
|
|
|
return if to_index < my_index { |
|
|
|
self.get_next(me, to_index > my_index) |
|
|
|
Option::from(self.nodes[my_index - 1].clone()) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Option::from(self.nodes[my_index + 1].clone()) |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn next_nodes(&self, me: &PublicKey) -> Vec<PublicKey> { |
|
|
|
pub fn next_nodes(&self, me: &PublicKey) -> Vec<PublicKey> { |
|
|
|