chore: remove dead "fast set" code (#3764)
* chore: remove old fast set code * chore: remove TR_SHA1_DIGEST_LEN declaration * chore: remove TR_SHA256_DIGEST_LEN declaration
This commit is contained in:
parent
ae74a13eb1
commit
8eab7d3ae7
|
@ -753,7 +753,8 @@ static ReadState readCryptoProvide(tr_handshake* handshake, struct evbuffer* inb
|
|||
|
||||
uint16_t padc_len = 0;
|
||||
uint32_t crypto_provide = 0;
|
||||
size_t const needlen = SHA_DIGEST_LENGTH + /* HASH('req2', SKEY) xor HASH('req3', S) */
|
||||
auto obfuscated_hash = tr_sha1_digest_t{};
|
||||
size_t const needlen = sizeof(obfuscated_hash) + /* HASH('req2', SKEY) xor HASH('req3', S) */
|
||||
std::size(VC) + sizeof(crypto_provide) + sizeof(padc_len);
|
||||
|
||||
if (evbuffer_get_length(inbuf) < needlen)
|
||||
|
@ -769,7 +770,6 @@ static ReadState readCryptoProvide(tr_handshake* handshake, struct evbuffer* inb
|
|||
evbuffer_remove(inbuf, std::data(req2), std::size(req2));
|
||||
|
||||
auto const req3 = tr_sha1::digest("req3"sv, handshake->dh.secret());
|
||||
auto obfuscated_hash = tr_sha1_digest_t{};
|
||||
for (size_t i = 0; i < std::size(obfuscated_hash); ++i)
|
||||
{
|
||||
obfuscated_hash[i] = req2[i] ^ req3[i];
|
||||
|
|
|
@ -703,12 +703,6 @@ public:
|
|||
EncryptionPreference encryption_preference = EncryptionPreference::Unknown;
|
||||
|
||||
size_t metadata_size_hint = 0;
|
||||
#if 0
|
||||
/* number of pieces we'll allow in our fast set */
|
||||
static auto constexpr MAX_FAST_SET_SIZE = int{ 3 };
|
||||
size_t fastsetSize;
|
||||
tr_piece_index_t fastset[MAX_FAST_SET_SIZE];
|
||||
#endif
|
||||
|
||||
tr_torrent* const torrent;
|
||||
|
||||
|
@ -830,25 +824,6 @@ static void protocolSendHave(tr_peerMsgsImpl* msgs, tr_piece_index_t index)
|
|||
msgs->pokeBatchPeriod(LowPriorityIntervalSecs);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
static void protocolSendAllowedFast(tr_peerMsgs* msgs, uint32_t pieceIndex)
|
||||
{
|
||||
TR_ASSERT(msgs->io->supportsFEXT());
|
||||
|
||||
tr_peerIo* io = msgs->io;
|
||||
struct evbuffer* out = msgs->outMessages;
|
||||
|
||||
evbuffer_add_uint32(io, out, sizeof(uint8_t) + sizeof(uint32_t));
|
||||
evbuffer_add_uint8(io, out, BtPeerMsgs::FextAllowedFast);
|
||||
evbuffer_add_uint32(io, out, pieceIndex);
|
||||
|
||||
logtrace(msgs, "sending Allowed Fast %u...", pieceIndex);
|
||||
msgs->dbgOutMessageLen();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void protocolSendChoke(tr_peerMsgsImpl* msgs, bool choke)
|
||||
{
|
||||
struct evbuffer* out = msgs->outMessages;
|
||||
|
@ -889,89 +864,6 @@ static void protocolSendHaveNone(tr_peerMsgsImpl* msgs)
|
|||
msgs->pokeBatchPeriod(ImmediatePriorityIntervalSecs);
|
||||
}
|
||||
|
||||
/**
|
||||
*** ALLOWED FAST SET
|
||||
*** For explanation, see http://www.bittorrent.org/beps/bep_0006.html
|
||||
**/
|
||||
|
||||
#if 0
|
||||
|
||||
size_t tr_generateAllowedSet(tr_piece_index_t* setmePieces, size_t desiredSetSize, size_t pieceCount, uint8_t const* infohash,
|
||||
tr_address const* addr)
|
||||
{
|
||||
TR_ASSERT(setmePieces != nullptr);
|
||||
TR_ASSERT(desiredSetSize <= pieceCount);
|
||||
TR_ASSERT(desiredSetSize != 0);
|
||||
TR_ASSERT(pieceCount != 0);
|
||||
TR_ASSERT(infohash != nullptr);
|
||||
TR_ASSERT(addr != nullptr);
|
||||
|
||||
size_t setSize = 0;
|
||||
|
||||
if (addr->isIPv4())
|
||||
{
|
||||
uint8_t w[SHA_DIGEST_LENGTH + 4];
|
||||
uint8_t* walk = w;
|
||||
uint8_t x[SHA_DIGEST_LENGTH];
|
||||
|
||||
uint32_t ui32 = ntohl(htonl(addr->addr.addr4.s_addr) & 0xffffff00); /* (1) */
|
||||
memcpy(w, &ui32, sizeof(uint32_t));
|
||||
walk += sizeof(uint32_t);
|
||||
memcpy(walk, infohash, SHA_DIGEST_LENGTH); /* (2) */
|
||||
walk += SHA_DIGEST_LENGTH;
|
||||
tr_sha1(x, w, walk - w, nullptr); /* (3) */
|
||||
TR_ASSERT(sizeof(w) == walk - w);
|
||||
|
||||
while (setSize < desiredSetSize)
|
||||
{
|
||||
for (int i = 0; i < 5 && setSize < desiredSetSize; ++i) /* (4) */
|
||||
{
|
||||
uint32_t j = i * 4; /* (5) */
|
||||
uint32_t y = ntohl(*(uint32_t*)(x + j)); /* (6) */
|
||||
uint32_t index = y % pieceCount; /* (7) */
|
||||
bool found = false;
|
||||
|
||||
for (size_t k = 0; !found && k < setSize; ++k) /* (8) */
|
||||
{
|
||||
found = setmePieces[k] == index;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
setmePieces[setSize++] = index; /* (9) */
|
||||
}
|
||||
}
|
||||
|
||||
tr_sha1(x, x, sizeof(x), nullptr); /* (3) */
|
||||
}
|
||||
}
|
||||
|
||||
return setSize;
|
||||
}
|
||||
|
||||
static void updateFastSet(tr_peerMsgs*)
|
||||
{
|
||||
bool const fext = msgs->io->supportsFEXT();
|
||||
bool const peerIsNeedy = msgs->peer->progress < 0.10;
|
||||
|
||||
if (fext && peerIsNeedy && !msgs->haveFastSet)
|
||||
{
|
||||
tr_info const* inf = &msgs->torrent->info;
|
||||
size_t const numwant = std::min(MAX_FAST_SET_SIZE, inf->pieceCount);
|
||||
|
||||
/* build the fast set */
|
||||
msgs->fastsetSize = tr_generateAllowedSet(msgs->fastset, numwant, inf->pieceCount, inf->hash, msgs->io->address());
|
||||
msgs->haveFastSet = true;
|
||||
|
||||
/* send it to the peer */
|
||||
for (size_t i = 0; i < msgs->fastsetSize; ++i)
|
||||
{
|
||||
protocolSendAllowedFast(msgs, msgs->fastset[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
*** INTEREST
|
||||
**/
|
||||
|
|
|
@ -596,11 +596,6 @@ private:
|
|||
static auto constexpr TorrentAnnounceIntervalSec = time_t{ 240U }; // how frequently to reannounce the same torrent
|
||||
static auto constexpr TtlSameSubnet = int{ 1 };
|
||||
static auto constexpr AnnounceScope = int{ TtlSameSubnet }; /**<the maximum scope for LPD datagrams */
|
||||
|
||||
// static auto constexpr TtlSameSite = int{ 32 };
|
||||
// static auto constexpr TtlSameRegion = int{ 64 };
|
||||
// static auto constexpr TtlSameContinent = int{ 128 };
|
||||
// static auto constexpr TtlUnrestricted = int{ 255 };
|
||||
};
|
||||
|
||||
std::unique_ptr<tr_lpd> tr_lpd::create(
|
||||
|
|
|
@ -80,16 +80,10 @@
|
|||
auto inline constexpr PEER_ID_LEN = size_t{ 20 };
|
||||
using tr_peer_id_t = std::array<char, PEER_ID_LEN>;
|
||||
|
||||
#define SHA_DIGEST_LENGTH 20
|
||||
|
||||
// TODO #1: all arrays of SHA_DIGEST_LENGTH should be replaced with tr_sha1_digest_t
|
||||
// TODO #2: tr_peer_id_t, tr_sha1_digest_t should be moved into a new 'types.h' header
|
||||
auto inline constexpr TR_SHA1_DIGEST_LEN = size_t{ 20 };
|
||||
auto inline constexpr TR_SHA1_DIGEST_STRLEN = size_t{ 40 };
|
||||
using tr_sha1_digest_t = std::array<std::byte, TR_SHA1_DIGEST_LEN>;
|
||||
using tr_sha1_digest_t = std::array<std::byte, 20>;
|
||||
using tr_sha1_digest_string_t = std::array<char, TR_SHA1_DIGEST_STRLEN + 1>; // +1 for '\0'
|
||||
|
||||
auto inline constexpr TR_SHA256_DIGEST_LEN = size_t{ 32 };
|
||||
auto inline constexpr TR_SHA256_DIGEST_STRLEN = size_t{ 64 };
|
||||
using tr_sha256_digest_t = std::array<std::byte, TR_SHA256_DIGEST_LEN>;
|
||||
using tr_sha256_digest_t = std::array<std::byte, 32>;
|
||||
using tr_sha256_digest_string_t = std::array<char, TR_SHA256_DIGEST_STRLEN + 1>; // +1 for '\0'
|
||||
|
|
Loading…
Reference in New Issue