Эх сурвалжийг харах

Remove IpEndpoint::accepts.

Unclear purpose, one use, we don't need it.
whitequark 7 жил өмнө
parent
commit
5e448db950
2 өөрчлөгдсөн 5 нэмэгдсэн , 11 устгасан
  1. 5 3
      src/socket/udp.rs
  2. 0 8
      src/wire/ip.rs

+ 5 - 3
src/socket/udp.rs

@@ -188,12 +188,14 @@ impl<'a, 'b> UdpSocket<'a, 'b> {
         let packet = UdpPacket::new_checked(&payload[..ip_repr.payload_len()])?;
         let repr = UdpRepr::parse(&packet, &ip_repr.src_addr(), &ip_repr.dst_addr())?;
 
-        let endpoint = IpEndpoint { addr: ip_repr.src_addr(), port: repr.src_port };
-        if !self.endpoint.accepts(&endpoint) { return Err(Error::Rejected) }
+        // Reject packets with a wrong destination.
+        if self.endpoint.port != repr.dst_port { return Err(Error::Rejected) }
+        if !self.endpoint.addr.is_unspecified() &&
+           self.endpoint.addr != ip_repr.dst_addr() { return Err(Error::Rejected) }
 
         let packet_buf = self.rx_buffer.try_enqueue(|buf| buf.resize(repr.payload.len()))?;
         packet_buf.as_mut().copy_from_slice(repr.payload);
-        packet_buf.endpoint = endpoint;
+        packet_buf.endpoint = IpEndpoint { addr: ip_repr.src_addr(), port: repr.src_port };
         net_trace!("[{}]{}:{}: receiving {} octets",
                    self.debug_id, self.endpoint,
                    packet_buf.endpoint, packet_buf.size);

+ 0 - 8
src/wire/ip.rs

@@ -139,14 +139,6 @@ impl Endpoint {
     pub fn is_specified(&self) -> bool {
         !self.addr.is_unspecified() && self.port != 0
     }
-
-    /// Query whether `self` should accept packets from `other`.
-    ///
-    /// Returns `true` if `other` is a specified endpoint and `self` either
-    /// has an unspecified address, or the addresses are equal.
-    pub fn accepts(&self, other: &Endpoint) -> bool {
-        other.is_specified() && (self.addr == other.addr || self.addr.is_unspecified())
-    }
 }
 
 impl fmt::Display for Endpoint {