Trait cfxcore::sync::request_manager::Request
source · pub trait Request: Send + Debug + AsAny + Message + SetRequestId + MallocSizeOf {
// Required methods
fn timeout(&self, conf: &ProtocolConfiguration) -> Duration;
fn on_removed(&self, inflight_keys: &KeyContainer);
fn with_inflight(&mut self, inflight_keys: &KeyContainer);
fn is_empty(&self) -> bool;
fn resend(&self) -> Option<Box<dyn Request>>;
// Provided methods
fn notify_empty(&mut self) { ... }
fn required_capability(&self) -> Option<DynamicCapability> { ... }
fn notify_timeout(&mut self) { ... }
fn preferred_node_type(&self) -> Option<NodeType> { ... }
}
Expand description
Trait of request message
Required Methods§
sourcefn timeout(&self, conf: &ProtocolConfiguration) -> Duration
fn timeout(&self, conf: &ProtocolConfiguration) -> Duration
Request timeout for resend purpose.
sourcefn on_removed(&self, inflight_keys: &KeyContainer)
fn on_removed(&self, inflight_keys: &KeyContainer)
Cleanup the inflight request items when peer disconnected or invalid message received.
sourcefn with_inflight(&mut self, inflight_keys: &KeyContainer)
fn with_inflight(&mut self, inflight_keys: &KeyContainer)
Before send a request, check if its items already in flight.
If in flight, do not request duplicated items.
Otherwise, insert the item key into inflight_keys
.
sourcefn is_empty(&self) -> bool
fn is_empty(&self) -> bool
If all requested items are already in flight, then do not send request to remote peer.
sourcefn resend(&self) -> Option<Box<dyn Request>>
fn resend(&self) -> Option<Box<dyn Request>>
When a request failed (send fail, invalid response or timeout), it will be resend automatically.
For some kind of requests, it will resend other kind of request other than the original one. E.g. when get compact block failed, it will request the whole block instead.
If resend is not required, return None
, e.g. request transactions
failed.
Provided Methods§
sourcefn notify_empty(&mut self)
fn notify_empty(&mut self)
Notify the handler when the request gets cancelled by empty.
sourcefn required_capability(&self) -> Option<DynamicCapability>
fn required_capability(&self) -> Option<DynamicCapability>
Required peer capability to send this request
sourcefn notify_timeout(&mut self)
fn notify_timeout(&mut self)
Notify the handler when the request gets timeout.
sourcefn preferred_node_type(&self) -> Option<NodeType>
fn preferred_node_type(&self) -> Option<NodeType>
Epoch-gap-limit required by this request.