aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/CMakeLists.txt24
-rw-r--r--src/rpc/core_rpc_server.cpp45
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h4
-rw-r--r--src/rpc/daemon_handler.cpp6
-rw-r--r--src/rpc/instanciations.cpp37
-rw-r--r--src/rpc/message.cpp2
-rw-r--r--src/rpc/rpc_args.cpp1
7 files changed, 102 insertions, 17 deletions
diff --git a/src/rpc/CMakeLists.txt b/src/rpc/CMakeLists.txt
index 23bb6aaae..748c6b8c1 100644
--- a/src/rpc/CMakeLists.txt
+++ b/src/rpc/CMakeLists.txt
@@ -26,9 +26,12 @@
# 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.
+set(rpc_base_sources
+ rpc_args.cpp)
+
set(rpc_sources
core_rpc_server.cpp
- rpc_args.cpp)
+ instanciations)
set(daemon_messages_sources
message.cpp
@@ -39,9 +42,11 @@ set(daemon_rpc_server_sources
zmq_server.cpp)
-set(rpc_headers
+set(rpc_base_headers
rpc_args.h)
+set(rpc_headers)
+
set(daemon_rpc_server_headers)
@@ -69,6 +74,11 @@ monero_private_headers(daemon_rpc_server
${daemon_rpc_server_private_headers})
+monero_add_library(rpc_base
+ ${rpc_base_sources}
+ ${rpc_base_headers}
+ ${rpc_base_private_headers})
+
monero_add_library(rpc
${rpc_sources}
${rpc_headers}
@@ -85,8 +95,18 @@ monero_add_library(daemon_rpc_server
${daemon_rpc_server_private_headers})
+target_link_libraries(rpc_base
+ PUBLIC
+ common
+ epee
+ ${Boost_REGEX_LIBRARY}
+ ${Boost_THREAD_LIBRARY}
+ PRIVATE
+ ${EXTRA_LIBRARIES})
+
target_link_libraries(rpc
PUBLIC
+ rpc_base
common
cryptonote_core
cryptonote_protocol
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index c9c668e8f..a6109cb89 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -29,6 +29,7 @@
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#include "include_base_utils.h"
+#include "string_tools.h"
using namespace epee;
#include "core_rpc_server.h"
@@ -44,12 +45,14 @@ using namespace epee;
#include "crypto/hash.h"
#include "rpc/rpc_args.h"
#include "core_rpc_server_error_codes.h"
+#include "p2p/net_node.h"
+#include "version.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "daemon.rpc"
#define MAX_RESTRICTED_FAKE_OUTS_COUNT 40
-#define MAX_RESTRICTED_GLOBAL_FAKE_OUTS_COUNT 500
+#define MAX_RESTRICTED_GLOBAL_FAKE_OUTS_COUNT 5000
namespace
{
@@ -152,6 +155,7 @@ namespace cryptonote
res.status = CORE_RPC_STATUS_OK;
res.start_time = (uint64_t)m_core.get_start_time();
res.free_space = m_restricted ? std::numeric_limits<uint64_t>::max() : m_core.get_free_space();
+ res.offline = m_core.offline();
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
@@ -488,6 +492,11 @@ namespace cryptonote
{
if (std::find(missed_txs.begin(), missed_txs.end(), h) == missed_txs.end())
{
+ if (txs.empty())
+ {
+ res.status = "Failed: internal error - txs is empty";
+ return true;
+ }
// core returns the ones it finds in the right order
if (get_transaction_hash(txs.front()) != h)
{
@@ -1146,7 +1155,7 @@ namespace cryptonote
error_resp.message = "Internal error: can't get block by hash. Hash = " + req.hash + '.';
return false;
}
- if (blk.miner_tx.vin.front().type() != typeid(txin_gen))
+ if (blk.miner_tx.vin.size() != 1 || blk.miner_tx.vin.front().type() != typeid(txin_gen))
{
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
error_resp.message = "Internal error: coinbase transaction in the block has the wrong type";
@@ -1184,7 +1193,7 @@ namespace cryptonote
error_resp.message = "Internal error: can't get block by height. Height = " + boost::lexical_cast<std::string>(h) + ". Hash = " + epee::string_tools::pod_to_hex(block_hash) + '.';
return false;
}
- if (blk.miner_tx.vin.front().type() != typeid(txin_gen))
+ if (blk.miner_tx.vin.size() != 1 || blk.miner_tx.vin.front().type() != typeid(txin_gen))
{
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
error_resp.message = "Internal error: coinbase transaction in the block has the wrong type";
@@ -1270,7 +1279,7 @@ namespace cryptonote
error_resp.message = "Internal error: can't get block by hash. Hash = " + req.hash + '.';
return false;
}
- if (blk.miner_tx.vin.front().type() != typeid(txin_gen))
+ if (blk.miner_tx.vin.size() != 1 || blk.miner_tx.vin.front().type() != typeid(txin_gen))
{
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
error_resp.message = "Internal error: coinbase transaction in the block has the wrong type";
@@ -1332,6 +1341,7 @@ namespace cryptonote
res.status = CORE_RPC_STATUS_OK;
res.start_time = (uint64_t)m_core.get_start_time();
res.free_space = m_restricted ? std::numeric_limits<uint64_t>::max() : m_core.get_free_space();
+ res.offline = m_core.offline();
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
@@ -1431,19 +1441,25 @@ namespace cryptonote
{
failed = true;
}
- crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
- txids.push_back(txid);
+ else
+ {
+ crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
+ txids.push_back(txid);
+ }
}
}
if (!m_core.get_blockchain_storage().flush_txes_from_pool(txids))
{
- res.status = "Failed to remove one more tx";
+ res.status = "Failed to remove one or more tx(es)";
return false;
}
if (failed)
{
- res.status = "Failed to parse txid";
+ if (txids.empty())
+ res.status = "Failed to parse txid";
+ else
+ res.status = "Failed to parse some of the txids";
return false;
}
@@ -1549,7 +1565,7 @@ namespace cryptonote
res.status = CORE_RPC_ERROR_CODE_WRONG_PARAM;
return false;
}
- epee::net_utils::connection_basic::set_rate_down_limit(nodetool::default_limit_down * 1024);
+ epee::net_utils::connection_basic::set_rate_down_limit(nodetool::default_limit_down);
}
if (req.limit_up > 0)
@@ -1563,7 +1579,7 @@ namespace cryptonote
res.status = CORE_RPC_ERROR_CODE_WRONG_PARAM;
return false;
}
- epee::net_utils::connection_basic::set_rate_up_limit(nodetool::default_limit_up * 1024);
+ epee::net_utils::connection_basic::set_rate_up_limit(nodetool::default_limit_up);
}
res.limit_down = epee::net_utils::connection_basic::get_rate_down_limit();
@@ -1700,13 +1716,16 @@ namespace cryptonote
PERF_TIMER(on_relay_tx);
bool failed = false;
+ res.status = "";
for (const auto &str: req.txids)
{
cryptonote::blobdata txid_data;
if(!epee::string_tools::parse_hexstr_to_binbuff(str, txid_data))
{
- res.status = std::string("Invalid transaction id: ") + str;
+ if (!res.status.empty()) res.status += ", ";
+ res.status += std::string("invalid transaction id: ") + str;
failed = true;
+ continue;
}
crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
@@ -1722,8 +1741,10 @@ namespace cryptonote
}
else
{
- res.status = std::string("Transaction not found in pool: ") + str;
+ if (!res.status.empty()) res.status += ", ";
+ res.status += std::string("transaction not found in pool: ") + str;
failed = true;
+ continue;
}
}
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index 58a6ce9e1..ad0bff077 100644
--- a/src/rpc/core_rpc_server_commands_defs.h
+++ b/src/rpc/core_rpc_server_commands_defs.h
@@ -49,7 +49,7 @@ namespace cryptonote
// advance which version they will stop working with
// Don't go over 32767 for any of these
#define CORE_RPC_VERSION_MAJOR 1
-#define CORE_RPC_VERSION_MINOR 16
+#define CORE_RPC_VERSION_MINOR 17
#define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor))
#define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR)
@@ -928,6 +928,7 @@ namespace cryptonote
uint64_t block_size_limit;
uint64_t start_time;
uint64_t free_space;
+ bool offline;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(status)
@@ -949,6 +950,7 @@ namespace cryptonote
KV_SERIALIZE(block_size_limit)
KV_SERIALIZE(start_time)
KV_SERIALIZE(free_space)
+ KV_SERIALIZE(offline)
END_KV_SERIALIZE_MAP()
};
};
diff --git a/src/rpc/daemon_handler.cpp b/src/rpc/daemon_handler.cpp
index 4d3fbf491..908f9e187 100644
--- a/src/rpc/daemon_handler.cpp
+++ b/src/rpc/daemon_handler.cpp
@@ -32,7 +32,7 @@
// but including here for clarity
#include "cryptonote_core/cryptonote_core.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
-#include "cryptonote_protocol/blobdatatype.h"
+#include "cryptonote_basic/blobdatatype.h"
#include "ringct/rctSigs.h"
namespace cryptonote
@@ -799,6 +799,10 @@ namespace rpc
}
header.hash = hash_in;
+ if (b.miner_tx.vin.size() != 1 || b.miner_tx.vin.front().type() != typeid(txin_gen))
+ {
+ return false;
+ }
header.height = boost::get<txin_gen>(b.miner_tx.vin.front()).height;
header.major_version = b.major_version;
diff --git a/src/rpc/instanciations.cpp b/src/rpc/instanciations.cpp
new file mode 100644
index 000000000..ac521247e
--- /dev/null
+++ b/src/rpc/instanciations.cpp
@@ -0,0 +1,37 @@
+// Copyright (c) 2017, 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
+
+#include "p2p/net_node.h"
+#include "p2p/net_node.inl"
+#include "cryptonote_protocol/cryptonote_protocol_handler.h"
+#include "cryptonote_protocol/cryptonote_protocol_handler.inl"
+
+namespace nodetool { template class node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core>>; }
+namespace cryptonote { template class t_cryptonote_protocol_handler<cryptonote::core>; }
diff --git a/src/rpc/message.cpp b/src/rpc/message.cpp
index d6da124d1..98b40e667 100644
--- a/src/rpc/message.cpp
+++ b/src/rpc/message.cpp
@@ -111,7 +111,7 @@ FullMessage::FullMessage(Message* message)
FullMessage::FullMessage(const std::string& json_string, bool request)
{
doc.Parse(json_string.c_str());
- if (doc.HasParseError())
+ if (doc.HasParseError() || !doc.IsObject())
{
throw cryptonote::json::PARSE_FAIL();
}
diff --git a/src/rpc/rpc_args.cpp b/src/rpc/rpc_args.cpp
index e03c5472d..ce4070270 100644
--- a/src/rpc/rpc_args.cpp
+++ b/src/rpc/rpc_args.cpp
@@ -30,6 +30,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/asio/ip/address.hpp>
+#include <boost/bind.hpp>
#include "common/command_line.h"
#include "common/i18n.h"