mirror of
https://github.com/threefoldtech/mycelium.git
synced 2026-10-23 14:02:21 +00:00
Move RouteKey to submodule
Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
1 parent
34e4a7b5a7
commit
49e397969c
2 files changed
+42
-34
No files matched your search
@@ -16,29 +16,9 @@ use crate::{
|
||||
source_table::SourceKey, subnet::Subnet,
|
||||
};
|
||||
|
||||
/// RouteKey uniquely defines a route via a peer.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct RouteKey {
|
||||
subnet: Subnet,
|
||||
neighbour: Peer,
|
||||
}
|
||||
pub use route_key::RouteKey;
|
||||
|
||||
impl RouteKey {
|
||||
/// Creates a new `RouteKey` for the given [`Subnet`] and [`neighbour`](Peer).
|
||||
pub fn new(subnet: Subnet, neighbour: Peer) -> Self {
|
||||
Self { subnet, neighbour }
|
||||
}
|
||||
|
||||
/// Get's the [`Subnet`] identified by this `RouteKey`.
|
||||
pub fn subnet(&self) -> Subnet {
|
||||
self.subnet
|
||||
}
|
||||
|
||||
/// Gets the [`neighbour`](Peer) identified by this `RouteKey`.
|
||||
pub fn neighbour(&self) -> &Peer {
|
||||
&self.neighbour
|
||||
}
|
||||
}
|
||||
mod route_key;
|
||||
|
||||
/// RouteEntry holds all relevant information about a specific route. Since this includes the next
|
||||
/// hop, a single subnet can have multiple route entries.
|
||||
@@ -199,7 +179,7 @@ impl RouteList {
|
||||
self.list
|
||||
.iter()
|
||||
.map(|(_, e)| e)
|
||||
.find(|entry| entry.neighbour == route_key.neighbour)
|
||||
.find(|entry| &entry.neighbour == route_key.neighbour())
|
||||
}
|
||||
|
||||
/// Returns the selected route for the [`Subnet`] this is the `RouteList` for, if one exists.
|
||||
@@ -605,7 +585,7 @@ impl<'a> WriteGuard<'a> {
|
||||
.list
|
||||
.iter_mut()
|
||||
.map(|(_, e)| e)
|
||||
.position(|entry| entry.neighbour == route_key.neighbour)
|
||||
.position(|entry| &entry.neighbour == route_key.neighbour())
|
||||
{
|
||||
EntryIdentifier::Pos(pos)
|
||||
} else {
|
||||
@@ -748,13 +728,3 @@ impl Drop for RoutingTable {
|
||||
self.cancel_token.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for RouteKey {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_fmt(format_args!(
|
||||
"{} via {}",
|
||||
self.subnet,
|
||||
self.neighbour.connection_identifier()
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
use crate::{peer::Peer, subnet::Subnet};
|
||||
|
||||
/// RouteKey uniquely defines a route via a peer.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct RouteKey {
|
||||
subnet: Subnet,
|
||||
neighbour: Peer,
|
||||
}
|
||||
|
||||
impl RouteKey {
|
||||
/// Creates a new `RouteKey` for the given [`Subnet`] and [`neighbour`](Peer).
|
||||
#[inline]
|
||||
pub fn new(subnet: Subnet, neighbour: Peer) -> Self {
|
||||
Self { subnet, neighbour }
|
||||
}
|
||||
|
||||
/// Get's the [`Subnet`] identified by this `RouteKey`.
|
||||
#[inline]
|
||||
pub fn subnet(&self) -> Subnet {
|
||||
self.subnet
|
||||
}
|
||||
|
||||
/// Gets the [`neighbour`](Peer) identified by this `RouteKey`.
|
||||
#[inline]
|
||||
pub fn neighbour(&self) -> &Peer {
|
||||
&self.neighbour
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for RouteKey {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_fmt(format_args!(
|
||||
"{} via {}",
|
||||
self.subnet,
|
||||
self.neighbour.connection_identifier()
|
||||
))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user