Some cleanup in span/connection_context + few more checks

This commit is contained in:
Lee *!* Clagett
2024-10-08 20:27:09 -04:00
parent 893916ad09
commit 16b5c11f74
6 changed files with 131 additions and 35 deletions

View File

@@ -29,6 +29,7 @@
#include "connection_context.h"
#include <boost/optional/optional.hpp>
#include "cryptonote_protocol/cryptonote_protocol_defs.h"
#include "p2p/p2p_protocol_defs.h"
@@ -69,4 +70,23 @@ namespace cryptonote
};
return std::numeric_limits<size_t>::max();
}
void cryptonote_connection_context::set_state_normal()
{
m_state = state_normal;
m_expected_heights_start = 0;
m_needed_objects.clear();
m_needed_objects.shrink_to_fit();
m_expected_heights.clear();
m_expected_heights.shrink_to_fit();
m_requested_objects.clear();
}
boost::optional<crypto::hash> cryptonote_connection_context::get_expected_hash(const uint64_t height) const
{
const auto difference = height - m_expected_heights_start;
if (height < m_expected_heights_start || m_expected_heights.size() < difference)
return boost::none;
return m_expected_heights[difference];
}
} // cryptonote