merged some of steven siloti's changes. expose optimistic unchoke logic to plugins
This commit is contained in:
parent
46f309f8b9
commit
5b89c3f5f9
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<policy::peer*>& /* 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; }
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -193,6 +193,7 @@ void item::assign(entry const& v, std::pair<char const*, int> 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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue