From 4ddedc6a21be13c8249652a1a1b808aee01bc983 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 26 Aug 2014 04:26:16 +0000 Subject: [PATCH] add extension hook on sending payload --- include/libtorrent/extensions.hpp | 7 +++++-- src/peer_connection.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/extensions.hpp b/include/libtorrent/extensions.hpp index 8e0f2302f..8e7f0cf9b 100644 --- a/include/libtorrent/extensions.hpp +++ b/include/libtorrent/extensions.hpp @@ -181,7 +181,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #include "libtorrent/sha1_hash.hpp" // for sha1_hash #include "libtorrent/error_code.hpp" -#include "libtorrent/torrent_peer.hpp" // for torrent_peer namespace libtorrent { @@ -198,8 +197,8 @@ namespace libtorrent class alert; struct torrent_plugin; class torrent; - struct add_torrent_params; struct torrent_peer; + struct add_torrent_params; // this is the base class for a session plugin. One primary feature // is that it is notified of all torrents that are added to the session, @@ -415,6 +414,10 @@ namespace libtorrent // called after a choke message has been sent to the peer virtual void sent_unchoke() {} + // called after piece data has been sent to the peer + // this can be used for stats book keeping + virtual void sent_payload(int /* bytes */) {} + // called when libtorrent think this peer should be disconnected. // if the plugin returns false, the peer will not be disconnected. virtual bool can_disconnect(error_code const& /*ec*/) { return true; } diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index a0efd5517..54853ca6f 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1148,6 +1148,16 @@ namespace libtorrent void peer_connection::sent_bytes(int bytes_payload, int bytes_protocol) { m_statistics.sent_bytes(bytes_payload, bytes_protocol); +#ifndef TORRENT_DISABLE_EXTENSIONS + if (bytes_payload) + { + for (extension_list_t::iterator i = m_extensions.begin() + , end(m_extensions.end()); i != end; ++i) + { + (*i)->sent_payload(bytes_payload); + } + } +#endif if (m_ignore_stats) return; boost::shared_ptr t = m_torrent.lock(); if (!t) return;