aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_basic/connection_context.h
diff options
context:
space:
mode:
authorLee Clagett <code@leeclagett.com>2021-01-06 11:47:09 -0500
committerLee Clagett <code@leeclagett.com>2020-12-23 23:53:27 +0000
commitba3c627c57e3aebd56c35b45ec8bd310995fa467 (patch)
treeed1972e6578cf5ab1a91534222b14da3b5fd3bd6 /src/cryptonote_basic/connection_context.h
parentMerge pull request #7282 (diff)
downloadmonero-ba3c627c57e3aebd56c35b45ec8bd310995fa467.tar.xz
Command max_bytes moved from dynamic map to static switch
Diffstat (limited to 'src/cryptonote_basic/connection_context.h')
-rw-r--r--src/cryptonote_basic/connection_context.h25
1 files changed, 3 insertions, 22 deletions
diff --git a/src/cryptonote_basic/connection_context.h b/src/cryptonote_basic/connection_context.h
index 8cd896a36..a7d688300 100644
--- a/src/cryptonote_basic/connection_context.h
+++ b/src/cryptonote_basic/connection_context.h
@@ -39,7 +39,6 @@
namespace cryptonote
{
-
struct cryptonote_connection_context: public epee::net_utils::connection_context_base
{
cryptonote_connection_context(): m_state(state_before_handshake), m_remote_blockchain_height(0), m_last_response_height(0),
@@ -56,28 +55,11 @@ namespace cryptonote
state_normal
};
+ static constexpr int handshake_command() noexcept { return 1001; }
bool handshake_complete() const noexcept { return m_state != state_before_handshake; }
- void set_max_bytes(int command, size_t bytes) {
- const auto i = std::lower_bound(m_max_bytes.begin(), m_max_bytes.end(), std::make_pair(command, bytes), [](const std::pair<int, size_t> &e0, const std::pair<int, size_t> &e1){
- return e0.first < e1.first;
- });
- if (i == m_max_bytes.end())
- m_max_bytes.push_back(std::make_pair(command, bytes));
- else if (i->first == command)
- i->second = bytes;
- else
- m_max_bytes.insert(i, std::make_pair(command, bytes));
- }
- size_t get_max_bytes(int command) const {
- const auto i = std::lower_bound(m_max_bytes.begin(), m_max_bytes.end(), std::make_pair(command, 0), [](const std::pair<int, size_t> &e0, const std::pair<int, size_t> &e1){
- return e0.first < e1.first;
- });
- if (i == m_max_bytes.end() || i->first != command)
- return std::numeric_limits<size_t>::max();
- else
- return i->second;
- }
+ //! \return Maximum number of bytes permissible for `command`.
+ static size_t get_max_bytes(int command) noexcept;
state m_state;
std::vector<std::pair<crypto::hash, uint64_t>> m_needed_objects;
@@ -95,7 +77,6 @@ namespace cryptonote
int m_expect_response;
uint64_t m_expect_height;
size_t m_num_requested;
- std::vector<std::pair<int, size_t>> m_max_bytes;
};
inline std::string get_protocol_state_string(cryptonote_connection_context::state s)