pub struct LogServer { /* private fields */ }Expand description
LogServer wraps the NWEP C library’s Merkle log server.
LogServer handles HTTP-like requests to the /log and /log/* endpoints,
enabling peers to submit new Merkle log entries and read existing ones. The server
holds a mutable reference to the underlying MerkleLog for the duration of its
lifetime.
§Safety
The raw pointer ptr must remain valid for the lifetime of this value. LogServer
is Send because access to the C object is mediated through &mut self methods.
Implementations§
Source§impl LogServer
impl LogServer
Sourcepub fn new(
log: &mut MerkleLog,
settings: LogServerSettings,
) -> Result<Self, Error>
pub fn new( log: &mut MerkleLog, settings: LogServerSettings, ) -> Result<Self, Error>
new creates a new log server backed by the given MerkleLog.
The settings argument configures the optional write-authorization callback.
Ownership of the callback closures is transferred into the returned LogServer
and kept alive for as long as the server exists.
§Errors
Returns Err if the underlying C call fails (e.g. allocation failure or an
invalid log pointer).
§Examples
let mut log = MerkleLog::new(MemLog(vec![])).unwrap();
let settings = LogServerSettings {
authorize: Some(Box::new(|node_id, entry| {
// allow all writes from any peer
Ok(())
})),
};
let server = LogServer::new(&mut log, settings).unwrap();Sourcepub fn handle_request(
&mut self,
stream: *mut nwep_stream,
req: *const nwep_request,
) -> Result<(), Error>
pub fn handle_request( &mut self, stream: *mut nwep_stream, req: *const nwep_request, ) -> Result<(), Error>
handle_request dispatches a single incoming NWEP request to the log server.
Both stream and req are raw C pointers supplied by the NWEP server
callback infrastructure. In practice callers do not invoke this method
directly — it is called automatically when a LogServer is registered with
ServerBuilder::log_server().
§Errors
Returns Err if the C library reports a protocol or I/O error while handling
the request.