routing table refactor

This commit is contained in:
John Smith
2022-10-18 21:53:45 -04:00
parent 63768580c6
commit 6d5df71ac1
17 changed files with 1904 additions and 1586 deletions
+25 -19
View File
@@ -8,7 +8,7 @@ pub enum Destination {
/// The node to send to
target: NodeRef,
/// Require safety route or not
safety: Option<SafetySpec>,
safety_spec: Option<SafetySpec>,
},
/// Send to node for relay purposes
Relay {
@@ -17,14 +17,14 @@ pub enum Destination {
/// The final destination the relay should send to
target: DHTKey,
/// Require safety route or not
safety: Option<SafetySpec>,
safety_spec: Option<SafetySpec>,
},
/// Send to private route (privateroute)
PrivateRoute {
/// A private route to send to
private_route: PrivateRoute,
/// Require safety route or not
safety: Option<SafetySpec>,
safety_spec: Option<SafetySpec>,
/// Prefer reliability or not
reliable: bool,
},
@@ -34,46 +34,49 @@ impl Destination {
pub fn direct(target: NodeRef) -> Self {
Self::Direct {
target,
safety: None,
safety_spec: None,
}
}
pub fn relay(relay: NodeRef, target: DHTKey) -> Self {
Self::Relay {
relay,
target,
safety: None,
safety_spec: None,
}
}
pub fn private_route(private_route: PrivateRoute, reliable: bool) -> Self {
Self::PrivateRoute {
private_route,
safety: None,
safety_spec: None,
reliable,
}
}
pub fn with_safety(self, spec: SafetySpec) -> Self {
pub fn with_safety(self, safety_spec: SafetySpec) -> Self {
match self {
Destination::Direct { target, safety: _ } => Self::Direct {
Destination::Direct {
target,
safety: Some(spec),
safety_spec: _,
} => Self::Direct {
target,
safety_spec: Some(safety_spec),
},
Destination::Relay {
relay,
target,
safety: _,
safety_spec: _,
} => Self::Relay {
relay,
target,
safety: Some(spec),
safety_spec: Some(safety_spec),
},
Destination::PrivateRoute {
private_route,
safety: _,
safety_spec: _,
reliable,
} => Self::PrivateRoute {
private_route,
safety: Some(spec),
safety_spec: Some(safety_spec),
reliable,
},
}
@@ -83,26 +86,29 @@ impl Destination {
impl fmt::Display for Destination {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Destination::Direct { target, safety } => {
let sr = if safety.is_some() { "+SR" } else { "" };
Destination::Direct {
target,
safety_spec,
} => {
let sr = if safety_spec.is_some() { "+SR" } else { "" };
write!(f, "{}{}", target, sr)
}
Destination::Relay {
relay,
target,
safety,
safety_spec,
} => {
let sr = if safety.is_some() { "+SR" } else { "" };
let sr = if safety_spec.is_some() { "+SR" } else { "" };
write!(f, "{}@{}{}", target.encode(), relay, sr)
}
Destination::PrivateRoute {
private_route,
safety,
safety_spec,
reliable,
} => {
let sr = if safety.is_some() { "+SR" } else { "" };
let sr = if safety_spec.is_some() { "+SR" } else { "" };
let rl = if *reliable { "+RL" } else { "" };
write!(f, "{}{}{}", private_route, sr, rl)