use sc_network::{
request_responses::IncomingRequest, service::traits::NetworkBackend, ProtocolName,
};
use sp_runtime::traits::Block as BlockT;
use std::time::Duration;
pub const MAX_ADDRESSES: usize = 32;
const INBOUND_CHANNEL_SIZE: usize = 1000;
const MAX_REQUEST_SIZE: u64 = 128;
const MAX_RESPONSE_SIZE: u64 = 16 * 1024;
const TIMEOUT: Duration = Duration::from_secs(20);
pub fn paranode_protocol_name<Hash: AsRef<[u8]>>(
genesis_hash: Hash,
fork_id: Option<&str>,
) -> ProtocolName {
let genesis_hash = genesis_hash.as_ref();
if let Some(fork_id) = fork_id {
format!("/{}/{}/paranode", array_bytes::bytes2hex("", genesis_hash), fork_id)
} else {
format!("/{}/paranode", array_bytes::bytes2hex("", genesis_hash))
}
.into()
}
pub fn bootnode_request_response_config<
Hash: AsRef<[u8]>,
B: BlockT,
N: NetworkBackend<B, <B as BlockT>::Hash>,
>(
genesis_hash: Hash,
fork_id: Option<&str>,
) -> (N::RequestResponseProtocolConfig, async_channel::Receiver<IncomingRequest>) {
let (inbound_tx, inbound_rx) = async_channel::bounded(INBOUND_CHANNEL_SIZE);
let config = N::request_response_config(
paranode_protocol_name(genesis_hash, fork_id),
Vec::new(),
MAX_REQUEST_SIZE,
MAX_RESPONSE_SIZE,
TIMEOUT,
Some(inbound_tx),
);
(config, inbound_rx)
}