Skip to main content

HttpTransport

Struct HttpTransport 

Source
pub struct HttpTransport { /* private fields */ }
Expand description

HTTP-based transport for Raft consensus communication.

Sends outgoing Raft messages as JSON POST requests to peer nodes. Receives incoming messages via an internal channel that should be fed by an external HTTP endpoint handler.

Implementations§

Source§

impl HttpTransport

Source

pub fn new(peer_urls: HashMap<NodeId, String>) -> Self

Create a new HTTP transport with the given peer URL mappings.

§Arguments
  • peer_urls - A map of NodeId to base HTTP URL for each peer node.
§Example
use std::collections::HashMap;
use aegis_replication::node::NodeId;
use aegis_replication::http_transport::HttpTransport;

let mut peers = HashMap::new();
peers.insert(NodeId::new("node2"), "http://127.0.0.1:9091".to_string());
peers.insert(NodeId::new("node3"), "http://127.0.0.1:7001".to_string());
let transport = HttpTransport::new(peers);
Source

pub fn sender(&self) -> Sender<Message>

Get a sender handle for pushing incoming messages into this transport.

Use this to integrate with an HTTP server endpoint. When a Raft message arrives via HTTP, deserialize it and call sender.send(message).

Source

pub fn push_message(&self, message: Message) -> Result<(), TransportError>

Push an incoming message into the receive channel.

This is the primary way to feed messages from an external HTTP handler into the transport layer.

Source

pub fn add_peer(&self, node_id: NodeId, url: String)

Add or update a peer URL mapping.

Source

pub fn remove_peer(&self, node_id: &NodeId)

Remove a peer URL mapping.

Source

pub fn peer_url(&self, node_id: &NodeId) -> Option<String>

Get the URL for a peer node.

Trait Implementations§

Source§

impl Transport for HttpTransport

Source§

fn send(&self, message: Message) -> Result<(), TransportError>

Send a message to the target node via HTTP POST.

The message’s to field is used to look up the peer’s URL. The message is serialized as JSON and sent to {peer_url}/api/v1/cluster/raft.

Source§

fn recv(&self) -> Result<Message, TransportError>

Receive a message (blocking).

Blocks until a message is available in the incoming channel. Messages are pushed into this channel by external HTTP handlers via push_message() or the sender() handle.

Source§

fn try_recv(&self) -> Option<Message>

Try to receive a message (non-blocking).

Returns None if no message is currently available.

Source§

fn broadcast( &self, message: Message, peers: &[NodeId], ) -> Vec<Result<(), TransportError>>

Broadcast a message to all specified peers via HTTP POST.

Sends the message to each peer independently. Failures for individual peers do not affect delivery to other peers.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more