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§

source

fn timeout(&self, conf: &ProtocolConfiguration) -> Duration

Request timeout for resend purpose.

source

fn on_removed(&self, inflight_keys: &KeyContainer)

Cleanup the inflight request items when peer disconnected or invalid message received.

source

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.

source

fn is_empty(&self) -> bool

If all requested items are already in flight, then do not send request to remote peer.

source

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§

source

fn notify_empty(&mut self)

Notify the handler when the request gets cancelled by empty.

source

fn required_capability(&self) -> Option<DynamicCapability>

Required peer capability to send this request

source

fn notify_timeout(&mut self)

Notify the handler when the request gets timeout.

source

fn preferred_node_type(&self) -> Option<NodeType>

Epoch-gap-limit required by this request.

Implementors§