Skip to content

Commit

Permalink
feat: add path service implementation for static paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcsmith committed Dec 19, 2023
1 parent d4e1182 commit b4c3f81
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions crates/scion/src/pan/path_service.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
use bytes::Bytes;
use chrono::Utc;
use scion_proto::{address::IsdAsn, path::Path};

#[derive(Debug, thiserror::Error)]
pub enum PathLookupError {}
pub enum PathLookupError {
#[error("no path available to destination")]
NoPath,
}

/// Trait for asynchronously retrieving paths to SCION ASes.
#[async_trait::async_trait]
pub trait AsyncPathService {
/// Return a path to the specified AS.
async fn path_to(&self, scion_as: IsdAsn) -> Result<&Path, PathLookupError>;
async fn path_to<'a>(&'a self, scion_as: IsdAsn) -> Result<&'a Path, PathLookupError>;

/// Provide the service with a path that it may choose to store.
///
Expand All @@ -28,3 +32,32 @@ pub trait AsyncPathService {
/// See [`Self::maybe_add_shared_path`] for a variant which may avoid copying the path.
fn maybe_add_path(&self, path: &Path<&mut [u8]>) -> bool;
}

#[async_trait::async_trait]
impl AsyncPathService for Path<Bytes> {
/// Return a path to the specified AS.
async fn path_to(&self, scion_as: IsdAsn) -> Result<&Path, PathLookupError> {
if self.isd_asn.destination != scion_as {
return Err(PathLookupError::NoPath);
}
if let Some(metadata) = self.metadata.as_ref() {
if metadata.expiration < Utc::now() {
tracing::warn!(
destination=%scion_as,
path=?self,
"attempted to send packet with expired, static path"
);
return Err(PathLookupError::NoPath);
}
}
Ok(self)
}

fn maybe_add_shared_path(&self, _path: &Path<Bytes>) -> bool {
false
}

fn maybe_add_path(&self, _path: &Path<&mut [u8]>) -> bool {
false
}
}

0 comments on commit b4c3f81

Please sign in to comment.