Expand description
Raw, bindgen-generated FFI bindings to the i2pd-sys/shim C shim over libi2pd
(PurpleI2P/i2pd) — a real I2P router built in-process, not a client for a separately-running
i2pd daemon.
§What’s here
Every symbol in this module is generated at build time from shim/shim.h (the
only header bindgen ever runs against — never libi2pd’s own C++ headers, which use
std::shared_ptr/STL types with no stable C ABI). See that file for the fully documented API
surface; the short version:
§Example
use i2pd_sys::*;
use std::ffi::CString;
unsafe {
let app_name = CString::new("my-app").unwrap();
i2pd_init(app_name.as_ptr()); // exactly once, before anything else
i2pd_start();
let dest = i2pd_create_transient_destination();
assert!(!dest.is_null());
// ... i2pd_accept_stream / i2pd_create_stream / i2pd_stream_send / i2pd_stream_receive ...
i2pd_destroy_destination(dest);
i2pd_stop();
i2pd_terminate();
}§Safety
This is a raw C ABI with all the usual obligations: i2pd_init must be called exactly once
before any other function; every I2pdDestination/I2pdStream pointer must be destroyed
exactly once (via the matching i2pd_destroy_*) and never used afterwards; buffers returned
by i2pd_generate_keys/i2pd_destination_b32_address must be freed with
i2pd_free_buffer/i2pd_free_string respectively, exactly once.
i2pd_stream_send and i2pd_stream_receive are safe to call concurrently from
different threads on the same stream (one sending, one receiving) — each posts work onto
i2pd’s internal io_service and blocks the calling thread on a condition variable, the same
pattern i2pd’s own SAM/BOB bridges use. The callback registered via i2pd_accept_stream
runs on i2pd’s own internal thread and must return quickly without blocking, or it stalls the
event loop for every destination sharing that router.
Every shim function catches all C++ exceptions internally, so a C++ exception can never
unwind across the extern "C" boundary (which would be undefined behavior) — failures
surface as NULL/0/-1 return values instead, not panics or aborts.
§Crypto backend: aws-lc (default) vs fips
i2pd needs an OpenSSL-API-compatible crypto library; this crate provides one via exactly
one of two backends, chosen with a priority rule rather than a hard exclusivity check:
aws-lc(default): regular AWS-LC viaaws-lc-sys.fips: the FIPS-validated AWS-LC-FIPS module viaaws-lc-fips-sysinstead.fipswins if both end up enabled (e.g. because a dependent crate’s own default pulled inaws-lcwhile a workspace-widefipsflag also reached in here) —aws-lc-sysmay still get compiled in that case (as an unused, inert dependency), butbuild.rsonly ever emits link directives for thefipsbackend, andaws-lc/aws-lc-fipslink with per-version-prefixed symbol names (see their ownlinksmetadata), so nothing actually collides at link time. See the “FIPS” section ofREADME.mdfor what this does (and does not) get you, and what it costs, before reaching for it to satisfy a compliance requirement.
Structs§
Functions§
- i2pd_
accept_ ⚠stream - i2pd_
create_ ⚠persistent_ destination - i2pd_
create_ ⚠stream - i2pd_
create_ ⚠transient_ destination - i2pd_
destination_ ⚠b32_ address - i2pd_
destination_ ⚠ident_ hash - i2pd_
destroy_ ⚠destination - i2pd_
destroy_ ⚠stream - i2pd_
free_ ⚠buffer - i2pd_
free_ ⚠string - i2pd_
generate_ ⚠keys - i2pd_
init ⚠ - i2pd_
start ⚠ - i2pd_
stop ⚠ - i2pd_
stream_ ⚠close - i2pd_
stream_ ⚠is_ open - i2pd_
stream_ ⚠receive - i2pd_
stream_ ⚠send - i2pd_
terminate ⚠