Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions edge-http/src/io/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,10 +849,9 @@ impl<const P: usize, const B: usize, const N: usize> Server<P, B, N> {
Q, P, Q
);

for acceptor_id in 0..Q {
for (acceptor_id, signal) in accept_signals.iter().enumerate() {
let acceptor = &acceptor;
let socket_queue = &socket_queue;
let signal = &accept_signals[acceptor_id];

unwrap!(acceptor_tasks
.push(async move {
Expand Down
12 changes: 5 additions & 7 deletions edge-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,13 +645,11 @@ impl BodyType {
Err(HeadersMismatchError::BodyTypeError("Raw body response with a Keep-Alive connection. This is not allowed."))?;
}
}
BodyType::Chunked => {
if !http11 {
warn!("Chunked body with an HTTP/1.0 connection. This is not allowed.");
Err(HeadersMismatchError::BodyTypeError(
"Chunked body with an HTTP/1.0 connection. This is not allowed.",
))?;
}
BodyType::Chunked if !http11 => {
warn!("Chunked body with an HTTP/1.0 connection. This is not allowed.");
Err(HeadersMismatchError::BodyTypeError(
"Chunked body with an HTTP/1.0 connection. This is not allowed.",
))?;
}
_ => {}
}
Expand Down
15 changes: 3 additions & 12 deletions edge-mdns/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,18 +387,9 @@ where
for remote_addr in
core::iter::once(SocketAddr::V4(SocketAddrV4::new(IP_BROADCAST_ADDR, PORT)))
.filter(|_| self.ipv4_interface.is_some())
.chain(
self.ipv6_interface
.map(|interface| {
SocketAddr::V6(SocketAddrV6::new(
IPV6_BROADCAST_ADDR,
PORT,
0,
interface,
))
})
.into_iter(),
)
.chain(self.ipv6_interface.map(|interface| {
SocketAddr::V6(SocketAddrV6::new(IPV6_BROADCAST_ADDR, PORT, 0, interface))
}))
{
if !data.is_empty() {
debug!("Broadcasting mDNS entry to {}", remote_addr);
Expand Down
1 change: 1 addition & 0 deletions edge-nal-embassy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
* Breaking: new trait: `UdpSplitMulticast` which is now required on the socket provided by `UdpBind` and `UdpConnect`
* Update to `embassy-net` 0.9
* Remove the unused `heapless` dependency
* Raise MSRV to 1.91 to compile `smoltcp`
Expand Down
215 changes: 154 additions & 61 deletions edge-nal-embassy/src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use core::fmt::Display;
use core::net::{Ipv4Addr, Ipv6Addr, SocketAddr};
use core::ptr::NonNull;

use edge_nal::{MulticastV4, MulticastV6, Readable, UdpBind, UdpReceive, UdpSend, UdpSplit};
use edge_nal::{
MulticastV4, MulticastV6, Readable, UdpBind, UdpReceive, UdpSend, UdpSplit, UdpSplitMulticast,
};

use embassy_net::udp::{BindError, PacketMetadata, RecvError, SendError};
use embassy_net::Stack;
Expand Down Expand Up @@ -111,6 +113,90 @@ impl<'d> UdpSocket<'d> {
buffer_token: socket_buffers.token,
})
}

async fn join_v4(
&self,
#[allow(unused)] multicast_addr: Ipv4Addr,
_interface: Ipv4Addr,
) -> Result<(), UdpError> {
#[cfg(feature = "multicast")]
{
self.stack.join_multicast_group(
crate::to_emb_addr(core::net::IpAddr::V4(multicast_addr))
.ok_or(UdpError::UnsupportedProto)?,
)?;
}

#[cfg(not(feature = "multicast"))]
{
Err(UdpError::UnsupportedProto)?;
}

Ok(())
}

async fn leave_v4(
&self,
#[allow(unused)] multicast_addr: Ipv4Addr,
_interface: Ipv4Addr,
) -> Result<(), UdpError> {
#[cfg(feature = "multicast")]
{
self.stack.leave_multicast_group(
crate::to_emb_addr(core::net::IpAddr::V4(multicast_addr))
.ok_or(UdpError::UnsupportedProto)?,
)?;
}

#[cfg(not(feature = "multicast"))]
{
Err(UdpError::UnsupportedProto)?;
}

Ok(())
}

async fn join_v6(
&self,
#[allow(unused)] multicast_addr: Ipv6Addr,
_interface: u32,
) -> Result<(), UdpError> {
#[cfg(feature = "multicast")]
{
self.stack.join_multicast_group(
crate::to_emb_addr(core::net::IpAddr::V6(multicast_addr))
.ok_or(UdpError::UnsupportedProto)?,
)?;
}

#[cfg(not(feature = "multicast"))]
{
Err(UdpError::UnsupportedProto)?;
}

Ok(())
}

async fn leave_v6(
&self,
#[allow(unused)] multicast_addr: Ipv6Addr,
_interface: u32,
) -> Result<(), UdpError> {
#[cfg(feature = "multicast")]
{
self.stack.leave_multicast_group(
crate::to_emb_addr(core::net::IpAddr::V6(multicast_addr))
.ok_or(UdpError::UnsupportedProto)?,
)?;
}

#[cfg(not(feature = "multicast"))]
{
Err(UdpError::UnsupportedProto)?;
}

Ok(())
}
}

impl Drop for UdpSocket<'_> {
Expand Down Expand Up @@ -195,91 +281,98 @@ impl UdpSplit for UdpSocket<'_> {
}
}

impl<'d> UdpSplitMulticast for UdpSocket<'d> {
type MulticastV4<'a>
= &'a Self
where
Self: 'a;

type MulticastV6<'a>
= &'a Self
where
Self: 'a;

fn split_multicast(
&mut self,
) -> (
Self::Receive<'_>,
Self::Send<'_>,
Self::MulticastV4<'_>,
Self::MulticastV6<'_>,
) {
(&*self, &*self, &*self, &*self)
}
}

impl MulticastV4 for UdpSocket<'_> {
async fn join_v4(
&mut self,
#[allow(unused)] multicast_addr: Ipv4Addr,
_interface: Ipv4Addr,
multicast_addr: Ipv4Addr,
interface: Ipv4Addr,
) -> Result<(), Self::Error> {
#[cfg(feature = "multicast")]
{
self.stack.join_multicast_group(
crate::to_emb_addr(core::net::IpAddr::V4(multicast_addr))
.ok_or(UdpError::UnsupportedProto)?,
)?;
}

#[cfg(not(feature = "multicast"))]
{
Err(UdpError::UnsupportedProto)?;
}

Ok(())
Self::join_v4(self, multicast_addr, interface).await
}

async fn leave_v4(
&mut self,
#[allow(unused)] multicast_addr: Ipv4Addr,
_interface: Ipv4Addr,
multicast_addr: Ipv4Addr,
interface: Ipv4Addr,
) -> Result<(), Self::Error> {
#[cfg(feature = "multicast")]
{
self.stack.leave_multicast_group(
crate::to_emb_addr(core::net::IpAddr::V4(multicast_addr))
.ok_or(UdpError::UnsupportedProto)?,
)?;
}
Self::leave_v4(self, multicast_addr, interface).await
}
}

