From 730ef15b08008188d38b6f89da073aff7abd6921 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 24 Jul 2018 12:16:43 +0200 Subject: [PATCH] minor cleanups --- include/libtorrent/peer_connection.hpp | 4 ++-- src/session_impl.cpp | 8 +++++--- src/torrent.cpp | 2 +- src/udp_socket.cpp | 12 +++++++++--- src/udp_tracker_connection.cpp | 3 ++- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index a59f98ab9..f7d007966 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -516,9 +516,9 @@ namespace aux { int est_reciprocation_rate() const { return m_est_reciprocation_rate; } #ifndef TORRENT_DISABLE_LOGGING - bool should_log(peer_log_alert::direction_t direction) const override final; + bool should_log(peer_log_alert::direction_t direction) const final; void peer_log(peer_log_alert::direction_t direction - , char const* event, char const* fmt, ...) const noexcept override final TORRENT_FORMAT(4,5); + , char const* event, char const* fmt, ...) const noexcept final TORRENT_FORMAT(4,5); void peer_log(peer_log_alert::direction_t direction , char const* event) const noexcept; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 9d022f3e4..7fc8ef1b5 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2422,10 +2422,12 @@ namespace aux { // socket bool handled = false; #ifndef TORRENT_DISABLE_DHT - if (m_dht && buf.size() > 20 && buf.front() == 'd' && buf.back() == 'e') + if (m_dht && buf.size() > 20 + && buf.front() == 'd' + && buf.back() == 'e' + && listen_socket) { - if (listen_socket) - handled = m_dht->incoming_packet(listen_socket, packet.from, buf); + handled = m_dht->incoming_packet(listen_socket, packet.from, buf); } #endif diff --git a/src/torrent.cpp b/src/torrent.cpp index 979cbd1d5..1054ed8eb 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -10785,12 +10785,12 @@ bool is_downloading_state(int const st) if (st->state == torrent_status::finished || st->state == torrent_status::seeding) { + // it may be tempting to assume that st->is_finished == true here, but // this assumption does not always hold. We transition to "finished" // when we receive the last block of the last piece, which is before // the hash check comes back. "is_finished" is set to true once all the // pieces have been hash checked. So, there's a short window where it // doesn't hold. -// TORRENT_ASSERT(st->is_finished); } #endif diff --git a/src/udp_socket.cpp b/src/udp_socket.cpp index 442e06270..be035f8e7 100644 --- a/src/udp_socket.cpp +++ b/src/udp_socket.cpp @@ -52,6 +52,12 @@ namespace libtorrent { using namespace std::placeholders; +// used to build SOCKS messages in +std::size_t const tmp_buffer_size = 270; + +// used for SOCKS5 UDP wrapper header +std::size_t const max_header_size = 25; + // this class hold the state of the SOCKS5 connection to maintain the UDP // ASSOCIATE tunnel. It's instantiated on the heap for two reasons: // @@ -97,7 +103,7 @@ private: tcp::resolver m_resolver; deadline_timer m_timer; deadline_timer m_retry_timer; - std::array m_tmp_buf; + std::array m_tmp_buf; aux::proxy_settings m_proxy_settings; @@ -312,7 +318,7 @@ void udp_socket::wrap(udp::endpoint const& ep, span p TORRENT_UNUSED(flags); using namespace libtorrent::detail; - std::array header; + std::array header; char* h = header.data(); write_uint16(0, h); // reserved @@ -336,7 +342,7 @@ void udp_socket::wrap(char const* hostname, int const port, span p { using namespace libtorrent::detail; - std::array header; + std::array header; char* h = header.data(); write_uint16(0, h); // reserved diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index 9fa8d1589..1ce470d58 100644 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -513,7 +513,8 @@ namespace libtorrent { return; } - std::array buf; + std::size_t const connect_packet_size = 16; + std::array buf; span view = buf; TORRENT_ASSERT(m_transaction_id != 0);