From 3c51ceb7c55b928d62af49aed57399cdf46ad007 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 21 Apr 2009 19:27:52 +0000 Subject: [PATCH] fixed bug when receiving keepalive message --- src/bt_peer_connection.cpp | 1 + src/peer_connection.cpp | 2 ++ test/test_fast_extension.cpp | 15 +++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index f8e0cc318..41aa4366b 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -2035,6 +2035,7 @@ namespace libtorrent TORRENT_ASSERT(!m_rc4_encrypted); TORRENT_ASSERT(packet_size() == dh_key_len); TORRENT_ASSERT(recv_buffer == receive_buffer()); + TORRENT_ASSERT(packet_size() == 5); if (!packet_finished()) return; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 515405395..29356be4b 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -2999,6 +2999,8 @@ namespace libtorrent return m_disk_recv_buffer.release(); } + // size = the packet size to remove from the receive buffer + // packet_size = the next packet size to receive in the buffer void peer_connection::cut_receive_buffer(int size, int packet_size) { INVARIANT_CHECK; diff --git a/test/test_fast_extension.cpp b/test/test_fast_extension.cpp index caa18805d..500d32907 100644 --- a/test/test_fast_extension.cpp +++ b/test/test_fast_extension.cpp @@ -97,6 +97,19 @@ void send_suggest_piece(stream_socket& s, int piece) } } +void send_keepalive(stream_socket& s) +{ + std::cout << "send keepalive" << std::endl; + char msg[] = "\0\0\0\0"; + error_code ec; + libtorrent::asio::write(s, libtorrent::asio::buffer(msg, 4), libtorrent::asio::transfer_all(), ec); + if (ec) + { + std::cout << ec.message() << std::endl; + exit(1); + } +} + void send_unchoke(stream_socket& s) { std::cout << "send unchoke" << std::endl; @@ -249,6 +262,8 @@ void test_respect_suggest() send_unchoke(s); + send_keepalive(s); + int fail_counter = 100; while (!suggested.empty() && fail_counter > 0) {