|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
use crate::crypto::PublicKey; |
|
|
|
|
|
|
|
|
|
use alloc::vec::Vec; |
|
|
|
|
use alloc::boxed::Box; |
|
|
|
|
use serde::{Serialize, Deserialize}; |
|
|
|
|
use core::option::Option; |
|
|
|
|
|
|
|
|
@ -15,6 +14,13 @@ impl Tunnel {
|
|
|
|
|
Self { nodes } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn is_in_tunnel(&self, node: &PublicKey) -> bool { |
|
|
|
|
self.nodes |
|
|
|
|
.iter() |
|
|
|
|
.enumerate() |
|
|
|
|
.find(|¤t_node| current_node.1 == node).is_some() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn tunnel_to(&self, me: &PublicKey, to: &PublicKey) -> Option<Tunnel> { |
|
|
|
|
let my_index = self.nodes |
|
|
|
|
.iter() |
|
|
|
@ -36,7 +42,19 @@ impl Tunnel {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn next(&self, to: &PublicKey) -> PublicKey { |
|
|
|
|
PublicKey { key: [0u8; 32] } |
|
|
|
|
#[allow(dead_code)] |
|
|
|
|
pub fn next(&self, me: &PublicKey, to: &PublicKey) -> Option<PublicKey> { |
|
|
|
|
let my_index = self.nodes |
|
|
|
|
.iter() |
|
|
|
|
.enumerate() |
|
|
|
|
.find(|&node| node.1 == me).unwrap().0; |
|
|
|
|
let to_index = self.nodes |
|
|
|
|
.iter() |
|
|
|
|
.enumerate() |
|
|
|
|
.find(|&node| node.1 == to).unwrap().0; |
|
|
|
|
if to_index <= my_index { |
|
|
|
|
return None; |
|
|
|
|
} |
|
|
|
|
Option::from(self.nodes[my_index + 1].clone()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|