diem_config/config/
json_rpc_config.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4// Copyright 2021 Conflux Foundation. All rights reserved.
5// Conflux is free software and distributed under GNU General Public License.
6// See http://www.gnu.org/licenses/
7
8use crate::utils;
9use serde::{Deserialize, Serialize};
10use std::net::SocketAddr;
11
12#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
13#[serde(default, deny_unknown_fields)]
14pub struct JsonRpcConfig {
15    pub address: SocketAddr,
16    pub batch_size_limit: u16,
17    pub page_size_limit: u16,
18    pub content_length_limit: usize,
19    pub tls_cert_path: Option<String>,
20    pub tls_key_path: Option<String>,
21}
22
23pub const DEFAULT_JSON_RPC_ADDRESS: &str = "127.0.0.1";
24pub const DEFAULT_JSON_RPC_PORT: u16 = 8080;
25pub const DEFAULT_BATCH_SIZE_LIMIT: u16 = 20;
26pub const DEFAULT_PAGE_SIZE_LIMIT: u16 = 1000;
27pub const DEFAULT_CONTENT_LENGTH_LIMIT: usize = 32 * 1024; // 32kb
28
29impl Default for JsonRpcConfig {
30    fn default() -> JsonRpcConfig {
31        JsonRpcConfig {
32            address: format!(
33                "{}:{}",
34                DEFAULT_JSON_RPC_ADDRESS, DEFAULT_JSON_RPC_PORT
35            )
36            .parse()
37            .unwrap(),
38            batch_size_limit: DEFAULT_BATCH_SIZE_LIMIT,
39            page_size_limit: DEFAULT_PAGE_SIZE_LIMIT,
40            content_length_limit: DEFAULT_CONTENT_LENGTH_LIMIT,
41            tls_cert_path: None,
42            tls_key_path: None,
43        }
44    }
45}
46
47impl JsonRpcConfig {
48    pub fn randomize_ports(&mut self) {
49        self.address.set_port(utils::get_available_port());
50    }
51}