sc_network_light/
light_client_requests.rs1use sc_network::{
22 config::ProtocolId, request_responses::IncomingRequest, NetworkBackend, MAX_RESPONSE_SIZE,
23};
24use sp_runtime::traits::Block;
25
26use std::time::Duration;
27
28pub mod handler;
30
31fn generate_protocol_name<Hash: AsRef<[u8]>>(genesis_hash: Hash, fork_id: Option<&str>) -> String {
33 let genesis_hash = genesis_hash.as_ref();
34 if let Some(fork_id) = fork_id {
35 format!("/{}/{}/light/2", array_bytes::bytes2hex("", genesis_hash), fork_id)
36 } else {
37 format!("/{}/light/2", array_bytes::bytes2hex("", genesis_hash))
38 }
39}
40
41fn generate_legacy_protocol_name(protocol_id: &ProtocolId) -> String {
43 format!("/{}/light/2", protocol_id.as_ref())
44}
45
46pub fn generate_protocol_config<
49 Hash: AsRef<[u8]>,
50 B: Block,
51 N: NetworkBackend<B, <B as Block>::Hash>,
52>(
53 protocol_id: &ProtocolId,
54 genesis_hash: Hash,
55 fork_id: Option<&str>,
56 inbound_queue: async_channel::Sender<IncomingRequest>,
57) -> N::RequestResponseProtocolConfig {
58 N::request_response_config(
59 generate_protocol_name(genesis_hash, fork_id).into(),
60 std::iter::once(generate_legacy_protocol_name(protocol_id).into()).collect(),
61 1 * 1024 * 1024,
62 MAX_RESPONSE_SIZE,
63 Duration::from_secs(15),
64 Some(inbound_queue),
65 )
66}