From df4fcaaeed29ccf0d90f94b899332a2928f9108c Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 9 Apr 2013 01:04:43 +0000 Subject: [PATCH] remove disable-dht build configuration from the public API (simplify linking) --- Jamfile | 10 +++---- docs/building.rst | 2 +- include/libtorrent/build_config.hpp | 9 +------ include/libtorrent/session.hpp | 10 +++---- include/libtorrent/session_settings.hpp | 4 --- include/libtorrent/session_status.hpp | 6 ----- include/libtorrent/torrent_handle.hpp | 2 -- src/session.cpp | 36 ++++++++++++++++++------- src/session_impl.cpp | 9 +++++-- src/torrent_handle.cpp | 4 +-- test/test_primitives.cpp | 7 +++++ 11 files changed, 53 insertions(+), 46 deletions(-) diff --git a/Jamfile b/Jamfile index 64a46f78b..87fa7c68d 100755 --- a/Jamfile +++ b/Jamfile @@ -365,9 +365,9 @@ feature.compose default : TORRENT_LOGGING ; feature.compose errors : TORRENT_ERROR_LOGGING ; feature.compose verbose : TORRENT_VERBOSE_LOGGING ; -feature dht-support : on off logging : composite propagated link-incompatible ; -feature.compose off : TORRENT_DISABLE_DHT ; -feature.compose logging : TORRENT_DHT_VERBOSE_LOGGING ; +feature dht : on off logging : composite propagated link-incompatible ; +feature.compose off : TORRENT_DISABLE_DHT ; +feature.compose logging : TORRENT_DHT_VERBOSE_LOGGING ; feature encryption : tommath off openssl gcrypt : composite propagated link-incompatible ; feature.compose openssl : TORRENT_USE_OPENSSL ; @@ -620,8 +620,8 @@ lib torrent shared:BOOST_ASIO_SOURCE shared:BOOST_SYSTEM_SOURCE - on:src/kademlia/$(KADEMLIA_SOURCES).cpp - logging:src/kademlia/$(KADEMLIA_SOURCES).cpp + on:src/kademlia/$(KADEMLIA_SOURCES).cpp + logging:src/kademlia/$(KADEMLIA_SOURCES).cpp @building system:$(CXXFLAGS) diff --git a/docs/building.rst b/docs/building.rst index d44f4d49e..64312da6f 100644 --- a/docs/building.rst +++ b/docs/building.rst @@ -254,7 +254,7 @@ Build features: | | * ``verbose`` - verbose peer wire logging. | | | * ``errors`` - like verbose, but limited to errors.| +--------------------------+----------------------------------------------------+ -| ``dht-support`` | * ``on`` - build with support for tracker less | +| ``dht`` | * ``on`` - build with support for tracker less | | | torrents and DHT support. | | | * ``logging`` - build with DHT support and verbose | | | logging of the DHT protocol traffic. | diff --git a/include/libtorrent/build_config.hpp b/include/libtorrent/build_config.hpp index 4f43a332d..053826846 100644 --- a/include/libtorrent/build_config.hpp +++ b/include/libtorrent/build_config.hpp @@ -63,12 +63,6 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_CFG_IPV6 noipv_- #endif -#ifdef TORRENT_DISABLE_DHT -#define TORRENT_CFG_DHT nodht_ -#else -#define TORRENT_CFG_DHT dht_ -#endif - #ifdef TORRENT_DISABLE_POOL_ALLOCATORS #define TORRENT_CFG_POOL nopools_ #else @@ -105,8 +99,7 @@ POSSIBILITY OF SUCH DAMAGE. BOOST_PP_CAT(TORRENT_CFG_POOL, \ BOOST_PP_CAT(TORRENT_CFG_LOG, \ BOOST_PP_CAT(TORRENT_CFG_DEPR, \ - BOOST_PP_CAT(TORRENT_CFG_DHT, \ - TORRENT_CFG_EXT)))))) + TORRENT_CFG_EXT))))) #define TORRENT_CFG_STRING BOOST_PP_STRINGIZE(TORRENT_CFG) diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index cd22b9eaf..f4f9a9f01 100644 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -264,10 +264,12 @@ namespace libtorrent void remove_feed(feed_handle h); void get_feeds(std::vector& f) const; -#ifndef TORRENT_DISABLE_DHT void start_dht(); void stop_dht(); void set_dht_settings(dht_settings const& settings); + void add_dht_node(std::pair const& node); + void add_dht_router(std::pair const& node); + bool is_dht_running() const; #ifndef TORRENT_NO_DEPRECATE // deprecated in 0.15 // use save_state and load_state instead @@ -276,10 +278,6 @@ namespace libtorrent TORRENT_DEPRECATED_PREFIX void start_dht(entry const& startup_state) TORRENT_DEPRECATED; #endif - void add_dht_node(std::pair const& node); - void add_dht_router(std::pair const& node); - bool is_dht_running() const; -#endif #ifndef TORRENT_DISABLE_ENCRYPTION void set_pe_settings(pe_settings const& settings); @@ -408,12 +406,10 @@ namespace libtorrent TORRENT_DEPRECATED_PREFIX proxy_settings tracker_proxy() const TORRENT_DEPRECATED; -#ifndef TORRENT_DISABLE_DHT TORRENT_DEPRECATED_PREFIX void set_dht_proxy(proxy_settings const& s) TORRENT_DEPRECATED; TORRENT_DEPRECATED_PREFIX proxy_settings dht_proxy() const TORRENT_DEPRECATED; -#endif #endif // TORRENT_NO_DEPRECATE #if TORRENT_USE_I2P diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index ff13a9b29..28893cc69 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -286,11 +286,9 @@ namespace libtorrent // within this time, the peer is disconnected. int handshake_timeout; -#ifndef TORRENT_DISABLE_DHT // while this is true, the dht will not be used unless the // tracker is online bool use_dht_as_fallback; -#endif // if this is true, the piece hashes will be freed, in order // to save memory, once the torrent is seeding. This will @@ -975,7 +973,6 @@ namespace libtorrent bool use_disk_cache_pool; }; -#ifndef TORRENT_DISABLE_DHT struct dht_settings { dht_settings() @@ -1044,7 +1041,6 @@ namespace libtorrent // outstanding requests bool aggressive_lookups; }; -#endif #ifndef TORRENT_DISABLE_ENCRYPTION diff --git a/include/libtorrent/session_status.hpp b/include/libtorrent/session_status.hpp index 59c41f0ad..77bcfddf5 100644 --- a/include/libtorrent/session_status.hpp +++ b/include/libtorrent/session_status.hpp @@ -40,8 +40,6 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { -#ifndef TORRENT_DISABLE_DHT - struct dht_lookup { char const* type; @@ -70,8 +68,6 @@ namespace libtorrent int last_active; }; -#endif - struct utp_status { int num_idle; @@ -129,7 +125,6 @@ namespace libtorrent int disk_write_queue; int disk_read_queue; -#ifndef TORRENT_DISABLE_DHT int dht_nodes; int dht_node_cache; int dht_torrents; @@ -137,7 +132,6 @@ namespace libtorrent std::vector active_requests; std::vector dht_routing_table; int dht_total_allocations; -#endif utp_status utp_stats; diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index ad1ba5e02..5d29cf502 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -366,10 +366,8 @@ namespace libtorrent // forces this torrent to reannounce // (make a rerequest from the tracker) void force_reannounce() const; -#ifndef TORRENT_DISABLE_DHT // announces this torrent to the DHT immediately void force_dht_announce() const; -#endif // forces a reannounce in the specified amount of time. // This overrides the default announce interval, and no diff --git a/src/session.cpp b/src/session.cpp index 7ac65dc14..99dbe5fe7 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -786,54 +786,70 @@ namespace libtorrent return m_impl->m_disk_thread.status(); } -#ifndef TORRENT_DISABLE_DHT - void session::start_dht() { +#ifndef TORRENT_DISABLE_DHT // the state is loaded in load_state() TORRENT_ASYNC_CALL(start_dht); +#endif } void session::stop_dht() { +#ifndef TORRENT_DISABLE_DHT TORRENT_ASYNC_CALL(stop_dht); +#endif } void session::set_dht_settings(dht_settings const& settings) { +#ifndef TORRENT_DISABLE_DHT TORRENT_ASYNC_CALL1(set_dht_settings, settings); +#endif } #ifndef TORRENT_NO_DEPRECATE void session::start_dht(entry const& startup_state) { +#ifndef TORRENT_DISABLE_DHT TORRENT_ASYNC_CALL1(start_dht, startup_state); +#endif } entry session::dht_state() const { +#ifndef TORRENT_DISABLE_DHT TORRENT_SYNC_CALL_RET(entry, dht_state); return r; - } +#else + return entry(); #endif + } +#endif // TORRENT_NO_DEPRECATE void session::add_dht_node(std::pair const& node) { +#ifndef TORRENT_DISABLE_DHT TORRENT_ASYNC_CALL1(add_dht_node_name, node); +#endif } void session::add_dht_router(std::pair const& node) { +#ifndef TORRENT_DISABLE_DHT TORRENT_ASYNC_CALL1(add_dht_router, node); +#endif } bool session::is_dht_running() const { +#ifndef TORRENT_DISABLE_DHT TORRENT_SYNC_CALL_RET(bool, is_dht_running); return r; - } - +#else + return false; #endif + } #ifndef TORRENT_DISABLE_ENCRYPTION void session::set_pe_settings(pe_settings const& settings) @@ -911,18 +927,22 @@ namespace libtorrent } -#ifndef TORRENT_DISABLE_DHT void session::set_dht_proxy(proxy_settings const& s) { +#ifndef TORRENT_DISABLE_DHT TORRENT_ASYNC_CALL1(set_dht_proxy, s); +#endif } proxy_settings session::dht_proxy() const { +#ifndef TORRENT_DISABLE_DHT TORRENT_SYNC_CALL_RET(proxy_settings, dht_proxy); return r; - } +#else + return proxy_settings(); #endif + } #endif // TORRENT_NO_DEPRECATE #if TORRENT_USE_I2P @@ -1165,9 +1185,7 @@ namespace libtorrent , max_queued_disk_bytes(1024 * 1024) , max_queued_disk_bytes_low_watermark(0) , handshake_timeout(10) -#ifndef TORRENT_DISABLE_DHT , use_dht_as_fallback(false) -#endif , free_torrent_hashes(true) , upnp_ignore_nonrouters(false) , send_buffer_low_watermark(512) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index b6706c32b..7898a5a44 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -5558,7 +5558,12 @@ retry: s.total_dht_download = m_stat.total_transfer(stat::download_dht_protocol); s.dht_upload_rate = m_stat.transfer_rate(stat::upload_dht_protocol); s.total_dht_upload = m_stat.total_transfer(stat::upload_dht_protocol); -#endif +#else + s.dht_download_rate = 0; + s.total_dht_download = 0; + s.dht_upload_rate = 0; + s.total_dht_upload = 0; +#endif // TORRENT_DISABLE_DHT // tracker s.tracker_download_rate = m_stat.transfer_rate(stat::download_tracker_protocol); @@ -5591,6 +5596,7 @@ retry: m_dht->dht_status(s); } else +#endif { s.dht_nodes = 0; s.dht_node_cache = 0; @@ -5598,7 +5604,6 @@ retry: s.dht_global_nodes = 0; s.dht_total_allocations = 0; } -#endif m_utp_socket_manager.get_status(s.utp_stats); diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 594586ce9..783151c83 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -905,13 +905,13 @@ namespace libtorrent TORRENT_ASYNC_CALL1(force_tracker_request, time_now() + seconds(duration.total_seconds())); } -#ifndef TORRENT_DISABLE_DHT void torrent_handle::force_dht_announce() const { INVARIANT_CHECK; +#ifndef TORRENT_DISABLE_DHT TORRENT_ASYNC_CALL(dht_announce); - } #endif + } void torrent_handle::force_reannounce() const { diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp index ca5139ab7..e54c322bf 100644 --- a/test/test_primitives.cpp +++ b/test/test_primitives.cpp @@ -69,11 +69,14 @@ using namespace boost::tuples; namespace libtorrent { TORRENT_EXPORT std::string sanitize_path(std::string const& p); + +#ifndef TORRENT_DISABLE_DHT namespace dht { TORRENT_EXPORT libtorrent::dht::node_id generate_id_impl( address const& ip_, boost::uint32_t r); } +#endif } sha1_hash to_hash(char const* s) @@ -451,6 +454,7 @@ int test_main() TEST_CHECK(ret == 1); #endif +#ifndef TORRENT_DISABLE_DHT // test verify_message const static key_desc_t msg_desc[] = { {"A", lazy_entry::string_t, 4, 0}, @@ -543,6 +547,7 @@ int test_main() TEST_CHECK(ent.list_at(1)->string_value() == ""); } } +#endif // TORRENT_DISABLE_DHT // test external ip voting external_ip ipv1; @@ -896,6 +901,7 @@ int test_main() TEST_CHECK(ec == error_code(errors::missing_info_hash_in_uri)); ec.clear(); +#ifndef TORRENT_DISABLE_DHT parse_magnet_uri("magnet:?xt=urn:btih:cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd&dn=foo&dht=127.0.0.1:43", p, ec); TEST_CHECK(!ec); if (ec) fprintf(stderr, "%s\n", ec.message().c_str()); @@ -904,6 +910,7 @@ int test_main() TEST_CHECK(p.dht_nodes.size() == 1); TEST_CHECK(p.dht_nodes[0].first == "127.0.0.1"); TEST_CHECK(p.dht_nodes[0].second == 43); +#endif // make sure settings that haven't been changed from their defaults are not saved TEST_CHECK(session_state2.dict_find("settings")->dict_find("optimistic_disk_retry") == 0);