lt sync 1947
This commit is contained in:
parent
cc81e1073d
commit
790eda0f2c
|
@ -144,7 +144,7 @@ struct bandwidth_manager
|
||||||
// this is used by web seeds
|
// this is used by web seeds
|
||||||
void request_bandwidth(intrusive_ptr<PeerConnection> peer
|
void request_bandwidth(intrusive_ptr<PeerConnection> peer
|
||||||
, int blk
|
, int blk
|
||||||
, bool non_prioritized) throw()
|
, bool non_prioritized)
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
@ -214,11 +214,9 @@ struct bandwidth_manager
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void add_history_entry(history_entry<PeerConnection, Torrent> const& e) throw()
|
void add_history_entry(history_entry<PeerConnection, Torrent> const& e)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
|
||||||
try {
|
try {
|
||||||
#endif
|
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
m_history.push_front(e);
|
m_history.push_front(e);
|
||||||
m_current_quota += e.amount;
|
m_current_quota += e.amount;
|
||||||
|
@ -230,17 +228,13 @@ private:
|
||||||
|
|
||||||
m_history_timer.expires_at(e.expires_at);
|
m_history_timer.expires_at(e.expires_at);
|
||||||
m_history_timer.async_wait(bind(&bandwidth_manager::on_history_expire, this, _1));
|
m_history_timer.async_wait(bind(&bandwidth_manager::on_history_expire, this, _1));
|
||||||
#ifndef NDEBUG
|
|
||||||
}
|
}
|
||||||
catch (std::exception&) { TORRENT_ASSERT(false); }
|
catch (std::exception&) {}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_history_expire(asio::error_code const& e) throw()
|
void on_history_expire(asio::error_code const& e)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
|
||||||
try {
|
try {
|
||||||
#endif
|
|
||||||
if (e) return;
|
if (e) return;
|
||||||
|
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
@ -273,13 +267,8 @@ private:
|
||||||
// means we can hand out more (in case there
|
// means we can hand out more (in case there
|
||||||
// are still consumers in line)
|
// are still consumers in line)
|
||||||
if (!m_queue.empty()) hand_out_bandwidth(l);
|
if (!m_queue.empty()) hand_out_bandwidth(l);
|
||||||
#ifndef NDEBUG
|
|
||||||
}
|
}
|
||||||
catch (std::exception&)
|
catch (std::exception&) {}
|
||||||
{
|
|
||||||
TORRENT_ASSERT(false);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void hand_out_bandwidth(boost::mutex::scoped_lock& l) throw()
|
void hand_out_bandwidth(boost::mutex::scoped_lock& l) throw()
|
||||||
|
@ -289,9 +278,8 @@ private:
|
||||||
// to the loop further down on the callstack
|
// to the loop further down on the callstack
|
||||||
if (m_in_hand_out_bandwidth) return;
|
if (m_in_hand_out_bandwidth) return;
|
||||||
m_in_hand_out_bandwidth = true;
|
m_in_hand_out_bandwidth = true;
|
||||||
#ifndef NDEBUG
|
|
||||||
try {
|
try {
|
||||||
#endif
|
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
ptime now(time_now());
|
ptime now(time_now());
|
||||||
|
@ -406,11 +394,12 @@ private:
|
||||||
}
|
}
|
||||||
if (!q.empty()) m_queue.insert(m_queue.begin(), q.begin(), q.end());
|
if (!q.empty()) m_queue.insert(m_queue.begin(), q.begin(), q.end());
|
||||||
if (!tmp.empty()) m_queue.insert(m_queue.begin(), tmp.begin(), tmp.end());
|
if (!tmp.empty()) m_queue.insert(m_queue.begin(), tmp.begin(), tmp.end());
|
||||||
#ifndef NDEBUG
|
|
||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
{ TORRENT_ASSERT(false); };
|
{
|
||||||
#endif
|
m_in_hand_out_bandwidth = false;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
m_in_hand_out_bandwidth = false;
|
m_in_hand_out_bandwidth = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -224,7 +224,7 @@ namespace libtorrent
|
||||||
void add_stat(size_type downloaded, size_type uploaded);
|
void add_stat(size_type downloaded, size_type uploaded);
|
||||||
|
|
||||||
// is called once every second by the main loop
|
// is called once every second by the main loop
|
||||||
void second_tick(float tick_interval) throw();
|
void second_tick(float tick_interval);
|
||||||
|
|
||||||
boost::shared_ptr<socket_type> get_socket() const { return m_socket; }
|
boost::shared_ptr<socket_type> get_socket() const { return m_socket; }
|
||||||
tcp::endpoint const& remote() const { return m_remote; }
|
tcp::endpoint const& remote() const { return m_remote; }
|
||||||
|
|
|
@ -333,7 +333,11 @@ namespace libtorrent
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
{
|
{
|
||||||
// std::cerr << "DISK THREAD: exception: " << e.what() << std::endl;
|
// std::cerr << "DISK THREAD: exception: " << e.what() << std::endl;
|
||||||
j.str = e.what();
|
try
|
||||||
|
{
|
||||||
|
j.str = e.what();
|
||||||
|
}
|
||||||
|
catch (std::exception&) {}
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright (c) 2007, Un Shyam
|
Copyright (c) 2007, Un Shyam & Arvid Norberg
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -40,23 +40,33 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/pe_crypto.hpp"
|
#include "libtorrent/pe_crypto.hpp"
|
||||||
#include "libtorrent/assert.hpp"
|
#include "libtorrent/assert.hpp"
|
||||||
|
|
||||||
namespace libtorrent {
|
namespace libtorrent
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
// Set the prime P and the generator, generate local public key
|
// Set the prime P and the generator, generate local public key
|
||||||
DH_key_exchange::DH_key_exchange ()
|
DH_key_exchange::DH_key_exchange()
|
||||||
{
|
{
|
||||||
m_DH = DH_new ();
|
m_DH = DH_new();
|
||||||
|
if (m_DH == 0) throw std::bad_alloc();
|
||||||
|
|
||||||
|
m_DH->p = BN_bin2bn(m_dh_prime, sizeof(m_dh_prime), NULL);
|
||||||
|
m_DH->g = BN_bin2bn(m_dh_generator, sizeof(m_dh_generator), NULL);
|
||||||
|
if (m_DH->p == 0 || m_DH->g == 0)
|
||||||
|
{
|
||||||
|
DH_free(m_DH);
|
||||||
|
throw std::bad_alloc();
|
||||||
|
}
|
||||||
|
|
||||||
m_DH->p = BN_bin2bn (m_dh_prime, sizeof(m_dh_prime), NULL);
|
|
||||||
m_DH->g = BN_bin2bn (m_dh_generator, sizeof(m_dh_generator), NULL);
|
|
||||||
m_DH->length = 160l;
|
m_DH->length = 160l;
|
||||||
|
|
||||||
TORRENT_ASSERT(sizeof(m_dh_prime) == DH_size(m_DH));
|
TORRENT_ASSERT(sizeof(m_dh_prime) == DH_size(m_DH));
|
||||||
|
|
||||||
DH_generate_key (m_DH); // TODO Check != 0
|
DH_generate_key(m_DH);
|
||||||
|
if (m_DH->pub_key == 0)
|
||||||
TORRENT_ASSERT(m_DH->pub_key);
|
{
|
||||||
|
DH_free(m_DH);
|
||||||
|
throw std::bad_alloc();
|
||||||
|
}
|
||||||
|
|
||||||
// DH can generate key sizes that are smaller than the size of
|
// DH can generate key sizes that are smaller than the size of
|
||||||
// P with exponentially decreasing probability, in which case
|
// P with exponentially decreasing probability, in which case
|
||||||
|
@ -79,24 +89,25 @@ namespace libtorrent {
|
||||||
DH_key_exchange::~DH_key_exchange ()
|
DH_key_exchange::~DH_key_exchange ()
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(m_DH);
|
TORRENT_ASSERT(m_DH);
|
||||||
DH_free (m_DH);
|
DH_free(m_DH);
|
||||||
}
|
}
|
||||||
|
|
||||||
char const* DH_key_exchange::get_local_key () const
|
char const* DH_key_exchange::get_local_key() const
|
||||||
{
|
{
|
||||||
return m_dh_local_key;
|
return m_dh_local_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// compute shared secret given remote public key
|
// compute shared secret given remote public key
|
||||||
void DH_key_exchange::compute_secret (char const* remote_pubkey)
|
void DH_key_exchange::compute_secret(char const* remote_pubkey)
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(remote_pubkey);
|
TORRENT_ASSERT(remote_pubkey);
|
||||||
BIGNUM* bn_remote_pubkey = BN_bin2bn ((unsigned char*)remote_pubkey, 96, NULL);
|
BIGNUM* bn_remote_pubkey = BN_bin2bn ((unsigned char*)remote_pubkey, 96, NULL);
|
||||||
|
if (bn_remote_pubkey == 0) throw std::bad_alloc();
|
||||||
char dh_secret[96];
|
char dh_secret[96];
|
||||||
|
|
||||||
int secret_size = DH_compute_key ( (unsigned char*)dh_secret,
|
int secret_size = DH_compute_key((unsigned char*)dh_secret
|
||||||
bn_remote_pubkey, m_DH); // TODO Check for errors
|
, bn_remote_pubkey, m_DH);
|
||||||
|
|
||||||
if (secret_size != 96)
|
if (secret_size != 96)
|
||||||
{
|
{
|
||||||
|
@ -104,11 +115,10 @@ namespace libtorrent {
|
||||||
std::fill(m_dh_secret, m_dh_secret + 96 - secret_size, 0);
|
std::fill(m_dh_secret, m_dh_secret + 96 - secret_size, 0);
|
||||||
}
|
}
|
||||||
std::copy(dh_secret, dh_secret + secret_size, m_dh_secret + 96 - secret_size);
|
std::copy(dh_secret, dh_secret + secret_size, m_dh_secret + 96 - secret_size);
|
||||||
|
BN_free(bn_remote_pubkey);
|
||||||
BN_free (bn_remote_pubkey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char const* DH_key_exchange::get_secret () const
|
char const* DH_key_exchange::get_secret() const
|
||||||
{
|
{
|
||||||
return m_dh_secret;
|
return m_dh_secret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2182,7 +2182,7 @@ namespace libtorrent
|
||||||
if (m_packet_size >= m_recv_pos) m_recv_buffer.resize(m_packet_size);
|
if (m_packet_size >= m_recv_pos) m_recv_buffer.resize(m_packet_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void peer_connection::second_tick(float tick_interval) throw()
|
void peer_connection::second_tick(float tick_interval)
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
|
@ -2359,8 +2359,7 @@ namespace libtorrent
|
||||||
else if (buffer_size_watermark > 80 * 1024) buffer_size_watermark = 80 * 1024;
|
else if (buffer_size_watermark > 80 * 1024) buffer_size_watermark = 80 * 1024;
|
||||||
|
|
||||||
while (!m_requests.empty()
|
while (!m_requests.empty()
|
||||||
&& (send_buffer_size() + m_reading_bytes < buffer_size_watermark)
|
&& (send_buffer_size() + m_reading_bytes < buffer_size_watermark))
|
||||||
&& !m_choked)
|
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(t->valid_metadata());
|
TORRENT_ASSERT(t->valid_metadata());
|
||||||
peer_request& r = m_requests.front();
|
peer_request& r = m_requests.front();
|
||||||
|
|
|
@ -2250,7 +2250,8 @@ namespace libtorrent
|
||||||
// skip forward in the queue until we find a prioritized peer
|
// skip forward in the queue until we find a prioritized peer
|
||||||
// or hit the front of it.
|
// or hit the front of it.
|
||||||
queue_t::reverse_iterator i = m_bandwidth_queue[channel].rbegin();
|
queue_t::reverse_iterator i = m_bandwidth_queue[channel].rbegin();
|
||||||
while (i != m_bandwidth_queue[channel].rend() && i->non_prioritized) ++i;
|
if (!non_prioritized)
|
||||||
|
while (i != m_bandwidth_queue[channel].rend() && i->non_prioritized) ++i;
|
||||||
m_bandwidth_queue[channel].insert(i.base(), bw_queue_entry<peer_connection>(
|
m_bandwidth_queue[channel].insert(i.base(), bw_queue_entry<peer_connection>(
|
||||||
p, block_size, non_prioritized));
|
p, block_size, non_prioritized));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue