added alerts for added and removed torrents

This commit is contained in:
Arvid Norberg 2011-02-01 03:25:40 +00:00
parent 77a4ac782a
commit 6692f05655
6 changed files with 105 additions and 27 deletions

View File

@ -1,3 +1,4 @@
* added alerts for added and removed torrents
* expanded plugin interface to support session wide states
* made the metadata block requesting algorithm more robust against hash check failures
* support a separate option to use proxies for peers or not

View File

@ -90,6 +90,15 @@ void bind_alert()
.def_readonly("url", &tracker_alert::url)
;
class_<torrent_added_alert, bases<torrent_alert>, noncopyable>(
"torrent_added_alert", no_init)
;
class_<torrent_removed_alert, bases<torrent_alert>, noncopyable>(
"torrent_removed_alert", no_init)
.def_readonly("info_hash", &torrent_removed_alert::info_hash)
;
class_<read_piece_alert, bases<torrent_alert>, noncopyable>(
"read_piece_alert", 0, no_init)
.add_property("buffer", get_buffer)

View File

@ -5903,6 +5903,37 @@ There's also a base class for all alerts referring to tracker events::
The specific alerts are:
torrent_added_alert
-------------------
The ``torrent_added_alert`` is posted once every time a torrent is added.
It doesn't contain any members of its own, but inherits the torrent handle
from its base class.
It's posted when the ``status_notification`` bit is set in the alert mask.
::
struct torrent_added_alert: torrent_alert
{
// ...
};
torrent_removed_alert
---------------------
The ``torrent_removed_alert`` is posted whenever a torrent is removed. Since
the torrent handle in its baseclass will always be invalid (since the torrent
is already removed) it has the info hash as a member, to identify it.
It's posted when the ``status_notification`` bit is set in the alert mask.
::
struct torrent_removed_alert: torrent_alert
{
// ...
sha1_hash info_hash;
};
read_piece_alert
----------------

View File

@ -107,6 +107,30 @@ namespace libtorrent
virtual int category() const { return static_category; } \
virtual char const* what() const { return #name; }
struct TORRENT_EXPORT torrent_added_alert: torrent_alert
{
torrent_added_alert(torrent_handle const& h)
: torrent_alert(h)
{}
TORRENT_DEFINE_ALERT(torrent_added_alert);
const static int static_category = alert::status_notification;
virtual std::string message() const;
};
struct TORRENT_EXPORT torrent_removed_alert: torrent_alert
{
torrent_removed_alert(torrent_handle const& h, sha1_hash const& ih)
: torrent_alert(h)
, info_hash(ih)
{}
TORRENT_DEFINE_ALERT(torrent_removed_alert);
const static int static_category = alert::status_notification;
virtual std::string message() const;
sha1_hash info_hash;
};
struct TORRENT_EXPORT read_piece_alert: torrent_alert
{
read_piece_alert(torrent_handle const& h

View File

@ -535,7 +535,16 @@ namespace libtorrent {
snprintf(msg, sizeof(msg), " ERROR: %s", error.message().c_str());
return torrent_alert::message() + msg;
}
std::string torrent_added_alert::message() const
{
return torrent_alert::message() + " added";
}
std::string torrent_removed_alert::message() const
{
return torrent_alert::message() + " removed";
}
} // namespace libtorrent

View File

@ -3703,6 +3703,9 @@ namespace aux {
m_uuids.insert(std::make_pair(params.uuid.empty()
? params.url : params.uuid, torrent_ptr));
if (m_alerts.should_post<torrent_added_alert>())
m_alerts.post_alert(torrent_added_alert(torrent_ptr->get_handle()));
return torrent_handle(torrent_ptr);
}
@ -3778,43 +3781,44 @@ namespace aux {
i = m_torrents.find(urlhash);
}
if (i != m_torrents.end())
{
torrent& t = *i->second;
if (options & session::delete_files)
t.delete_files();
t.abort();
if (i == m_torrents.end()) return;
torrent& t = *i->second;
if (options & session::delete_files)
t.delete_files();
t.abort();
if (m_alerts.should_post<torrent_removed_alert>())
m_alerts.post_alert(torrent_removed_alert(t.get_handle(), t.info_hash()));
#ifdef TORRENT_DEBUG
sha1_hash i_hash = t.torrent_file().info_hash();
sha1_hash i_hash = t.torrent_file().info_hash();
#endif
#ifndef TORRENT_DISABLE_DHT
if (i == m_next_dht_torrent)
++m_next_dht_torrent;
if (i == m_next_dht_torrent)
++m_next_dht_torrent;
#endif
if (i == m_next_lsd_torrent)
++m_next_lsd_torrent;
if (i == m_next_connect_torrent)
++m_next_connect_torrent;
if (i == m_next_lsd_torrent)
++m_next_lsd_torrent;
if (i == m_next_connect_torrent)
++m_next_connect_torrent;
t.set_queue_position(-1);
m_torrents.erase(i);
t.set_queue_position(-1);
m_torrents.erase(i);
#ifndef TORRENT_DISABLE_DHT
if (m_next_dht_torrent == m_torrents.end())
m_next_dht_torrent = m_torrents.begin();
if (m_next_dht_torrent == m_torrents.end())
m_next_dht_torrent = m_torrents.begin();
#endif
if (m_next_lsd_torrent == m_torrents.end())
m_next_lsd_torrent = m_torrents.begin();
if (m_next_connect_torrent == m_torrents.end())
m_next_connect_torrent = m_torrents.begin();
if (m_next_lsd_torrent == m_torrents.end())
m_next_lsd_torrent = m_torrents.begin();
if (m_next_connect_torrent == m_torrents.end())
m_next_connect_torrent = m_torrents.begin();
std::list<boost::shared_ptr<torrent> >::iterator k
= std::find(m_queued_for_checking.begin(), m_queued_for_checking.end(), tptr);
if (k != m_queued_for_checking.end()) m_queued_for_checking.erase(k);
TORRENT_ASSERT(m_torrents.find(i_hash) == m_torrents.end());
return;
}
std::list<boost::shared_ptr<torrent> >::iterator k
= std::find(m_queued_for_checking.begin(), m_queued_for_checking.end(), tptr);
if (k != m_queued_for_checking.end()) m_queued_for_checking.erase(k);
TORRENT_ASSERT(m_torrents.find(i_hash) == m_torrents.end());
}
bool session_impl::listen_on(