Skip to content

Commit

Permalink
fix(coap): Don't require synchronized features
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Oct 29, 2024
1 parent 7112e38 commit 44f284b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
3 changes: 1 addition & 2 deletions examples/coap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 10 additions & 5 deletions src/riot-rs-coap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]
18 changes: 8 additions & 10 deletions src/riot-rs-coap/src/udp_nal/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,34 @@ pub(super) fn sockaddr_nal2smol(sockaddr: nal::SocketAddr) -> Result<IpEndpoint,
match sockaddr {
#[allow(unused)]
nal::SocketAddr::V4(sockaddr) => {
#[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()
Expand Down

0 comments on commit 44f284b

Please sign in to comment.