forked from premiere/premiere-libtorrent
move some initialization of torrent from start() into the constructor
This commit is contained in:
parent
24d08cdf82
commit
7087a16b36
|
@ -327,7 +327,7 @@ namespace libtorrent {
|
||||||
bool is_deleted() const { return m_deleted; }
|
bool is_deleted() const { return m_deleted; }
|
||||||
|
|
||||||
// starts the announce timer
|
// starts the announce timer
|
||||||
void start(add_torrent_params const& p);
|
void start();
|
||||||
|
|
||||||
void added()
|
void added()
|
||||||
{
|
{
|
||||||
|
@ -1305,9 +1305,8 @@ namespace libtorrent {
|
||||||
// the piece has had its hash verified. This
|
// the piece has had its hash verified. This
|
||||||
// is only used in seed mode (when m_seed_mode
|
// is only used in seed mode (when m_seed_mode
|
||||||
// is true)
|
// is true)
|
||||||
|
|
||||||
// TODO: These two bitfields should probably be coalesced into one
|
|
||||||
typed_bitfield<piece_index_t> m_verified;
|
typed_bitfield<piece_index_t> m_verified;
|
||||||
|
|
||||||
// this means there is an outstanding, async, operation
|
// this means there is an outstanding, async, operation
|
||||||
// to verify each piece that has a 1
|
// to verify each piece that has a 1
|
||||||
typed_bitfield<piece_index_t> m_verifying;
|
typed_bitfield<piece_index_t> m_verifying;
|
||||||
|
@ -1331,8 +1330,8 @@ namespace libtorrent {
|
||||||
// the posix time this torrent was added and when
|
// the posix time this torrent was added and when
|
||||||
// it was completed. If the torrent isn't yet
|
// it was completed. If the torrent isn't yet
|
||||||
// completed, m_completed_time is 0
|
// completed, m_completed_time is 0
|
||||||
std::time_t m_added_time = time(nullptr);
|
std::time_t m_added_time;
|
||||||
std::time_t m_completed_time = 0;
|
std::time_t m_completed_time;
|
||||||
|
|
||||||
// this was the last time _we_ saw a seed in this swarm
|
// this was the last time _we_ saw a seed in this swarm
|
||||||
std::time_t m_last_seen_complete = 0;
|
std::time_t m_last_seen_complete = 0;
|
||||||
|
|
|
@ -4779,7 +4779,7 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
torrent_ptr->set_ip_filter(m_ip_filter);
|
torrent_ptr->set_ip_filter(m_ip_filter);
|
||||||
torrent_ptr->start(params);
|
torrent_ptr->start();
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_EXTENSIONS
|
#ifndef TORRENT_DISABLE_EXTENSIONS
|
||||||
for (auto& ext : params.extensions)
|
for (auto& ext : params.extensions)
|
||||||
|
|
127
src/torrent.cpp
127
src/torrent.cpp
|
@ -177,6 +177,8 @@ namespace libtorrent {
|
||||||
#endif
|
#endif
|
||||||
, m_stats_counters(ses.stats_counters())
|
, m_stats_counters(ses.stats_counters())
|
||||||
, m_storage_constructor(p.storage)
|
, m_storage_constructor(p.storage)
|
||||||
|
, m_added_time(p.added_time ? p.added_time : std::time(nullptr))
|
||||||
|
, m_completed_time(p.completed_time)
|
||||||
, m_info_hash(info_hash)
|
, m_info_hash(info_hash)
|
||||||
, m_error_file(torrent_status::error_file_none)
|
, m_error_file(torrent_status::error_file_none)
|
||||||
, m_sequence_number(-1)
|
, m_sequence_number(-1)
|
||||||
|
@ -187,10 +189,10 @@ namespace libtorrent {
|
||||||
, m_storage_mode(p.storage_mode)
|
, m_storage_mode(p.storage_mode)
|
||||||
, m_announcing(false)
|
, m_announcing(false)
|
||||||
, m_added(false)
|
, m_added(false)
|
||||||
, m_sequential_download(false)
|
, m_sequential_download(p.flags & torrent_flags::sequential_download)
|
||||||
, m_auto_sequential(false)
|
, m_auto_sequential(false)
|
||||||
, m_seed_mode(false)
|
, m_seed_mode(false)
|
||||||
, m_super_seeding(false)
|
, m_super_seeding(p.flags & torrent_flags::super_seeding)
|
||||||
, m_stop_when_ready(p.flags & torrent_flags::stop_when_ready)
|
, m_stop_when_ready(p.flags & torrent_flags::stop_when_ready)
|
||||||
, m_need_save_resume_data(p.flags & torrent_flags::need_save_resume)
|
, m_need_save_resume_data(p.flags & torrent_flags::need_save_resume)
|
||||||
, m_max_uploads((1 << 24) - 1)
|
, m_max_uploads((1 << 24) - 1)
|
||||||
|
@ -374,10 +376,18 @@ namespace libtorrent {
|
||||||
m_finished_time = seconds(p.finished_time);
|
m_finished_time = seconds(p.finished_time);
|
||||||
m_seeding_time = seconds(p.seeding_time);
|
m_seeding_time = seconds(p.seeding_time);
|
||||||
|
|
||||||
m_added_time = p.added_time ? p.added_time : std::time(nullptr);
|
|
||||||
m_completed_time = p.completed_time;
|
|
||||||
if (m_completed_time != 0 && m_completed_time < m_added_time)
|
if (m_completed_time != 0 && m_completed_time < m_added_time)
|
||||||
m_completed_time = m_added_time;
|
m_completed_time = m_added_time;
|
||||||
|
|
||||||
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
|
if (!m_name && !m_url.empty()) m_name.reset(new std::string(m_url));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (valid_metadata())
|
||||||
|
{
|
||||||
|
inc_stats_counter(counters::num_total_pieces_added
|
||||||
|
, m_torrent_file->num_pieces());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent::inc_stats_counter(int c, int value)
|
void torrent::inc_stats_counter(int c, int value)
|
||||||
|
@ -583,7 +593,7 @@ namespace libtorrent {
|
||||||
m_verified.set_bit(piece);
|
m_verified.set_bit(piece);
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent::start(add_torrent_params const& p)
|
void torrent::start()
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(is_single_thread());
|
TORRENT_ASSERT(is_single_thread());
|
||||||
TORRENT_ASSERT(m_was_started == false);
|
TORRENT_ASSERT(m_was_started == false);
|
||||||
|
@ -591,18 +601,33 @@ namespace libtorrent {
|
||||||
m_was_started = true;
|
m_was_started = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
// Some of these calls may log to the torrent debug log, which requires a
|
||||||
if (m_add_torrent_params
|
// call to get_handle(), which requires the torrent object to be fully
|
||||||
&& m_add_torrent_params->internal_resume_data_error
|
// constructed, as it relies on get_shared_from_this()
|
||||||
&& m_ses.alerts().should_post<fastresume_rejected_alert>())
|
if (m_add_torrent_params)
|
||||||
{
|
{
|
||||||
m_ses.alerts().emplace_alert<fastresume_rejected_alert>(get_handle()
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
, m_add_torrent_params->internal_resume_data_error, ""
|
if (m_add_torrent_params->internal_resume_data_error
|
||||||
, operation_t::unknown);
|
&& m_ses.alerts().should_post<fastresume_rejected_alert>())
|
||||||
}
|
{
|
||||||
|
m_ses.alerts().emplace_alert<fastresume_rejected_alert>(get_handle()
|
||||||
|
, m_add_torrent_params->internal_resume_data_error, ""
|
||||||
|
, operation_t::unknown);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO: 3 why isn't this done in the constructor?
|
add_torrent_params const& p = *m_add_torrent_params;
|
||||||
|
|
||||||
|
set_max_uploads(p.max_uploads, false);
|
||||||
|
set_max_connections(p.max_connections, false);
|
||||||
|
set_limit_impl(p.upload_limit, peer_connection::upload_channel, false);
|
||||||
|
set_limit_impl(p.download_limit, peer_connection::download_channel, false);
|
||||||
|
|
||||||
|
for (auto const& peer : p.peers)
|
||||||
|
{
|
||||||
|
add_peer(peer, peer_info::resume_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
if (should_log())
|
if (should_log())
|
||||||
|
@ -611,64 +636,27 @@ namespace libtorrent {
|
||||||
"upload-limit: %d download-limit: %d flags: %s%s%s%s%s%s%s%s%s%s%s "
|
"upload-limit: %d download-limit: %d flags: %s%s%s%s%s%s%s%s%s%s%s "
|
||||||
"save-path: %s"
|
"save-path: %s"
|
||||||
, torrent_file().name().c_str()
|
, torrent_file().name().c_str()
|
||||||
, p.max_uploads
|
, int(m_max_uploads)
|
||||||
, p.max_connections
|
, int(m_max_connections)
|
||||||
, p.upload_limit
|
, upload_limit()
|
||||||
, p.download_limit
|
, download_limit()
|
||||||
, (p.flags & torrent_flags::seed_mode)
|
, m_seed_mode ? "seed-mode " : ""
|
||||||
? "seed-mode " : ""
|
, m_upload_mode ? "upload-mode " : ""
|
||||||
, (p.flags & torrent_flags::upload_mode)
|
, m_share_mode ? "share-mode " : ""
|
||||||
? "upload-mode " : ""
|
, m_apply_ip_filter ? "apply-ip-filter " : ""
|
||||||
, (p.flags & torrent_flags::share_mode)
|
, m_paused ? "paused " : ""
|
||||||
? "share-mode " : ""
|
, m_auto_managed ? "auto-managed " : ""
|
||||||
, (p.flags & torrent_flags::apply_ip_filter)
|
, m_state_subscription ? "update-subscribe " : ""
|
||||||
? "apply-ip-filter " : ""
|
, m_super_seeding ? "super-seeding " : ""
|
||||||
, (p.flags & torrent_flags::paused)
|
, m_sequential_download ? "sequential-download " : ""
|
||||||
? "paused " : ""
|
, (m_add_torrent_params && m_add_torrent_params->flags & torrent_flags::override_trackers)
|
||||||
, (p.flags & torrent_flags::auto_managed)
|
|
||||||
? "auto-managed " : ""
|
|
||||||
, (p.flags & torrent_flags::update_subscribe)
|
|
||||||
? "update-subscribe " : ""
|
|
||||||
, (p.flags & torrent_flags::super_seeding)
|
|
||||||
? "super-seeding " : ""
|
|
||||||
, (p.flags & torrent_flags::sequential_download)
|
|
||||||
? "sequential-download " : ""
|
|
||||||
, (p.flags & torrent_flags::override_trackers)
|
|
||||||
? "override-trackers" : ""
|
? "override-trackers" : ""
|
||||||
, (p.flags & torrent_flags::override_web_seeds)
|
, (m_add_torrent_params && m_add_torrent_params->flags & torrent_flags::override_web_seeds)
|
||||||
? "override-web-seeds " : ""
|
? "override-web-seeds " : ""
|
||||||
, p.save_path.c_str()
|
, m_save_path.c_str()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (p.flags & torrent_flags::sequential_download)
|
|
||||||
m_sequential_download = true;
|
|
||||||
|
|
||||||
if (p.flags & torrent_flags::super_seeding)
|
|
||||||
{
|
|
||||||
m_super_seeding = true;
|
|
||||||
set_need_save_resume();
|
|
||||||
}
|
|
||||||
|
|
||||||
set_max_uploads(p.max_uploads, false);
|
|
||||||
set_max_connections(p.max_connections, false);
|
|
||||||
set_limit_impl(p.upload_limit, peer_connection::upload_channel, false);
|
|
||||||
set_limit_impl(p.download_limit, peer_connection::download_channel, false);
|
|
||||||
|
|
||||||
for (auto const& peer : p.peers)
|
|
||||||
{
|
|
||||||
add_peer(peer, peer_info::resume_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
|
||||||
if (!m_name && !m_url.empty()) m_name.reset(new std::string(m_url));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (valid_metadata())
|
|
||||||
{
|
|
||||||
inc_stats_counter(counters::num_total_pieces_added
|
|
||||||
, m_torrent_file->num_pieces());
|
|
||||||
}
|
|
||||||
|
|
||||||
update_gauge();
|
update_gauge();
|
||||||
|
|
||||||
|
@ -8078,10 +8066,11 @@ namespace libtorrent {
|
||||||
TORRENT_ASSERT(limit >= -1);
|
TORRENT_ASSERT(limit >= -1);
|
||||||
if (limit <= 0) limit = 0;
|
if (limit <= 0) limit = 0;
|
||||||
|
|
||||||
if (m_peer_class == peer_class_t{0} && limit == 0) return;
|
|
||||||
|
|
||||||
if (m_peer_class == peer_class_t{0})
|
if (m_peer_class == peer_class_t{0})
|
||||||
|
{
|
||||||
|
if (limit == 0) return;
|
||||||
setup_peer_class();
|
setup_peer_class();
|
||||||
|
}
|
||||||
|
|
||||||
struct peer_class* tpc = m_ses.peer_classes().at(m_peer_class);
|
struct peer_class* tpc = m_ses.peer_classes().at(m_peer_class);
|
||||||
TORRENT_ASSERT(tpc);
|
TORRENT_ASSERT(tpc);
|
||||||
|
|
Loading…
Reference in New Issue