diff --git a/CMakeLists.txt b/CMakeLists.txt index 37befa0ca..75230547f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,6 +114,7 @@ set(kademlia_sources dos_blocker dht_tracker node + node_entry refresh rpc_manager find_data diff --git a/Jamfile b/Jamfile index e347272a2..ae7388805 100755 --- a/Jamfile +++ b/Jamfile @@ -631,6 +631,7 @@ SOURCES = KADEMLIA_SOURCES = dht_tracker node + node_entry refresh rpc_manager find_data diff --git a/examples/rss_reader.cpp b/examples/rss_reader.cpp index 85dc60af1..f406f245b 100644 --- a/examples/rss_reader.cpp +++ b/examples/rss_reader.cpp @@ -40,6 +40,17 @@ POSSIBILITY OF SUCH DAMAGE. using namespace libtorrent; namespace lt = libtorrent; +void sleep_ms(int milliseconds) +{ +#if defined TORRENT_WINDOWS || defined TORRENT_CYGWIN + Sleep(milliseconds); +#elif defined TORRENT_BEOS + snooze_until(system_time() + boost::int64_t(milliseconds) * 1000, B_SYSTEM_TIMEBASE); +#else + usleep(milliseconds * 1000); +#endif +} + int load_file(std::string const& filename, std::vector& v, libtorrent::error_code& ec, int limit = 8000000) { ec.clear(); @@ -210,7 +221,7 @@ int main(int argc, char* argv[]) fprintf(stderr, "fetching feed ... %c", spinner[i]); while (fs.updating) { - sleep(100); + sleep_ms(100); i = (i + 1) % 4; fprintf(stderr, "\b%c", spinner[i]); fs = fh.get_feed_status(); @@ -251,7 +262,7 @@ int main(int argc, char* argv[]) , st.num_peers, st.num_seeds, status.c_str()); } - sleep(500); + sleep_ms(500); if (quit) break; printf("\033[%dA", int(t.size())); } diff --git a/include/libtorrent/http_parser.hpp b/include/libtorrent/http_parser.hpp index 563989d7e..93cf5a50d 100644 --- a/include/libtorrent/http_parser.hpp +++ b/include/libtorrent/http_parser.hpp @@ -56,10 +56,10 @@ namespace libtorrent { // return true if the status code is 200, 206, or in the 300-400 range - bool is_ok_status(int http_status); + TORRENT_EXTRA_EXPORT bool is_ok_status(int http_status); // return true if the status code is a redirect - bool is_redirect(int http_status); + TORRENT_EXTRA_EXPORT bool is_redirect(int http_status); TORRENT_EXTRA_EXPORT std::string resolve_redirect_location(std::string referrer , std::string location); diff --git a/include/libtorrent/kademlia/node_entry.hpp b/include/libtorrent/kademlia/node_entry.hpp index eefc66162..906bce782 100644 --- a/include/libtorrent/kademlia/node_entry.hpp +++ b/include/libtorrent/kademlia/node_entry.hpp @@ -37,7 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #include "libtorrent/address.hpp" #include "libtorrent/union_endpoint.hpp" -#include "libtorrent/aux_/time.hpp" // for aux::time_now() +#include "libtorrent/time.hpp" // for time_point namespace libtorrent { namespace dht { @@ -45,43 +45,10 @@ namespace libtorrent { namespace dht struct node_entry { node_entry(node_id const& id_, udp::endpoint ep, int roundtriptime = 0xffff - , bool pinged = false) - : last_queried(pinged ? aux::time_now() : min_time()) - , id(id_) - , a(ep.address().to_v4().to_bytes()) - , p(ep.port()) - , rtt(roundtriptime & 0xffff) - , timeout_count(pinged ? 0 : 0xff) - { -#ifdef TORRENT_DHT_VERBOSE_LOGGING - first_seen = aux::time_now(); -#endif - } - - node_entry(udp::endpoint ep) - : last_queried(min_time()) - , id(0) - , a(ep.address().to_v4().to_bytes()) - , p(ep.port()) - , rtt(0xffff) - , timeout_count(0xff) - { -#ifdef TORRENT_DHT_VERBOSE_LOGGING - first_seen = aux::time_now(); -#endif - } - - node_entry() - : last_queried(min_time()) - , id(0) - , p(0) - , rtt(0xffff) - , timeout_count(0xff) - { -#ifdef TORRENT_DHT_VERBOSE_LOGGING - first_seen = aux::time_now(); -#endif - } + , bool pinged = false); + node_entry(udp::endpoint ep); + node_entry(); + void update_rtt(int new_rtt); bool pinged() const { return timeout_count != 0xff; } void set_pinged() { if (timeout_count == 0xff) timeout_count = 0; } @@ -90,14 +57,6 @@ struct node_entry void reset_fail_count() { if (pinged()) timeout_count = 0; } udp::endpoint ep() const { return udp::endpoint(address_v4(a), p); } bool confirmed() const { return timeout_count == 0; } - void update_rtt(int new_rtt) - { - TORRENT_ASSERT(new_rtt <= 0xffff); - TORRENT_ASSERT(new_rtt >= 0); - if (new_rtt == 0xffff) return; - if (rtt == 0xffff) rtt = new_rtt; - else rtt = int(rtt) * 2 / 3 + int(new_rtt) / 3; - } address addr() const { return address_v4(a); } int port() const { return p; } diff --git a/src/Makefile.am b/src/Makefile.am index 7642d01c6..bb1e65312 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,6 +7,7 @@ KADEMLIA_SOURCES = \ kademlia/dht_tracker.cpp \ kademlia/find_data.cpp \ kademlia/node.cpp \ + kademlia/node_entry.cpp \ kademlia/node_id.cpp \ kademlia/refresh.cpp \ kademlia/routing_table.cpp \ diff --git a/src/kademlia/node_entry.cpp b/src/kademlia/node_entry.cpp new file mode 100644 index 000000000..71a5a952d --- /dev/null +++ b/src/kademlia/node_entry.cpp @@ -0,0 +1,90 @@ +/* + +Copyright (c) 2006-2014, Arvid Norberg +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * 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. + * Neither the name of the author 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 OWNER 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. + +*/ + +#include "libtorrent/kademlia/node_entry.hpp" +#include "libtorrent/aux_/time.hpp" // for aux::time_now() + +namespace libtorrent { namespace dht +{ + + node_entry::node_entry(node_id const& id_, udp::endpoint ep + , int roundtriptime + , bool pinged) + : last_queried(pinged ? aux::time_now() : min_time()) + , id(id_) + , a(ep.address().to_v4().to_bytes()) + , p(ep.port()) + , rtt(roundtriptime & 0xffff) + , timeout_count(pinged ? 0 : 0xff) + { +#ifdef TORRENT_DHT_VERBOSE_LOGGING + first_seen = aux::time_now(); +#endif + } + + node_entry::node_entry(udp::endpoint ep) + : last_queried(min_time()) + , id(0) + , a(ep.address().to_v4().to_bytes()) + , p(ep.port()) + , rtt(0xffff) + , timeout_count(0xff) + { +#ifdef TORRENT_DHT_VERBOSE_LOGGING + first_seen = aux::time_now(); +#endif + } + + node_entry::node_entry() + : last_queried(min_time()) + , id(0) + , p(0) + , rtt(0xffff) + , timeout_count(0xff) + { +#ifdef TORRENT_DHT_VERBOSE_LOGGING + first_seen = aux::time_now(); +#endif + } + + void node_entry::update_rtt(int new_rtt) + { + TORRENT_ASSERT(new_rtt <= 0xffff); + TORRENT_ASSERT(new_rtt >= 0); + if (new_rtt == 0xffff) return; + if (rtt == 0xffff) rtt = new_rtt; + else rtt = int(rtt) * 2 / 3 + int(new_rtt) / 3; + } + +}} + + diff --git a/src/kademlia/rpc_manager.cpp b/src/kademlia/rpc_manager.cpp index d067ff66d..2c4b22ce7 100644 --- a/src/kademlia/rpc_manager.cpp +++ b/src/kademlia/rpc_manager.cpp @@ -48,6 +48,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include // for dht_settings #include +#include // for aux::time_now #ifdef TORRENT_DHT_VERBOSE_LOGGING #include diff --git a/test/test_priority.cpp b/test/test_priority.cpp index 8569c5a39..cbe74265e 100644 --- a/test/test_priority.cpp +++ b/test/test_priority.cpp @@ -284,7 +284,7 @@ void test_transfer(settings_pack const& sett) } TEST_CHECK(resume_data.size()); - fprintf(stderr, "%s\n", resume_data.data()); + fprintf(stderr, "%s\n", &resume_data[0]); ses2.remove_torrent(tor2);