#[cfg(not(feature = "multicast"))]
{
Err(UdpError::UnsupportedProto)?;
}
impl MulticastV4 for &UdpSocket<'_> {
async fn join_v4(
&mut self,
multicast_addr: Ipv4Addr,
interface: Ipv4Addr,
) -> Result<(), Self::Error> {
UdpSocket::join_v4(self, multicast_addr, interface).await
}

Ok(())
async fn leave_v4(
&mut self,
multicast_addr: Ipv4Addr,
interface: Ipv4Addr,
) -> Result<(), Self::Error> {
UdpSocket::leave_v4(self, multicast_addr, interface).await
}
}

impl MulticastV6 for UdpSocket<'_> {
async fn join_v6(
&mut self,
#[allow(unused)] multicast_addr: Ipv6Addr,
_interface: u32,
multicast_addr: Ipv6Addr,
interface: u32,
) -> Result<(), Self::Error> {
#[cfg(feature = "multicast")]
{
self.stack.join_multicast_group(
crate::to_emb_addr(core::net::IpAddr::V6(multicast_addr))
.ok_or(UdpError::UnsupportedProto)?,
)?;
}

#[cfg(not(feature = "multicast"))]
{
Err(UdpError::UnsupportedProto)?;
}

Ok(())
Self::join_v6(self, multicast_addr, interface).await
}

async fn leave_v6(
&mut self,
#[allow(unused)] multicast_addr: Ipv6Addr,
_interface: u32,
multicast_addr: Ipv6Addr,
interface: u32,
) -> Result<(), Self::Error> {
#[cfg(feature = "multicast")]
{
self.stack.leave_multicast_group(
crate::to_emb_addr(core::net::IpAddr::V6(multicast_addr))
.ok_or(UdpError::UnsupportedProto)?,
)?;
}
Self::leave_v6(self, multicast_addr, interface).await
}
}

#[cfg(not(feature = "multicast"))]
{
Err(UdpError::UnsupportedProto)?;
}
impl MulticastV6 for &UdpSocket<'_> {
async fn join_v6(
&mut self,
multicast_addr: Ipv6Addr,
interface: u32,
) -> Result<(), Self::Error> {
UdpSocket::join_v6(self, multicast_addr, interface).await
}

Ok(())
async fn leave_v6(
&mut self,
multicast_addr: Ipv6Addr,
interface: u32,
) -> Result<(), Self::Error> {
UdpSocket::leave_v6(self, multicast_addr, interface).await
}
}

Expand Down
27 changes: 26 additions & 1 deletion edge-nal-std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use embedded_io_async::{ErrorType, Read, Write};

use edge_nal::{
AddrType, Dns, MulticastV4, MulticastV6, Readable, TcpAccept, TcpBind, TcpConnect, TcpShutdown,
TcpSplit, UdpBind, UdpConnect, UdpReceive, UdpSend, UdpSplit,
TcpSplit, UdpBind, UdpConnect, UdpReceive, UdpSend, UdpSplit, UdpSplitMulticast,
};

#[cfg(any(target_os = "linux", target_os = "android"))]
Expand Down Expand Up @@ -576,6 +576,31 @@ impl UdpSplit for UdpSocket {
}
}

impl UdpSplitMulticast for UdpSocket {
type MulticastV4<'a>
= &'a Self
where
Self: 'a;

type MulticastV6<'a>
= &'a Self
where
Self: 'a;

fn split_multicast(
&mut self,
) -> (
Self::Receive<'_>,
Self::Send<'_>,
Self::MulticastV4<'_>,
Self::MulticastV6<'_>,
) {
let socket = &*self;

(socket, socket, socket, socket)
}
}

impl Dns for Stack {
type Error = io::Error;

Expand Down
Loading
Loading