Skip to content

Commit

Permalink
fix: correct and test send and receive corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcsmith committed Dec 14, 2023
1 parent 4295724 commit 3320b01
Show file tree
Hide file tree
Showing 4 changed files with 398 additions and 25 deletions.
1 change: 0 additions & 1 deletion crates/scion-proto/src/address/scion_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ macro_rules! scion_address {
fn from_str(s: &str) -> Result<Self, Self::Err> {
s.split_once(',')
.and_then(|(ia_str, host_str)| {
println!("{}, {}", ia_str, host_str);
ia_str.parse().ok().zip(host_str.parse().ok())
})
.map(|(isd_asn, host)| Self {isd_asn, host})
Expand Down
33 changes: 33 additions & 0 deletions crates/scion-proto/src/packet/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,39 @@ pub struct ScionPacketUdp {
pub datagram: UdpDatagram,
}

impl ScionPacketUdp {
/// Returns the source socket address of the UDP packet.
pub fn source(&self) -> Option<SocketAddr> {
self.headers
.address
.source()
.map(|scion_addr| SocketAddr::new(scion_addr, self.src_port()))
}

/// Returns the destination socket address of the UDP packet.
pub fn destination(&self) -> Option<SocketAddr> {
self.headers
.address
.destination()
.map(|scion_addr| SocketAddr::new(scion_addr, self.dst_port()))
}

/// Returns the UDP packet payload.
pub fn payload(&self) -> &Bytes {
&self.datagram.payload
}

/// Returns the UDP source port
pub fn src_port(&self) -> u16 {
self.datagram.port.source
}

/// Returns the UDP destination port
pub fn dst_port(&self) -> u16 {
self.datagram.port.destination
}
}

impl ScionPacketUdp {
/// Creates a new SCION UDP packet based on the UDP payload
pub fn new(
Expand Down
10 changes: 10 additions & 0 deletions crates/scion-proto/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ impl Path {
}
}

/// Returns a path for sending packets within the specified AS.
///
/// # Panics
///
/// Panics if the AS is a wildcard AS.
pub fn local(isd_asn: IsdAsn) -> Self {
assert!(!isd_asn.is_wildcard(), "no local path for wildcard AS");
Self::empty(ByEndpoint::with_cloned(isd_asn))
}

pub fn empty(isd_asn: ByEndpoint<IsdAsn>) -> Self {
Self {
dataplane_path: DataplanePath::EmptyPath,
Expand Down
Loading

0 comments on commit 3320b01

Please sign in to comment.