Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct and test send and receive corner cases #99

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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