refactor in msg verify_message and minor cleanup (#1131)

This commit is contained in:
Alden Torres 2016-09-22 02:04:05 -04:00 committed by Arvid Norberg
parent c75b243490
commit c7ec987a1b
10 changed files with 90 additions and 142 deletions

View File

@ -616,7 +616,6 @@ for filename in files:
continue
if (l == 'namespace detail' or \
l == 'namespace dht_detail' or \
l == 'namespace impl' or \
l == 'namespace aux') \
and not internal:

View File

@ -33,10 +33,11 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef LIBTORRENT_GET_ITEM_HPP
#define LIBTORRENT_GET_ITEM_HPP
#include <string>
#include <libtorrent/kademlia/find_data.hpp>
#include <libtorrent/kademlia/item.hpp>
#include <memory>
namespace libtorrent { namespace dht
{
@ -50,7 +51,7 @@ public:
sequence_number seq,
signature const& sig);
// for immutable itms
// for immutable items
get_item(node& dht_node
, node_id const& target
, data_callback const& dcallback

View File

@ -34,11 +34,11 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_KADEMLIA_MSG_HPP
#include "libtorrent/socket.hpp"
#include "libtorrent/span.hpp"
namespace libtorrent {
struct bdecode_node;
class entry;
namespace dht {
@ -82,25 +82,17 @@ struct key_desc_t
};
};
// generate an error response message
void incoming_error(entry& e, char const* msg, int error_code = 203);
// given a redundant name to avoid clashing with libtorrent::detail
namespace dht_detail {
//#error move this to its own .hpp/.cpp pair and make it take an span instead of being a template
TORRENT_EXPORT bool verify_message(bdecode_node const& msg, key_desc_t const desc[]
, bdecode_node ret[], int size, char* error, int error_size);
}
// TODO: move this to its own .hpp/.cpp pair?
TORRENT_EXTRA_EXPORT bool verify_message_impl(bdecode_node const& msg, span<key_desc_t const> desc
, span<bdecode_node> ret, span<char> error);
// verifies that a message has all the required
// entries and returns them in ret
template <int Size>
bool verify_message(bdecode_node const& msg, key_desc_t const (&desc)[Size]
, bdecode_node (&ret)[Size], char* error, int error_size)
, bdecode_node (&ret)[Size], span<char> error)
{
return dht_detail::verify_message(msg, desc, ret, Size, error, error_size);
return verify_message_impl(msg, desc, ret, error);
}
} }

View File

@ -44,7 +44,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <libtorrent/kademlia/routing_table.hpp>
#include <libtorrent/kademlia/rpc_manager.hpp>
#include <libtorrent/kademlia/node_id.hpp>
#include <libtorrent/kademlia/msg.hpp>
#include <libtorrent/kademlia/find_data.hpp>
#include <libtorrent/kademlia/put_data.hpp>
#include <libtorrent/kademlia/item.hpp>
@ -71,6 +70,7 @@ namespace libtorrent { namespace dht
struct traversal_algorithm;
struct dht_observer;
struct msg;
TORRENT_EXTRA_EXPORT entry write_nodes_entry(std::vector<node_entry> const& nodes);

View File

@ -36,7 +36,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "settings.hpp"
#include "setup_transfer.hpp" // for ep()
#include "libtorrent/config.hpp"
#include "libtorrent/kademlia/node.hpp" // for verify_message
#include "libtorrent/kademlia/dht_storage.hpp"
#include "libtorrent/io_service.hpp"

View File

@ -66,15 +66,14 @@ namespace
{
ptr += std::snprintf(ptr, left, "4:salt%d:", int(salt.size()));
left = out.size() - (ptr - out.data());
std::memcpy(ptr, salt.data(), (std::min)(salt.size(), left));
ptr += (std::min)(salt.size(), left);
std::memcpy(ptr, salt.data(), std::min(salt.size(), left));
ptr += std::min(salt.size(), left);
left = out.size() - (ptr - out.data());
}
ptr += std::snprintf(ptr, out.size() - (ptr - out.data())
, "3:seqi%" PRId64 "e1:v", seq.value);
ptr += std::snprintf(ptr, left, "3:seqi%" PRId64 "e1:v", seq.value);
left = out.size() - (ptr - out.data());
std::memcpy(ptr, v.data(), (std::min)(v.size(), left));
ptr += (std::min)(v.size(), left);
std::memcpy(ptr, v.data(), std::min(v.size(), left));
ptr += std::min(v.size(), left);
TORRENT_ASSERT((ptr - out.data()) <= out.size());
return ptr - out.data();
}

