make incoming request timeout and respect a failed sendInit()

This commit is contained in:
Green Sky 2023-01-18 01:52:39 +01:00
parent d888e91ada
commit 365edc35e9
No known key found for this signature in database
2 changed files with 37 additions and 23 deletions

View File

@ -104,6 +104,18 @@ bool SHA1::iterate(float delta) {
it++;
}
}
// queued requests
for (auto it = _queue_requested_chunk.begin(); it != _queue_requested_chunk.end();) {
float& timer = std::get<float>(*it);
timer += delta;
if (timer >= 15.f) {
it = _queue_requested_chunk.erase(it);
} else {
it++;
}
}
}
// if we have not reached the total cap for transfers
@ -117,14 +129,13 @@ bool SHA1::iterate(float delta) {
uint8_t transfer_id {0};
_tcl.sendFT1InitPrivate(
if (_tcl.sendFT1InitPrivate(
group_number, peer_number,
NGC_FT1_file_kind::HASH_SHA1_INFO,
_sha1_info_hash.data.data(), _sha1_info_hash.size(), // id (info hash)
_sha1_info_data.size(), // "file_size"
transfer_id
);
)) {
_transfers_requested_info.push_back({
group_number, peer_number,
transfer_id,
@ -132,22 +143,22 @@ bool SHA1::iterate(float delta) {
});
_queue_requested_info.pop_front();
}
} else if (!_queue_requested_chunk.empty()) { // then check for chunk requests
const auto [group_number, peer_number, chunk_hash] = _queue_requested_chunk.front();
const auto [group_number, peer_number, chunk_hash, _] = _queue_requested_chunk.front();
size_t chunk_index = chunkIndex(chunk_hash).value();
size_t chunk_file_size = chunkSize(chunk_index);
uint8_t transfer_id {0};
_tcl.sendFT1InitPrivate(
if (_tcl.sendFT1InitPrivate(
group_number, peer_number,
NGC_FT1_file_kind::HASH_SHA1_CHUNK,
chunk_hash.data.data(), chunk_hash.size(), // id (chunk hash)
chunk_file_size,
transfer_id
);
)) {
_transfers_sending_chunk.push_back({
group_number, peer_number,
transfer_id,
@ -158,6 +169,7 @@ bool SHA1::iterate(float delta) {
_queue_requested_chunk.pop_front();
}
}
}
if (!_have_all && !_chunk_want_queue.empty() && _chunks_requested.size() + _transfers_receiving_chunk.size() < _max_concurrent_in) {
// send out request, no burst tho
@ -438,15 +450,17 @@ void SHA1::queueUpRequestInfo(uint32_t group_number, uint32_t peer_number) {
void SHA1::queueUpRequestChunk(uint32_t group_number, uint32_t peer_number, const SHA1Digest& hash) {
// TODO: transfers
for (auto& [i_g, i_p, i_h] : _queue_requested_chunk) {
for (auto& [i_g, i_p, i_h, i_t] : _queue_requested_chunk) {
// if already in queue
if (i_g == group_number && i_p == peer_number && i_h == hash) {
// update timer
i_t = 0.f;
return;
}
}
// not in queue yet
_queue_requested_chunk.push_back(std::make_tuple(group_number, peer_number, hash));
_queue_requested_chunk.push_back(std::make_tuple(group_number, peer_number, hash, 0.f));
}
std::optional<size_t> SHA1::chunkIndex(const SHA1Digest& hash) const {

View File

@ -91,7 +91,7 @@ struct SHA1 final : public StateI {
std::vector<std::tuple<uint32_t, uint32_t, uint8_t, float>> _transfers_requested_info;
// group_number, peer_number, chunk_hash
std::deque<std::tuple<uint32_t, uint32_t, SHA1Digest>> _queue_requested_chunk;
std::deque<std::tuple<uint32_t, uint32_t, SHA1Digest, float>> _queue_requested_chunk;
// group_number, peer_number, transfer_id(i/o), seconds since (remote) activity, chunk index
std::vector<std::tuple<uint32_t, uint32_t, uint8_t, float, size_t>> _transfers_sending_chunk;