summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcos Pinto <markybob@dipconsultants.com>2007-10-15 05:34:32 +0000
committerMarcos Pinto <markybob@dipconsultants.com>2007-10-15 05:34:32 +0000
commitb403530fab691432d580b63a6888bdec2fd4df2c (patch)
tree2221801a3cd4e66bc5ac83737b8b4f62f166e44d
parent7d98d4980332e641d9d61360cf2745226e9832f1 (diff)
downloaddeluge-b403530fab691432d580b63a6888bdec2fd4df2c.tar.gz
deluge-b403530fab691432d580b63a6888bdec2fd4df2c.tar.bz2
deluge-b403530fab691432d580b63a6888bdec2fd4df2c.zip
fast reconnect fixes
-rwxr-xr-xlibtorrent/include/libtorrent/peer_connection.hpp8
-rw-r--r--libtorrent/include/libtorrent/session_settings.hpp2
-rwxr-xr-xlibtorrent/src/bt_peer_connection.cpp1
-rwxr-xr-xlibtorrent/src/peer_connection.cpp11
-rwxr-xr-xlibtorrent/src/policy.cpp3
-rwxr-xr-xlibtorrent/src/session_impl.cpp15
-rwxr-xr-xlibtorrent/src/torrent.cpp9
7 files changed, 31 insertions, 18 deletions
diff --git a/libtorrent/include/libtorrent/peer_connection.hpp b/libtorrent/include/libtorrent/peer_connection.hpp
index c682388e3..e1581affe 100755
--- a/libtorrent/include/libtorrent/peer_connection.hpp
+++ b/libtorrent/include/libtorrent/peer_connection.hpp
@@ -176,13 +176,7 @@ namespace libtorrent
void set_non_prioritized(bool b)
{ m_non_prioritized = b; }
- void fast_reconnect(bool r)
- {
- if (peer_info_struct() && peer_info_struct()->fast_reconnects > 0) return;
- m_fast_reconnect = r;
- if (peer_info_struct()) ++peer_info_struct()->fast_reconnects;
-
- }
+ void fast_reconnect(bool r);
bool fast_reconnect() const { return m_fast_reconnect; }
// this adds an announcement in the announcement queue
diff --git a/libtorrent/include/libtorrent/session_settings.hpp b/libtorrent/include/libtorrent/session_settings.hpp
index fbf2c8a03..a792e296a 100644
--- a/libtorrent/include/libtorrent/session_settings.hpp
+++ b/libtorrent/include/libtorrent/session_settings.hpp
@@ -99,7 +99,7 @@ namespace libtorrent
, allow_multiple_connections_per_ip(false)
, max_failcount(3)
, min_reconnect_time(60)
- , peer_connect_timeout(10)
+ , peer_connect_timeout(7)
, ignore_limits_on_local_network(true)
, connection_speed(20)
, send_redundant_have(false)
diff --git a/libtorrent/src/bt_peer_connection.cpp b/libtorrent/src/bt_peer_connection.cpp
index 4fe3e764d..0559aff95 100755
--- a/libtorrent/src/bt_peer_connection.cpp
+++ b/libtorrent/src/bt_peer_connection.cpp
@@ -204,7 +204,6 @@ namespace libtorrent
// if this fails, we need to reconnect
// fast.
- pi->connected = time_now() - seconds(m_ses.settings().min_reconnect_time);
fast_reconnect(true);
write_pe1_2_dhkey();
diff --git a/libtorrent/src/peer_connection.cpp b/libtorrent/src/peer_connection.cpp
index ad1ea3173..625b8eacd 100755
--- a/libtorrent/src/peer_connection.cpp
+++ b/libtorrent/src/peer_connection.cpp
@@ -394,6 +394,16 @@ namespace libtorrent
#endif
}
+ void peer_connection::fast_reconnect(bool r)
+ {
+ if (peer_info_struct() && peer_info_struct()->fast_reconnects > 1) return;
+ m_fast_reconnect = r;
+ peer_info_struct()->connected = time_now()
+ - seconds(m_ses.settings().min_reconnect_time
+ * m_ses.settings().max_failcount);
+ if (peer_info_struct()) ++peer_info_struct()->fast_reconnects;
+ }
+
void peer_connection::announce_piece(int index)
{
// dont announce during handshake
@@ -1922,7 +1932,6 @@ namespace libtorrent
void peer_connection::timed_out()
{
- if (m_peer_info) ++m_peer_info->failcount;
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
(*m_ses.m_logger) << "CONNECTION TIMED OUT: " << m_remote.address().to_string()
<< "\n";
diff --git a/libtorrent/src/policy.cpp b/libtorrent/src/policy.cpp
index cc11b80e3..4de01d055 100755
--- a/libtorrent/src/policy.cpp
+++ b/libtorrent/src/policy.cpp
@@ -986,7 +986,8 @@ namespace libtorrent
i->second.prev_amount_upload = 0;
i->second.connection = &c;
TORRENT_ASSERT(i->second.connection);
- i->second.connected = time_now();
+ if (!c.fast_reconnect())
+ i->second.connected = time_now();
// m_last_optimistic_disconnect = time_now();
}
diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp
index 182f935bb..63c039010 100755
--- a/libtorrent/src/session_impl.cpp
+++ b/libtorrent/src/session_impl.cpp
@@ -569,8 +569,19 @@ namespace detail
, m_checker_impl(*this)
{
#ifdef WIN32
- // windows XP has a limit of 10 simultaneous connections
- m_half_open.limit(8);
+ // windows XP has a limit on the number of
+ // simultaneous half-open TCP connections
+ DWORD windows_version = ::GetVersion();
+ if ((windows_version & 0xff) >= 6)
+ {
+ // on vista the limit is 5 (in home edition)
+ m_half_open.limit(4);
+ }
+ else
+ {
+ // on XP SP2 it's 10
+ m_half_open.limit(8);
+ }
#endif
m_bandwidth_manager[peer_connection::download_channel] = &m_download_channel;
diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp
index 742c1c6de..840e488ba 100755
--- a/libtorrent/src/torrent.cpp
+++ b/libtorrent/src/torrent.cpp
@@ -1678,8 +1678,6 @@ namespace libtorrent
try
{
- TORRENT_ASSERT(m_connections.find(a) == m_connections.end());
-
// add the newly connected peer to this torrent's peer list
TORRENT_ASSERT(m_connections.find(a) == m_connections.end());
m_connections.insert(
@@ -1893,10 +1891,13 @@ namespace libtorrent
std::make_pair(a, boost::get_pointer(c)));
m_ses.m_connections.insert(std::make_pair(s, c));
+ int timeout = settings().peer_connect_timeout;
+ if (peerinfo) timeout += 3 * peerinfo->failcount;
+
m_ses.m_half_open.enqueue(
bind(&peer_connection::connect, c, _1)
, bind(&peer_connection::timed_out, c)
- , seconds(settings().peer_connect_timeout));
+ , seconds(timeout));
}
catch (std::exception& e)
{
@@ -2400,8 +2401,6 @@ namespace libtorrent
piece_manager& torrent::filesystem()
{
- INVARIANT_CHECK;
-
TORRENT_ASSERT(m_owning_storage.get());
return *m_owning_storage;
}