From 4ba0151cb97f09d6a9d77653317394ec80872203 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 29 Oct 2016 22:56:46 -0400 Subject: [PATCH 1/4] documentation fixes (#1274) --- bindings/python/src/session.cpp | 5 +++-- include/libtorrent/session_handle.hpp | 10 ++-------- include/libtorrent/settings_pack.hpp | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 1363f02b6..587519e26 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -50,7 +50,6 @@ namespace if (ec) throw libtorrent_exception(ec); #endif } -#endif void outgoing_ports(lt::session& s, int _min, int _max) { @@ -61,6 +60,8 @@ namespace s.apply_settings(p); return; } +#endif // TORRENT_NO_DEPRECATE + #ifndef TORRENT_DISABLE_DHT void add_dht_node(lt::session& s, tuple n) { @@ -770,10 +771,10 @@ void bind_session() , arg("flags")=lt::session::start_default_features | lt::session::add_default_plugins , arg("alert_mask")=int(alert::error_notification))) ) + .def("outgoing_ports", &outgoing_ports) #endif .def("post_torrent_updates", allow_threads(<::session::post_torrent_updates), arg("flags") = 0xffffffff) .def("post_session_stats", allow_threads(<::session::post_session_stats)) - .def("outgoing_ports", &outgoing_ports) .def("is_listening", allow_threads(<::session::is_listening)) .def("listen_port", allow_threads(<::session::listen_port)) #ifndef TORRENT_DISABLE_DHT diff --git a/include/libtorrent/session_handle.hpp b/include/libtorrent/session_handle.hpp index c696bcbd2..f2662796d 100644 --- a/include/libtorrent/session_handle.hpp +++ b/include/libtorrent/session_handle.hpp @@ -613,8 +613,8 @@ namespace libtorrent // listen_failed_alert with port 0 even if you didn't ask to listen on // it. // - // It is possible to prevent libtorrent from binding to port 0 by passing - // in the flag ``session::no_system_port`` in the ``flags`` argument. + // It is possible to prevent libtorrent from falling back to binding to + // port 0 by clearing the ``listen_system_port_fallback`` settings. // // The interface parameter can also be a hostname that will resolve to // the device you want to listen on. If you don't specify an interface, @@ -622,12 +622,6 @@ namespace libtorrent // 0.0.0.0 and ::). This means that if your IPv6 interface doesn't work, // you may still see a listen_failed_alert, even though the IPv4 port // succeeded. - // - // The ``flags`` parameter can either be 0 or - // ``session::listen_reuse_address``, which will set the reuse address - // socket option on the listen socket(s). By default, the listen socket - // does not use reuse address. If you're running a service that needs to - // run on a specific port no matter if it's in use, set this flag. unsigned short listen_port() const; unsigned short ssl_listen_port() const; bool is_listening() const; diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index 3a042c0ef..55ae26c21 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -1383,7 +1383,7 @@ namespace libtorrent // normal client. If this is a high performance server which expects // to receive a lot of connections, or used in a simulator or test, it // might make sense to raise this number. It will not take affect - // until listen_on() is called again (or for the first time). + // until the ``listen_interfaces`` settings is updated. listen_queue_size, // ``torrent_connect_boost`` is the number of peers to try to connect From 21d05945f24e0791093d82bc8a891ae276b3406c Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 31 Oct 2016 20:00:01 -0400 Subject: [PATCH 2/4] documentation and deprecation fixes (#1275) documentation and deprecation fixes --- examples/client_test.cpp | 18 ---------------- include/libtorrent/session_handle.hpp | 30 +++++++-------------------- include/libtorrent/settings_pack.hpp | 11 ++++++++-- src/session_handle.cpp | 2 ++ 4 files changed, 18 insertions(+), 43 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index ce42693d4..2b528b55d 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -1322,9 +1322,6 @@ int main(int argc, char* argv[]) settings.set_int(settings_pack::choking_algorithm, settings_pack::rate_based_choker); int refresh_delay = 500; -#ifndef TORRENT_DISABLE_DHT - bool start_dht = true; -#endif bool rate_limit_locals = false; std::deque events; @@ -1420,9 +1417,6 @@ int main(int argc, char* argv[]) case 't': poll_interval = atoi(arg); break; case 'F': refresh_delay = atoi(arg); break; case 'H': -#ifndef TORRENT_DISABLE_DHT - start_dht = false; -#endif settings.set_bool(settings_pack::enable_dht, false); --i; break; @@ -1601,18 +1595,6 @@ int main(int argc, char* argv[]) dht.privacy_lookups = true; ses.set_dht_settings(dht); - if (start_dht) - { - settings.set_bool(settings_pack::use_dht_as_fallback, false); - - ses.add_dht_router(std::make_pair( - std::string("router.bittorrent.com"), 6881)); - ses.add_dht_router(std::make_pair( - std::string("router.utorrent.com"), 6881)); - ses.add_dht_router(std::make_pair( - std::string("router.bitcomet.com"), 6881)); - } - std::vector in; if (load_file(".ses_state", in, ec) == 0) { diff --git a/include/libtorrent/session_handle.hpp b/include/libtorrent/session_handle.hpp index f2662796d..03c225f14 100644 --- a/include/libtorrent/session_handle.hpp +++ b/include/libtorrent/session_handle.hpp @@ -367,6 +367,10 @@ namespace libtorrent // ``add_dht_node`` takes a host name and port pair. That endpoint will be // pinged, and if a valid DHT reply is received, the node will be added to // the routing table. + void add_dht_node(std::pair const& node); + +#ifndef TORRENT_NO_DEPRECATE + // deprecated, use settings_pack::dht_bootstrap_nodes instead // // ``add_dht_router`` adds the given endpoint to a list of DHT router // nodes. If a search is ever made while the routing table is empty, @@ -377,8 +381,9 @@ namespace libtorrent // // An example routing node that you could typically add is // ``router.bittorrent.com``. - void add_dht_node(std::pair const& node); + TORRENT_DEPRECATED void add_dht_router(std::pair const& node); +#endif // query the DHT for an immutable item at the ``target`` hash. // the result is posted as a dht_immutable_item_alert. @@ -600,28 +605,7 @@ namespace libtorrent // settings_pack::listen_interfaces to try another interface and port to // bind to. // - // ``listen_port()`` returns the port we ended up listening on. If the - // port specified in settings_pack::listen_interfaces failed, libtorrent - // will try to bind to the next port, and so on. If it fails - // settings_pack::max_retry_port_bind times, it will bind to port 0 - // (meaning the OS picks the port). The only way to know which port it - // ended up binding to is to ask for it by calling ``listen_port()``. - // - // If all ports in the specified range fails to be opened for listening, - // libtorrent will try to use port 0 (which tells the operating system to - // pick a port that's free). If that still fails you may see a - // listen_failed_alert with port 0 even if you didn't ask to listen on - // it. - // - // It is possible to prevent libtorrent from falling back to binding to - // port 0 by clearing the ``listen_system_port_fallback`` settings. - // - // The interface parameter can also be a hostname that will resolve to - // the device you want to listen on. If you don't specify an interface, - // libtorrent may attempt to listen on multiple interfaces (typically - // 0.0.0.0 and ::). This means that if your IPv6 interface doesn't work, - // you may still see a listen_failed_alert, even though the IPv4 port - // succeeded. + // ``listen_port()`` returns the port we ended up listening on. unsigned short listen_port() const; unsigned short ssl_listen_port() const; bool is_listening() const; diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index 55ae26c21..11182d450 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -173,11 +173,18 @@ namespace libtorrent // IPs and multiple ports. Binding to port 0 will make the // operating system pick the port. The default is "0.0.0.0:6881", which // binds to all interfaces on port 6881. - // + // + // If binding fails because the port is busy, the port number will be + // incremented by one, ``settings_pack::max_retry_port_bind`` times. + // + // if all retry attempts fail, the socket will be bound to port 0, + // meaning the operating system will pick a port. This behavior can be + // disabled by disabling ``settings_pack::listen_system_port_fallback``. + // // if binding fails, the listen_failed_alert is posted, potentially // more than once. Once/if binding the listen socket(s) succeed, // listen_succeeded_alert is posted. - // + // // Each port will attempt to open both a UDP and a TCP listen socket, // to allow accepting uTP connections as well as TCP. If using the DHT, // this will also make the DHT use the same UDP ports. diff --git a/src/session_handle.cpp b/src/session_handle.cpp index 08f437fb6..b3ab55c78 100644 --- a/src/session_handle.cpp +++ b/src/session_handle.cpp @@ -370,6 +370,7 @@ namespace libtorrent #endif } +#ifndef TORRENT_NO_DEPRECATE void session_handle::add_dht_router(std::pair const& node) { #ifndef TORRENT_DISABLE_DHT @@ -378,6 +379,7 @@ namespace libtorrent TORRENT_UNUSED(node); #endif } +#endif // TORRENT_NO_DEPRECATE void session_handle::dht_get_item(sha1_hash const& target) { From c1fbd31bf1d3423f5c554d679508da35b2c613b0 Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 2 Nov 2016 23:40:48 -0400 Subject: [PATCH 3/4] make deprecation ifdefs more uniform --- bindings/python/src/create_torrent.cpp | 8 ++++---- bindings/python/src/session.cpp | 4 ++++ bindings/python/src/torrent_info.cpp | 6 +++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bindings/python/src/create_torrent.cpp b/bindings/python/src/create_torrent.cpp index 95f512d18..b42272116 100644 --- a/bindings/python/src/create_torrent.cpp +++ b/bindings/python/src/create_torrent.cpp @@ -54,7 +54,7 @@ namespace ct.add_node(std::make_pair(addr, port)); } -#if !defined TORRENT_NO_DEPRECATE +#ifndef TORRENT_NO_DEPRECATE void add_file(file_storage& ct, file_entry const& fe) { ct.add_file(fe); @@ -121,7 +121,7 @@ void bind_create_torrent() { void (file_storage::*add_file0)(std::string const&, boost::int64_t , int, std::time_t, std::string const&) = &file_storage::add_file; -#if !defined TORRENT_NO_DEPRECATE +#ifndef TORRENT_NO_DEPRECATE #if TORRENT_USE_WSTRING void (file_storage::*add_file1)(std::wstring const&, boost::int64_t , int, std::time_t, std::string const&) = &file_storage::add_file; @@ -147,7 +147,7 @@ void bind_create_torrent() boost::int64_t (file_storage::*file_storage_file_offset)(int) const = &file_storage::file_offset; int (file_storage::*file_storage_file_flags)(int) const = &file_storage::file_flags; -#if !defined TORRENT_NO_DEPRECATE +#ifndef TORRENT_NO_DEPRECATE file_entry (file_storage::*at)(int) const = &file_storage::at; #endif @@ -159,7 +159,7 @@ void bind_create_torrent() .def("add_file", add_file1, (arg("path"), arg("size"), arg("flags") = 0, arg("mtime") = 0, arg("linkpath") = "")) #endif .def("num_files", &file_storage::num_files) -#if !defined TORRENT_NO_DEPRECATE +#ifndef TORRENT_NO_DEPRECATE .def("at", at) .def("add_file", add_file, arg("entry")) .def("__iter__", boost::python::range(&begin_files, &end_files)) diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 587519e26..3884965c5 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -71,11 +71,13 @@ namespace s.add_dht_node(std::make_pair(ip, port)); } +#ifndef TORRENT_NO_DEPRECATE void add_dht_router(lt::session& s, std::string router_, int port_) { allow_threading_guard guard; return s.add_dht_router(std::make_pair(router_, port_)); } +#endif #endif // TORRENT_DISABLE_DHT @@ -779,10 +781,12 @@ void bind_session() .def("listen_port", allow_threads(<::session::listen_port)) #ifndef TORRENT_DISABLE_DHT .def("add_dht_node", &add_dht_node) +#ifndef TORRENT_NO_DEPRECATE .def( "add_dht_router", &add_dht_router , (arg("router"), "port") ) +#endif // TORRENT_NO_DEPRECATE .def("is_dht_running", allow_threads(<::session::is_dht_running)) .def("set_dht_settings", allow_threads(<::session::set_dht_settings)) .def("get_dht_settings", allow_threads(<::session::get_dht_settings)) diff --git a/bindings/python/src/torrent_info.cpp b/bindings/python/src/torrent_info.cpp index 78e3547c3..477c6fcdc 100644 --- a/bindings/python/src/torrent_info.cpp +++ b/bindings/python/src/torrent_info.cpp @@ -123,7 +123,7 @@ namespace bool get_complete_sent(announce_entry const& ae) { return ae.complete_sent; } bool get_send_stats(announce_entry const& ae) { return ae.send_stats; } -#if !defined TORRENT_NO_DEPRECATE +#ifndef TORRENT_NO_DEPRECATE boost::int64_t get_size(file_entry const& fe) { return fe.size; } boost::int64_t get_offset(file_entry const& fe) { return fe.offset; } boost::int64_t get_file_base(file_entry const& fe) { return fe.file_base; } @@ -246,7 +246,7 @@ void bind_torrent_info() .def("remap_files", &torrent_info::remap_files) .def("files", &torrent_info::files, return_internal_reference<>()) .def("orig_files", &torrent_info::orig_files, return_internal_reference<>()) -#if !defined TORRENT_NO_DEPRECATE +#ifndef TORRENT_NO_DEPRECATE .def("file_at", &torrent_info::file_at) .def("file_at_offset", &torrent_info::file_at_offset) #if TORRENT_USE_WSTRING @@ -267,7 +267,7 @@ void bind_torrent_info() .def("map_file", &torrent_info::map_file) ; -#if !defined TORRENT_NO_DEPRECATE +#ifndef TORRENT_NO_DEPRECATE class_("file_entry") .def_readwrite("path", &file_entry::path) .def_readwrite("symlink_path", &file_entry::symlink_path) From 11856d64e9ee1d133764ead6501701b84750d66f Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 3 Nov 2016 01:01:48 -0400 Subject: [PATCH 4/4] treat an unknown key in a settings_pack as an error in python (#1287) --- bindings/python/src/session.cpp | 6 +++++- bindings/python/test.py | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 3884965c5..1bcafbe3d 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -112,7 +112,11 @@ namespace std::string const key = extract(iterkeys[i]); int sett = setting_by_name(key); - if (sett < 0) continue; + if (sett < 0) + { + PyErr_SetString(PyExc_ValueError, ("unknown name in settings_pack: " + key).c_str()); + throw_error_already_set(); + } TORRENT_TRY { diff --git a/bindings/python/test.py b/bindings/python/test.py index 3d6ff5325..76fce40b5 100644 --- a/bindings/python/test.py +++ b/bindings/python/test.py @@ -81,7 +81,7 @@ class test_torrent_info(unittest.TestCase): idx = 0 expected = ['bar.txt', 'var.txt'] for f in files: - print f.path + print(f.path) self.assertEqual(os.path.split(f.path)[1], expected[idx]) self.assertEqual(os.path.split(os.path.split(f.path)[0]), ('temp', 'foo')) @@ -165,6 +165,13 @@ class test_session(unittest.TestCase): self.assertTrue(isinstance(a.values, dict)) self.assertTrue(len(a.values) > 0) + def test_unknown_settings(self): + try: + s = lt.session({'unexpected-key-name': 42}) + self.assertFalse('should have thrown an exception') + except Exception as e: + print(e) + def test_deprecated_settings(self): # this detects whether libtorrent was built with deprecated APIs