Skip to content

Commit

Permalink
fix: integrate review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcsmith committed Dec 20, 2023
1 parent 662ecd3 commit 555c6d3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
14 changes: 7 additions & 7 deletions crates/scion-proto/src/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub enum UdpEncodeError {
///
/// [RFC]: https://www.ietf.org/archive/id/draft-dekater-scion-dataplane-00.html
#[derive(Debug, Default, PartialEq)]
pub struct UdpDatagram {
pub struct UdpMessage {
/// The source and destination ports
pub port: ByEndpoint<u16>,
/// The length of the header and payload
Expand All @@ -41,7 +41,7 @@ pub struct UdpDatagram {
pub payload: Bytes,
}

impl UdpDatagram {
impl UdpMessage {
/// SCION protocol number for UDP.
///
/// See the [IETF SCION-dataplane RFC draft][rfc] for possible values.
Expand Down Expand Up @@ -89,7 +89,7 @@ impl UdpDatagram {
}
}

impl WireEncodeVec<2> for UdpDatagram {
impl WireEncodeVec<2> for UdpMessage {
type Error = InadequateBufferSize;

fn encode_with_unchecked(&self, buffer: &mut BytesMut) -> [Bytes; 2] {
Expand All @@ -111,11 +111,11 @@ impl WireEncodeVec<2> for UdpDatagram {
}
}

impl<T: Buf> WireDecode<T> for UdpDatagram {
impl<T: Buf> WireDecode<T> for UdpMessage {
type Error = UdpDecodeError;

fn decode(data: &mut T) -> Result<Self, Self::Error> {
if data.remaining() < UdpDatagram::HEADER_LEN {
if data.remaining() < UdpMessage::HEADER_LEN {
return Err(Self::Error::DatagramEmptyOrTruncated);
}

Expand Down Expand Up @@ -161,7 +161,7 @@ mod tests {
destination: MaybeEncoded::Decoded(Ipv4Addr::from_str("10.0.0.2")?.into()),
},
};
let mut datagram = UdpDatagram::new(
let mut datagram = UdpMessage::new(
ByEndpoint {
source: 10001,
destination: 10002,
Expand Down Expand Up @@ -193,7 +193,7 @@ mod tests {
let mut encoded_bytes = BytesMut::new();
encoded_bytes.put(encoded_datagram[0].clone());
encoded_bytes.put(encoded_datagram[1].clone());
assert_eq!(UdpDatagram::decode(&mut encoded_bytes.freeze())?, datagram);
assert_eq!(UdpMessage::decode(&mut encoded_bytes.freeze())?, datagram);

Ok(())
}
Expand Down
14 changes: 7 additions & 7 deletions crates/scion-proto/src/packet/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bytes::Bytes;
use super::{InadequateBufferSize, ScionHeaders, ScionPacketRaw};
use crate::{
address::SocketAddr,
datagram::{UdpDatagram, UdpDecodeError},
datagram::{UdpDecodeError, UdpMessage},
packet::{ByEndpoint, EncodeError},
path::Path,
wire_encoding::{WireDecode, WireEncodeVec},
Expand All @@ -16,7 +16,7 @@ pub struct ScionPacketUdp {
/// Packet headers
pub headers: ScionHeaders,
/// The contained UDP datagram
pub datagram: UdpDatagram,
pub datagram: UdpMessage,
}

impl ScionPacketUdp {
Expand Down Expand Up @@ -62,11 +62,11 @@ impl ScionPacketUdp {
let headers = ScionHeaders::new(
endhosts,
path,
UdpDatagram::PROTOCOL_NUMBER,
payload.len() + UdpDatagram::HEADER_LEN,
UdpMessage::PROTOCOL_NUMBER,
payload.len() + UdpMessage::HEADER_LEN,
)?;
let mut datagram =
UdpDatagram::new(endhosts.map(|e| e.port()), payload).map_err(|_| todo!())?;
UdpMessage::new(endhosts.map(|e| e.port()), payload).map_err(|_| todo!())?;
datagram.set_checksum(&headers.address);

Ok(Self { headers, datagram })
Expand All @@ -77,14 +77,14 @@ impl TryFrom<ScionPacketRaw> for ScionPacketUdp {
type Error = UdpDecodeError;

fn try_from(mut value: ScionPacketRaw) -> Result<Self, Self::Error> {
if value.headers.common.next_header != UdpDatagram::PROTOCOL_NUMBER {
if value.headers.common.next_header != UdpMessage::PROTOCOL_NUMBER {
return Err(UdpDecodeError::WrongProtocolNumber(
value.headers.common.next_header,
));
}
Ok(Self {
headers: value.headers,
datagram: UdpDatagram::decode(&mut value.payload)?,
datagram: UdpMessage::decode(&mut value.payload)?,
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/scion-proto/src/reliable/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use bytes::{Buf, BufMut};
use super::wire_utils::LAYER4_PORT_OCTETS;
use crate::{
address::{HostType, IsdAsn, ServiceAddr, SocketAddr as ScionSocketAddr},
datagram::UdpDatagram,
datagram::UdpMessage,
reliable::{
wire_utils::{encoded_address_and_port_length, encoded_address_length},
ADDRESS_TYPE_OCTETS,
Expand Down Expand Up @@ -85,7 +85,7 @@ impl RegistrationRequest {

self.encode_command_flag(buffer);

buffer.put_u8(UdpDatagram::PROTOCOL_NUMBER);
buffer.put_u8(UdpMessage::PROTOCOL_NUMBER);
buffer.put_u64(self.isd_asn.as_u64());

encode_address(buffer, &self.public_address);
Expand Down
2 changes: 0 additions & 2 deletions crates/scion/src/pan/path_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ pub enum PathLookupError {
}

/// Trait for asynchronously retrieving paths to SCION ASes.
///
/// If an implementation wants to receive paths from the network
#[async_trait::async_trait]
pub trait AsyncPathService {
/// Return a path to the specified AS.
Expand Down
6 changes: 3 additions & 3 deletions crates/scion/src/udp_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bytes::Bytes;
use chrono::Utc;
use scion_proto::{
address::SocketAddr,
datagram::{UdpDatagram, UdpEncodeError},
datagram::{UdpEncodeError, UdpMessage},
packet::{ByEndpoint, ScionPacketRaw, ScionPacketUdp},
path::{DataplanePath, Path},
reliable::Packet,
Expand Down Expand Up @@ -47,7 +47,7 @@ impl From<UdpEncodeError> for SendError {
/// be [sent to][AsyncScionDatagram::send_to_via] and [received from][AsyncScionDatagram::recv_from]
/// any other socket address by using the methods on the [`AsyncScionDatagram`] trait.
///
/// As SCION is a path-aware internet architecture, sending packets with the `UdpSocket` allows
/// As SCION is a path-aware Internet architecture, sending packets with the `UdpSocket` allows
/// specifying the path over which the packet should be sent. See
/// [`PathAwareDatagram`][crate::pan::PathAwareDatagram] for a wrapping socket than handles
/// the selection of paths.
Expand Down Expand Up @@ -298,7 +298,7 @@ impl UdpSocketInner {
.map_err(log_err!("failed to decode SCION packet"))
.ok()?;

let udp_datagram = UdpDatagram::decode(&mut scion_packet.payload)
let udp_datagram = UdpMessage::decode(&mut scion_packet.payload)
.map_err(log_err!("failed to decode UDP datagram"))
.ok()?;

Expand Down

0 comments on commit 555c6d3

Please sign in to comment.