Skip to main content

LogServer

Struct LogServer 

Source
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

Source

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();
Source

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.

Source

pub fn as_ptr(&mut self) -> *mut nwep_log_server

as_ptr returns the raw nwep_log_server pointer for use in FFI calls.

The pointer is valid for the lifetime of this LogServer. Callers must not free or outlive the returned pointer.

Trait Implementations§

Source§

impl Drop for LogServer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for LogServer

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.