aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorluigi1111 <luigi1111w@gmail.com>2022-04-18 12:13:32 -0500
committerluigi1111 <luigi1111w@gmail.com>2022-04-18 12:13:32 -0500
commit53bf62d11457b011ac77d6d2947e662259cfec5e (patch)
tree7067e3a6f538ba7bdb2434cedb414dd6063f3087 /src
parentMerge pull request #8207 (diff)
parent"Change C-cast to static_cast in net_peerlist.h" (diff)
downloadmonero-53bf62d11457b011ac77d6d2947e662259cfec5e.tar.xz
Merge pull request #8211
1137142 Change C-cast to static_cast in net_peerlist.h (Jeffrey) 175b411 Change C-style-casts to static_cast in time_helper.h (Jeffrey) b49ed59 Remove the only 4 non-UTF8 characters in codebase (Jeffrey) 1f25aa2 Factor out move_it_backward from misc_language.h (Jeffrey) 7764d69 Move copyable_atomic into connection_context (Jeffrey) 801568d Refactor out to_nonconst_iterator.h (Jeffrey) 87ec36c Refactor out pragma_comp_defs (Jeffrey) 441c860 Merge functionality of misc_os_dependent into time_helper.h (Jeffrey) 40f02f9 Add Include statements (Jeffrey) 12b1b74 Trimming Fat (Jeffrey 690ce56 Boring Old Deletes (Jeffrey)
Diffstat (limited to 'src')
-rw-r--r--src/common/perf_timer.cpp2
-rw-r--r--src/common/util.cpp2
-rw-r--r--src/cryptonote_basic/connection_context.h39
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp1
-rw-r--r--src/daemon/command_parser_executor.h1
-rw-r--r--src/daemon/command_server.h1
-rw-r--r--src/daemon/rpc_command_executor.h1
-rw-r--r--src/p2p/net_node.inl1
-rw-r--r--src/p2p/net_peerlist.h23
-rw-r--r--src/p2p/p2p_protocol_defs.h1
-rw-r--r--src/p2p/stdafx.h53
-rw-r--r--src/rpc/core_rpc_server.cpp1
12 files changed, 54 insertions, 72 deletions
diff --git a/src/common/perf_timer.cpp b/src/common/perf_timer.cpp
index 1152bf25a..30164a557 100644
--- a/src/common/perf_timer.cpp
+++ b/src/common/perf_timer.cpp
@@ -27,7 +27,7 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <vector>
-#include "misc_os_dependent.h"
+#include "time_helper.h"
#include "perf_timer.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
diff --git a/src/common/util.cpp b/src/common/util.cpp
index d607d8f7f..89dcf4fef 100644
--- a/src/common/util.cpp
+++ b/src/common/util.cpp
@@ -59,7 +59,7 @@
#include "include_base_utils.h"
#include "file_io_utils.h"
#include "wipeable_string.h"
-#include "misc_os_dependent.h"
+#include "time_helper.h"
using namespace epee;
#include "crypto/crypto.h"
diff --git a/src/cryptonote_basic/connection_context.h b/src/cryptonote_basic/connection_context.h
index 11e54b479..818999a60 100644
--- a/src/cryptonote_basic/connection_context.h
+++ b/src/cryptonote_basic/connection_context.h
@@ -27,6 +27,7 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+// Parts of this file are originally copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
#pragma once
#include <unordered_set>
@@ -34,7 +35,6 @@
#include <algorithm>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "net/net_utils_base.h"
-#include "copyable_atomic.h"
#include "crypto/hash.h"
namespace cryptonote
@@ -55,6 +55,37 @@ namespace cryptonote
state_normal
};
+ /*
+ This class was originally from the EPEE module. It is identical in function to std::atomic<uint32_t> except
+ that it has copy-construction and copy-assignment defined, which means that earliers devs didn't have to write
+ custom copy-contructors and copy-assingment operators for the outer class, cryptonote_connection_context.
+ cryptonote_connection_context should probably be refactored because it is both trying to be POD-like while
+ also (very loosely) controlling access to its atomic members.
+ */
+ class copyable_atomic: public std::atomic<uint32_t>
+ {
+ public:
+ copyable_atomic()
+ {};
+ copyable_atomic(uint32_t value)
+ { store(value); }
+ copyable_atomic(const copyable_atomic& a):std::atomic<uint32_t>(a.load())
+ {}
+ copyable_atomic& operator= (const copyable_atomic& a)
+ {
+ store(a.load());
+ return *this;
+ }
+ uint32_t operator++()
+ {
+ return std::atomic<uint32_t>::operator++();
+ }
+ uint32_t operator++(int fake)
+ {
+ return std::atomic<uint32_t>::operator++(fake);
+ }
+ };
+
static constexpr int handshake_command() noexcept { return 1001; }
bool handshake_complete() const noexcept { return m_state != state_before_handshake; }
@@ -67,7 +98,7 @@ namespace cryptonote
uint64_t m_remote_blockchain_height;
uint64_t m_last_response_height;
boost::posix_time::ptime m_last_request_time;
- epee::copyable_atomic m_callback_request_count; //in debug purpose: problem with double callback rise
+ copyable_atomic m_callback_request_count; //in debug purpose: problem with double callback rise
crypto::hash m_last_known_hash;
uint32_t m_pruning_seed;
uint16_t m_rpc_port;
@@ -77,8 +108,8 @@ namespace cryptonote
int m_expect_response;
uint64_t m_expect_height;
size_t m_num_requested;
- epee::copyable_atomic m_new_stripe_notification{0};
- epee::copyable_atomic m_idle_peer_notification{0};
+ copyable_atomic m_new_stripe_notification{0};
+ copyable_atomic m_idle_peer_notification{0};
};
inline std::string get_protocol_state_string(cryptonote_connection_context::state s)
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp b/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp
index 4c21de7a5..92ee08054 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp
@@ -43,7 +43,6 @@
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/thread/thread.hpp>
#include "misc_language.h"
-#include "pragma_comp_defs.h"
#include <algorithm>
diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h
index ac95c3afc..cd9e6544e 100644
--- a/src/daemon/command_parser_executor.h
+++ b/src/daemon/command_parser_executor.h
@@ -40,7 +40,6 @@
#include "daemon/rpc_command_executor.h"
#include "common/common_fwd.h"
-#include "net/net_fwd.h"
#include "rpc/core_rpc_server.h"
namespace daemonize {
diff --git a/src/daemon/command_server.h b/src/daemon/command_server.h
index 113f99cbc..babb8e85a 100644
--- a/src/daemon/command_server.h
+++ b/src/daemon/command_server.h
@@ -43,7 +43,6 @@ Passing RPC commands:
#include "common/common_fwd.h"
#include "console_handler.h"
#include "daemon/command_parser_executor.h"
-#include "net/net_fwd.h"
namespace daemonize {
diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h
index 8cbb59716..ebd7eda85 100644
--- a/src/daemon/rpc_command_executor.h
+++ b/src/daemon/rpc_command_executor.h
@@ -43,7 +43,6 @@
#include "common/common_fwd.h"
#include "common/rpc_client.h"
#include "cryptonote_basic/cryptonote_basic.h"
-#include "net/net_fwd.h"
#include "rpc/core_rpc_server.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 5c61ede3f..a3bc3bf24 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -55,7 +55,6 @@
#include "math_helper.h"
#include "misc_log_ex.h"
#include "p2p_protocol_defs.h"
-#include "net/local_ip.h"
#include "crypto/crypto.h"
#include "storages/levin_abstract_invoke2.h"
#include "cryptonote_core/cryptonote_core.h"
diff --git a/src/p2p/net_peerlist.h b/src/p2p/net_peerlist.h
index 2cb85d270..dc480462d 100644
--- a/src/p2p/net_peerlist.h
+++ b/src/p2p/net_peerlist.h
@@ -31,6 +31,7 @@
#pragma once
#include <iosfwd>
+#include <iterator>
#include <list>
#include <string>
#include <vector>
@@ -46,7 +47,6 @@
#include "crypto/crypto.h"
#include "cryptonote_config.h"
#include "net/enums.h"
-#include "net/local_ip.h"
#include "p2p_protocol_defs.h"
#include "syncobj.h"
@@ -184,6 +184,7 @@ namespace nodetool
private:
void trim_white_peerlist();
void trim_gray_peerlist();
+ static peerlist_entry get_nth_latest_peer(peers_indexed& peerlist, size_t n);
friend class boost::serialization::access;
epee::critical_section m_peerlist_lock;
@@ -214,6 +215,16 @@ namespace nodetool
}
}
//--------------------------------------------------------------------------------------------------
+ inline
+ peerlist_entry peerlist_manager::get_nth_latest_peer(peers_indexed& peerlist, const size_t n)
+ {
+ // Is not thread-safe nor does it check bounds. Do this before calling. Indexing starts at 0.
+ peers_indexed::index<by_time>::type& by_time_index = peerlist.get<by_time>();
+ auto by_time_it = --by_time_index.end();
+ std::advance(by_time_it, -static_cast<long long>(n));
+ return *by_time_it;
+ }
+ //--------------------------------------------------------------------------------------------------
inline
bool peerlist_manager::merge_peerlist(const std::vector<peerlist_entry>& outer_bs, const std::function<bool(const peerlist_entry&)> &f)
{
@@ -235,8 +246,7 @@ namespace nodetool
if(i >= m_peers_white.size())
return false;
- peers_indexed::index<by_time>::type& by_time_index = m_peers_white.get<by_time>();
- p = *epee::misc_utils::move_it_backward(--by_time_index.end(), i);
+ p = peerlist_manager::get_nth_latest_peer(m_peers_white, i);
return true;
}
//--------------------------------------------------------------------------------------------------
@@ -247,8 +257,7 @@ namespace nodetool
if(i >= m_peers_gray.size())
return false;
- peers_indexed::index<by_time>::type& by_time_index = m_peers_gray.get<by_time>();
- p = *epee::misc_utils::move_it_backward(--by_time_index.end(), i);
+ p = peerlist_manager::get_nth_latest_peer(m_peers_gray, i);
return true;
}
//--------------------------------------------------------------------------------------------------
@@ -437,9 +446,7 @@ namespace nodetool
}
size_t random_index = crypto::rand_idx(m_peers_gray.size());
-
- peers_indexed::index<by_time>::type& by_time_index = m_peers_gray.get<by_time>();
- pe = *epee::misc_utils::move_it_backward(--by_time_index.end(), random_index);
+ pe = peerlist_manager::get_nth_latest_peer(m_peers_gray, random_index);
return true;
diff --git a/src/p2p/p2p_protocol_defs.h b/src/p2p/p2p_protocol_defs.h
index fbeef6e62..8b9cd0f09 100644
--- a/src/p2p/p2p_protocol_defs.h
+++ b/src/p2p/p2p_protocol_defs.h
@@ -30,6 +30,7 @@
#pragma once
+#include <iomanip>
#include <boost/uuid/uuid.hpp>
#include <boost/serialization/version.hpp>
#include "serialization/keyvalue_serialization.h"
diff --git a/src/p2p/stdafx.h b/src/p2p/stdafx.h
deleted file mode 100644
index 27157c8cd..000000000
--- a/src/p2p/stdafx.h
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (c) 2014-2022, The Monero Project
-//
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification, are
-// permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this list of
-// conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice, this list
-// of conditions and the following disclaimer in the documentation and/or other
-// materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be
-// used to endorse or promote products derived from this software without specific
-// prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
-// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
-// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
-// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
-
-#pragma once
-
-#include "targetver.h"
-
-
-#if !defined(__GNUC__)
-#define _CRTDBG_MAP_ALLOC
-#include <stdlib.h>
-#include <crtdbg.h>
-#endif
-
-
-
-#include <stdio.h>
-
-
-#define BOOST_FILESYSTEM_VERSION 3
-#define ENABLE_RELEASE_LOGGING
-#include "log_opt_defs.h"
-#include "misc_log_ex.h"
-
-
-
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index b28583e37..bbcfa6168 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -48,6 +48,7 @@ using namespace epee;
#include "cryptonote_basic/merge_mining.h"
#include "cryptonote_core/tx_sanity_check.h"
#include "misc_language.h"
+#include "net/local_ip.h"
#include "net/parse.h"
#include "storages/http_abstract_invoke.h"
#include "crypto/hash.h"