Skip to content

Commit 1d9b10a

Browse files
aldenmlarvidn
authored andcommitted
fix warning for Xcode 9, added const and minor code refactor to bt_peer_connection.cpp
1 parent 8648de3 commit 1d9b10a

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

include/libtorrent/bt_peer_connection.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ namespace libtorrent {
410410
#pragma clang diagnostic push
411411
// macOS clang doesn't have -Wshadow-field
412412
#pragma clang diagnostic ignored "-Wunknown-pragmas"
413+
// Xcode 9 needs this
414+
#pragma clang diagnostic ignored "-Wunknown-warning-option"
413415
#pragma clang diagnostic ignored "-Wshadow-field"
414416
#endif
415417
crypto_receive_buffer m_recv_buffer;

src/bt_peer_connection.cpp

+24-26
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,11 @@ POSSIBILITY OF SUCH DAMAGE.
7777

7878
namespace libtorrent {
7979

80-
namespace mp = boost::multiprecision;
81-
8280
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
8381
namespace {
8482

85-
std::size_t const handshake_len = 68;
86-
std::size_t const dh_key_len = 96;
83+
constexpr std::size_t handshake_len = 68;
84+
constexpr std::size_t dh_key_len = 96;
8785

8886
// stream key (info hash of attached torrent)
8987
// secret is the DH shared secret
@@ -135,15 +133,15 @@ namespace {
135133
if (ep.address().is_v4())
136134
{
137135
#endif
138-
peers4_t::value_type v(ep.address().to_v4().to_bytes(), ep.port());
139-
auto i = std::lower_bound(m_peers.begin(), m_peers.end(), v);
136+
peers4_t::value_type const v(ep.address().to_v4().to_bytes(), ep.port());
137+
auto const i = std::lower_bound(m_peers.begin(), m_peers.end(), v);
140138
return i != m_peers.end() && *i == v;
141139
#if TORRENT_USE_IPV6
142140
}
143141
else
144142
{
145-
peers6_t::value_type v(ep.address().to_v6().to_bytes(), ep.port());
146-
auto i = std::lower_bound(m_peers6.begin(), m_peers6.end(), v);
143+
peers6_t::value_type const v(ep.address().to_v6().to_bytes(), ep.port());
144+
auto const i = std::lower_bound(m_peers6.begin(), m_peers6.end(), v);
147145
return i != m_peers6.end() && *i == v;
148146
}
149147
#endif
@@ -193,13 +191,13 @@ namespace {
193191
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
194192
void bt_peer_connection::switch_send_crypto(std::shared_ptr<crypto_plugin> crypto)
195193
{
196-
if (m_enc_handler.switch_send_crypto(crypto, send_buffer_size() - get_send_barrier()))
194+
if (m_enc_handler.switch_send_crypto(std::move(crypto), send_buffer_size() - get_send_barrier()))
197195
set_send_barrier(send_buffer_size());
198196
}
199197

200198
void bt_peer_connection::switch_recv_crypto(std::shared_ptr<crypto_plugin> crypto)
201199
{
202-
m_enc_handler.switch_recv_crypto(crypto, m_recv_buffer);
200+
m_enc_handler.switch_recv_crypto(std::move(crypto), m_recv_buffer);
203201
}
204202
#endif
205203

@@ -215,7 +213,7 @@ namespace {
215213
#ifndef TORRENT_DISABLE_LOGGING
216214
peer_log(peer_log_alert::info, "ON_CONNECTED", "graceful-paused");
217215
#endif
218-
disconnect(error_code(errors::torrent_paused), operation_t::bittorrent);
216+
disconnect(errors::torrent_paused, operation_t::bittorrent);
219217
return;
220218
}
221219

@@ -339,7 +337,7 @@ namespace {
339337
#endif
340338
}
341339

342-
void bt_peer_connection::write_dht_port(int listen_port)
340+
void bt_peer_connection::write_dht_port(int const listen_port)
343341
{
344342
INVARIANT_CHECK;
345343

@@ -605,7 +603,7 @@ namespace {
605603
send_buffer({msg, sizeof(msg) - 512 + pad_size});
606604
}
607605

608-
void bt_peer_connection::write_pe4_sync(int crypto_select)
606+
void bt_peer_connection::write_pe4_sync(int const crypto_select)
609607
{
610608
INVARIANT_CHECK;
611609

@@ -1028,14 +1026,14 @@ namespace {
10281026
// ----------- PIECE -----------
10291027
// -----------------------------
10301028

1031-
void bt_peer_connection::on_piece(int received)
1029+
void bt_peer_connection::on_piece(int const received)
10321030
{
10331031
INVARIANT_CHECK;
10341032

10351033
TORRENT_ASSERT(received >= 0);
10361034

10371035
span<char const> recv_buffer = m_recv_buffer.get();
1038-
int recv_pos = m_recv_buffer.pos(); // recv_buffer.end - recv_buffer.begin;
1036+
int const recv_pos = m_recv_buffer.pos(); // recv_buffer.end - recv_buffer.begin;
10391037

10401038
std::shared_ptr<torrent> t = associated_torrent().lock();
10411039
TORRENT_ASSERT(t);
@@ -1249,7 +1247,7 @@ namespace {
12491247
span<char const> recv_buffer = m_recv_buffer.get();
12501248

12511249
const char* ptr = recv_buffer.begin() + 1;
1252-
int listen_port = detail::read_uint16(ptr);
1250+
int const listen_port = detail::read_uint16(ptr);
12531251

12541252
incoming_dht_port(listen_port);
12551253

@@ -1344,7 +1342,7 @@ namespace {
13441342
if (!m_recv_buffer.packet_finished()) return;
13451343
span<char const> recv_buffer = m_recv_buffer.get();
13461344
const char* ptr = recv_buffer.begin() + 1;
1347-
piece_index_t index(detail::read_int32(ptr));
1345+
piece_index_t const index(detail::read_int32(ptr));
13481346

13491347
incoming_allowed_fast(index);
13501348
}
@@ -1597,7 +1595,7 @@ namespace {
15971595
TORRENT_ASSERT(recv_buffer.front() == msg_extended);
15981596
recv_buffer = recv_buffer.subspan(1);
15991597

1600-
int extended_id = aux::read_uint8(recv_buffer);
1598+
int const extended_id = aux::read_uint8(recv_buffer);
16011599

16021600
if (extended_id == 0)
16031601
{
@@ -1743,7 +1741,7 @@ namespace {
17431741
}
17441742

17451743
// there is supposed to be a remote listen port
1746-
int listen_port = int(root.dict_find_int_value("p"));
1744+
int const listen_port = int(root.dict_find_int_value("p"));
17471745
if (listen_port > 0 && peer_info_struct() != nullptr)
17481746
{
17491747
t->update_peer_port(listen_port, peer_info_struct(), peer_info::incoming);
@@ -1757,10 +1755,10 @@ namespace {
17571755
int const last_seen_complete = int(root.dict_find_int_value("complete_ago", -1));
17581756
if (last_seen_complete >= 0) set_last_seen_complete(last_seen_complete);
17591757

1760-
auto client_info = root.dict_find_string_value("v");
1758+
auto const client_info = root.dict_find_string_value("v");
17611759
if (!client_info.empty()) m_client_version = client_info.to_string();
17621760

1763-
int reqq = int(root.dict_find_int_value("reqq"));
1761+
int const reqq = int(root.dict_find_int_value("reqq"));
17641762
if (reqq > 0) max_out_request_queue(reqq);
17651763

17661764
if (root.dict_find_int_value("upload_only", 0))
@@ -1770,7 +1768,7 @@ namespace {
17701768
&& root.dict_find_int_value("share_mode", 0))
17711769
set_share_mode(true);
17721770

1773-
auto myip = root.dict_find_string_value("yourip");
1771+
auto const myip = root.dict_find_string_value("yourip");
17741772
if (!myip.empty())
17751773
{
17761774
if (myip.size() == std::tuple_size<address_v4::bytes_type>::value)
@@ -2080,7 +2078,7 @@ namespace {
20802078

20812079
// add predictive pieces to the bitfield as well, since we won't
20822080
// announce them again
2083-
for (piece_index_t p : t->predictive_pieces())
2081+
for (piece_index_t const p : t->predictive_pieces())
20842082
msg[5 + static_cast<int>(p) / 8] |= (0x80 >> (static_cast<int>(p) & 7));
20852083

20862084
#ifndef TORRENT_DISABLE_LOGGING
@@ -2255,7 +2253,7 @@ namespace {
22552253
send_message(msg_not_interested, counters::num_outgoing_not_interested, 0);
22562254
}
22572255

2258-
void bt_peer_connection::write_have(piece_index_t index)
2256+
void bt_peer_connection::write_have(piece_index_t const index)
22592257
{
22602258
INVARIANT_CHECK;
22612259
TORRENT_ASSERT(associated_torrent().lock()->valid_metadata());
@@ -3325,7 +3323,7 @@ namespace {
33253323
int packet_size = detail::read_int32(ptr);
33263324

33273325
// don't accept packets larger than 1 MB
3328-
if (packet_size > 1024*1024 || packet_size < 0)
3326+
if (packet_size > 1024 * 1024 || packet_size < 0)
33293327
{
33303328
// packet too large
33313329
received_bytes(0, int(bytes_transferred));
@@ -3409,7 +3407,7 @@ namespace {
34093407
// --------------------------
34103408

34113409
void bt_peer_connection::on_sent(error_code const& error
3412-
, std::size_t bytes_transferred)
3410+
, std::size_t const bytes_transferred)
34133411
{
34143412
INVARIANT_CHECK;
34153413

0 commit comments

Comments
 (0)