From b44f71e217cbdf6b324f5215dd9bff92016fc688 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 25 Aug 2010 06:22:49 +0000 Subject: [PATCH] post alerts for socks failures. fix unit tests --- src/peer_connection.cpp | 5 ++++- src/session_impl.cpp | 23 ++++++++++++++++------- src/socks5_stream.cpp | 20 ++++++++++---------- test/setup_transfer.cpp | 19 +++++++++++-------- test/test_transfer.cpp | 8 ++++---- 5 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index b13d881ad..ffdcd2cef 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -3228,7 +3228,10 @@ namespace libtorrent if (ec) { - if (error > 1 && m_ses.m_alerts.should_post()) + if ((error > 1 + || ec.category() == get_libtorrent_category() + || ec.category() == socks_category) + && m_ses.m_alerts.should_post()) { m_ses.m_alerts.post_alert( peer_error_alert(handle, remote(), pid(), ec)); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 5fe9dc46e..eb461e7ae 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1363,6 +1363,13 @@ namespace aux { listen_socket_t s; s.sock.reset(new socket_acceptor(m_io_service)); s.sock->open(ep.protocol(), ec); +#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING + if (ec) + { + (*m_logger) << "failed to open socket: " << print_endpoint(ep) + << ": " << ec.message() << "\n" << "\n"; + } +#endif if (reuse_address) s.sock->set_option(socket_acceptor::reuse_address(true), ec); #if TORRENT_USE_IPV6 @@ -1382,6 +1389,12 @@ namespace aux { s.sock->bind(ep, ec); while (ec && retries > 0) { +#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING + char msg[200]; + snprintf(msg, 200, "failed to bind to interface \"%s\": %s" + , print_endpoint(ep).c_str(), ec.message().c_str()); + (*m_logger) << msg << "\n"; +#endif ec = error_code(); TORRENT_ASSERT(!ec); --retries; @@ -1454,15 +1467,11 @@ namespace aux { if (s.sock) { - // if we're configured to listen on port 0 (i.e. let the - // OS decide), update the listen_interface member with the + // update the listen_interface member with the // actual port we ended up listening on, so that the other // sockets can be bound to the same one - if (m_listen_interface.port() == 0) - { - error_code ec; - m_listen_interface.port(s.sock->local_endpoint(ec).port()); - } + error_code ec; + m_listen_interface.port(s.sock->local_endpoint(ec).port()); m_listen_sockets.push_back(s); async_accept(s.sock); diff --git a/src/socks5_stream.cpp b/src/socks5_stream.cpp index 2f33cdc45..7fe732cd0 100644 --- a/src/socks5_stream.cpp +++ b/src/socks5_stream.cpp @@ -51,16 +51,16 @@ namespace libtorrent { static char const* messages[] = { - "no error", - "unsupported version", - "unsupported authentication method", - "unsupported authentication version", - "authentication error", - "username required", - "general failure", - "command not supported", - "no identd running", - "identd could not identify username" + "SOCKS no error", + "SOCKS unsupported version", + "SOCKS unsupported authentication method", + "SOCKS unsupported authentication version", + "SOCKS authentication error", + "SOCKS username required", + "SOCKS general failure", + "SOCKS command not supported", + "SOCKS no identd running", + "SOCKS identd could not identify username" }; if (ev < 0 || ev > socks_error::num_errors) return "unknown error"; diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index c37ff97a7..60c3bd3a0 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -90,15 +90,18 @@ bool print_alerts(libtorrent::session& ses, char const* name } TEST_CHECK(alert_cast(a.get()) == 0 || allow_failed_fastresume); - TEST_CHECK(alert_cast(a.get()) == 0 + peer_error_alert* pea = alert_cast(a.get()); + TEST_CHECK(pea == 0 || (!handles.empty() && h.is_seed()) - || a->message() == "connecting to peer" - || a->message() == "closing connection to ourself" - || a->message() == "duplicate connection" - || a->message() == "duplicate peer-id, connection closed" - || (allow_disconnects && a->message() == "Broken pipe") - || (allow_disconnects && a->message() == "Connection reset by peer") - || (allow_disconnects && a->message() == "End of file.")); + || pea->error.message() == "connecting to peer" + || pea->error.message() == "closing connection to ourself" + || pea->error.message() == "duplicate connection" + || pea->error.message() == "duplicate peer-id" + || pea->error.message() == "upload to upload connection" + || pea->error.message() == "stopping torrent" + || (allow_disconnects && pea->error.message() == "Broken pipe") + || (allow_disconnects && pea->error.message() == "Connection reset by peer") + || (allow_disconnects && pea->error.message() == "End of file.")); a = ses.pop_alert(); } return ret; diff --git a/test/test_transfer.cpp b/test/test_transfer.cpp index 8d4096e74..6a3c1881f 100644 --- a/test/test_transfer.cpp +++ b/test/test_transfer.cpp @@ -277,8 +277,8 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe #ifndef TORRENT_DISABLE_ENCRYPTION pe_settings pes; - pes.out_enc_policy = pe_settings::forced; - pes.in_enc_policy = pe_settings::forced; + pes.out_enc_policy = pe_settings::disabled; + pes.in_enc_policy = pe_settings::disabled; ses1.set_pe_settings(pes); ses2.set_pe_settings(pes); #endif @@ -322,7 +322,7 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe ses2.set_alert_mask(alert::all_categories & ~alert::progress_notification & ~alert::stats_notification); - ses1.set_alert_dispatch(&print_alert); +// ses1.set_alert_dispatch(&print_alert); ses2.set_download_rate_limit(tor2.get_torrent_info().piece_length() * 5); @@ -380,7 +380,7 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe } // 1 announce per tracker to start - TEST_EQUAL(tracker_responses, 2); + TEST_CHECK(tracker_responses >= 2); TEST_CHECK(!tor2.is_seed()); TEST_CHECK(tor2.is_finished());