2022-09-25 22:04:53 +00:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Privacy Specs
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
|
|
|
pub struct RouteHopSpec {
|
|
|
|
pub dial_info: NodeDialInfo,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
2022-10-09 18:59:01 +00:00
|
|
|
pub struct RouteSpec {
|
2022-09-25 22:04:53 +00:00
|
|
|
//
|
|
|
|
pub public_key: DHTKey,
|
|
|
|
pub secret_key: DHTKeySecret,
|
|
|
|
pub hops: Vec<RouteHopSpec>,
|
|
|
|
}
|
|
|
|
|
2022-10-09 18:59:01 +00:00
|
|
|
impl RouteSpec {
|
2022-09-25 22:04:53 +00:00
|
|
|
pub fn new() -> Self {
|
|
|
|
let (pk, sk) = generate_secret();
|
2022-10-09 18:59:01 +00:00
|
|
|
RouteSpec {
|
2022-09-25 22:04:53 +00:00
|
|
|
public_key: pk,
|
|
|
|
secret_key: sk,
|
|
|
|
hops: Vec::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Compiled Privacy Objects
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct RouteHopData {
|
|
|
|
pub nonce: Nonce,
|
|
|
|
pub blob: Vec<u8>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct RouteHop {
|
|
|
|
pub dial_info: NodeDialInfo,
|
|
|
|
pub next_hop: Option<RouteHopData>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct PrivateRoute {
|
|
|
|
pub public_key: DHTKey,
|
|
|
|
pub hop_count: u8,
|
|
|
|
pub hops: Option<RouteHop>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PrivateRoute {
|
|
|
|
pub fn new_stub(public_key: DHTKey) -> Self {
|
|
|
|
Self {
|
|
|
|
public_key,
|
|
|
|
hop_count: 0,
|
|
|
|
hops: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for PrivateRoute {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"PR({:?}+{}{})",
|
|
|
|
self.public_key,
|
|
|
|
self.hop_count,
|
|
|
|
if let Some(hops) = &self.hops {
|
|
|
|
format!("->{}", hops.dial_info)
|
|
|
|
} else {
|
|
|
|
"".to_owned()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum SafetyRouteHops {
|
|
|
|
Data(RouteHopData),
|
|
|
|
Private(PrivateRoute),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct SafetyRoute {
|
|
|
|
pub public_key: DHTKey,
|
|
|
|
pub hop_count: u8,
|
|
|
|
pub hops: SafetyRouteHops,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for SafetyRoute {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"SR({:?}+{}{})",
|
|
|
|
self.public_key,
|
|
|
|
self.hop_count,
|
|
|
|
match &self.hops {
|
|
|
|
SafetyRouteHops::Data(_) => "".to_owned(),
|
|
|
|
SafetyRouteHops::Private(p) => format!("->{}", p),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// xxx impl to_blob and from_blob using capnp here
|