str0m's DTLS stack (dimpl) hard-codes the SRTP profile a DTLS server picks (AES-256-GCM first), with no way to configure it. Official TeamSpeak 6 clients use AES_CM_128_HMAC_SHA1_80, so we need to patch dimpl. This commit only vendors the crate as published and routes crates.io's dimpl to it; the change follows separately so it can be reviewed and dropped on its own. third_party is excluded from the workspace so dimpl's dev-dependencies and tests stay out of our builds, and own-crates.sh skips it like crates/proto. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
3.3 KiB
CLAUDE.md
Code style guide for Claude sessions working on dimpl.
File Ordering
- Imports
- Constants
- Primary type (matches module name:
foo.rs→struct Foo) - Related types, ordered by first appearance in primary type's fields/variants
implblock for primary type- Helper types and functions
- Standard trait impls (
Display,Debug,From) - Tests (
#[cfg(test)] mod tests)
Example: struct Foo { bar: Bar, baz: Baz } → define Bar before Baz.
State Machine Files (client.rs, server.rs)
Protocol flow dictates ordering throughout:
- Module-level comment documenting the protocol flow
- Imports
- Primary struct (
Client/Server) Stateenum (variants in protocol order)impl PrimaryType(public API:new,handle_*,poll_*)impl State(name(),make_progress(), then handlers in enum order)- Free helper functions (ordered by first use in protocol flow)
Imports
Group: std → external → crate. Alphabetical within groups.
use std::collections::VecDeque;
use std::time::Instant;
use arrayvec::ArrayVec;
use crate::buffer::Buf;
use crate::engine::Engine;
Use short paths: std::Vec not std::vec::Vec.
Modules
Private modules with selective re-exports:
mod certificate;
pub use certificate::Certificate;
Visibility
Prefer pub over pub(crate). Only use pub(crate) when explicitly preventing
items from becoming part of the public API. Internal modules that are kept private
by their parent don't need pub(crate) on their items.
// Good: parent module is private, so pub here won't leak
mod internal {
pub struct Helper; // Not in public API because `internal` is private
}
// Bad: unnecessary restriction
mod internal {
pub(crate) struct Helper; // Redundant - parent already private
}
Fields and Methods
Fields are private. Expose via getter methods.
Documentation
Doc examples must compile and run as tests. Never use ignore. Use no_run only
when hardware/network required.
Unwrap
Comment unwrap() calls explaining why they're safe:
// unwrap: is ok because we set the random in handle_timeout
let random = self.random.unwrap();
Sans-IO API Contract
dimpl is Sans-IO: no sockets, no threads, no async. The caller drives I/O.
Poll-to-Timeout Rule: Every mutation (handle_packet, handle_timeout) must
be followed by polling until Output::Timeout:
client.handle_timeout(now);
loop {
match client.poll_output(&mut buf) {
Output::Packet(data) => { /* send to peer */ }
Output::Connected => { /* handshake complete */ }
Output::Timeout(when) => break,
}
}
Never stop polling early. Internal state is only consistent after reaching Timeout.
Memory
Summary: Allocation-conscious design - pool reuse, single-copy, in-place mutation, boxing for ABI, bounded stack collections.
Buffer Pooling
- Reuse allocations instead of malloc/free per packet
- Clear contents but retain capacity
Single-Copy Parsing
- One copy from network into working buffer
- Parse and decrypt in-place on that buffer
ABI Optimization
- Box large inner data so outer structs fit in registers
- Avoids memmove on function calls
Bounded Stack Collections
- Fixed-capacity arrays for small, known-bounded collections
- Fail explicitly if bounds exceeded