Skip to content

Commit

Permalink
feat: split connectable and non-connectable pool (transmission#5801)
Browse files Browse the repository at this point in the history
  • Loading branch information
tearfur authored Aug 1, 2023
1 parent 212bf69 commit a284921
Show file tree
Hide file tree
Showing 12 changed files with 523 additions and 238 deletions.
2 changes: 1 addition & 1 deletion libtransmission/global-ip-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace global_source_ip_helpers
auto const save = errno;

auto const [dst_ss, dst_sslen] = dst_addr.to_sockaddr(dst_port);
auto const [bind_ss, bind_sslen] = bind_addr.to_sockaddr(tr_port::fromHost(0));
auto const [bind_ss, bind_sslen] = bind_addr.to_sockaddr(tr_port{});
if (auto const sock = socket(dst_ss.ss_family, SOCK_DGRAM, 0); sock != TR_BAD_SOCKET)
{
if (bind(sock, reinterpret_cast<sockaddr const*>(&bind_ss), bind_sslen) == 0)
Expand Down
9 changes: 2 additions & 7 deletions libtransmission/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,12 @@ class std::hash<tr_socket_address>
std::size_t operator()(tr_socket_address const& socket_address) const noexcept
{
auto const& [addr, port] = socket_address;
return hash_combine(ip_hash(addr), port_hash(port));
return hash_combine(ip_hash(addr), PortHasher(port.host()));
}

private:
// https://stackoverflow.com/a/27952689/11390656
[[nodiscard]] static constexpr std::size_t hash_combine(std::size_t const& a, std::size_t const& b)
[[nodiscard]] static constexpr std::size_t hash_combine(std::size_t const a, std::size_t const b)
{
return a ^ (b + 0x9e3779b9U + (a << 6U) + (a >> 2U));
}
Expand All @@ -414,11 +414,6 @@ class std::hash<tr_socket_address>
}
}

[[nodiscard]] static std::size_t port_hash(tr_port const& port) noexcept
{
return PortHasher(port.host());
}

constexpr static std::hash<uint32_t> IPv4Hasher{};
constexpr static std::hash<std::string_view> IPv6Hasher{};
constexpr static std::hash<uint16_t> PortHasher{};
Expand Down
27 changes: 12 additions & 15 deletions libtransmission/peer-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
#include <cstdint> // uint8_t, uint32_t, uint64_t
#include <string>

#include "transmission.h"
#include "libtransmission/transmission.h"

#include "bitfield.h"
#include "block-info.h"
#include "history.h"
#include "net.h" // tr_port
#include "libtransmission/bitfield.h"
#include "libtransmission/block-info.h"
#include "libtransmission/history.h"
#include "libtransmission/net.h" // tr_port

/**
* @addtogroup peers Peers
Expand All @@ -28,7 +28,6 @@

class tr_peer;
class tr_swarm;
class tr_peer_info;
struct tr_bandwidth;

// --- Peer Publish / Subscribe
Expand All @@ -38,19 +37,20 @@ class tr_peer_event
public:
enum class Type
{
ClientGotBlock,
// Unless otherwise specified, all events are for BT peers only
ClientGotBlock, // applies to webseed too
ClientGotChoke,
ClientGotPieceData,
ClientGotPieceData, // applies to webseed too
ClientGotAllowedFast,
ClientGotSuggest,
ClientGotPort,
ClientGotRej,
ClientGotRej, // applies to webseed too
ClientGotBitfield,
ClientGotHave,
ClientGotHaveAll,
ClientGotHaveNone,
ClientSentPieceData,
Error
Error // generic
};

Type type = Type::Error;
Expand Down Expand Up @@ -170,7 +170,7 @@ class tr_peer_event
}
};

using tr_peer_callback = void (*)(tr_peer* peer, tr_peer_event const& event, void* client_data);
using tr_peer_callback_generic = void (*)(tr_peer* peer, tr_peer_event const& event, void* client_data);

/**
* State information about a connected peer.
Expand All @@ -181,7 +181,7 @@ using tr_peer_callback = void (*)(tr_peer* peer, tr_peer_event const& event, voi
class tr_peer
{
public:
tr_peer(tr_torrent const* tor, tr_peer_info* const peer_info = nullptr);
tr_peer(tr_torrent const* tor);
virtual ~tr_peer();

virtual bool isTransferringPieces(uint64_t now, tr_direction dir, tr_bytes_per_second_t* setme_bytes_per_second) const = 0;
Expand Down Expand Up @@ -241,9 +241,6 @@ class tr_peer
/// The following fields are only to be used in peer-mgr.cc.
/// TODO(ckerr): refactor them out of `tr_peer`

// hook to private peer-mgr information
tr_peer_info* const peer_info;

// whether or not this peer sent us any given block
tr_bitfield blame;

Expand Down
2 changes: 1 addition & 1 deletion libtransmission/peer-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class tr_peerIo final : public std::enable_shared_from_this<tr_peerIo>

[[nodiscard]] constexpr auto const& socket_address() const noexcept
{
return socket_.socketAddress();
return socket_.socket_address();
}

[[nodiscard]] auto display_name() const
Expand Down
Loading

0 comments on commit a284921

Please sign in to comment.