merged some of steven siloti's changes. expose optimistic unchoke logic to plugins

This commit is contained in:
Arvid Norberg 2014-05-12 07:28:34 +00:00
parent 46f309f8b9
commit 5b89c3f5f9
6 changed files with 43 additions and 0 deletions

View File

@ -1,5 +1,6 @@
1.0 release 1.0 release
* expose optimistic unchoke logic to plugins
* fix issue with large UDP packets on windows * fix issue with large UDP packets on windows
* remove set_ratio() feature * remove set_ratio() feature
* improve piece_deadline/streaming * improve piece_deadline/streaming

View File

@ -5,6 +5,16 @@
#include "libtorrent/config.hpp" // for TORRENT_EXPORT #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 #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View File

@ -180,6 +180,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/buffer.hpp" #include "libtorrent/buffer.hpp"
#include "libtorrent/socket.hpp" #include "libtorrent/socket.hpp"
#include "libtorrent/error_code.hpp" #include "libtorrent/error_code.hpp"
#include "libtorrent/policy.hpp" // for policy::peer
namespace libtorrent namespace libtorrent
{ {
@ -196,6 +197,7 @@ namespace libtorrent
class alert; class alert;
struct torrent_plugin; struct torrent_plugin;
class torrent; class torrent;
struct torrent_peer;
// this is the base class for a session plugin. One primary feature // 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, // is that it is notified of all torrents that are added to the session,
@ -227,6 +229,15 @@ namespace libtorrent
// called once per second // called once per second
virtual void on_tick() {} 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<policy::peer*>& /* peers */)
{ return false; }
// called when saving settings state // called when saving settings state
virtual void save_state(entry&) const {} virtual void save_state(entry&) const {}
@ -381,6 +392,9 @@ namespace libtorrent
virtual bool on_reject(peer_request const&) { return false; } virtual bool on_reject(peer_request const&) { return false; }
virtual bool on_suggest(int /*index*/) { 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. // called when libtorrent think this peer should be disconnected.
// if the plugin returns false, the peer will not be disconnected. // if the plugin returns false, the peer will not be disconnected.
virtual bool can_disconnect(error_code const& /*ec*/) { return true; } virtual bool can_disconnect(error_code const& /*ec*/) { return true; }

View File

@ -2254,6 +2254,14 @@ namespace libtorrent
char msg[] = {0,0,0,1,msg_unchoke}; char msg[] = {0,0,0,1,msg_unchoke};
send_buffer(msg, sizeof(msg)); 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() void bt_peer_connection::write_interested()

View File

@ -193,6 +193,7 @@ void item::assign(entry const& v, std::pair<char const*, int> salt
TORRENT_ASSERT(bsize <= 1000); TORRENT_ASSERT(bsize <= 1000);
sign_mutable_item(std::make_pair(buffer, bsize) sign_mutable_item(std::make_pair(buffer, bsize)
, salt, seq, pk, sk, m_sig.c_array()); , salt, seq, pk, sk, m_sig.c_array());
m_salt.assign(salt.first, salt.second);
memcpy(m_pk.c_array(), pk, item_pk_len); memcpy(m_pk.c_array(), pk, item_pk_len);
m_seq = seq; m_seq = seq;
m_mutable = true; m_mutable = true;

View File

@ -4391,6 +4391,15 @@ retry:
, boost::bind(&policy::peer::last_optimistically_unchoked, _1) , boost::bind(&policy::peer::last_optimistically_unchoked, _1)
< boost::bind(&policy::peer::last_optimistically_unchoked, _2)); < 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; 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); if (num_opt_unchoke == 0) num_opt_unchoke = (std::max)(1, m_allowed_upload_slots / 5);