Skip to content

Commit

Permalink
Add flag to set HttpServerBuilder max_connections
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouzo committed Sep 14, 2023
1 parent a3145b1 commit 75e6843
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/ain-cpp-imports/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub mod ffi {
fn getAccounts() -> Vec<String>;
fn getDatadir() -> String;
fn getNetwork() -> String;
fn getEthMaxConnections() -> u32;
fn getDifficulty(block_hash: [u8; 32]) -> u32;
fn getChainWork(block_hash: [u8; 32]) -> [u8; 32];
fn getPoolTransactions() -> Vec<String>;
Expand Down
7 changes: 7 additions & 0 deletions lib/ain-cpp-imports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ mod ffi {
pub fn getDatadir() -> String {
unimplemented!("{}", UNIMPL_MSG)
}
pub fn getEthMaxConnections() -> u32 {
unimplemented!("{}", UNIMPL_MSG)
}
pub fn getNetwork() -> String {
unimplemented!("{}", UNIMPL_MSG)
}
Expand Down Expand Up @@ -107,6 +110,10 @@ pub fn get_datadir() -> String {
ffi::getDatadir()
}

pub fn get_max_connections() -> u32 {
ffi::getEthMaxConnections()
}

pub fn get_network() -> String {
ffi::getNetwork()
}
Expand Down
3 changes: 3 additions & 0 deletions lib/ain-grpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ pub fn init_network_services(json_addr: &str, grpc_addr: &str) -> Result<()> {
pub fn init_network_json_rpc_service(runtime: &Services, addr: &str) -> Result<()> {
info!("Starting JSON RPC server at {}", addr);
let addr = addr.parse::<SocketAddr>()?;
let max_connections = ain_cpp_imports::get_max_connections();

let handle = runtime.tokio_runtime.clone();
let server = runtime.tokio_runtime.block_on(
HttpServerBuilder::default()
.max_connections(max_connections)
.custom_tokio_runtime(handle)
.build(addr),
)?;
Expand Down
4 changes: 4 additions & 0 deletions src/ffi/ffiexports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ Attributes getAttributeDefaults() {
return Attributes::Default();
}

uint32_t getEthMaxConnections() {
return gArgs.GetArg("-ethmaxconnections", DEFAULT_ETH_MAX_CONNECTIONS);
}

rust::vec<DST20Token> getDST20Tokens(std::size_t mnview_ptr) {
LOCK(cs_main);

Expand Down
2 changes: 2 additions & 0 deletions src/ffi/ffiexports.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
static constexpr uint64_t DEFAULT_EVM_BLOCK_GAS_TARGET = 15000000;
static constexpr uint64_t DEFAULT_EVM_BLOCK_GAS_LIMIT = 30000000;
static constexpr uint64_t DEFAULT_EVM_FINALITY_COUNT = 100;
static constexpr uint32_t DEFAULT_ETH_MAX_CONNECTIONS = 100;

struct Attributes {
uint64_t blockGasTarget;
Expand Down Expand Up @@ -36,6 +37,7 @@ rust::vec<rust::string> getAccounts();
rust::string getDatadir();
rust::string getNetwork();
uint32_t getDifficulty(std::array<uint8_t, 32> blockHash);
uint32_t getEthMaxConnections();
std::array<uint8_t, 32> getChainWork(std::array<uint8_t, 32> blockHash);
rust::vec<rust::string> getPoolTransactions();
uint64_t getNativeTxSize(rust::Vec<uint8_t> rawTransaction);
Expand Down
2 changes: 2 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include <walletinitinterface.h>
#include <wallet/wallet.h>
#include <ffi/ffihelpers.h>
#include <ffi/ffiexports.h>

#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -649,6 +650,7 @@ void SetupServerArgs()
gArgs.AddArg("-grpcport=<port>", strprintf("Start GRPC connections on <port> and <port + 1> (default: %u, testnet: %u, changi: %u, devnet: %u, regtest: %u)", defaultBaseParams->GRPCPort(), testnetBaseParams->GRPCPort(), changiBaseParams->GRPCPort(), devnetBaseParams->GRPCPort(), regtestBaseParams->GRPCPort()), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::RPC);
gArgs.AddArg("-ethrpcbind=<addr>[:port]", "Bind to given address to listen for ETH-JSON-RPC connections. Do not expose the ETH-RPC server to untrusted networks such as the public internet! This option is ignored unless -rpcallowip is also passed. Port is optional and overrides -ethrpcport. This option can be specified multiple times (default: 127.0.0.1 i.e., localhost)", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::RPC);
gArgs.AddArg("-ethrpcport=<port>", strprintf("Listen for ETH-JSON-RPC connections on <port>> (default: %u, testnet: %u, changi: %u, devnet: %u, regtest: %u)", defaultBaseParams->ETHRPCPort(), testnetBaseParams->ETHRPCPort(), changiBaseParams->ETHRPCPort(), devnetBaseParams->ETHRPCPort(), regtestBaseParams->ETHRPCPort()), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::RPC);
gArgs.AddArg("-ethmaxconnections=<connections>", strprintf("Set the maximum number of connections allowed (default: %u, testnet: %u, changi: %u, devnet: %u, regtest: %u)", DEFAULT_ETH_MAX_CONNECTIONS, DEFAULT_ETH_MAX_CONNECTIONS, DEFAULT_ETH_MAX_CONNECTIONS, DEFAULT_ETH_MAX_CONNECTIONS, DEFAULT_ETH_MAX_CONNECTIONS), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::RPC);

#if HAVE_DECL_DAEMON
gArgs.AddArg("-daemon", "Run in the background as a daemon and accept commands", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
Expand Down

0 comments on commit 75e6843

Please sign in to comment.