From 44f284be5d3aecb39f7e8239dbb6b8025bb6a6ef Mon Sep 17 00:00:00 2001 From: chrysn Date: Tue, 29 Oct 2024 13:25:22 +0100 Subject: [PATCH] fix(coap): Don't require synchronized features --- examples/coap/Cargo.toml | 3 +-- src/riot-rs-coap/Cargo.toml | 15 ++++++++++----- src/riot-rs-coap/src/udp_nal/util.rs | 18 ++++++++---------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/examples/coap/Cargo.toml b/examples/coap/Cargo.toml index 8149eddc7..c8a788bf4 100644 --- a/examples/coap/Cargo.toml +++ b/examples/coap/Cargo.toml @@ -33,5 +33,4 @@ static-alloc = { version = "0.2.5", features = ["polyfill"] } coap-scroll-ring-server = "0.2.0" scroll-ring = "0.1.1" -# FIXME: Where should this be pulled through? -riot-rs-coap = { workspace = true, features = ["proto-ipv4"] } +riot-rs-coap.workspace = true diff --git a/src/riot-rs-coap/Cargo.toml b/src/riot-rs-coap/Cargo.toml index 8a1be1eaf..9e778dedb 100644 --- a/src/riot-rs-coap/Cargo.toml +++ b/src/riot-rs-coap/Cargo.toml @@ -12,7 +12,16 @@ coap-handler = "0.2.0" coap-handler-implementations = "0.5.0" critical-section.workspace = true embassy-futures = "0.1.1" -embassy-net = { workspace = true, features = ["udp"] } +# These features should be more selective and not enabled here, but as things +# stand, this modules also contains the embedded-nal implementation for +# embassy-net, and that needs its features in sync; enabling them all ensures a +# working state until that NAL wrapper moves into embassy-net, where features +# will be in sync all the time. +embassy-net = { workspace = true, features = [ + "udp", + "proto-ipv4", + "proto-ipv6", +] } embassy-sync.workspace = true embedded-nal-async = "0.7" embedded-nal-coap = "0.1.0-alpha.2" @@ -39,7 +48,3 @@ doc = ["embassy-net/proto-ipv6", "embassy-net/medium-ip"] ## Enables defmt logging of coapcore defmt = ["coapcore/defmt"] - -# Only around while we carry the embedded-nal-async impl -proto-ipv4 = ["embassy-net/proto-ipv4"] -proto-ipv6 = ["embassy-net/proto-ipv6"] diff --git a/src/riot-rs-coap/src/udp_nal/util.rs b/src/riot-rs-coap/src/udp_nal/util.rs index 09edf7122..5d04060d8 100644 --- a/src/riot-rs-coap/src/udp_nal/util.rs +++ b/src/riot-rs-coap/src/udp_nal/util.rs @@ -7,36 +7,34 @@ pub(super) fn sockaddr_nal2smol(sockaddr: nal::SocketAddr) -> Result { - #[cfg(feature = "proto-ipv4")] + // #[cfg(feature = "proto-ipv4")] return Ok(IpEndpoint { addr: embassy_net::Ipv4Address(sockaddr.ip().octets()).into(), port: sockaddr.port(), }); - #[cfg(not(feature = "proto-ipv4"))] - return Err(Error::AddressFamilyUnavailable); + // #[cfg(not(feature = "proto-ipv4"))] + // return Err(Error::AddressFamilyUnavailable); } #[allow(unused)] nal::SocketAddr::V6(sockaddr) => { - #[cfg(feature = "proto-ipv6")] + // #[cfg(feature = "proto-ipv6")] return Ok(IpEndpoint { addr: embassy_net::Ipv6Address(sockaddr.ip().octets()).into(), port: sockaddr.port(), }); - #[cfg(not(feature = "proto-ipv6"))] - return Err(Error::AddressFamilyUnavailable); + // #[cfg(not(feature = "proto-ipv6"))] + // return Err(Error::AddressFamilyUnavailable); } } } pub(super) fn sockaddr_smol2nal(endpoint: IpEndpoint) -> nal::SocketAddr { match endpoint.addr { - // Let's hope those are in sync; what we'll really need to know is whether smoltcp has the - // relevant flags set (but we can't query that). - #[cfg(feature = "proto-ipv4")] + // #[cfg(feature = "proto-ipv4")] IpAddress::Ipv4(addr) => { embedded_nal_async::SocketAddrV4::new(addr.0.into(), endpoint.port).into() } - #[cfg(feature = "proto-ipv6")] + // #[cfg(feature = "proto-ipv6")] IpAddress::Ipv6(addr) => { // FIXME: Where is smoltcp's zone identifier? embedded_nal_async::SocketAddrV6::new(addr.0.into(), endpoint.port, 0, 0).into()