|
|
|
@ -1,7 +1,9 @@
|
|
|
|
|
use crate::crypto::PublicKey; |
|
|
|
|
|
|
|
|
|
use alloc::vec::Vec; |
|
|
|
|
use alloc::boxed::Box; |
|
|
|
|
use serde::{Serialize, Deserialize}; |
|
|
|
|
use core::option::Option; |
|
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] |
|
|
|
|
pub struct Tunnel { |
|
|
|
@ -9,8 +11,29 @@ pub struct Tunnel {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Tunnel { |
|
|
|
|
pub fn from_vec(nodes: Vec<PublicKey>) -> Self { |
|
|
|
|
Self { nodes } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn tunnel_to(&self, me: &PublicKey, to: &PublicKey) -> Option<Tunnel> { |
|
|
|
|
None |
|
|
|
|
let my_index = self.nodes |
|
|
|
|
.iter() |
|
|
|
|
.enumerate() |
|
|
|
|
.find(|&node| node.1 == me).unwrap().0; |
|
|
|
|
match self.nodes |
|
|
|
|
.iter() |
|
|
|
|
.enumerate() |
|
|
|
|
.find(|&node| node.1 == to) { |
|
|
|
|
Some(en) => { |
|
|
|
|
match my_index < en.0 { |
|
|
|
|
true => { Some(Tunnel::from_vec(Vec::<PublicKey>::from(self.nodes.clone()[en.0..].to_vec()))) } |
|
|
|
|
false => { Some(Tunnel::from_vec(Vec::<PublicKey>::from(self.nodes.clone()[..=en.0].to_vec()))) } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
None => { |
|
|
|
|
None |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn next(&self, to: &PublicKey) -> PublicKey { |
|
|
|
|