From 5b89c3f5f9353c1a30a2fe72ff75f0243d43bea1 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 12 May 2014 07:28:34 +0000 Subject: [PATCH] merged some of steven siloti's changes. expose optimistic unchoke logic to plugins --- ChangeLog | 1 + ed25519/src/ed25519.h | 10 ++++++++++ include/libtorrent/extensions.hpp | 14 ++++++++++++++ src/bt_peer_connection.cpp | 8 ++++++++ src/kademlia/item.cpp | 1 + src/session_impl.cpp | 9 +++++++++ 6 files changed, 43 insertions(+) diff --git a/ChangeLog b/ChangeLog index 80e2ca869..5535102b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 1.0 release + * expose optimistic unchoke logic to plugins * fix issue with large UDP packets on windows * remove set_ratio() feature * improve piece_deadline/streaming diff --git a/ed25519/src/ed25519.h b/ed25519/src/ed25519.h index 1f60ad352..83d12ed61 100644 --- a/ed25519/src/ed25519.h +++ b/ed25519/src/ed25519.h @@ -5,6 +5,16 @@ #include "libtorrent/config.hpp" // for TORRENT_EXPORT +enum +{ + ed25519_seed_size = 32, + ed25519_private_key_size = 64, + ed25519_public_key_size = 32, + ed25519_signature_size = 64, + ed25519_scalar_size = 32, + ed25519_shared_secret_size = 32, +}; + #ifdef __cplusplus extern "C" { #endif diff --git a/include/libtorrent/extensions.hpp b/include/libtorrent/extensions.hpp index d5943937e..c78d52d5f 100644 --- a/include/libtorrent/extensions.hpp +++ b/include/libtorrent/extensions.hpp @@ -180,6 +180,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/buffer.hpp" #include "libtorrent/socket.hpp" #include "libtorrent/error_code.hpp" +#include "libtorrent/policy.hpp" // for policy::peer namespace libtorrent { @@ -196,6 +197,7 @@ namespace libtorrent class alert; struct torrent_plugin; class torrent; + struct torrent_peer; // 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, @@ -227,6 +229,15 @@ namespace libtorrent // called once per second virtual void on_tick() {} + // called when choosing peers to optimisticly unchoke + // peer's will be unchoked in the order they appear in the given + // vector which is initiallity sorted by when they were last + // optimistically unchoked. + // if the plugin returns true then the ordering provided will be + // used and no other plugin will be allowed to change it. + virtual bool on_optimistic_unchoke(std::vector& /* peers */) + { return false; } + // called when saving settings state virtual void save_state(entry&) const {} @@ -381,6 +392,9 @@ namespace libtorrent virtual bool on_reject(peer_request const&) { return false; } virtual bool on_suggest(int /*index*/) { return false; } + // called after a choke message has been sent to the peer + virtual void sent_unchoke() {} + // 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/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 31f15653b..6860ceedd 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -2254,6 +2254,14 @@ namespace libtorrent char msg[] = {0,0,0,1,msg_unchoke}; send_buffer(msg, sizeof(msg)); + +#ifndef TORRENT_DISABLE_EXTENSIONS + for (extension_list_t::iterator i = m_extensions.begin() + , end(m_extensions.end()); i != end; ++i) + { + (*i)->sent_unchoke(); + } +#endif } void bt_peer_connection::write_interested() diff --git a/src/kademlia/item.cpp b/src/kademlia/item.cpp index 18c3591a5..974966fee 100644 --- a/src/kademlia/item.cpp +++ b/src/kademlia/item.cpp @@ -193,6 +193,7 @@ void item::assign(entry const& v, std::pair salt TORRENT_ASSERT(bsize <= 1000); sign_mutable_item(std::make_pair(buffer, bsize) , salt, seq, pk, sk, m_sig.c_array()); + m_salt.assign(salt.first, salt.second); memcpy(m_pk.c_array(), pk, item_pk_len); m_seq = seq; m_mutable = true; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 5b6bad6de..fc68042c8 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -4391,6 +4391,15 @@ retry: , boost::bind(&policy::peer::last_optimistically_unchoked, _1) < boost::bind(&policy::peer::last_optimistically_unchoked, _2)); +#ifndef TORRENT_DISABLE_EXTENSIONS + for (ses_extension_list_t::iterator i = m_ses_extensions.begin() + , end(m_ses_extensions.end()); i != end; ++i) + { + if ((*i)->on_optimistic_unchoke(opt_unchoke)) + break; + } +#endif + int num_opt_unchoke = m_settings.num_optimistic_unchoke_slots; if (num_opt_unchoke == 0) num_opt_unchoke = (std::max)(1, m_allowed_upload_slots / 5);