introduced a new alert torrent_update_alert, for when a torrent_handle changes info-hash
This commit is contained in:
parent
ef87b3ada9
commit
360c6a6e16
|
@ -521,4 +521,10 @@ void bind_alert()
|
|||
.def_readonly("error", &add_torrent_alert::error)
|
||||
.add_property("params", &get_params)
|
||||
;
|
||||
|
||||
class_<torrent_update_alert, bases<torrent_alert>, noncopyable>(
|
||||
"torrent_update_alert", no_init)
|
||||
.def_readonly("old_ih", &torrent_update_alert::old_ih)
|
||||
.def_readonly("new_ih", &torrent_update_alert::new_ih)
|
||||
;
|
||||
}
|
||||
|
|
|
@ -463,6 +463,12 @@ the torrent will be stopped and the torrent error state (``torrent_status::error
|
|||
will indicate what went wrong. The ``url`` may refer to a magnet link or a regular
|
||||
http URL.
|
||||
|
||||
If it refers to an HTTP URL, the info-hash for the added torrent will not be the
|
||||
true info-hash of the .torrent. Instead a placeholder, unique, info-hash is used
|
||||
which is later updated once the .torrent file has been downloaded.
|
||||
|
||||
Once the info-hash change happens, a torrent_update_alert_ is posted.
|
||||
|
||||
``dht_nodes`` is a list of hostname and port pairs, representing DHT nodes to be
|
||||
added to the session (if DHT is enabled). The hostname may be an IP address.
|
||||
|
||||
|
@ -7702,6 +7708,26 @@ this message was posted. Note that you can map a torrent status to a specific to
|
|||
via its ``handle`` member. The receiving end is suggested to have all torrents sorted
|
||||
by the ``torrent_handle`` or hashed by it, for efficient updates.
|
||||
|
||||
torrent_update_alert
|
||||
--------------------
|
||||
|
||||
When a torrent changes its info-hash, this alert is posted. This only happens in very
|
||||
specific cases. For instance, when a torrent is downloaded from a URL, the true info
|
||||
hash is not known immediately. First the .torrent file must be downloaded and parsed.
|
||||
|
||||
Once this download completes, the ``torrent_update_alert`` is posted to notify the client
|
||||
of the info-hash changing.
|
||||
|
||||
::
|
||||
|
||||
struct torrent_update_alert: torrent_alert
|
||||
{
|
||||
// ...
|
||||
sha1_hash old_ih;
|
||||
sha1_hash new_ih;
|
||||
};
|
||||
|
||||
``old_ih`` and ``new_ih`` are the previous and new info-hash for the torrent, respectively.
|
||||
|
||||
alert dispatcher
|
||||
================
|
||||
|
|
|
@ -1343,6 +1343,25 @@ namespace libtorrent
|
|||
std::vector<torrent_status> status;
|
||||
};
|
||||
|
||||
struct TORRENT_EXPORT torrent_update_alert : torrent_alert
|
||||
{
|
||||
torrent_update_alert(torrent_handle h, sha1_hash const& old_hash, sha1_hash const& new_hash)
|
||||
: torrent_alert(h)
|
||||
, old_ih(old_hash)
|
||||
, new_ih(new_hash)
|
||||
{}
|
||||
|
||||
TORRENT_DEFINE_ALERT(torrent_update_alert);
|
||||
|
||||
const static int static_category = alert::status_notification;
|
||||
virtual std::string message() const;
|
||||
virtual bool discardable() const { return false; }
|
||||
|
||||
sha1_hash old_ih;
|
||||
sha1_hash new_ih;
|
||||
};
|
||||
|
||||
|
||||
#undef TORRENT_DEFINE_ALERT
|
||||
|
||||
}
|
||||
|
|
|
@ -479,5 +479,14 @@ namespace libtorrent {
|
|||
return msg;
|
||||
}
|
||||
|
||||
std::string torrent_update_alert::message() const
|
||||
{
|
||||
char msg[200];
|
||||
snprintf(msg, sizeof(msg), " torrent changed info-hash from: %s to %s"
|
||||
, to_hex(old_ih.to_string()).c_str()
|
||||
, to_hex(new_ih.to_string()).c_str());
|
||||
return torrent_alert::message() + msg;
|
||||
}
|
||||
|
||||
} // namespace libtorrent
|
||||
|
||||
|
|
|
@ -725,6 +725,9 @@ namespace libtorrent
|
|||
|
||||
m_ses.remove_torrent_impl(me, 0);
|
||||
|
||||
if (alerts().should_post<torrent_update_alert>())
|
||||
alerts().post_alert(torrent_update_alert(get_handle(), info_hash(), tf->info_hash()));
|
||||
|
||||
m_torrent_file = tf;
|
||||
|
||||
// now, we might already have this torrent in the session.
|
||||
|
|
Loading…
Reference in New Issue