Struct cfxcore::sync::request_manager::RequestManager
source · pub struct RequestManager {
pub received_transactions: Arc<RwLock<ReceivedTransactionContainer>>,
pub inflight_pending_transactions: Arc<RwLock<InflightPendingTransactionContainer>>,
/* private fields */
}
Expand description
When a header or block is requested by the RequestManager
, it is ensured
that if it’s not fully received, its hash exists
in in_flight
after every function call.
The thread who removes a hash from in_flight
is responsible to request it
again if it’s not received.
No lock is held when we call another function in this struct, and all locks are acquired in the same order, so there should exist no deadlocks.
Fields§
§received_transactions: Arc<RwLock<ReceivedTransactionContainer>>
§inflight_pending_transactions: Arc<RwLock<InflightPendingTransactionContainer>>
Implementations§
source§impl RequestManager
impl RequestManager
pub fn new( protocol_config: &ProtocolConfiguration, syn: Arc<SynchronizationState>, recover_public_queue: Arc<AsyncTaskQueue<RecoverPublicTask>> ) -> Self
pub fn num_epochs_in_flight(&self) -> u64
pub fn in_flight_blocks(&self) -> HashSet<H256>
sourcepub fn request_with_delay(
&self,
io: &dyn NetworkContext,
request: Box<dyn Request>,
peer: Option<NodeId>,
delay: Option<Duration>
)
pub fn request_with_delay( &self, io: &dyn NetworkContext, request: Box<dyn Request>, peer: Option<NodeId>, delay: Option<Duration> )
Send request to remote peer with delay mechanism. If failed, add the request to waiting queue to resend later.
pub fn request_block_headers( &self, io: &dyn NetworkContext, peer_id: Option<NodeId>, hashes: Vec<H256>, delay: Option<Duration> )
pub fn request_epoch_hashes( &self, io: &dyn NetworkContext, peer_id: Option<NodeId>, epochs: Vec<u64>, delay: Option<Duration> )
pub fn request_blocks( &self, io: &dyn NetworkContext, peer_id: Option<NodeId>, hashes: Vec<H256>, with_public: bool, delay: Option<Duration>, preferred_node_type: Option<NodeType> )
pub fn request_transactions_from_digest( &self, io: &dyn NetworkContext, peer_id: NodeId, transaction_digests: &TransactionDigests )
pub fn request_transactions_from_tx_hashes( &self, io: &dyn NetworkContext, peer_id: NodeId, responded_tx_hashes: Vec<H256>, window_index: usize, tx_hashes_indices: &Vec<usize> )
pub fn request_compact_blocks( &self, io: &dyn NetworkContext, peer_id: Option<NodeId>, hashes: Vec<H256>, delay: Option<Duration> )
pub fn request_blocktxn( &self, io: &dyn NetworkContext, peer_id: NodeId, block_hash: H256, index_skips: Vec<usize>, delay: Option<Duration> )
pub fn send_pending_requests(&self, io: &dyn NetworkContext, peer: &NodeId)
pub fn resend_request_to_another_peer( &self, io: &dyn NetworkContext, req: &RequestMessage )
pub fn match_request( &self, peer_id: &NodeId, request_id: u64 ) -> Result<RequestMessage, Error>
sourcepub fn headers_received(
&self,
io: &dyn NetworkContext,
req_hashes: HashSet<H256>,
received_headers: HashSet<H256>,
delay: Option<Duration>
)
pub fn headers_received( &self, io: &dyn NetworkContext, req_hashes: HashSet<H256>, received_headers: HashSet<H256>, delay: Option<Duration> )
Remove inflight keys when a header is received.
If a request is removed from req_hashes
, it’s the caller’s
responsibility to ensure that the removed request either has already
received or will be requested by the caller again.
sourcepub fn epochs_received(
&self,
io: &dyn NetworkContext,
req_epochs: HashSet<u64>,
received_epochs: HashSet<u64>,
delay: Option<Duration>
)
pub fn epochs_received( &self, io: &dyn NetworkContext, req_epochs: HashSet<u64>, received_epochs: HashSet<u64>, delay: Option<Duration> )
Remove from inflight keys when a epoch is received.
sourcepub fn blocks_received(
&self,
io: &dyn NetworkContext,
requested_hashes: HashSet<H256>,
received_blocks: HashSet<H256>,
ask_full_block: bool,
peer: Option<NodeId>,
with_public: bool,
delay: Option<Duration>,
preferred_node_type_for_block_request: Option<NodeType>
)
pub fn blocks_received( &self, io: &dyn NetworkContext, requested_hashes: HashSet<H256>, received_blocks: HashSet<H256>, ask_full_block: bool, peer: Option<NodeId>, with_public: bool, delay: Option<Duration>, preferred_node_type_for_block_request: Option<NodeType> )
Remove from inflight keys when a block is received.
If a request is removed from req_hashes
, it’s the caller’s
responsibility to ensure that the removed request either has already
received or will be requested by the caller again (the case for
Blocktxn
).
pub fn transactions_received_from_digests( &self, io: &dyn NetworkContext, get_transactions_request: &GetTransactions, signed_transactions: Vec<Arc<SignedTransaction>> )
pub fn transactions_received_from_tx_hashes( &self, get_transactions_request: &GetTransactionsFromTxHashes, signed_transactions: Vec<Arc<SignedTransaction>> )
pub fn get_sent_transactions( &self, window_index: usize, indices: &Vec<usize> ) -> Vec<TransactionWithSignature>
pub fn append_sent_transactions( &self, transactions: Vec<Arc<SignedTransaction>> ) -> usize
pub fn append_received_transactions( &self, transactions: Vec<Arc<SignedTransaction>> )
pub fn resend_timeout_requests(&self, io: &dyn NetworkContext)
sourcepub fn resend_waiting_requests(
&self,
io: &dyn NetworkContext,
remove_timeout_requests: bool,
prefer_archive_node_for_blocks: bool
) -> Vec<Box<dyn Request>>
pub fn resend_waiting_requests( &self, io: &dyn NetworkContext, remove_timeout_requests: bool, prefer_archive_node_for_blocks: bool ) -> Vec<Box<dyn Request>>
Send waiting requests that their backoff delay have passes. Return the cancelled requests that have timeout too many times.
pub fn on_peer_connected(&self, peer: &NodeId)
pub fn on_peer_disconnected(&self, io: &dyn NetworkContext, peer: &NodeId)
pub fn remove_net_inflight_blocks<'a, I: Iterator<Item = &'a H256>>( &self, blocks: I )
Trait Implementations§
source§impl MallocSizeOf for RequestManager
impl MallocSizeOf for RequestManager
source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Auto Trait Implementations§
impl !RefUnwindSafe for RequestManager
impl Send for RequestManager
impl Sync for RequestManager
impl Unpin for RequestManager
impl !UnwindSafe for RequestManager
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
source§impl<T> ElementSatisfy<ElementNoConstrain> for T
impl<T> ElementSatisfy<ElementNoConstrain> for T
fn to_constrain_object(&self) -> &ElementNoConstrain
fn to_constrain_object_mut(&mut self) -> &mut ElementNoConstrain
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.