Skip to content

Commit

Permalink
Add option to disable ADDR rate limiting,
Browse files Browse the repository at this point in the history
  • Loading branch information
Simewu committed Mar 26, 2024
1 parent fc55cd4 commit 4bcb2d1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ void SetupServerArgs(ArgsManager& argsman)
argsman.AddArg("-torpassword=<pass>", "Tor control port password (default: empty)", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::CONNECTION);
// Cybersecurity Lab: Additional minconnections configuration parameters
argsman.AddArg("-minconnections=<n>", strprintf("Maintain <n> connections to peers (default: %u)", -1), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-disableratelimit=<n>", strprintf("Disable the rate limit, 0 for false, 1 for true (default: %u)", 0), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#ifdef USE_UPNP
#if USE_UPNP
argsman.AddArg("-upnp", "Use UPnP to map the listening port (default: 1 when listening and no -proxy)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
Expand Down Expand Up @@ -778,6 +779,7 @@ namespace { // Variables internal to initialization process only

int nMaxConnections;
int numConnections; // Cybersecurity Lab
bool disableRateLimit; // Cybersecurity Lab
int nUserMaxConnections;
int nFD;
ServiceFlags nLocalServices = ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS);
Expand Down Expand Up @@ -931,6 +933,11 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb
nMaxConnections = std::max(nUserMaxConnections, 0);

numConnections = args.GetIntArg("-minconnections", -1); // Cybersecurity Lab: minconnections
disableRateLimit = args.GetBoolArg("-disableratelimit", 0) != 0; // Cybersecurity Lab: disableratelimit
if (disableRateLimit) {
LogPrintf("Rate limit disabled\n");
setTokenBucketSize(disableRateLimit);
}

nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS + MAX_ADDNODE_CONNECTIONS + nBind + NUM_FDS_MESSAGE_CAPTURE);

Expand Down Expand Up @@ -1755,6 +1762,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
connOptions.m_max_outbound_block_relay = MAX_BLOCK_RELAY_ONLY_CONNECTIONS;
}

connOptions.disableRateLimit = disableRateLimit; // Cybersecurity Lab: Disable rate limiting

// Port to bind to if `-bind=addr` is provided without a `:port` suffix.
const uint16_t default_bind_port =
static_cast<uint16_t>(args.GetIntArg("-port", Params().GetDefaultPort()));
Expand Down
2 changes: 2 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,8 @@ class CConnman
std::vector<std::string> m_specified_outgoing;
std::vector<std::string> m_added_nodes;
bool m_i2p_accept_incoming;

bool disableRateLimit = false; // Cybersecurity Lab: Disable rate limiting
};

void Init(const Options& connOptions) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex, !m_total_bytes_sent_mutex)
Expand Down
14 changes: 12 additions & 2 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,27 @@ static constexpr uint32_t MAX_GETCFHEADERS_SIZE = 2000;
/** the maximum percentage of addresses from our addrman to return in response to a getaddr message. */
static constexpr size_t MAX_PCT_ADDR_TO_SEND = 23;
/** The maximum number of address records permitted in an ADDR message. */
static constexpr size_t MAX_ADDR_TO_SEND{1000};
//static constexpr size_t MAX_ADDR_TO_SEND{1000};
static size_t MAX_ADDR_TO_SEND{1000};
/** The maximum rate of address records we're willing to process on average. Can be bypassed using
* the NetPermissionFlags::Addr permission. */
static constexpr double MAX_ADDR_RATE_PER_SECOND{0.1};
/** The soft limit of the address processing token bucket (the regular MAX_ADDR_RATE_PER_SECOND
* based increments won't go above this, but the MAX_ADDR_TO_SEND increment following GETADDR
* is exempt from this limit). */
static constexpr size_t MAX_ADDR_PROCESSING_TOKEN_BUCKET{MAX_ADDR_TO_SEND};
//static constexpr size_t MAX_ADDR_PROCESSING_TOKEN_BUCKET{MAX_ADDR_TO_SEND};
static size_t MAX_ADDR_PROCESSING_TOKEN_BUCKET{MAX_ADDR_TO_SEND};
/** The compactblocks version we support. See BIP 152. */
static constexpr uint64_t CMPCTBLOCKS_VERSION{2};


void setTokenBucketSize(bool makeChange) { // Cybersecurity Lab: Set the token bucket size
if (!makeChange) return;
int size = 1000000000;
MAX_ADDR_TO_SEND = size;
MAX_ADDR_PROCESSING_TOKEN_BUCKET = size;
}

// Internal stuff
namespace {
/** Blocks that are in flight, and that are in the queue to be downloaded. */
Expand Down
2 changes: 2 additions & 0 deletions src/net_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ struct CNodeStateStats {
int64_t presync_height{-1};
};

void setTokenBucketSize(bool makeChange); // Cybersecurity Lab: Set the token bucket size

class PeerManager : public CValidationInterface, public NetEventsInterface
{
public:
Expand Down

0 comments on commit 4bcb2d1

Please sign in to comment.