aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/epee/include/readline_buffer.h14
-rw-r--r--contrib/epee/src/readline_buffer.cpp33
-rw-r--r--src/cryptonote_basic/connection_context.h8
-rw-r--r--src/cryptonote_core/blockchain.cpp1
-rw-r--r--src/cryptonote_core/blockchain.h10
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp5
-rw-r--r--src/cryptonote_core/cryptonote_core.h7
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_defs.h4
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.inl5
-rw-r--r--src/daemon/rpc_command_executor.cpp17
-rw-r--r--tests/core_proxy/core_proxy.h1
-rw-r--r--tests/unit_tests/ban.cpp1
12 files changed, 75 insertions, 31 deletions
diff --git a/contrib/epee/include/readline_buffer.h b/contrib/epee/include/readline_buffer.h
index 8dd082a70..28a153414 100644
--- a/contrib/epee/include/readline_buffer.h
+++ b/contrib/epee/include/readline_buffer.h
@@ -21,23 +21,15 @@ namespace rdln
}
void get_line(std::string& line) const;
void set_prompt(const std::string& prompt);
- static void add_completion(const std::string& command)
- {
- if(std::find(completion_commands.begin(), completion_commands.end(), command) != completion_commands.end())
- return;
- completion_commands.push_back(command);
- }
- static const std::vector<std::string>& get_completions()
- {
- return completion_commands;
- }
+ static void add_completion(const std::string& command);
+ static const std::vector<std::string>& get_completions();
protected:
virtual int sync();
private:
std::streambuf* m_cout_buf;
- static std::vector<std::string> completion_commands;
+ static std::vector<std::string>& completion_commands();
};
class suspend_readline
diff --git a/contrib/epee/src/readline_buffer.cpp b/contrib/epee/src/readline_buffer.cpp
index ce8260ef6..42b474052 100644
--- a/contrib/epee/src/readline_buffer.cpp
+++ b/contrib/epee/src/readline_buffer.cpp
@@ -14,10 +14,8 @@ static void remove_line_handler();
static std::string last_line;
static std::string last_prompt;
-std::mutex line_mutex, sync_mutex, process_mutex;
-std::condition_variable have_line;
-
-std::vector<std::string> rdln::readline_buffer::completion_commands = {"exit"};
+static std::mutex line_mutex, sync_mutex, process_mutex;
+static std::condition_variable have_line;
namespace
{
@@ -43,6 +41,12 @@ rdln::suspend_readline::~suspend_readline()
m_buffer->start();
}
+std::vector<std::string>& rdln::readline_buffer::completion_commands()
+{
+ static std::vector<std::string> commands = {"exit"};
+ return commands;
+}
+
rdln::readline_buffer::readline_buffer()
: std::stringbuf(), m_cout_buf(NULL)
{
@@ -61,7 +65,8 @@ void rdln::readline_buffer::start()
void rdln::readline_buffer::stop()
{
- std::unique_lock<std::mutex> lock(process_mutex);
+ std::unique_lock<std::mutex> lock_process(process_mutex);
+ std::unique_lock<std::mutex> lock_sync(sync_mutex);
have_line.notify_all();
if(m_cout_buf == NULL)
return;
@@ -87,6 +92,18 @@ void rdln::readline_buffer::set_prompt(const std::string& prompt)
rl_redisplay();
}
+void rdln::readline_buffer::add_completion(const std::string& command)
+{
+ if(std::find(completion_commands().begin(), completion_commands().end(), command) != completion_commands().end())
+ return;
+ completion_commands().push_back(command);
+}
+
+const std::vector<std::string>& rdln::readline_buffer::get_completions()
+{
+ return completion_commands();
+}
+
int rdln::readline_buffer::process()
{
process_mutex.lock();
@@ -152,9 +169,7 @@ static int process_input()
static void handle_line(char* line)
{
- // This function never gets called now as we are trapping newlines.
- // However, it still needs to be present for readline to know we are
- // manually handling lines.
+ free(line);
rl_done = 1;
return;
}
@@ -166,6 +181,7 @@ static int handle_enter(int x, int y)
line = rl_copy_text(0, rl_end);
std::string test_line = line;
+ free(line);
boost::trim_right(test_line);
rl_crlf();
@@ -191,7 +207,6 @@ static int handle_enter(int x, int y)
add_history(test_line.c_str());
history_set_pos(history_length);
}
- free(line);
if(last_line != "exit" && last_line != "q")
{
diff --git a/src/cryptonote_basic/connection_context.h b/src/cryptonote_basic/connection_context.h
index 28bd73918..3283543e2 100644
--- a/src/cryptonote_basic/connection_context.h
+++ b/src/cryptonote_basic/connection_context.h
@@ -39,12 +39,12 @@ namespace cryptonote
struct cryptonote_connection_context: public epee::net_utils::connection_context_base
{
- cryptonote_connection_context(): m_state(state_befor_handshake), m_remote_blockchain_height(0), m_last_response_height(0),
+ cryptonote_connection_context(): m_state(state_before_handshake), m_remote_blockchain_height(0), m_last_response_height(0),
m_last_known_hash(cryptonote::null_hash) {}
enum state
{
- state_befor_handshake = 0, //default state
+ state_before_handshake = 0, //default state
state_synchronizing,
state_standby,
state_idle,
@@ -66,8 +66,8 @@ namespace cryptonote
{
switch (s)
{
- case cryptonote_connection_context::state_befor_handshake:
- return "state_befor_handshake";
+ case cryptonote_connection_context::state_before_handshake:
+ return "state_before_handshake";
case cryptonote_connection_context::state_synchronizing:
return "state_synchronizing";
case cryptonote_connection_context::state_standby:
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 61ddff3d0..14a990131 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -2038,6 +2038,7 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc
{
resp.m_block_ids.push_back(m_db->get_block_hash_from_height(i));
}
+ resp.cumulative_difficulty = m_db->get_block_cumulative_difficulty(m_db->height() - 1);
m_db->block_txn_stop();
return true;
}
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 7137f50a7..7fa78584b 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -831,6 +831,16 @@ namespace cryptonote
*
* @return a reference to the BlockchainDB instance
*/
+ const BlockchainDB& get_db() const
+ {
+ return *m_db;
+ }
+
+ /**
+ * @brief get a reference to the BlockchainDB in use by Blockchain
+ *
+ * @return a reference to the BlockchainDB instance
+ */
BlockchainDB& get_db()
{
return *m_db;
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 046b0eca0..19f4aaca9 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -1118,6 +1118,11 @@ namespace cryptonote
return m_blockchain_storage.get_tail_id();
}
//-----------------------------------------------------------------------------------------------
+ difficulty_type core::get_block_cumulative_difficulty(uint64_t height) const
+ {
+ return m_blockchain_storage.get_db().get_block_cumulative_difficulty(height);
+ }
+ //-----------------------------------------------------------------------------------------------
size_t core::get_pool_transactions_count() const
{
return m_mempool.get_transactions_count();
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index 982d67169..f17a6dfe6 100644
--- a/src/cryptonote_core/cryptonote_core.h
+++ b/src/cryptonote_core/cryptonote_core.h
@@ -521,6 +521,13 @@ namespace cryptonote
crypto::hash get_tail_id() const;
/**
+ * @copydoc Blockchain::get_block_cumulative_difficulty
+ *
+ * @note see Blockchain::get_block_cumulative_difficulty
+ */
+ difficulty_type get_block_cumulative_difficulty(uint64_t height) const;
+
+ /**
* @copydoc Blockchain::get_random_outs_for_amounts
*
* @note see Blockchain::get_random_outs_for_amounts
diff --git a/src/cryptonote_protocol/cryptonote_protocol_defs.h b/src/cryptonote_protocol/cryptonote_protocol_defs.h
index 6e6c83f04..71e205c23 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_defs.h
+++ b/src/cryptonote_protocol/cryptonote_protocol_defs.h
@@ -197,11 +197,13 @@ namespace cryptonote
struct CORE_SYNC_DATA
{
uint64_t current_height;
+ uint64_t cumulative_difficulty;
crypto::hash top_id;
uint8_t top_version;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(current_height)
+ KV_SERIALIZE(cumulative_difficulty)
KV_SERIALIZE_VAL_POD_AS_BLOB(top_id)
KV_SERIALIZE_OPT(top_version, (uint8_t)0)
END_KV_SERIALIZE_MAP()
@@ -229,11 +231,13 @@ namespace cryptonote
{
uint64_t start_height;
uint64_t total_height;
+ uint64_t cumulative_difficulty;
std::list<crypto::hash> m_block_ids;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(start_height)
KV_SERIALIZE(total_height)
+ KV_SERIALIZE(cumulative_difficulty)
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(m_block_ids)
END_KV_SERIALIZE_MAP()
};
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index 60cce4594..daefe88b7 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -204,7 +204,7 @@ namespace cryptonote
}
std::stringstream peer_id_str;
- peer_id_str << std::hex << peer_id;
+ peer_id_str << std::hex << std::setw(16) << peer_id;
peer_id_str >> cnx.peer_id;
cnx.support_flags = support_flags;
@@ -253,7 +253,7 @@ namespace cryptonote
template<class t_core>
bool t_cryptonote_protocol_handler<t_core>::process_payload_sync_data(const CORE_SYNC_DATA& hshd, cryptonote_connection_context& context, bool is_inital)
{
- if(context.m_state == cryptonote_connection_context::state_befor_handshake && !is_inital)
+ if(context.m_state == cryptonote_connection_context::state_before_handshake && !is_inital)
return true;
if(context.m_state == cryptonote_connection_context::state_synchronizing)
@@ -310,6 +310,7 @@ namespace cryptonote
{
m_core.get_blockchain_top(hshd.current_height, hshd.top_id);
hshd.top_version = m_core.get_hard_fork_version(hshd.current_height);
+ hshd.cumulative_difficulty = m_core.get_block_cumulative_difficulty(hshd.current_height);
hshd.current_height +=1;
return true;
}
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index 995fee484..bd2142ab1 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -55,7 +55,9 @@ namespace {
std::string port_str;
std::string elapsed = epee::misc_utils::get_time_interval_string(now - last_seen);
std::string ip_str = epee::string_tools::get_ip_string_from_int32(peer.ip);
- epee::string_tools::xtype_to_string(peer.id, id_str);
+ std::stringstream peer_id_str;
+ peer_id_str << std::hex << std::setw(16) << peer.id;
+ peer_id_str >> id_str;
epee::string_tools::xtype_to_string(peer.port, port_str);
std::string addr_str = ip_str + ":" + port_str;
tools::msg_writer() << boost::format("%-10s %-25s %-25s %s") % prefix % id_str % addr_str % elapsed;
@@ -112,10 +114,15 @@ namespace {
return base + " -- " + status;
}
- std::string pad(std::string s, size_t n)
+ std::string pad(std::string s, size_t n, char c = ' ', bool prepend = false)
{
if (s.size() < n)
- s.append(n - s.size(), ' ');
+ {
+ if (prepend)
+ s = std::string(n - s.size(), c) + s;
+ else
+ s.append(n - s.size(), c);
+ }
return s;
}
}
@@ -490,7 +497,7 @@ bool t_rpc_command_executor::print_connections() {
tools::msg_writer()
//<< std::setw(30) << std::left << in_out
<< std::setw(30) << std::left << address
- << std::setw(20) << info.peer_id
+ << std::setw(20) << pad(info.peer_id, 16, '0', true)
<< std::setw(20) << info.support_flags
<< std::setw(30) << std::to_string(info.recv_count) + "(" + std::to_string(info.recv_idle_time) + ")/" + std::to_string(info.send_count) + "(" + std::to_string(info.send_idle_time) + ")"
<< std::setw(25) << info.state
@@ -1742,7 +1749,7 @@ bool t_rpc_command_executor::sync_info()
for (const auto &s: res.spans)
if (s.rate > 0.0f && s.connection_id == p.info.connection_id)
nblocks += s.nblocks, size += s.size;
- tools::success_msg_writer() << address << " " << p.info.peer_id << " " << p.info.height << " " << p.info.current_download << " kB/s, " << nblocks << " blocks / " << size/1e6 << " MB queued";
+ tools::success_msg_writer() << address << " " << pad(p.info.peer_id, 16, '0', true) << " " << p.info.height << " " << p.info.current_download << " kB/s, " << nblocks << " blocks / " << size/1e6 << " MB queued";
}
uint64_t total_size = 0;
diff --git a/tests/core_proxy/core_proxy.h b/tests/core_proxy/core_proxy.h
index 6df7e7fc9..516d1f515 100644
--- a/tests/core_proxy/core_proxy.h
+++ b/tests/core_proxy/core_proxy.h
@@ -98,5 +98,6 @@ namespace tests
bool get_block_by_hash(const crypto::hash &h, cryptonote::block &blk, bool *orphan = NULL) const { return false; }
uint8_t get_ideal_hard_fork_version(uint64_t height) const { return 0; }
uint8_t get_hard_fork_version(uint64_t height) const { return 0; }
+ cryptonote::difficulty_type get_block_cumulative_difficulty(uint64_t height) const { return 0; }
};
}
diff --git a/tests/unit_tests/ban.cpp b/tests/unit_tests/ban.cpp
index 6a1a37fe3..627e85348 100644
--- a/tests/unit_tests/ban.cpp
+++ b/tests/unit_tests/ban.cpp
@@ -75,6 +75,7 @@ public:
bool get_block_by_hash(const crypto::hash &h, cryptonote::block &blk, bool *orphan = NULL) const { return false; }
uint8_t get_ideal_hard_fork_version(uint64_t height) const { return 0; }
uint8_t get_hard_fork_version(uint64_t height) const { return 0; }
+ cryptonote::difficulty_type get_block_cumulative_difficulty(uint64_t height) const { return 0; }
};
typedef nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<test_core>> Server;