Struct mainline::rpc::Rpc

source ·
pub struct Rpc { /* private fields */ }
Expand description

Internal Rpc called in the Dht thread loop, useful to create your own actor setup.

Implementations§

source§

impl Rpc

source

pub fn new(settings: &DhtSettings) -> Result<Self>

Create a new Rpc

source

pub fn with_id(self, id: Id) -> Self

Override the Rpc’s Id which is set randomly be default.

source

pub fn id(&self) -> &Id

Returns the node’s Id

source

pub fn local_addr(&self) -> SocketAddr

Returns the address the server is listening to.

source

pub fn tick(&mut self) -> RpcTickReport

Advance the inflight queries, receive incoming requests, maintain the routing table, and everything else that needs to happen at every tick.

source

pub fn request(&mut self, address: SocketAddr, request: RequestSpecific) -> u16

Send a request to the given address and return the transaction_id

source

pub fn response( &mut self, address: SocketAddr, transaction_id: u16, response: ResponseSpecific, )

Send a response to the given address.

source

pub fn error( &mut self, address: SocketAddr, transaction_id: u16, error: ErrorSpecific, )

Send an error to the given address.

source

pub fn put( &mut self, target: Id, request: PutRequestSpecific, sender: Option<Sender<PutResult>>, )

Store a value in the closest nodes, optionally trigger a lookup query if the cached closest_nodes aren’t fresh enough.

salt is only relevant for mutable values.

source

pub fn get( &mut self, target: Id, request: RequestTypeSpecific, sender: Option<ResponseSender>, extra_nodes: Option<Vec<SocketAddr>>, )

Send a message to closer and closer nodes until we can’t find any more nodes.

Queries take few seconds to fully traverse the network, once it is done, it will be removed from self.queries. But until then, calling rpc.query() multiple times, will just add the sender to the query, send all the responses seen so far, as well as subsequent responses.

Effectively, we are caching responses and backing off the network for the duration it takes to traverse it.

extra_nodes option allows the query to visit specific nodes, that won’t necessesarily be visited through the query otherwise.

Trait Implementations§

source§

impl Debug for Rpc

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Rpc

§

impl RefUnwindSafe for Rpc

§

impl Send for Rpc

§

impl Sync for Rpc

§

impl Unpin for Rpc

§

impl UnwindSafe for Rpc

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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

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