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
impl Rpc
sourcepub fn new(settings: &DhtSettings) -> Result<Self>
pub fn new(settings: &DhtSettings) -> Result<Self>
Create a new Rpc
sourcepub fn local_addr(&self) -> SocketAddr
pub fn local_addr(&self) -> SocketAddr
Returns the address the server is listening to.
sourcepub fn tick(&mut self) -> RpcTickReport
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.
sourcepub fn request(&mut self, address: SocketAddr, request: RequestSpecific) -> u16
pub fn request(&mut self, address: SocketAddr, request: RequestSpecific) -> u16
Send a request to the given address and return the transaction_id
sourcepub fn response(
&mut self,
address: SocketAddr,
transaction_id: u16,
response: ResponseSpecific,
)
pub fn response( &mut self, address: SocketAddr, transaction_id: u16, response: ResponseSpecific, )
Send a response to the given address.
sourcepub fn error(
&mut self,
address: SocketAddr,
transaction_id: u16,
error: ErrorSpecific,
)
pub fn error( &mut self, address: SocketAddr, transaction_id: u16, error: ErrorSpecific, )
Send an error to the given address.
sourcepub fn put(
&mut self,
target: Id,
request: PutRequestSpecific,
sender: Option<Sender<PutResult>>,
)
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.
sourcepub fn get(
&mut self,
target: Id,
request: RequestTypeSpecific,
sender: Option<ResponseSender>,
extra_nodes: Option<Vec<SocketAddr>>,
)
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.