Skip to content
Snippets Groups Projects
Commit 53d9a50c authored by Sebastian Kunert's avatar Sebastian Kunert Committed by GitHub
Browse files

Add support for outbound only configs on request/response protocols (#6343)

* Add option ot add outbound_only configurations

* Improve comment
parent 01f81541
No related merge requests found
......@@ -126,6 +126,17 @@ const STATEMENT_RESPONSE_SIZE: u64 = MAX_CODE_SIZE as u64 + 10_000;
pub const DISPUTE_REQUEST_TIMEOUT: Duration = Duration::from_secs(12);
impl Protocol {
/// Get a configuration for a given Request response protocol.
///
/// Returns a `ProtocolConfig` for this protocol.
/// Use this if you plan only to send requests for this protocol.
pub fn get_outbound_only_config(
self,
req_protocol_names: &ReqProtocolNames,
) -> RequestResponseConfig {
self.create_config(req_protocol_names, None)
}
/// Get a configuration for a given Request response protocol.
///
/// Returns a receiver for messages received on this protocol and the requested
......@@ -134,10 +145,19 @@ impl Protocol {
self,
req_protocol_names: &ReqProtocolNames,
) -> (mpsc::Receiver<network::IncomingRequest>, RequestResponseConfig) {
let (tx, rx) = mpsc::channel(self.get_channel_size());
let cfg = self.create_config(req_protocol_names, Some(tx));
(rx, cfg)
}
fn create_config(
self,
req_protocol_names: &ReqProtocolNames,
tx: Option<mpsc::Sender<network::IncomingRequest>>,
) -> RequestResponseConfig {
let name = req_protocol_names.get_name(self);
let fallback_names = self.get_fallback_names();
let (tx, rx) = mpsc::channel(self.get_channel_size());
let cfg = match self {
match self {
Protocol::ChunkFetchingV1 => RequestResponseConfig {
name,
fallback_names,
......@@ -145,7 +165,7 @@ impl Protocol {
max_response_size: POV_RESPONSE_SIZE as u64 * 3,
// We are connected to all validators:
request_timeout: CHUNK_REQUEST_TIMEOUT,
inbound_queue: Some(tx),
inbound_queue: tx,
},
Protocol::CollationFetchingV1 => RequestResponseConfig {
name,
......@@ -154,7 +174,7 @@ impl Protocol {
max_response_size: POV_RESPONSE_SIZE,
// Taken from initial implementation in collator protocol:
request_timeout: POV_REQUEST_TIMEOUT_CONNECTED,
inbound_queue: Some(tx),
inbound_queue: tx,
},
Protocol::PoVFetchingV1 => RequestResponseConfig {
name,
......@@ -162,7 +182,7 @@ impl Protocol {
max_request_size: 1_000,
max_response_size: POV_RESPONSE_SIZE,
request_timeout: POV_REQUEST_TIMEOUT_CONNECTED,
inbound_queue: Some(tx),
inbound_queue: tx,
},
Protocol::AvailableDataFetchingV1 => RequestResponseConfig {
name,
......@@ -171,7 +191,7 @@ impl Protocol {
// Available data size is dominated by the PoV size.
max_response_size: POV_RESPONSE_SIZE,
request_timeout: POV_REQUEST_TIMEOUT_CONNECTED,
inbound_queue: Some(tx),
inbound_queue: tx,
},
Protocol::StatementFetchingV1 => RequestResponseConfig {
name,
......@@ -189,7 +209,7 @@ impl Protocol {
// fail, but this is desired, so we can quickly move on to a faster one - we should
// also decrease its reputation.
request_timeout: Duration::from_secs(1),
inbound_queue: Some(tx),
inbound_queue: tx,
},
Protocol::DisputeSendingV1 => RequestResponseConfig {
name,
......@@ -199,10 +219,9 @@ impl Protocol {
/// plenty.
max_response_size: 100,
request_timeout: DISPUTE_REQUEST_TIMEOUT,
inbound_queue: Some(tx),
inbound_queue: tx,
},
};
(rx, cfg)
}
}
// Channel sizes for the supported protocols.
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment