forked from premiere/premiere-libtorrent
fix sign conversion warning in peer_class_type_filter
This commit is contained in:
parent
d4864b8b18
commit
b88c193742
|
@ -49,7 +49,7 @@ namespace libtorrent {
|
|||
std::memset(m_peer_class_type, 0, sizeof(m_peer_class_type));
|
||||
}
|
||||
|
||||
enum socket_type_t
|
||||
enum socket_type_t : std::uint8_t
|
||||
{
|
||||
// these match the socket types from socket_type.hpp
|
||||
// shifted one down
|
||||
|
@ -63,22 +63,22 @@ namespace libtorrent {
|
|||
|
||||
// ``add()`` and ``remove()`` adds and removes a peer class to be added
|
||||
// to new peers based on socket type.
|
||||
void add(socket_type_t st, peer_class_t const peer_class)
|
||||
void add(socket_type_t const st, peer_class_t const peer_class)
|
||||
{
|
||||
TORRENT_ASSERT(peer_class < peer_class_t{32});
|
||||
if (peer_class > peer_class_t{31}) return;
|
||||
|
||||
TORRENT_ASSERT(st < num_socket_types && st >= 0);
|
||||
if (st < 0 || st >= num_socket_types) return;
|
||||
TORRENT_ASSERT(st < num_socket_types);
|
||||
if (st >= num_socket_types) return;
|
||||
m_peer_class_type[st] |= 1 << static_cast<std::uint32_t>(peer_class);
|
||||
}
|
||||
void remove(socket_type_t st, peer_class_t const peer_class)
|
||||
void remove(socket_type_t const st, peer_class_t const peer_class)
|
||||
{
|
||||
TORRENT_ASSERT(peer_class < peer_class_t{32});
|
||||
if (peer_class > peer_class_t{31}) return;
|
||||
|
||||
TORRENT_ASSERT(st < num_socket_types && st >= 0);
|
||||
if (st < 0 || st >= num_socket_types) return;
|
||||
TORRENT_ASSERT(st < num_socket_types);
|
||||
if (st >= num_socket_types) return;
|
||||
m_peer_class_type[st] &= ~(1 << static_cast<std::uint32_t>(peer_class));
|
||||
}
|
||||
|
||||
|
@ -87,32 +87,32 @@ namespace libtorrent {
|
|||
//
|
||||
// The ``peer_class`` argument cannot be greater than 31. The bitmasks representing
|
||||
// peer classes in the ``peer_class_type_filter`` are 32 bits.
|
||||
void disallow(socket_type_t st, peer_class_t const peer_class)
|
||||
void disallow(socket_type_t const st, peer_class_t const peer_class)
|
||||
{
|
||||
TORRENT_ASSERT(peer_class < peer_class_t{32});
|
||||
if (peer_class > peer_class_t{31}) return;
|
||||
|
||||
TORRENT_ASSERT(st < num_socket_types && st >= 0);
|
||||
if (st < 0 || st >= num_socket_types) return;
|
||||
TORRENT_ASSERT(st < num_socket_types);
|
||||
if (st >= num_socket_types) return;
|
||||
m_peer_class_type_mask[st] &= ~(1 << static_cast<std::uint32_t>(peer_class));
|
||||
}
|
||||
void allow(socket_type_t st, peer_class_t const peer_class)
|
||||
void allow(socket_type_t const st, peer_class_t const peer_class)
|
||||
{
|
||||
TORRENT_ASSERT(peer_class < peer_class_t{32});
|
||||
if (peer_class > peer_class_t{31}) return;
|
||||
|
||||
TORRENT_ASSERT(st < num_socket_types && st >= 0);
|
||||
if (st < 0 || st >= num_socket_types) return;
|
||||
TORRENT_ASSERT(st < num_socket_types);
|
||||
if (st >= num_socket_types) return;
|
||||
m_peer_class_type_mask[st] |= 1 << static_cast<std::uint32_t>(peer_class);
|
||||
}
|
||||
|
||||
// takes a bitmask of peer classes and returns a new bitmask of
|
||||
// peer classes after the rules have been applied, based on the socket type argument
|
||||
// (``st``).
|
||||
std::uint32_t apply(int st, std::uint32_t peer_class_mask)
|
||||
std::uint32_t apply(socket_type_t const st, std::uint32_t peer_class_mask)
|
||||
{
|
||||
TORRENT_ASSERT(st < num_socket_types && st >= 0);
|
||||
if (st < 0 || st >= num_socket_types) return peer_class_mask;
|
||||
TORRENT_ASSERT(st < num_socket_types);
|
||||
if (st >= num_socket_types) return peer_class_mask;
|
||||
|
||||
// filter peer classes based on type
|
||||
peer_class_mask &= m_peer_class_type_mask[st];
|
||||
|
|
|
@ -1201,9 +1201,16 @@ namespace {
|
|||
{
|
||||
std::uint32_t peer_class_mask = m_peer_class_filter.access(a);
|
||||
|
||||
using sock_t = peer_class_type_filter::socket_type_t;
|
||||
// assign peer class based on socket type
|
||||
static const int mapping[] = { 0, 0, 0, 0, 1, 4, 2, 2, 2, 3};
|
||||
int socket_type = mapping[st];
|
||||
static const sock_t mapping[] = {
|
||||
sock_t::tcp_socket, sock_t::tcp_socket
|
||||
, sock_t::tcp_socket, sock_t::tcp_socket
|
||||
, sock_t::utp_socket, sock_t::i2p_socket
|
||||
, sock_t::ssl_tcp_socket, sock_t::ssl_tcp_socket
|
||||
, sock_t::ssl_tcp_socket, sock_t::ssl_utp_socket
|
||||
};
|
||||
sock_t const socket_type = mapping[st];
|
||||
// filter peer classes based on type
|
||||
peer_class_mask = m_peer_class_type_filter.apply(socket_type, peer_class_mask);
|
||||
|
||||
|
|
|
@ -269,7 +269,7 @@ struct unit_directory_guard
|
|||
|
||||
void EXPORT reset_output()
|
||||
{
|
||||
if (current_test == nullptr || current_test->output == 0) return;
|
||||
if (current_test == nullptr || current_test->output == nullptr) return;
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
rewind(current_test->output);
|
||||
|
|
Loading…
Reference in New Issue