Skip to content

Commit

Permalink
Merge pull request #3329 from embassy-rs/net-deinit
Browse files Browse the repository at this point in the history
net: refactor to simplify lifetimes/generics.
  • Loading branch information
Dirbaio authored Sep 16, 2024
2 parents a23f56b + 73aa40a commit e90b3bc
Show file tree
Hide file tree
Showing 43 changed files with 506 additions and 609 deletions.
5 changes: 3 additions & 2 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ cargo batch \
--- build --release --manifest-path embassy-sync/Cargo.toml --target thumbv6m-none-eabi --features defmt \
--- build --release --manifest-path embassy-time/Cargo.toml --target thumbv6m-none-eabi --features defmt,defmt-timestamp-uptime,generic-queue-8,mock-driver \
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,medium-ethernet,packet-trace \
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,igmp,medium-ethernet \
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,multicast,medium-ethernet \
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet \
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,dhcpv4-hostname \
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv6,medium-ethernet \
Expand Down Expand Up @@ -290,8 +290,9 @@ cargo batch \
$BUILD_EXTRA


# temporarily disabled, bluepill board got bricked
# temporarily disabled, these boards are dead.
rm -rf out/tests/stm32f103c8
rm -rf out/tests/nrf52840-dk

rm out/tests/stm32wb55rg/wpan_mac
rm out/tests/stm32wb55rg/wpan_ble
Expand Down
10 changes: 5 additions & 5 deletions embassy-net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ categories = [
[package.metadata.embassy_docs]
src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-v$VERSION/embassy-net/src/"
src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-net/src/"
features = ["defmt", "tcp", "udp", "raw", "dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip", "medium-ieee802154", "igmp", "dhcpv4-hostname"]
features = ["defmt", "tcp", "udp", "raw", "dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip", "medium-ieee802154", "multicast", "dhcpv4-hostname"]
target = "thumbv7em-none-eabi"

[package.metadata.docs.rs]
features = ["defmt", "tcp", "udp", "raw", "dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip", "medium-ieee802154", "igmp", "dhcpv4-hostname"]
features = ["defmt", "tcp", "udp", "raw", "dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip", "medium-ieee802154", "multicast", "dhcpv4-hostname"]

[features]
default = []
Expand Down Expand Up @@ -60,15 +60,15 @@ medium-ethernet = ["smoltcp/medium-ethernet"]
medium-ip = ["smoltcp/medium-ip"]
## Enable the IEEE 802.15.4 medium
medium-ieee802154 = ["smoltcp/medium-ieee802154"]
## Enable IGMP support
igmp = ["smoltcp/proto-igmp"]
## Enable multicast support (for both ipv4 and/or ipv6 if enabled)
multicast = ["smoltcp/multicast"]

[dependencies]

defmt = { version = "0.3", optional = true }
log = { version = "0.4.14", optional = true }

smoltcp = { version = "0.11.0", default-features = false, features = [
smoltcp = { git="https://github.com/smoltcp-rs/smoltcp", rev="dd43c8f189178b0ab3bda798ed8578b5b0a6f094", default-features = false, features = [
"socket",
"async",
] }
Expand Down
3 changes: 2 additions & 1 deletion embassy-net/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ memory management designed to work well for embedded systems, aiming for a more

- IPv4, IPv6
- Ethernet and bare-IP mediums.
- TCP, UDP, DNS, DHCPv4, IGMPv4
- TCP, UDP, DNS, DHCPv4
- TCP sockets implement the `embedded-io` async traits.
- Multicast

See the [`smoltcp`](https://github.com/smoltcp-rs/smoltcp) README for a detailed list of implemented and
unimplemented features of the network protocols.
Expand Down
25 changes: 10 additions & 15 deletions embassy-net/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use smoltcp::socket::dns::{DnsQuery, Socket};
pub(crate) use smoltcp::socket::dns::{GetQueryResultError, StartQueryError};
pub use smoltcp::wire::{DnsQueryType, IpAddress};

use crate::{Driver, Stack};
use crate::Stack;

/// Errors returned by DnsSocket.
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
Expand Down Expand Up @@ -44,21 +44,15 @@ impl From<StartQueryError> for Error {
/// This exists only for compatibility with crates that use `embedded-nal-async`.
/// Prefer using [`Stack::dns_query`](crate::Stack::dns_query) directly if you're
/// not using `embedded-nal-async`.
pub struct DnsSocket<'a, D>
where
D: Driver + 'static,
{
stack: &'a Stack<D>,
pub struct DnsSocket<'a> {
stack: Stack<'a>,
}

impl<'a, D> DnsSocket<'a, D>
where
D: Driver + 'static,
{
impl<'a> DnsSocket<'a> {
/// Create a new DNS socket using the provided stack.
///
/// NOTE: If using DHCP, make sure it has reconfigured the stack to ensure the DNS servers are updated.
pub fn new(stack: &'a Stack<D>) -> Self {
pub fn new(stack: Stack<'a>) -> Self {
Self { stack }
}

Expand All @@ -72,10 +66,7 @@ where
}
}

impl<'a, D> embedded_nal_async::Dns for DnsSocket<'a, D>
where
D: Driver + 'static,
{
impl<'a> embedded_nal_async::Dns for DnsSocket<'a> {
type Error = Error;

async fn get_host_by_name(
Expand Down Expand Up @@ -124,3 +115,7 @@ where
todo!()
}
}

fn _assert_covariant<'a, 'b: 'a>(x: DnsSocket<'b>) -> DnsSocket<'a> {
x
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ where
{
fn consume<R, F>(self, f: F) -> R
where
F: FnOnce(&mut [u8]) -> R,
F: FnOnce(&[u8]) -> R,
{
self.0.consume(|buf| {
#[cfg(feature = "packet-trace")]
Expand Down
Loading

0 comments on commit e90b3bc

Please sign in to comment.