mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
lt sync 2413
This commit is contained in:
parent
89cad666d5
commit
651523e7d0
8 changed files with 87 additions and 25 deletions
|
@ -129,7 +129,7 @@ namespace libtorrent
|
||||||
, resume_data(0)
|
, resume_data(0)
|
||||||
, storage_mode(storage_mode_sparse)
|
, storage_mode(storage_mode_sparse)
|
||||||
, paused(true)
|
, paused(true)
|
||||||
, auto_managed(true)
|
, auto_managed(false)
|
||||||
, duplicate_is_error(false)
|
, duplicate_is_error(false)
|
||||||
, storage(sc)
|
, storage(sc)
|
||||||
, userdata(0)
|
, userdata(0)
|
||||||
|
|
|
@ -321,7 +321,7 @@ namespace libtorrent
|
||||||
int rename_file_impl(int index, std::string const& new_filename)
|
int rename_file_impl(int index, std::string const& new_filename)
|
||||||
{ return m_storage->rename_file(index, new_filename); }
|
{ return m_storage->rename_file(index, new_filename); }
|
||||||
|
|
||||||
bool move_storage_impl(fs::path const& save_path);
|
int move_storage_impl(fs::path const& save_path);
|
||||||
|
|
||||||
int allocate_slot_for_piece(int piece_index);
|
int allocate_slot_for_piece(int piece_index);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
|
@ -164,6 +164,8 @@ namespace libtorrent
|
||||||
void abort();
|
void abort();
|
||||||
bool is_aborted() const { return m_abort; }
|
bool is_aborted() const { return m_abort; }
|
||||||
|
|
||||||
|
torrent_status::state_t state() const { return m_state; }
|
||||||
|
|
||||||
session_settings const& settings() const;
|
session_settings const& settings() const;
|
||||||
|
|
||||||
aux::session_impl& session() { return m_ses; }
|
aux::session_impl& session() { return m_ses; }
|
||||||
|
|
|
@ -3270,11 +3270,21 @@ namespace libtorrent
|
||||||
|
|
||||||
// this means the connection just succeeded
|
// this means the connection just succeeded
|
||||||
|
|
||||||
|
TORRENT_ASSERT(m_socket);
|
||||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
|
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
|
||||||
(*m_ses.m_logger) << time_now_string() << " COMPLETED: " << m_remote.address().to_string()
|
(*m_ses.m_logger) << time_now_string() << " COMPLETED: " << m_remote.address().to_string()
|
||||||
<< " rtt = " << m_rtt << "\n";
|
<< " rtt = " << m_rtt << "\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
error_code ec;
|
||||||
|
if (m_remote == m_socket->local_endpoint(ec))
|
||||||
|
{
|
||||||
|
// if the remote endpoint is the same as the local endpoint, we're connected
|
||||||
|
// to ourselves
|
||||||
|
disconnect("connected to ourselves", 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_remote.address().is_v4())
|
if (m_remote.address().is_v4())
|
||||||
{
|
{
|
||||||
error_code ec;
|
error_code ec;
|
||||||
|
|
|
@ -459,14 +459,19 @@ namespace libtorrent
|
||||||
pinged = true;
|
pinged = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// this timeout has to be customizable!
|
// if the number of peers is growing large
|
||||||
// don't remove banned peers, they should
|
// we need to start weeding.
|
||||||
// remain banned
|
// don't remove peers we're connected to
|
||||||
|
// don't remove peers we've never even tried
|
||||||
|
// don't remove banned peers unless they're 2
|
||||||
|
// hours old. They should remain banned for
|
||||||
|
// at least that long
|
||||||
|
// don't remove peers that we still can try again
|
||||||
if (pe.connection == 0
|
if (pe.connection == 0
|
||||||
&& pe.connected != min_time()
|
&& pe.connected != min_time()
|
||||||
&& !pe.banned
|
&& (!pe.banned || now - pe.connected > hours(2))
|
||||||
&& (now - pe.connected > minutes(120)
|
&& !is_connect_candidate(pe, finished)
|
||||||
|| m_peers.size() >= m_torrent->settings().max_peerlist_size * 0.9))
|
&& m_peers.size() >= m_torrent->settings().max_peerlist_size * 0.9)
|
||||||
{
|
{
|
||||||
erase_peer(m_round_robin++);
|
erase_peer(m_round_robin++);
|
||||||
continue;
|
continue;
|
||||||
|
@ -474,14 +479,13 @@ namespace libtorrent
|
||||||
|
|
||||||
++m_round_robin;
|
++m_round_robin;
|
||||||
|
|
||||||
|
|
||||||
if (!is_connect_candidate(pe, finished)) continue;
|
if (!is_connect_candidate(pe, finished)) continue;
|
||||||
|
|
||||||
if (candidate != m_peers.end()
|
if (candidate != m_peers.end()
|
||||||
&& !compare_peer(candidate->second, pe, external_ip)) continue;
|
&& !compare_peer(candidate->second, pe, external_ip)) continue;
|
||||||
|
|
||||||
if (now - pe.connected <
|
if (now - pe.connected <
|
||||||
seconds(pe.failcount * min_reconnect_time))
|
seconds((pe.failcount + 1) * min_reconnect_time))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
candidate = current;
|
candidate = current;
|
||||||
|
@ -614,6 +618,35 @@ namespace libtorrent
|
||||||
|
|
||||||
if (i->second.connection != 0)
|
if (i->second.connection != 0)
|
||||||
{
|
{
|
||||||
|
boost::shared_ptr<socket_type> other_socket
|
||||||
|
= i->second.connection->get_socket();
|
||||||
|
boost::shared_ptr<socket_type> this_socket
|
||||||
|
= c.get_socket();
|
||||||
|
|
||||||
|
error_code ec1;
|
||||||
|
error_code ec2;
|
||||||
|
bool self_connection =
|
||||||
|
other_socket->remote_endpoint(ec2) == this_socket->local_endpoint(ec1)
|
||||||
|
|| other_socket->local_endpoint(ec2) == this_socket->remote_endpoint(ec1);
|
||||||
|
|
||||||
|
if (ec1)
|
||||||
|
{
|
||||||
|
c.disconnect(ec1.message().c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ec2)
|
||||||
|
{
|
||||||
|
i->second.connection->disconnect(ec2.message().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self_connection)
|
||||||
|
{
|
||||||
|
c.disconnect("connected to ourselves", 1);
|
||||||
|
i->second.connection->disconnect("connected to ourselves", 1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
TORRENT_ASSERT(i->second.connection != &c);
|
TORRENT_ASSERT(i->second.connection != &c);
|
||||||
// the new connection is a local (outgoing) connection
|
// the new connection is a local (outgoing) connection
|
||||||
// or the current one is already connected
|
// or the current one is already connected
|
||||||
|
|
|
@ -1308,6 +1308,11 @@ namespace aux {
|
||||||
int num_downloaders = settings().active_downloads;
|
int num_downloaders = settings().active_downloads;
|
||||||
int num_seeds = settings().active_seeds;
|
int num_seeds = settings().active_seeds;
|
||||||
|
|
||||||
|
if (num_downloaders == -1)
|
||||||
|
num_downloaders = (std::numeric_limits<int>::max)();
|
||||||
|
if (num_seeds == -1)
|
||||||
|
num_seeds = (std::numeric_limits<int>::max)();
|
||||||
|
|
||||||
for (torrent_map::iterator i = m_torrents.begin()
|
for (torrent_map::iterator i = m_torrents.begin()
|
||||||
, end(m_torrents.end()); i != end; ++i)
|
, end(m_torrents.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
|
@ -1327,14 +1332,8 @@ namespace aux {
|
||||||
// this is not an auto managed torrent,
|
// this is not an auto managed torrent,
|
||||||
// if it's running, decrease the respective
|
// if it's running, decrease the respective
|
||||||
// counters.
|
// counters.
|
||||||
if (t->is_finished())
|
--num_downloaders;
|
||||||
{
|
--num_seeds;
|
||||||
--num_seeds;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
--num_downloaders;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1358,9 +1357,12 @@ namespace aux {
|
||||||
, end(downloaders.end()); i != end; ++i)
|
, end(downloaders.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
torrent* t = *i;
|
torrent* t = *i;
|
||||||
if (num_downloaders > 0)
|
if (num_downloaders > 0
|
||||||
|
&& t->state() != torrent_status::queued_for_checking
|
||||||
|
&& t->state() != torrent_status::checking_files)
|
||||||
{
|
{
|
||||||
--num_downloaders;
|
--num_downloaders;
|
||||||
|
--num_seeds;
|
||||||
if (t->is_paused()) t->resume();
|
if (t->is_paused()) t->resume();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1375,6 +1377,7 @@ namespace aux {
|
||||||
torrent* t = *i;
|
torrent* t = *i;
|
||||||
if (num_seeds > 0)
|
if (num_seeds > 0)
|
||||||
{
|
{
|
||||||
|
--num_downloaders;
|
||||||
--num_seeds;
|
--num_seeds;
|
||||||
if (t->is_paused()) t->resume();
|
if (t->is_paused()) t->resume();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1409,14 +1409,14 @@ namespace libtorrent
|
||||||
return m_storage->hash_for_slot(slot, ph, m_files.piece_size(piece));
|
return m_storage->hash_for_slot(slot, ph, m_files.piece_size(piece));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool piece_manager::move_storage_impl(fs::path const& save_path)
|
int piece_manager::move_storage_impl(fs::path const& save_path)
|
||||||
{
|
{
|
||||||
if (m_storage->move_storage(save_path))
|
if (m_storage->move_storage(save_path))
|
||||||
{
|
{
|
||||||
m_save_path = fs::complete(save_path);
|
m_save_path = fs::complete(save_path);
|
||||||
return true;
|
return 0;
|
||||||
}
|
}
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void piece_manager::write_resume_data(entry& rd) const
|
void piece_manager::write_resume_data(entry& rd) const
|
||||||
|
|
|
@ -632,6 +632,7 @@ namespace libtorrent
|
||||||
// assume that we don't have anything
|
// assume that we don't have anything
|
||||||
m_files_checked = false;
|
m_files_checked = false;
|
||||||
m_state = torrent_status::queued_for_checking;
|
m_state = torrent_status::queued_for_checking;
|
||||||
|
set_queue_position((std::numeric_limits<int>::max)());
|
||||||
|
|
||||||
m_resume_data = entry();
|
m_resume_data = entry();
|
||||||
m_storage->async_check_fastresume(&m_resume_data
|
m_storage->async_check_fastresume(&m_resume_data
|
||||||
|
@ -3249,6 +3250,7 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
alerts().post_alert(storage_moved_alert(get_handle(), j.str));
|
alerts().post_alert(storage_moved_alert(get_handle(), j.str));
|
||||||
}
|
}
|
||||||
|
m_save_path = j.str;
|
||||||
}
|
}
|
||||||
|
|
||||||
piece_manager& torrent::filesystem()
|
piece_manager& torrent::filesystem()
|
||||||
|
@ -3392,11 +3394,23 @@ namespace libtorrent
|
||||||
|
|
||||||
void torrent::set_queue_position(int p)
|
void torrent::set_queue_position(int p)
|
||||||
{
|
{
|
||||||
|
TORRENT_ASSERT((p == -1) == is_finished());
|
||||||
if (is_finished() && p != -1) return;
|
if (is_finished() && p != -1) return;
|
||||||
if (p == m_sequence_number) return;
|
if (p == m_sequence_number) return;
|
||||||
|
|
||||||
session_impl::torrent_map& torrents = m_ses.m_torrents;
|
session_impl::torrent_map& torrents = m_ses.m_torrents;
|
||||||
if (p < 0)
|
if (p >= 0 && m_sequence_number == -1)
|
||||||
|
{
|
||||||
|
int max_seq = 0;
|
||||||
|
for (session_impl::torrent_map::iterator i = torrents.begin()
|
||||||
|
, end(torrents.end()); i != end; ++i)
|
||||||
|
{
|
||||||
|
torrent* t = i->second.get();
|
||||||
|
if (t->m_sequence_number > max_seq) max_seq = t->m_sequence_number;
|
||||||
|
}
|
||||||
|
m_sequence_number = (std::min)(max_seq + 1, p);
|
||||||
|
}
|
||||||
|
else if (p < 0)
|
||||||
{
|
{
|
||||||
for (session_impl::torrent_map::iterator i = torrents.begin()
|
for (session_impl::torrent_map::iterator i = torrents.begin()
|
||||||
, end(torrents.end()); i != end; ++i)
|
, end(torrents.end()); i != end; ++i)
|
||||||
|
@ -3435,8 +3449,8 @@ namespace libtorrent
|
||||||
if (t == this) continue;
|
if (t == this) continue;
|
||||||
|
|
||||||
if (pos <= p
|
if (pos <= p
|
||||||
&& pos > m_sequence_number
|
&& pos > m_sequence_number
|
||||||
&& pos != -1)
|
&& pos != -1)
|
||||||
--t->m_sequence_number;
|
--t->m_sequence_number;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue