diff --git a/ChangeLog b/ChangeLog index f655d9e53..6a7f32de4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -102,6 +102,7 @@ * fix uTP edge case where udp socket buffer fills up * fix nagle implementation in uTP + * expose i2p_alert to python. cleaning up of i2p connection code * fixed overflow and download performance issue when downloading at high rates * fixed bug in add_torrent_alert::message for magnet links * disable optimistic disconnects when connection limit is low diff --git a/bindings/python/src/alert.cpp b/bindings/python/src/alert.cpp index 2a3d2c01a..7d8e7e05c 100644 --- a/bindings/python/src/alert.cpp +++ b/bindings/python/src/alert.cpp @@ -398,6 +398,11 @@ void bind_alert() .add_property("status", &get_status_from_update_alert) ; + class_, noncopyable>( + "i2p_alert", no_init) + .add_property("error", &i2p_alert::error) + ; + class_, noncopyable>( "dht_reply_alert", no_init) .def_readonly("num_peers", &dht_reply_alert::num_peers) diff --git a/include/libtorrent/i2p_stream.hpp b/include/libtorrent/i2p_stream.hpp index 7b7a5b56c..767f2ff24 100644 --- a/include/libtorrent/i2p_stream.hpp +++ b/include/libtorrent/i2p_stream.hpp @@ -188,7 +188,8 @@ private: , name_lookup_handler handler , boost::shared_ptr); - void set_local_endpoint(error_code const& ec, char const* dest); + void set_local_endpoint(error_code const& ec, char const* dest + , i2p_stream::handler_type const& h); // to talk to i2p SAM bridge boost::shared_ptr m_sam_socket; diff --git a/src/i2p_stream.cpp b/src/i2p_stream.cpp index 0eeaabea7..332e17534 100644 --- a/src/i2p_stream.cpp +++ b/src/i2p_stream.cpp @@ -152,18 +152,24 @@ namespace libtorrent #endif m_state = sam_idle; - do_name_lookup("ME", boost::bind(&i2p_connection::set_local_endpoint, this, _1, _2)); - h(ec); - } - - void i2p_connection::set_local_endpoint(error_code const& ec, char const* dest) - { - if (ec || dest == 0) + if (ec) { - m_i2p_local_endpoint.clear(); + h(ec); return; } - m_i2p_local_endpoint = dest; + + do_name_lookup("ME", boost::bind(&i2p_connection::set_local_endpoint, this, _1, _2, h)); + } + + void i2p_connection::set_local_endpoint(error_code const& ec, char const* dest + , i2p_stream::handler_type const& h) + { + if (!ec && dest != 0) + m_i2p_local_endpoint = dest; + else + m_i2p_local_endpoint.clear(); + + h(ec); } void i2p_connection::async_name_lookup(char const* name diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 7d344ec97..0d4efd330 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2688,11 +2688,15 @@ retry: // pause the session now and resume it once we've // established the i2p SAM connection #if TORRENT_USE_I2P + if (m_settings.get_str(settings_pack::i2p_hostname).empty()) + { + error_code ec; + m_i2p_conn.close(ec); + return; + } m_i2p_conn.open(m_settings.get_str(settings_pack::i2p_hostname) , m_settings.get_int(settings_pack::i2p_port) , boost::bind(&session_impl::on_i2p_open, this, _1)); - - open_new_incoming_i2p_connection(); #endif } diff --git a/src/torrent.cpp b/src/torrent.cpp index aac94c980..bc0d30570 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -7137,6 +7137,16 @@ namespace libtorrent bool i2p = peerinfo->is_i2p_addr; if (i2p) { + if (m_ses.i2p_proxy().hostname.empty()) + { + // we have an i2p torrent, but we're not connected to an i2p + // SAM proxy. + if (alerts().should_post()) + alerts().post_alert(i2p_alert(error_code(errors::no_i2p_router + , get_libtorrent_category()))); + return false; + } + bool ret = instantiate_connection(m_ses.get_io_service(), m_ses.i2p_proxy(), *s); (void)ret; TORRENT_ASSERT(ret); diff --git a/test/test_dht.cpp b/test/test_dht.cpp index af9e1c670..af1938a2c 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/alert_dispatcher.hpp" #include "libtorrent/performance_counters.hpp" // for counters #include "libtorrent/random.hpp" +#include "libtorrent/ed25519.hpp" #include "libtorrent/kademlia/node_id.hpp" #include "libtorrent/kademlia/routing_table.hpp"