Skip to main content

ab_networking/protocols/request_response/handlers/
segment_header.rs

1//! Helper for incoming super segment header requests.
2//!
3//! Handle (i.e. answer) incoming super segment headers requests from a remote peer received via
4//! `RequestResponsesBehaviour` with generic [`GenericRequestHandler`].
5
6use super::generic_request_handler::{GenericRequest, GenericRequestHandler};
7use ab_core_primitives::segments::{SuperSegmentHeader, SuperSegmentIndex};
8use parity_scale_codec::{Decode, Encode};
9use std::sync::Arc;
10
11/// Super segment header by super segment indices protocol request
12#[derive(Debug, Clone, Eq, PartialEq, Encode, Decode)]
13pub enum SuperSegmentHeaderRequest {
14    /// Super segment headers by super segment indices
15    SuperSegmentIndices {
16        /// Super segment indices to get
17        // TODO: Use `Arc<[SuperSegmentIndex]>` once
18        //  https://github.com/paritytech/parity-scale-codec/issues/633 is resolved
19        super_segment_indices: Arc<Vec<SuperSegmentIndex>>,
20    },
21    /// Defines how many super segment headers to return.
22    ///
23    /// Super segments will be in ascending order.
24    LastSuperSegmentHeaders {
25        /// Number of segment headers to return
26        limit: u32,
27    },
28}
29
30impl GenericRequest for SuperSegmentHeaderRequest {
31    const PROTOCOL_NAME: &'static str = "/subspace/super-segment-headers-by-indexes/0.1.0";
32    const LOG_TARGET: &'static str = "super-segment-headers-by-indexes-request-response-handler";
33    type Response = SuperSegmentHeaderResponse;
34}
35
36/// Super segment header by super segment indices protocol response
37#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
38pub struct SuperSegmentHeaderResponse {
39    /// Super segment headers
40    pub super_segment_headers: Vec<SuperSegmentHeader>,
41}
42
43/// Create a new `super-segment-headers-by-indexes` request handler
44pub type SuperSegmentHeaderBySegmentIndexesRequestHandler =
45    GenericRequestHandler<SuperSegmentHeaderRequest>;