Clients
Read bounded timestamps from the daemon using the Rust crate or the C/FFI library. Both require the clockbound daemon to be running.
A ClockBound client reads the daemon's shared-memory segment and returns the current time as an earliest/latest pair plus a clock status. First-party clients are provided as a Rust crate and a C library; any language that can memory-map a file can implement the protocol directly.
Rust client
Add the clock-bound crate to your Cargo.toml:
[dependencies]
clock-bound = "3.0.0-rc.0"Then use it in your application:
use clock_bound::{Client, ClockStatus, Error, TimeWindow};
fn main() -> Result<(), Error> {
// Opens the daemon's shared-memory segment.
let mut client = Client::new()?;
// Read the current bounded time.
let window: TimeWindow = client.now()?;
// Only trust the time window when the clock is synchronized or free running.
match window.clock_status {
ClockStatus::Synchronized | ClockStatus::FreeRunning => {
println!("Time window: {:?} to {:?}", window.earliest, window.latest);
}
status => eprintln!("Time window not trustworthy, clock status: {status:?}"),
}
Ok(())
}now() returns a TimeWindow: the earliest and latest timestamps that bound the current time, along with the clock status (see Concepts). API reference documentation is published on docs.rs for the clock-bound crate.
C / FFI client
The clock-bound-ffi crate builds the libclockbound C library. The daemon must be running for the library to work.
Build the library
# Build the FFI crate
cargo build --release
# Produces libclockbound.a and libclockbound.soInstall the header and library
# Copy the header to /usr/include/
sudo cp clock-bound-ffi/include/clockbound.h /usr/include/
# Copy the library artifacts to /usr/lib/
sudo cp target/release/libclockbound.a target/release/libclockbound.so /usr/lib/Use it from C
#include <clockbound.h>
clockbound_now_result now;
clockbound_err cb_err;
clockbound_ctx *ctx = clockbound_open(&cb_err);
clockbound_now(ctx, &now, &cb_err);
// Only trust the time window when the clock is synchronized or free running.
if (now.clock_status == CLOCKBOUND_STA_SYNCHRONIZED ||
now.clock_status == CLOCKBOUND_STA_FREE_RUNNING) {
printf("Time window: %ld.%09ld to %ld.%09ld\n",
now.earliest.tv_sec, now.earliest.tv_nsec,
now.latest.tv_sec, now.latest.tv_nsec);
} else {
fprintf(stderr, "Time window not trustworthy, clock status: %d\n", now.clock_status);
}Compile & link
gcc is required. Ensure the loader can find the shared library (for example, export LD_LIBRARY_PATH=/usr/lib), then compile against -lclockbound:
gcc clockbound_now.c -o clockbound_now -I/usr/include -L/usr/lib -lclockbound
./clockbound_nowRunnable example programs (clockbound_now and clockbound_loop_forever) are provided in the repository under examples/client/c.
Custom clients
Clients can be written in any programming language that can read from a shared-memory segment backed by a file. See the Protocol reference for the exact shared-memory layout and the read-time computation of the clock error bound.