View File

@ -36,11 +36,13 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent { namespace dht {
namespace dht_detail {
bool verify_message(bdecode_node const& message, key_desc_t const desc[]
, bdecode_node ret[], int size, char* error, int error_size)
bool verify_message_impl(bdecode_node const& message, span<key_desc_t const> desc
, span<bdecode_node> ret, span<char> error)
{
TORRENT_ASSERT(desc.size() == ret.size());
int const size = int(ret.size());
// get a non-root bdecode_node that still
// points to the root. message should not be copied
bdecode_node msg = message.non_owning();
@ -56,7 +58,7 @@ bool verify_message(bdecode_node const& message, key_desc_t const desc[]
if (msg.type() != bdecode_node::dict_t)
{
std::snprintf(error, error_size, "not a dictionary");
std::snprintf(error.data(), error.size(), "not a dictionary");
return false;
}
++stack_ptr;
@ -74,7 +76,7 @@ bool verify_message(bdecode_node const& message, key_desc_t const desc[]
if (ret[i] == 0 && (k.flags & key_desc_t::optional) == 0)
{
// the key was not found, and it's not an optional key
std::snprintf(error, error_size, "missing '%s' key", k.name);
std::snprintf(error.data(), error.size(), "missing '%s' key", k.name);
return false;
}
@ -82,11 +84,9 @@ bool verify_message(bdecode_node const& message, key_desc_t const desc[]
&& ret[i]
&& k.type == bdecode_node::string_t)
{
bool invalid = false;
if (k.flags & key_desc_t::size_divisible)
invalid = (ret[i].string_length() % k.size) != 0;
else
invalid = ret[i].string_length() != k.size;
bool const invalid = k.flags & key_desc_t::size_divisible
? (ret[i].string_length() % k.size) != 0
: ret[i].string_length() != k.size;
if (invalid)
{
@ -94,7 +94,7 @@ bool verify_message(bdecode_node const& message, key_desc_t const desc[]
ret[i].clear();
if ((k.flags & key_desc_t::optional) == 0)
{
std::snprintf(error, error_size, "invalid value for '%s'", k.name);
std::snprintf(error.data(), error.size(), "invalid value for '%s'", k.name);
return false;
}
}
@ -132,14 +132,4 @@ bool verify_message(bdecode_node const& message, key_desc_t const desc[]
return true;
}
}
void incoming_error(entry& e, char const* msg, int error_code)
{
e["y"] = "e";
entry::list_type& l = e["e"].list();
l.push_back(entry(error_code));
l.push_back(entry(msg));
}
} }

View File

@ -60,6 +60,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/kademlia/refresh.hpp"
#include "libtorrent/kademlia/get_peers.hpp"
#include "libtorrent/kademlia/get_item.hpp"
#include "libtorrent/kademlia/msg.hpp"
using namespace std::placeholders;
@ -90,6 +91,15 @@ node_id calculate_node_id(node_id const& nid, dht_observer* observer, udp protoc
return nid;
}
// generate an error response message
void incoming_error(entry& e, char const* msg, int error_code = 203)
{
e["y"] = "e";
entry::list_type& l = e["e"].list();
l.push_back(entry(error_code));
l.push_back(entry(msg));
}
} // anonymous namespace
node::node(udp proto, udp_socket_interface* sock
@ -778,7 +788,7 @@ void node::incoming_request(msg const& m, entry& e)
e["y"] = "r";
e["t"] = m.message.dict_find_string_value("t").to_string();
key_desc_t top_desc[] = {
key_desc_t const top_desc[] = {
{"q", bdecode_node::string_t, 0, 0},
{"ro", bdecode_node::int_t, 0, key_desc_t::optional},
{"a", bdecode_node::dict_t, 0, key_desc_t::parse_children},
@ -787,8 +797,7 @@ void node::incoming_request(msg const& m, entry& e)
bdecode_node top_level[4];
char error_string[200];
if (!verify_message(m.message, top_desc, top_level, error_string
, sizeof(error_string)))
if (!verify_message(m.message, top_desc, top_level, error_string))
{
incoming_error(e, error_string);
return;
@ -831,7 +840,7 @@ void node::incoming_request(msg const& m, entry& e)
}
else if (query == "get_peers")
{
key_desc_t msg_desc[] = {
key_desc_t const msg_desc[] = {
{"info_hash", bdecode_node::string_t, 20, 0},
{"noseed", bdecode_node::int_t, 0, key_desc_t::optional},
{"scrape", bdecode_node::int_t, 0, key_desc_t::optional},
@ -839,8 +848,7 @@ void node::incoming_request(msg const& m, entry& e)
};
bdecode_node msg_keys[4];
if (!verify_message(arg_ent, msg_desc, msg_keys, error_string
, sizeof(error_string)))
if (!verify_message(arg_ent, msg_desc, msg_keys, error_string))
{
m_counters.inc_stats_counter(counters::dht_invalid_get_peers);
incoming_error(e, error_string);
@ -874,13 +882,13 @@ void node::incoming_request(msg const& m, entry& e)
}
else if (query == "find_node")
{
key_desc_t msg_desc[] = {
key_desc_t const msg_desc[] = {
{"target", bdecode_node::string_t, 20, 0},
{"want", bdecode_node::list_t, 0, key_desc_t::optional},
};
bdecode_node msg_keys[2];
if (!verify_message(arg_ent, msg_desc, msg_keys, error_string, sizeof(error_string)))
if (!verify_message(arg_ent, msg_desc, msg_keys, error_string))
{
incoming_error(e, error_string);
return;
@ -893,7 +901,7 @@ void node::incoming_request(msg const& m, entry& e)
}
else if (query == "announce_peer")
{
key_desc_t msg_desc[] = {
key_desc_t const msg_desc[] = {
{"info_hash", bdecode_node::string_t, 20, 0},
{"port", bdecode_node::int_t, 0, 0},
{"token", bdecode_node::string_t, 0, 0},
@ -903,7 +911,7 @@ void node::incoming_request(msg const& m, entry& e)
};
bdecode_node msg_keys[6];
if (!verify_message(arg_ent, msg_desc, msg_keys, error_string, sizeof(error_string)))
if (!verify_message(arg_ent, msg_desc, msg_keys, error_string))
{
m_counters.inc_stats_counter(counters::dht_invalid_announce);
incoming_error(e, error_string);
@ -967,7 +975,7 @@ void node::incoming_request(msg const& m, entry& e)
// attempt to parse the message
bdecode_node msg_keys[7];
if (!verify_message(arg_ent, msg_desc, msg_keys, error_string, sizeof(error_string)))
if (!verify_message(arg_ent, msg_desc, msg_keys, error_string))
{
m_counters.inc_stats_counter(counters::dht_invalid_put);
incoming_error(e, error_string);
@ -1099,8 +1107,7 @@ void node::incoming_request(msg const& m, entry& e)
// attempt to parse the message
bdecode_node msg_keys[3];
if (!verify_message(arg_ent, msg_desc, msg_keys, error_string
, sizeof(error_string)))
if (!verify_message(arg_ent, msg_desc, msg_keys, error_string))
{
m_counters.inc_stats_counter(counters::dht_invalid_get);
incoming_error(e, error_string);

View File

@ -36,7 +36,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/kademlia/node.hpp" // for verify_message
#include "libtorrent/kademlia/msg.hpp" // for verify_message
#include "libtorrent/kademlia/node.hpp"
#include "libtorrent/bencode.hpp"
#include "libtorrent/bdecode.hpp"
#include "libtorrent/socket_io.hpp" // for hash_address
@ -333,8 +334,7 @@ void announce_immutable_items(node& node, udp::endpoint const* eps
char error_string[200];
// std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str());
int ret = verify_message(response, desc, parsed, error_string
, sizeof(error_string));
int ret = verify_message(response, desc, parsed, error_string);
if (ret)
{
TEST_EQUAL(parsed[4].string_value(), "r");
@ -368,8 +368,7 @@ void announce_immutable_items(node& node, udp::endpoint const* eps
};
bdecode_node parsed2[1];
ret = verify_message(response, desc2, parsed2, error_string
, sizeof(error_string));
ret = verify_message(response, desc2, parsed2, error_string);
if (ret)
{
if (parsed2[0].string_value() != "r")
@ -404,8 +403,7 @@ void announce_immutable_items(node& node, udp::endpoint const* eps
bdecode_node parsed[4];
char error_string[200];
int ret = verify_message(response, desc, parsed, error_string
, sizeof(error_string));
int ret = verify_message(response, desc, parsed, error_string);
if (ret)
{
items_num.insert(items_num.begin(), j);
@ -763,8 +761,7 @@ TORRENT_TEST(ping)
bdecode_node pong_keys[4];
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str());
bool ret = dht::verify_message(response, pong_desc, pong_keys, t.error_string
, sizeof(t.error_string));
bool ret = dht::verify_message(response, pong_desc, pong_keys, t.error_string);
TEST_CHECK(ret);
if (ret)
{
@ -786,8 +783,7 @@ TORRENT_TEST(invalid_message)
send_dht_request(t.dht_node, "find_node", t.source, &response);
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str());
bool ret = dht::verify_message(response, err_desc, err_keys, t.error_string
, sizeof(t.error_string));
bool ret = dht::verify_message(response, err_desc, err_keys, t.error_string);
TEST_CHECK(ret);
if (ret)
{
@ -833,8 +829,7 @@ TORRENT_TEST(get_peers_announce)
std::string token;
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str());
bool ret = dht::verify_message(response, peer1_desc, peer1_keys, t.error_string
, sizeof(t.error_string));
bool ret = dht::verify_message(response, peer1_desc, peer1_keys, t.error_string);
TEST_CHECK(ret);
if (ret)
{
@ -864,8 +859,7 @@ TORRENT_TEST(get_peers_announce)
bdecode_node ann_keys[3];
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str());
ret = dht::verify_message(response, ann_desc, ann_keys, t.error_string
, sizeof(t.error_string));
ret = dht::verify_message(response, ann_desc, ann_keys, t.error_string);
TEST_CHECK(ret);
if (ret)
{
@ -894,8 +888,7 @@ void test_scrape(address(&rand_addr)())
, msg_args().info_hash("01010101010101010101"));
bdecode_node peer1_keys[4];
bool ret = dht::verify_message(response, peer1_desc, peer1_keys, t.error_string
, sizeof(t.error_string));
bool ret = dht::verify_message(response, peer1_desc, peer1_keys, t.error_string);
std::string token;
if (ret)
@ -936,8 +929,7 @@ void test_scrape(address(&rand_addr)())
bdecode_node peer2_keys[5];
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str());
bool ret = dht::verify_message(response, peer2_desc, peer2_keys, t.error_string
, sizeof(t.error_string));
bool ret = dht::verify_message(response, peer2_desc, peer2_keys, t.error_string);
TEST_CHECK(ret);
if (ret)
{
@ -1007,8 +999,7 @@ void test_id_enforcement(address(&rand_addr)())
.nid(nid));
bdecode_node err_keys[2];
bool ret = dht::verify_message(response, err_desc, err_keys, t.error_string
, sizeof(t.error_string));
bool ret = dht::verify_message(response, err_desc, err_keys, t.error_string);
TEST_CHECK(ret);
if (ret)
{
@ -1052,8 +1043,7 @@ void test_id_enforcement(address(&rand_addr)())
bdecode_node nodes_keys[3];
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str());
ret = dht::verify_message(response, nodes_desc, nodes_keys, t.error_string
, sizeof(t.error_string));
ret = dht::verify_message(response, nodes_desc, nodes_keys, t.error_string);
TEST_CHECK(ret);
if (ret)
{
@ -1249,8 +1239,7 @@ void test_put(address(&rand_addr)())
bdecode_node desc_keys[5];
ret = verify_message(response, desc, desc_keys, t.error_string
, sizeof(t.error_string));
ret = verify_message(response, desc, desc_keys, t.error_string);
std::string token;
if (ret)
{
@ -1281,8 +1270,7 @@ void test_put(address(&rand_addr)())
.seq(seq)
.salt(salt));
ret = verify_message(response, desc2, desc2_keys, t.error_string
, sizeof(t.error_string));
ret = verify_message(response, desc2, desc2_keys, t.error_string);
if (ret)
{
std::fprintf(stderr, "put response: %s\n"
@ -1315,8 +1303,7 @@ void test_put(address(&rand_addr)())
bdecode_node desc3_keys[7];
ret = verify_message(response, desc3, desc3_keys, t.error_string
, sizeof(t.error_string));
ret = verify_message(response, desc3, desc3_keys, t.error_string);
if (ret == 0)
{
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str());
@ -1358,8 +1345,7 @@ void test_put(address(&rand_addr)())
.seq(seq)
.salt(salt));
ret = verify_message(response, desc_error, desc_error_keys, t.error_string
, sizeof(t.error_string));
ret = verify_message(response, desc_error, desc_error_keys, t.error_string);
if (ret)
{
std::fprintf(stderr, "put response: %s\n", print_entry(response).c_str());
@ -1422,8 +1408,7 @@ void test_put(address(&rand_addr)())
.cas(cas)
.salt(salt));
ret = verify_message(response, desc2, desc2_keys, t.error_string
, sizeof(t.error_string));
ret = verify_message(response, desc2, desc2_keys, t.error_string);
if (ret)
{
std::fprintf(stderr, "put response: %s\n"
@ -1452,8 +1437,7 @@ void test_put(address(&rand_addr)())
.cas(cas)
.salt(salt));
ret = verify_message(response, desc_error, desc_error_keys, t.error_string
, sizeof(t.error_string));
ret = verify_message(response, desc_error, desc_error_keys, t.error_string);
if (ret)
{
std::fprintf(stderr, "put response: %s\n"
@ -1736,8 +1720,7 @@ void test_bootstrap(address(&rand_addr)())
TEST_EQUAL(g_sent_packets.front().first, initial_node);
lazy_from_entry(g_sent_packets.front().second, response);
ret = verify_message(response, find_node_desc, find_node_keys, t.error_string
, sizeof(t.error_string));
ret = verify_message(response, find_node_desc, find_node_keys, t.error_string);
if (ret)
{
TEST_EQUAL(find_node_keys[0].string_value(), "q");
@ -1769,8 +1752,7 @@ void test_bootstrap(address(&rand_addr)())
TEST_EQUAL(g_sent_packets.front().first, found_node);
lazy_from_entry(g_sent_packets.front().second, response);
ret = verify_message(response, find_node_desc, find_node_keys, t.error_string
, sizeof(t.error_string));
ret = verify_message(response, find_node_desc, find_node_keys, t.error_string);
if (ret)
{
TEST_EQUAL(find_node_keys[0].string_value(), "q");
@ -1840,8 +1822,7 @@ void test_short_nodes(address(&rand_addr)())
TEST_EQUAL(g_sent_packets.front().first, initial_node);
lazy_from_entry(g_sent_packets.front().second, response);
ret = verify_message(response, find_node_desc, find_node_keys, t.error_string
, sizeof(t.error_string));
ret = verify_message(response, find_node_desc, find_node_keys, t.error_string);
if (ret)
{
TEST_EQUAL(find_node_keys[0].string_value(), "q");
@ -1927,8 +1908,7 @@ void test_get_peers(address(&rand_addr)())
TEST_EQUAL(g_sent_packets.front().first, initial_node);
lazy_from_entry(g_sent_packets.front().second, response);
ret = verify_message(response, get_peers_desc, get_peers_keys, t.error_string
, sizeof(t.error_string));
ret = verify_message(response, get_peers_desc, get_peers_keys, t.error_string);
if (ret)
{
TEST_EQUAL(get_peers_keys[0].string_value(), "q");
@ -1971,8 +1951,7 @@ void test_get_peers(address(&rand_addr)())
TEST_EQUAL(g_sent_packets.front().first, next_node);
lazy_from_entry(g_sent_packets.front().second, response);
ret = verify_message(response, get_peers_desc, get_peers_keys, t.error_string
, sizeof(t.error_string));
ret = verify_message(response, get_peers_desc, get_peers_keys, t.error_string);
if (ret)
{
TEST_EQUAL(get_peers_keys[0].string_value(), "q");
@ -2073,8 +2052,7 @@ void test_mutable_get(address(&rand_addr)(), bool const with_salt)
lazy_from_entry(g_sent_packets.front().second, response);
bdecode_node get_item_keys[6];
bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string
, sizeof(t.error_string));
bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string);
if (ret)
{
TEST_EQUAL(get_item_keys[0].string_value(), "q");
@ -2160,8 +2138,7 @@ TORRENT_TEST(immutable_get)
lazy_from_entry(g_sent_packets.front().second, response);
bdecode_node get_item_keys[6];
bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string
, sizeof(t.error_string));
bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string);
if (ret)
{
TEST_EQUAL(get_item_keys[0].string_value(), "q");
@ -2240,8 +2217,7 @@ TORRENT_TEST(immutable_put)
lazy_from_entry(packet->second, response);
bdecode_node get_item_keys[6];
bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string
, sizeof(t.error_string));
bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string);
if (!ret)
{
std::fprintf(stderr, " invalid get request: %s\n", print_entry(response).c_str());
@ -2270,7 +2246,7 @@ TORRENT_TEST(immutable_put)
lazy_from_entry(packet->second, response);
bool const ret = verify_message(response, put_immutable_item_desc, put_immutable_item_keys
, t.error_string, sizeof(t.error_string));
, t.error_string);
if (ret)
{
TEST_EQUAL(put_immutable_item_keys[0].string_value(), "q");
@ -2342,8 +2318,7 @@ TORRENT_TEST(mutable_put)
lazy_from_entry(packet->second, response);
bdecode_node get_item_keys[6];
bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string
, sizeof(t.error_string));
bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string);
if (!ret)
{
std::fprintf(stderr, " invalid get request: %s\n", print_entry(response).c_str());
@ -2372,7 +2347,7 @@ TORRENT_TEST(mutable_put)
lazy_from_entry(packet->second, response);
bool const ret = verify_message(response, put_mutable_item_desc, put_mutable_item_keys
, t.error_string, sizeof(t.error_string));
, t.error_string);
if (ret)
{
TEST_EQUAL(put_mutable_item_keys[0].string_value(), "q");
@ -2458,8 +2433,7 @@ TORRENT_TEST(traversal_done)
lazy_from_entry(packet->second, response);
bdecode_node get_item_keys[6];
bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string
, sizeof(t.error_string));
bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string);
if (!ret)
{
std::fprintf(stderr, " invalid get request: %s\n", print_entry(response).c_str());
@ -2534,8 +2508,7 @@ TORRENT_TEST(dht_dual_stack)
bdecode_node nodes6_keys[4];
ret = verify_message(response, nodes6_desc, nodes6_keys, error_string
, sizeof(error_string));
ret = verify_message(response, nodes6_desc, nodes6_keys, error_string);
if (ret)
{
@ -2567,8 +2540,7 @@ TORRENT_TEST(dht_dual_stack)
bdecode_node nodes_keys[4];
ret = verify_message(response, nodes_desc, nodes_keys, error_string
, sizeof(error_string));
ret = verify_message(response, nodes_desc, nodes_keys, error_string);
if (ret)
{
@ -2601,8 +2573,7 @@ TORRENT_TEST(dht_dual_stack)
bdecode_node nodes46_keys[5];
ret = verify_message(response, nodes46_desc, nodes46_keys, error_string
, sizeof(error_string));
ret = verify_message(response, nodes46_desc, nodes46_keys, error_string);
if (ret)
{
@ -2710,8 +2681,7 @@ TORRENT_TEST(verify_message)
bdecode(test_msg, test_msg + sizeof(test_msg)-1, ent, ec);
std::fprintf(stderr, "%s\n", print_entry(ent).c_str());
bool ret = verify_message(ent, msg_desc, msg_keys, error_string
, sizeof(error_string));
bool ret = verify_message(ent, msg_desc, msg_keys, error_string);
TEST_CHECK(ret);
TEST_CHECK(msg_keys[0]);
if (msg_keys[0]) TEST_EQUAL(msg_keys[0].string_value(), "test");
@ -2728,8 +2698,7 @@ TORRENT_TEST(verify_message)
bdecode(test_msg2, test_msg2 + sizeof(test_msg2)-1, ent, ec);
std::fprintf(stderr, "%s\n", print_entry(ent).c_str());
ret = verify_message(ent, msg_desc, msg_keys, error_string
, sizeof(error_string));
ret = verify_message(ent, msg_desc, msg_keys, error_string);
TEST_CHECK(ret);
TEST_CHECK(msg_keys[0]);
if (msg_keys[0]) TEST_EQUAL(msg_keys[0].string_value(), "test");
@ -2747,8 +2716,7 @@ TORRENT_TEST(verify_message)
bdecode(test_msg3, test_msg3 + sizeof(test_msg3)-1, ent, ec);
std::fprintf(stderr, "%s\n", print_entry(ent).c_str());
ret = verify_message(ent, msg_desc, msg_keys, error_string
, sizeof(error_string));
ret = verify_message(ent, msg_desc, msg_keys, error_string);
TEST_CHECK(!ret);
std::fprintf(stderr, "%s\n", error_string);
TEST_EQUAL(error_string, std::string("missing 'A' key"));
@ -2757,8 +2725,7 @@ TORRENT_TEST(verify_message)
bdecode(test_msg4, test_msg4 + sizeof(test_msg4)-1, ent, ec);
std::fprintf(stderr, "%s\n", print_entry(ent).c_str());
ret = verify_message(ent, msg_desc, msg_keys, error_string
, sizeof(error_string));
ret = verify_message(ent, msg_desc, msg_keys, error_string);
TEST_CHECK(!ret);
std::fprintf(stderr, "%s\n", error_string);
TEST_EQUAL(error_string, std::string("invalid value for 'A'"));
@ -2767,8 +2734,7 @@ TORRENT_TEST(verify_message)
bdecode(test_msg5, test_msg5 + sizeof(test_msg5)-1, ent, ec);
std::fprintf(stderr, "%s\n", print_entry(ent).c_str());
ret = verify_message(ent, msg_desc, msg_keys, error_string
, sizeof(error_string));
ret = verify_message(ent, msg_desc, msg_keys, error_string);
TEST_CHECK(!ret);
std::fprintf(stderr, "%s\n", error_string);
TEST_EQUAL(error_string, std::string("missing 'C2' key"));
@ -2953,8 +2919,7 @@ TORRENT_TEST(node_set_id)
{ "id", bdecode_node::string_t, 20, key_desc_t::last_child },
};
bdecode_node pong_keys[4];
bool ret = dht::verify_message(response, pong_desc, pong_keys, t.error_string
, sizeof(t.error_string));
bool ret = dht::verify_message(response, pong_desc, pong_keys, t.error_string);
TEST_CHECK(ret);
if (!ret) return;
@ -3013,8 +2978,7 @@ TORRENT_TEST(read_only_node)
};
lazy_from_entry(g_sent_packets.front().second, request);
bool ret = verify_message(request, get_item_desc, parsed, error_string
, sizeof(error_string));
bool ret = verify_message(request, get_item_desc, parsed, error_string);
TEST_CHECK(ret);
TEST_EQUAL(parsed[3].int_value(), 1);
@ -3039,15 +3003,13 @@ TORRENT_TEST(read_only_node)
// both of them shouldn't have a 'ro' key.
lazy_from_entry(g_sent_packets.front().second, request);
ret = verify_message(request, get_item_desc, parsed, error_string
, sizeof(error_string));
ret = verify_message(request, get_item_desc, parsed, error_string);
TEST_CHECK(ret);
TEST_CHECK(!parsed[3]);
lazy_from_entry(g_sent_packets.back().second, request);
ret = verify_message(request, get_item_desc, parsed, error_string
, sizeof(error_string));
ret = verify_message(request, get_item_desc, parsed, error_string);
TEST_CHECK(ret);
TEST_CHECK(!parsed[3]);

View File

@ -34,7 +34,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/kademlia/msg.hpp" // for verify_message
#include "libtorrent/bencode.hpp"
#include "libtorrent/socket_io.hpp" // for hash_address
#include "libtorrent/broadcast_socket.hpp" // for supports_ipv6