finish request strategy (for now)

This commit is contained in:
Green Sky 2023-01-16 15:29:49 +01:00
parent e89f1be660
commit 78069a8032
No known key found for this signature in database
5 changed files with 25 additions and 7 deletions

@ -1 +1 @@
Subproject commit 04befb21be0327996eb3597cb91d5bdd00066974
Subproject commit bbe4453833ad561c79a7cae1a5ac5e66d06535f7

View File

@ -27,7 +27,7 @@ SendStartSHA1::SendStartSHA1(ToxClient& tcl, const CommandLine& cl) : StateI(tcl
assert(!_file_map.empty());
// build info
_sha1_info.file_name = std::filesystem::path(cl.send_path).filename();
_sha1_info.file_name = std::filesystem::path(cl.send_path).filename().string();
_sha1_info.file_size = _file_map.length();
{ // build chunks

View File

@ -82,11 +82,24 @@ bool SHA1::iterate(float delta) {
// if we have not heard for 10sec, timeout
if (time_since_remove_activity >= 10.f) {
std::cerr << "SHA1 receiving chunk tansfer timed out " << std::get<0>(*it) << ":" << std::get<1>(*it) << "." << int(std::get<2>(*it)) << "\n";
_chunk_want_queue.push_back(std::get<4>(*it)); // put it back
it = _transfers_receiving_chunk.erase(it);
} else {
it++;
}
}
// sent requests
for (auto it = _chunks_requested.begin(); it != _chunks_requested.end();) {
it->second += delta;
// if we have not heard for 15sec, timeout
if (it->second >= 15.f) {
_chunk_want_queue.push_back(it->first); // put it back
it = _chunks_requested.erase(it);
} else {
it++;
}
}
}
// if we have not reached the total cap for transfers
@ -142,7 +155,7 @@ bool SHA1::iterate(float delta) {
}
}
if (!_have_all && !_chunk_want_queue.empty() && _transfers_receiving_chunk.size() < _max_concurrent_in) {
if (!_have_all && !_chunk_want_queue.empty() && _chunks_requested.size() + _transfers_receiving_chunk.size() < _max_concurrent_in) {
// send out request, no burst tho
std::vector<std::pair<uint32_t, uint32_t>> target_peers;
_tcl.forEachGroup([&target_peers, this](uint32_t group_number) {
@ -162,7 +175,7 @@ bool SHA1::iterate(float delta) {
auto [group_number, peer_number] = target_peers.at(target_index);
size_t chunk_index = _chunk_want_queue.front();
_chunks_requested.emplace(chunk_index);
_chunks_requested[chunk_index] = 0.f;
_chunk_want_queue.pop_front();
_tcl.sendFT1RequestPrivate(group_number, peer_number, NGC_FT1_file_kind::HASH_SHA1_CHUNK, _sha1_info.chunks[chunk_index].data.data(), 20);
@ -301,6 +314,9 @@ bool SHA1::onFT1ReceiveInitSHA1Chunk(uint32_t group_number, uint32_t peer_number
)
);
// remove form requests
_chunks_requested.erase(chunk_index);
return true;
}

View File

@ -7,7 +7,7 @@
#include <mio/mio.hpp>
#include <unordered_map>
#include <set>
#include <map>
#include <vector>
#include <deque>
#include <random>
@ -66,10 +66,11 @@ struct SHA1 final : public StateI {
bool _have_all {false};
size_t _have_count {0};
std::deque<size_t> _chunk_want_queue;
std::set<size_t> _chunks_requested;
// chunk_index -> time since request
std::map<size_t, float> _chunks_requested;
const size_t _max_concurrent_out {4};
const size_t _max_concurrent_in {4};
const size_t _max_concurrent_in {16};
std::minstd_rand _rng {1337};
std::uniform_int_distribution<size_t> _distrib;

View File

@ -253,6 +253,7 @@ void ToxClient::onToxGroupPeerExit(uint32_t group_number, uint32_t peer_id, Tox_
void ToxClient::onToxGroupSelfJoin(uint32_t group_number) {
std::cout << "TCL group self join " << group_number << "\n";
// ???
// can be triggered after other peers allready joined o.o
_tox_profile_dirty = true;
}