From 0977d94dbc9da4040fab8c50334df2c2d67083f6 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 25 Dec 2014 11:24:02 +0000 Subject: [PATCH] merged changes from RC_1_0 --- ChangeLog | 4 ++++ include/libtorrent/torrent_handle.hpp | 2 +- src/kademlia/node.cpp | 28 +++++++++++++++-------- src/peer_connection.cpp | 9 ++++---- src/session_impl.cpp | 1 + src/torrent.cpp | 1 + test/test_dht.cpp | 32 +++++++++++++++++++++++---- 7 files changed, 59 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9c62d8c2b..82a084e64 100644 --- a/ChangeLog +++ b/ChangeLog @@ -38,6 +38,10 @@ * almost completely changed the storage interface (for custom storage) * added support for hashing pieces in multiple threads + * support conditional DHT get + * OpenSSL build fixes + * fix DHT scrape bug + 1.0.3 release * python binding build fix for boost-1.57.0 diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index b4f888c2a..3592c8ef6 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -1000,7 +1000,7 @@ namespace libtorrent // The priority values are the same as for piece_priority(). // // Whenever a file priority is changed, all other piece priorities are - // reset to match the file priorities. In order to maintain sepcial + // reset to match the file priorities. In order to maintain special // priorities for particular pieces, piece_priority() has to be called // again for those pieces. // diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index d23ea1c6e..63ca8efba 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -614,7 +614,7 @@ void node_impl::lookup_peers(sha1_hash const& info_hash, entry& reply } reply["BFpe"] = downloaders.to_string(); - reply["BFse"] = seeds.to_string(); + reply["BFsd"] = seeds.to_string(); } else { @@ -1230,34 +1230,41 @@ void node_impl::incoming_request(msg const& m, entry& e) else if (strcmp(query, "get") == 0) { key_desc_t msg_desc[] = { + {"seq", lazy_entry::int_t, 0, key_desc_t::optional}, {"target", lazy_entry::string_t, 20, 0}, }; // k is not used for now // attempt to parse the message - lazy_entry const* msg_keys[1]; - if (!verify_message(arg_ent, msg_desc, msg_keys, 1, error_string, sizeof(error_string))) + lazy_entry const* msg_keys[2]; + if (!verify_message(arg_ent, msg_desc, msg_keys, 2, error_string, sizeof(error_string))) { incoming_error(e, error_string); return; } m_counters.inc_stats_counter(counters::dht_get_in); - sha1_hash target(msg_keys[0]->string_ptr()); + sha1_hash target(msg_keys[1]->string_ptr()); // fprintf(stderr, "%s GET target: %s\n" // , msg_keys[1] ? "mutable":"immutable" // , to_hex(target.to_string()).c_str()); - reply["token"] = generate_token(m.addr, msg_keys[0]->string_ptr()); + reply["token"] = generate_token(m.addr, msg_keys[1]->string_ptr()); nodes_t n; // always return nodes as well as peers m_table.find_node(target, n, 0); write_nodes_entry(reply, n); - dht_immutable_table_t::iterator i = m_immutable_table.find(target); + dht_immutable_table_t::iterator i = m_immutable_table.end(); + + // if the get has a sequence number it must be for a mutable item + // so don't bother searching the immutable table + if (!msg_keys[0]) + i = m_immutable_table.find(target); + if (i != m_immutable_table.end()) { dht_immutable_item const& f = i->second; @@ -1269,10 +1276,13 @@ void node_impl::incoming_request(msg const& m, entry& e) if (i != m_mutable_table.end()) { dht_mutable_item const& f = i->second; - reply["v"] = bdecode(f.value, f.value + f.size); reply["seq"] = f.seq; - reply["sig"] = std::string(f.sig, f.sig + sizeof(f.sig)); - reply["k"] = std::string(f.key.bytes, f.key.bytes + sizeof(f.key.bytes)); + if (!msg_keys[0] || uint64_t(msg_keys[0]->int_value()) < f.seq) + { + reply["v"] = bdecode(f.value, f.value + f.size); + reply["sig"] = std::string(f.sig, f.sig + sizeof(f.sig)); + reply["k"] = std::string(f.key.bytes, f.key.bytes + sizeof(f.key.bytes)); + } } } } diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 7085a68e9..215a86e2e 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -35,9 +35,11 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#if defined TORRENT_LOGGING +#ifdef TORRENT_LOGGING #include // for va_start, va_end #include // for vsnprintf +#include "libtorrent/escape_string.hpp" +#include "libtorrent/socket_io.hpp" #endif #include "libtorrent/peer_connection.hpp" @@ -73,9 +75,8 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif -#if defined TORRENT_LOGGING -#include "libtorrent/escape_string.hpp" -#include "libtorrent/socket_io.hpp" +#ifdef TORRENT_USE_OPENSSL +#include #endif //#define TORRENT_CORRUPT_DATA diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 620adbe88..7e659ebc6 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -147,6 +147,7 @@ namespace #ifdef TORRENT_USE_OPENSSL #include +#include namespace { diff --git a/src/torrent.cpp b/src/torrent.cpp index b3be45aa6..92a9eba1d 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -90,6 +90,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifdef TORRENT_USE_OPENSSL #include "libtorrent/ssl_stream.hpp" #include +#include #if BOOST_VERSION >= 104700 #include #endif // BOOST_VERSION diff --git a/test/test_dht.cpp b/test/test_dht.cpp index 48cb8425b..f4dc072a1 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -589,7 +589,7 @@ int test_main() {"y", lazy_entry::string_t, 1, 0}, {"r", lazy_entry::dict_t, 0, key_desc_t::parse_children}, {"BFpe", lazy_entry::string_t, 256, 0}, - {"BFse", lazy_entry::string_t, 256, 0}, + {"BFsd", lazy_entry::string_t, 256, 0}, {"id", lazy_entry::string_t, 20, key_desc_t::last_child}, }; @@ -810,7 +810,7 @@ int test_main() send_dht_request(node, "get", source, &response, "10", 0 , 0, no, 0, (char*)&target_id[0] - , 0, false, false, std::string(), std::string(), 64); + , 0, false, false, std::string(), std::string()); key_desc_t desc[] = { @@ -866,7 +866,7 @@ int test_main() send_dht_request(node, "get", source, &response, "10", 0 , 0, no, 0, (char*)&target_id[0] - , 0, false, false, std::string(), std::string(), 64); + , 0, false, false, std::string(), std::string()); fprintf(stderr, "target_id: %s\n" , to_hex(target_id.to_string()).c_str()); @@ -937,7 +937,31 @@ int test_main() , error_string, print_entry(response).c_str()); TEST_ERROR(error_string); } - + + // === test conditional get === + + send_dht_request(node, "get", source, &response, "10", 0 + , 0, no, 0, (char*)&target_id[0] + , 0, false, false, std::string(), std::string(), seq-1); + + { + lazy_entry const* r = response.dict_find_dict("r"); + TEST_CHECK(r->dict_find("v")); + TEST_CHECK(r->dict_find("k")); + TEST_CHECK(r->dict_find("sig")); + } + + send_dht_request(node, "get", source, &response, "10", 0 + , 0, no, 0, (char*)&target_id[0] + , 0, false, false, std::string(), std::string(), seq); + + { + lazy_entry const* r = response.dict_find_dict("r"); + TEST_CHECK(!r->dict_find("v")); + TEST_CHECK(!r->dict_find("k")); + TEST_CHECK(!r->dict_find("sig")); + } + // === test CAS put === // this is the sequence number we expect to be there