Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcsmith committed Oct 7, 2023
1 parent f5dd12d commit 61b07dc
Show file tree
Hide file tree
Showing 7 changed files with 678 additions and 236 deletions.
14 changes: 10 additions & 4 deletions crates/scion/src/reliable.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
mod common_header;
pub use common_header::DecodeError;
use std::net::SocketAddr;

mod error;
pub use error::ReliableRelayError;
use bytes::Bytes;
pub use common_header::DecodeError;

mod relay_protocol;
pub use relay_protocol::ReliableRelayProtocol;
pub use relay_protocol::{ReceiveError, ReliableRelayProtocol, SendError};

mod parser;
mod registration;
mod wire_utils;

const ADDRESS_TYPE_OCTETS: usize = 1;

#[derive(Debug)]
pub struct Packet {
pub last_hop: Option<SocketAddr>,
pub content: Vec<Bytes>,
}
14 changes: 4 additions & 10 deletions crates/scion/src/reliable/common_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::{
use crate::address::{HostAddress, HostType};

/// Errors occurring during decoding of packets received over the reliable-relay protocol.
#[derive(Error, Debug, Eq, PartialEq)]
#[derive(Error, Debug, Eq, PartialEq, Clone, Copy)]
pub enum DecodeError {
/// The decoded packet started with an incorrect token. This indicates a
/// synchronisation issue with the relay.
Expand All @@ -26,20 +26,20 @@ pub enum DecodeError {
}

/// Partial or fully decoded commonHeader
#[derive(Debug)]
pub(super) enum DecodedHeader {
Partial(PartialHeader),
Full(CommonHeader),
}

impl DecodedHeader {
#[allow(dead_code)]
pub fn is_fully_decoded(&self) -> bool {
matches!(self, DecodedHeader::Full(..))
}
}

/// A partially decoded common header
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
pub(super) struct PartialHeader {
pub host_type: HostType,
pub payload_length: u32,
Expand Down Expand Up @@ -126,21 +126,14 @@ impl CommonHeader {
/// The minimum length of a common header.
pub const MIN_LENGTH: usize =
Self::COOKIE_LENGTH + ADDRESS_TYPE_OCTETS + Self::PAYLOAD_SIZE_LENGTH;
#[allow(dead_code)]
/// The maximum length of the common header.
pub const MAX_LENGTH: usize = Self::MIN_LENGTH + IPV6_OCTETS + LAYER4_PORT_OCTETS;

const COOKIE: u64 = 0xde00ad01be02ef03;
const COOKIE_LENGTH: usize = 8;
const PAYLOAD_SIZE_LENGTH: usize = 4;

#[allow(dead_code)]
pub fn new() -> Self {
Self::default()
}

/// The size of the payload as a usize.
#[allow(dead_code)]
#[inline]
pub fn payload_size(&self) -> usize {
self.payload_length
Expand Down Expand Up @@ -210,6 +203,7 @@ impl CommonHeader {
/// Panics if there is insufficient data in the buffer to decode the entire header.
/// To avoid the panic, ensure there is [`Self::MAX_LENGTH`] bytes available, or
/// use [`Self::partial_decode()`] instead.
#[cfg(test)]
pub fn decode(buffer: &mut impl Buf) -> Result<Self, DecodeError> {
PartialHeader::decode(buffer).map(|header| header.finish_decoding(buffer))
}
Expand Down
10 changes: 0 additions & 10 deletions crates/scion/src/reliable/error.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
use thiserror::Error;

#[derive(Error, Debug, Eq, PartialEq)]
pub enum ReliableRelayError {
#[error("provided destination address must be specified, not 0.0.0.0 or ::0")]
DestinationUnspecified,
#[error("provided destination port mmust be specified")]
DestinationPortUnspecified,
#[error("port mismatch, requested port {requested}, received port {assigned}")]
PortMismatch { requested: u16, assigned: u16 },
}
Loading

0 comments on commit 61b07dc

Please sign in to comment.