summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Resch <andrewresch@gmail.com>2009-01-28 16:19:36 +0000
committerAndrew Resch <andrewresch@gmail.com>2009-01-28 16:19:36 +0000
commitb0f9117a3d8376f4bdeb4028360c50219d62d5ba (patch)
tree19fc948f252a134825112b07100b0174416c5573
parent040b4938e10d35454c5080f1d1816e42927cafae (diff)
downloaddeluge-b0f9117a3d8376f4bdeb4028360c50219d62d5ba.tar.gz
deluge-b0f9117a3d8376f4bdeb4028360c50219d62d5ba.tar.bz2
deluge-b0f9117a3d8376f4bdeb4028360c50219d62d5ba.zip
lt sync 3225
-rw-r--r--libtorrent/include/libtorrent/bt_peer_connection.hpp22
-rwxr-xr-xlibtorrent/src/bt_peer_connection.cpp52
-rwxr-xr-xlibtorrent/src/udp_tracker_connection.cpp5
3 files changed, 72 insertions, 7 deletions
diff --git a/libtorrent/include/libtorrent/bt_peer_connection.hpp b/libtorrent/include/libtorrent/bt_peer_connection.hpp
index 5d3b9bc48..306d706e6 100644
--- a/libtorrent/include/libtorrent/bt_peer_connection.hpp
+++ b/libtorrent/include/libtorrent/bt_peer_connection.hpp
@@ -262,8 +262,8 @@ namespace libtorrent
void write_pe3_sync();
void write_pe4_sync(int crypto_select);
- void write_pe_vc_cryptofield(buffer::interval& write_buf,
- int crypto_field, int pad_size);
+ void write_pe_vc_cryptofield(buffer::interval& write_buf
+ , int crypto_field, int pad_size);
// stream key (info hash of attached torrent)
// secret is the DH shared secret
@@ -282,7 +282,14 @@ public:
{
#ifndef TORRENT_DISABLE_ENCRYPTION
if (m_rc4_encrypted)
+ {
+ TORRENT_ASSERT(send_buffer_size() == m_encrypted_bytes);
m_RC4_handler->encrypt(buffer, size);
+#ifdef TORRENT_DEBUG
+ m_encrypted_bytes += size;
+ TORRENT_ASSERT(m_encrypted_bytes <= send_buffer_size() + size);
+#endif
+ }
#endif
peer_connection::append_send_buffer(buffer, size, destructor);
}
@@ -290,11 +297,13 @@ public:
private:
+ void encrypt_pending_buffer();
+
// Returns offset at which bytestream (src, src + src_size)
// matches bytestream(target, target + target_size).
// If no sync found, return -1
- int get_syncoffset(char const* src, int src_size,
- char const* target, int target_size) const;
+ int get_syncoffset(char const* src, int src_size
+ , char const* target, int target_size) const;
#endif
enum state
@@ -412,6 +421,11 @@ private:
bool m_in_constructor;
bool m_sent_handshake;
+
+ // the number of bytes in the send buffer
+ // that have been encrypted (only used for
+ // encrypted connections)
+ int m_encrypted_bytes;
#endif
};
diff --git a/libtorrent/src/bt_peer_connection.cpp b/libtorrent/src/bt_peer_connection.cpp
index 394b1e0d1..8eb96d2b0 100755
--- a/libtorrent/src/bt_peer_connection.cpp
+++ b/libtorrent/src/bt_peer_connection.cpp
@@ -120,6 +120,7 @@ namespace libtorrent
#ifdef TORRENT_DEBUG
m_in_constructor = false;
+ m_encrypted_bytes = 0;
#endif
}
@@ -167,6 +168,7 @@ namespace libtorrent
#ifdef TORRENT_DEBUG
m_in_constructor = false;
+ m_encrypted_bytes = 0;
#endif
}
@@ -412,6 +414,10 @@ namespace libtorrent
send_buf.begin);
std::generate(send_buf.begin + dh_key_len, send_buf.end, std::rand);
+#ifdef TORRENT_DEBUG
+ m_encrypted_bytes += send_buf.left();
+ TORRENT_ASSERT(m_encrypted_bytes <= send_buffer_size());
+#endif
setup_send();
#ifdef TORRENT_VERBOSE_LOGGING
@@ -496,6 +502,12 @@ namespace libtorrent
write_pe_vc_cryptofield(send_buf, crypto_provide, pad_size);
m_RC4_handler->encrypt(send_buf.end - encrypt_size, encrypt_size);
+#ifdef TORRENT_DEBUG
+ const int packet_size = 20 + 20 + 8 + 4 + 2 + pad_size + 2;
+ TORRENT_ASSERT(send_buffer_size() - packet_size == m_encrypted_bytes);
+ m_encrypted_bytes += packet_size;
+ TORRENT_ASSERT(m_encrypted_bytes <= send_buffer_size());
+#endif
TORRENT_ASSERT(send_buf.begin == send_buf.end);
setup_send();
@@ -519,6 +531,11 @@ namespace libtorrent
write_pe_vc_cryptofield(send_buf, crypto_select, pad_size);
m_RC4_handler->encrypt(send_buf.end - buf_size, buf_size);
+ TORRENT_ASSERT(send_buffer_size() - buf_size == m_encrypted_bytes);
+#ifdef TORRENT_DEBUG
+ m_encrypted_bytes += buf_size;
+ TORRENT_ASSERT(m_encrypted_bytes <= send_buffer_size());
+#endif
setup_send();
// encryption method has been negotiated
@@ -610,15 +627,25 @@ namespace libtorrent
{
TORRENT_ASSERT(buf);
TORRENT_ASSERT(size > 0);
+
+ encrypt_pending_buffer();
if (m_encrypted && m_rc4_encrypted)
+ {
+ TORRENT_ASSERT(send_buffer_size() == m_encrypted_bytes);
m_RC4_handler->encrypt(const_cast<char*>(buf), size);
+#ifdef TORRENT_DEBUG
+ m_encrypted_bytes += size;
+ TORRENT_ASSERT(m_encrypted_bytes <= send_buffer_size() + size);
+#endif
+ }
peer_connection::send_buffer(buf, size, flags);
}
buffer::interval bt_peer_connection::allocate_send_buffer(int size)
{
+ encrypt_pending_buffer();
if (m_encrypted && m_rc4_encrypted)
{
TORRENT_ASSERT(m_enc_send_buffer.left() == 0);
@@ -632,16 +659,27 @@ namespace libtorrent
}
}
- void bt_peer_connection::setup_send()
+ void bt_peer_connection::encrypt_pending_buffer()
{
if (m_encrypted && m_rc4_encrypted && m_enc_send_buffer.left())
{
TORRENT_ASSERT(m_enc_send_buffer.begin);
TORRENT_ASSERT(m_enc_send_buffer.end);
+ TORRENT_ASSERT(m_RC4_handler);
+ TORRENT_ASSERT(send_buffer_size() - m_enc_send_buffer.left() == m_encrypted_bytes);
+#ifdef TORRENT_DEBUG
+ m_encrypted_bytes += m_enc_send_buffer.left();
+ TORRENT_ASSERT(m_encrypted_bytes <= send_buffer_size());
+#endif
m_RC4_handler->encrypt(m_enc_send_buffer.begin, m_enc_send_buffer.left());
m_enc_send_buffer.end = m_enc_send_buffer.begin;
}
+ }
+
+ void bt_peer_connection::setup_send()
+ {
+ encrypt_pending_buffer();
peer_connection::setup_send();
}
@@ -1526,6 +1564,8 @@ namespace libtorrent
m_sent_bitfield = true;
#endif
+ setup_send();
+
if (num_lazy_pieces > 0)
{
for (int i = 0; i < num_lazy_pieces; ++i)
@@ -1540,7 +1580,6 @@ namespace libtorrent
if (m_supports_fast)
send_allowed_set();
- setup_send();
}
#ifndef TORRENT_DISABLE_EXTENSIONS
@@ -2629,6 +2668,15 @@ namespace libtorrent
std::remove_if(m_payloads.begin(), m_payloads.end(), range_below_zero)
, m_payloads.end());
+#ifdef TORRENT_DEBUG
+ if (m_encrypted_bytes > 0)
+ {
+ m_encrypted_bytes -= bytes_transferred;
+ TORRENT_ASSERT(m_encrypted_bytes >= 0);
+ TORRENT_ASSERT(m_encrypted_bytes <= send_buffer_size());
+ }
+#endif
+
TORRENT_ASSERT(amount_payload <= (int)bytes_transferred);
m_statistics.sent_bytes(amount_payload, bytes_transferred - amount_payload);
}
diff --git a/libtorrent/src/udp_tracker_connection.cpp b/libtorrent/src/udp_tracker_connection.cpp
index c742aea01..01d4224c5 100755
--- a/libtorrent/src/udp_tracker_connection.cpp
+++ b/libtorrent/src/udp_tracker_connection.cpp
@@ -45,7 +45,11 @@ POSSIBILITY OF SUCH DAMAGE.
#endif
#include <boost/bind.hpp>
+
+#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
#include <boost/lexical_cast.hpp>
+using boost::lexical_cast;
+#endif
#ifdef _MSC_VER
#pragma warning(pop)
@@ -69,7 +73,6 @@ namespace
}
using boost::bind;
-using boost::lexical_cast;
namespace libtorrent
{