Skip to content

Commit

Permalink
Remove the dependency on embedded_nal_async
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Mar 25, 2024
1 parent bdf28bb commit d499bc6
Show file tree
Hide file tree
Showing 55 changed files with 1,107 additions and 961 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish-crate-dry-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ on:
type: choice
description: Crate to publish
options:
- embedded-nal-async-xtra
- edge-std-nal-async
- edge-nal
- edge-nal-std
- edge-captive
- edge-dhcp
- edge-http
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-crate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ on:
type: choice
description: Crate to publish
options:
- embedded-nal-async-xtra
- edge-std-nal-async
- edge-nal
- edge-nal-std
- edge-captive
- edge-dhcp
- edge-http
Expand Down
25 changes: 11 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ description = "no_std and no-alloc async implementations of various network prot
repository = "https://github.com/ivmarkov/edge-net"
license = "MIT OR Apache-2.0"
readme = "README.md"
rust-version = "1.75"
rust-version = "1.77"

[features]
default = ["io"]
std = ["io", "edge-captive/std", "edge-dhcp/std", "edge-http/std", "edge-mdns/std", "edge-raw/std", "edge-mqtt", "edge-ws/std", "edge-std-nal-async"]
io = ["edge-captive/io", "edge-dhcp/io", "edge-http/io", "edge-mdns/io", "edge-raw/io", "edge-ws/io", "embedded-nal-async-xtra"]
default = ["io", "std"]
std = ["io", "edge-captive/std", "edge-dhcp/std", "edge-http/std", "edge-mdns/std", "edge-raw/std", "edge-mqtt", "edge-ws/std", "edge-nal-std"]
io = ["edge-captive/io", "edge-dhcp/io", "edge-http/io", "edge-mdns/io", "edge-raw/io", "edge-ws/io", "edge-nal"]
nightly = []
embedded-svc = ["edge-http/embedded-svc", "edge-mqtt/embedded-svc", "edge-ws/embedded-svc"]

Expand All @@ -24,17 +24,16 @@ edge-dhcp = { workspace = true }
edge-http = { workspace = true }
edge-mdns = { workspace = true }
edge-mqtt = { workspace = true, optional = true }
edge-nal = { workspace = true, optional = true }
edge-raw = { workspace = true }
edge-ws = { workspace = true }
edge-std-nal-async = { workspace = true, optional = true }
embedded-nal-async-xtra = { workspace = true, optional = true }
edge-nal-std = { workspace = true, optional = true }

[dev-dependencies]
log = "0.4"
anyhow = "1"
env_logger = "0.10"
embedded-io-async = "0.6"
embedded-nal-async = "0.7"
embassy-time = { version = "0.3", features = ["std", "generic-queue"] }
embassy-sync = "0.5"
embassy-futures = "0.1"
Expand Down Expand Up @@ -77,7 +76,7 @@ name = "ws_server"
required-features = ["std"]

[[example]]
name = "std_nal"
name = "nal_std"
required-features = ["std"]

[[example]]
Expand All @@ -92,22 +91,20 @@ members = [
"edge-http",
"edge-mdns",
"edge-mqtt",
"edge-nal",
"edge-raw",
"edge-ws",
"edge-std-nal-async",
"embedded-nal-async-xtra"
"edge-nal-std"
]

[workspace.dependencies]
embassy-futures = { version = "0.1", default-features = false }
embassy-sync = { version = "0.5", default-features = false }
embassy-time = { version = "0.3", default-features = false }
embedded-io-async = { version = "0.6", default-features = false }
embedded-nal-async = { version = "0.7", default-features = false }
embedded-svc = { version = "0.27", default-features = false }
log = { version = "0.4", default-features = false }
heapless = { version = "0.8", default-features = false }
no-std-net = { version = "0.6", default-features = false }
domain = { version = "0.9.3", default-features = false, features = ["heapless"] }
octseq = { version = "0.3.2", default-features = false }

Expand All @@ -116,7 +113,7 @@ edge-dhcp = { version = "0.2.0", path = "edge-dhcp", default-features = false }
edge-http = { version = "0.2.1", path = "edge-http", default-features = false }
edge-mdns = { version = "0.2.0", path = "edge-mdns", default-features = false }
edge-mqtt = { version = "0.2.0", path = "edge-mqtt", default-features = false }
edge-nal = { version = "0.2.0", path = "edge-nal", default-features = false }
edge-raw = { version = "0.2.0", path = "edge-raw", default-features = false }
edge-ws = { version = "0.2.0", path = "edge-ws", default-features = false }
edge-std-nal-async = { version = "0.2.0", path = "edge-std-nal-async", default-features = false }
embedded-nal-async-xtra = { version = "0.2.0", path = "embedded-nal-async-xtra", default-features = false }
edge-nal-std = { version = "0.2.0", path = "edge-nal-std", default-features = false }
6 changes: 3 additions & 3 deletions edge-captive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "edge-captive"
version = "0.2.0"
edition = "2021"
rust-version = "1.75"
rust-version = "1.77"
description = "Async + `no_std` + no-alloc implementation of a Captive Portal DNS"
repository = "https://github.com/ivmarkov/edge-net"
readme = "README.md"
Expand All @@ -18,10 +18,10 @@ categories = [
[features]
default = ["io"]
std = ["io"]
io = ["embedded-nal-async"]
io = ["edge-nal"]

[dependencies]
log = { workspace = true }
domain = { workspace = true }
octseq = { workspace = true }
embedded-nal-async = { workspace = true, optional = true }
edge-nal = { workspace = true, optional = true }
17 changes: 6 additions & 11 deletions edge-captive/src/io.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use core::fmt;
use core::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
use core::time::Duration;

use embedded_nal_async::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, UdpStack, UnconnectedUdp};
use edge_nal::{UdpReceive, UdpSend, UdpStack};

use log::*;

Expand Down Expand Up @@ -40,7 +41,7 @@ impl<E> std::error::Error for DnsIoError<E> where E: std::error::Error {}

pub async fn run<S>(
stack: &S,
socket: SocketAddr,
local_addr: SocketAddr,
tx_buf: &mut [u8],
rx_buf: &mut [u8],
ip: Ipv4Addr,
Expand All @@ -49,18 +50,12 @@ pub async fn run<S>(
where
S: UdpStack,
{
let (_, mut udp) = stack
.bind_single(socket)
.await
.map_err(DnsIoError::IoError)?;
let (_, mut udp) = stack.bind(local_addr).await.map_err(DnsIoError::IoError)?;

loop {
debug!("Waiting for data");

let (len, local, remote) = udp
.receive_into(rx_buf)
.await
.map_err(DnsIoError::IoError)?;
let (len, remote) = udp.receive(rx_buf).await.map_err(DnsIoError::IoError)?;

let request = &rx_buf[..len];

Expand All @@ -77,7 +72,7 @@ where
},
};

udp.send(local, remote, &tx_buf[..len])
udp.send(remote, &tx_buf[..len])
.await
.map_err(DnsIoError::IoError)?;

Expand Down
8 changes: 3 additions & 5 deletions edge-dhcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "edge-dhcp"
version = "0.2.0"
edition = "2021"
rust-version = "1.75"
rust-version = "1.77"
description = "Async + `no_std` + no-alloc implementation of the DHCP protocol"
repository = "https://github.com/ivmarkov/edge-net"
readme = "README.md"
Expand All @@ -18,16 +18,14 @@ categories = [
[features]
default = ["io"]
std = ["io"]
io = ["embassy-futures", "embedded-nal-async", "embedded-nal-async-xtra"]
io = ["embassy-futures", "edge-nal"]

[dependencies]
no-std-net = { workspace = true }
heapless = { workspace = true }
log = { workspace = true }
rand_core = "0.6"
embassy-futures = { workspace = true, optional = true }
embassy-time = { workspace = true, default-features = false } # TODO: Make optional
embedded-nal-async = { workspace = true, optional = true }
embedded-nal-async-xtra = { workspace = true, optional = true }
edge-nal = { workspace = true, optional = true }
num_enum = { version = "0.7", default-features = false }
edge-raw = { workspace = true, default-features = false }
68 changes: 1 addition & 67 deletions edge-dhcp/src/io.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use core::fmt::{self, Debug};

use embedded_nal_async::{SocketAddr, SocketAddrV4, UdpStack, UnconnectedUdp};
use embedded_nal_async_xtra::UnconnectedUdpWithMac;
use core::net::{SocketAddr, SocketAddrV4};

use crate as dhcp;

Expand Down Expand Up @@ -37,67 +35,3 @@ where

#[cfg(feature = "std")]
impl<E> std::error::Error for Error<E> where E: std::error::Error {}

/// A fallback implementation of `UnconnectedUdpWithMac` that does not support MAC addresses.
/// Might or might not work depending on the DHCP client.
pub struct UnconnectedUdpWithMacFallback<T>(pub T);

impl<T> UnconnectedUdp for UnconnectedUdpWithMacFallback<T>
where
T: UnconnectedUdp,
{
type Error = T::Error;

async fn send(
&mut self,
local: SocketAddr,
remote: SocketAddr,
data: &[u8],
) -> Result<(), Self::Error> {
self.0.send(local, remote, data).await
}

async fn receive_into(
&mut self,
buffer: &mut [u8],
) -> Result<(usize, SocketAddr, SocketAddr), Self::Error> {
self.0.receive_into(buffer).await
}
}

impl<T> UnconnectedUdpWithMac for UnconnectedUdpWithMacFallback<T>
where
T: UnconnectedUdp,
{
async fn send(
&mut self,
local: SocketAddr,
remote: SocketAddr,
_remote_mac: Option<&[u8; 6]>,
data: &[u8],
) -> Result<(), Self::Error> {
self.0.send(local, remote, data).await
}

async fn receive_into(
&mut self,
buffer: &mut [u8],
) -> Result<(usize, SocketAddr, SocketAddr, [u8; 6]), Self::Error> {
let (len, local, remote) = self.0.receive_into(buffer).await?;

Ok((len, local, remote, [0x00; 6]))
}
}

/// A utility method that binds a UDP socket in a way suitable for operating as a DHCP client or server.
pub async fn bind<T>(stack: &T, socket: SocketAddrV4) -> Result<T::MultiplyBound, Error<T::Error>>
where
T: UdpStack,
{
let socket = stack
.bind_multiple(SocketAddr::V4(socket))
.await
.map_err(Error::Io)?;

Ok(socket)
}
Loading

0 comments on commit d499bc6

Please sign in to comment.