Skip to content

Commit

Permalink
coap: Early clean up steps
Browse files Browse the repository at this point in the history
* The fixed slots are replaced with an LRUish pool
* Writes to stdout are redirected to a configurable logger, which the
  main application directs into a buffer accessible through CoAP.
  • Loading branch information
chrysn committed Apr 30, 2024
1 parent 80bf8f8 commit 60b8298
Show file tree
Hide file tree
Showing 5 changed files with 557 additions and 173 deletions.
48 changes: 48 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/coap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ liboscore-msgbackend = { git = "https://gitlab.com/oscore/liboscore/", features
], rev = "e7a4ecd037cbb9c7f085047fec5896f4bdc68d50" }
coap-message-implementations = "0.1.1"
static-alloc = "0.2.5"
arrayvec = { version = "0.7.4", default-features = false }
coap-scroll-ring-server = "0.2.0"
scroll-ring = "0.1.1"

[features]
default = ["proto-ipv4"] # shame
Expand Down
28 changes: 23 additions & 5 deletions examples/coap/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use embassy_net::udp::{PacketMetadata, UdpSocket};

// Moving work from https://github.com/embassy-rs/embassy/pull/2519 in here for the time being
mod udp_nal;
// Might warrant a standalone crate at some point
mod oluru;

mod seccontext;

Expand Down Expand Up @@ -63,11 +65,22 @@ async fn run<S>(mut sock: S)
where
S: embedded_nal_async::UnconnectedUdp,
{
use coap_handler_implementations::HandlerBuilder;
use coap_handler_implementations::{HandlerBuilder, ReportingHandlerBuilder};

let log = None;

let mut secpool: seccontext::SecContextPool = Default::default();
let buffer = scroll_ring::Buffer::<512>::default();
// FIXME: Why doesn't scroll_ring provide that?
struct Stdout<'a>(&'a scroll_ring::Buffer<512>);
impl<'a> core::fmt::Write for Stdout<'a> {
fn write_str(&mut self, s: &str) -> Result<(), core::fmt::Error> {
self.0.write(s.as_bytes());
Ok(())
}
}
let mut stdout = Stdout(&buffer);
use core::fmt::Write;
writeln!(stdout, "We have our own stdout now.");
writeln!(stdout, "With rings and atomics.");

use hexlit::hex;
const R: &[u8] = &hex!("72cc4761dbd4c78f758931aa589d348d1ef874a7e303ede2f140dcf3e6aa4aac");
Expand All @@ -76,9 +89,14 @@ where
R,
);

let mut handler = coap_message_demos::full_application_tree(log);
let mut handler = coap_message_demos::full_application_tree(log)
.at(
&["stdout"],
coap_scroll_ring_server::BufferHandler::new(&buffer),
)
.with_wkc();

let mut handler = seccontext::OscoreEdhocHandler::new(own_identity, handler);
let mut handler = seccontext::OscoreEdhocHandler::new(own_identity, handler, stdout);

println!("Server is ready.");

Expand Down
Loading

0 comments on commit 60b8298

Please sign in to comment.