From 7f1bedcee037839c77312d5ce667f2c199b473be Mon Sep 17 00:00:00 2001
From: chrysn <chrysn@fsfe.org>
Date: Fri, 2 Feb 2024 15:16:54 +0100
Subject: [PATCH 1/4] net/udp: Relay full UdpMetadata instead of only remote
 endpoint in poll_ functions

This is a breaking change for users of the poll_ functions. (Some might
not notice if they already pass in an IpEndpoint into poll_send_to, or
discard that item in poll_recv_from).
---
 embassy-net/src/udp.rs | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/embassy-net/src/udp.rs b/embassy-net/src/udp.rs
index a22cd8827..2fdf83e9d 100644
--- a/embassy-net/src/udp.rs
+++ b/embassy-net/src/udp.rs
@@ -8,7 +8,7 @@ use core::task::{Context, Poll};
 use embassy_net_driver::Driver;
 use smoltcp::iface::{Interface, SocketHandle};
 use smoltcp::socket::udp;
-pub use smoltcp::socket::udp::PacketMetadata;
+pub use smoltcp::socket::udp::{PacketMetadata, UdpMetadata};
 use smoltcp::wire::{IpEndpoint, IpListenEndpoint};
 
 use crate::{SocketStack, Stack};
@@ -112,7 +112,9 @@ impl<'a> UdpSocket<'a> {
     ///
     /// Returns the number of bytes received and the remote endpoint.
     pub async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, IpEndpoint), RecvError> {
-        poll_fn(move |cx| self.poll_recv_from(buf, cx)).await
+        poll_fn(move |cx| self.poll_recv_from(buf, cx))
+            .await
+            .map(|(size, metadata)| (size, metadata.endpoint))
     }
 
     /// Receive a datagram.
@@ -122,9 +124,13 @@ impl<'a> UdpSocket<'a> {
     ///
     /// When a datagram is received, this method will return `Poll::Ready` with the
     /// number of bytes received and the remote endpoint.
-    pub fn poll_recv_from(&self, buf: &mut [u8], cx: &mut Context<'_>) -> Poll<Result<(usize, IpEndpoint), RecvError>> {
+    pub fn poll_recv_from(
+        &self,
+        buf: &mut [u8],
+        cx: &mut Context<'_>,
+    ) -> Poll<Result<(usize, UdpMetadata), RecvError>> {
         self.with_mut(|s, _| match s.recv_slice(buf) {
-            Ok((n, meta)) => Poll::Ready(Ok((n, meta.endpoint))),
+            Ok((n, meta)) => Poll::Ready(Ok((n, meta))),
             // No data ready
             Err(udp::RecvError::Truncated) => Poll::Ready(Err(RecvError::Truncated)),
             Err(udp::RecvError::Exhausted) => {
@@ -157,7 +163,7 @@ impl<'a> UdpSocket<'a> {
     /// When the remote endpoint is not reachable, this method will return `Poll::Ready(Err(Error::NoRoute))`.
     pub fn poll_send_to<T>(&self, buf: &[u8], remote_endpoint: T, cx: &mut Context<'_>) -> Poll<Result<(), SendError>>
     where
-        T: Into<IpEndpoint>,
+        T: Into<UdpMetadata>,
     {
         self.with_mut(|s, _| match s.send_slice(buf, remote_endpoint) {
             // Entire datagram has been sent

From 8fe88847d81afceaa55aa68662d4162d5c12f804 Mon Sep 17 00:00:00 2001
From: chrysn <chrysn@fsfe.org>
Date: Mon, 15 Apr 2024 10:02:35 +0200
Subject: [PATCH 2/4] fixup! net/udp: Relay full UdpMetadata instead of only
 remote endpoint in poll_ functions

---
 embassy-net/src/udp.rs | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/embassy-net/src/udp.rs b/embassy-net/src/udp.rs
index 2fdf83e9d..3e72327c6 100644
--- a/embassy-net/src/udp.rs
+++ b/embassy-net/src/udp.rs
@@ -111,10 +111,8 @@ impl<'a> UdpSocket<'a> {
     /// This method will wait until a datagram is received.
     ///
     /// Returns the number of bytes received and the remote endpoint.
-    pub async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, IpEndpoint), RecvError> {
-        poll_fn(move |cx| self.poll_recv_from(buf, cx))
-            .await
-            .map(|(size, metadata)| (size, metadata.endpoint))
+    pub async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, UdpMetadata), RecvError> {
+        poll_fn(move |cx| self.poll_recv_from(buf, cx)).await
     }
 
     /// Receive a datagram.

From 2c7c39d1db198447e52d7c9c5c6a39a71868c311 Mon Sep 17 00:00:00 2001
From: chrysn <chrysn@fsfe.org>
Date: Fri, 19 Apr 2024 15:51:27 +0200
Subject: [PATCH 3/4] fixup! net/udp: Relay full UdpMetadata instead of only
 remote endpoint in poll_ functions

---
 embassy-net/src/udp.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/embassy-net/src/udp.rs b/embassy-net/src/udp.rs
index 3e72327c6..494a1bd71 100644
--- a/embassy-net/src/udp.rs
+++ b/embassy-net/src/udp.rs
@@ -145,9 +145,9 @@ impl<'a> UdpSocket<'a> {
     /// When the remote endpoint is not reachable, this method will return `Err(SendError::NoRoute)`
     pub async fn send_to<T>(&self, buf: &[u8], remote_endpoint: T) -> Result<(), SendError>
     where
-        T: Into<IpEndpoint>,
+        T: Into<UdpMetadata>,
     {
-        let remote_endpoint: IpEndpoint = remote_endpoint.into();
+        let remote_endpoint: UdpMetadata = remote_endpoint.into();
         poll_fn(move |cx| self.poll_send_to(buf, remote_endpoint, cx)).await
     }
 

From 49435f79b35cc031c5ccd93991bf4b7011741053 Mon Sep 17 00:00:00 2001
From: chrysn <chrysn@fsfe.org>
Date: Fri, 19 Apr 2024 15:54:56 +0200
Subject: [PATCH 4/4] fixup! net/udp: Relay full UdpMetadata instead of only
 remote endpoint in poll_ functions

---
 embassy-net/src/udp.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/embassy-net/src/udp.rs b/embassy-net/src/udp.rs
index 494a1bd71..6e50c4e01 100644
--- a/embassy-net/src/udp.rs
+++ b/embassy-net/src/udp.rs
@@ -9,7 +9,7 @@ use embassy_net_driver::Driver;
 use smoltcp::iface::{Interface, SocketHandle};
 use smoltcp::socket::udp;
 pub use smoltcp::socket::udp::{PacketMetadata, UdpMetadata};
-use smoltcp::wire::{IpEndpoint, IpListenEndpoint};
+use smoltcp::wire::IpListenEndpoint;
 
 use crate::{SocketStack, Stack};