make max transfers configurable

This commit is contained in:
Green Sky 2023-01-17 20:52:03 +01:00
parent 92dcc81731
commit 2f1bb3fac2
No known key found for this signature in database
8 changed files with 27 additions and 10 deletions

View File

@ -122,6 +122,8 @@ CommandLine::CommandLine(int argc, char** argv) {
} else if (parser.parseParam("--ft_sending_resend_without_ack_after", ft_sending_resend_without_ack_after)) {
} else if (parser.parseParam("--ft_sending_give_up_after", ft_sending_give_up_after)) {
} else if (parser.parseParam("--ft_packet_window_size", ft_packet_window_size)) {
} else if (parser.parseParam("-I", max_incoming_transfers)) {
} else if (parser.parseParam("-O", max_outgoing_transfers)) {
} else {
std::cerr << "ERROR: unknown parameter '" << arg_sv << "' !\n\n";
PRINT_HELP_AND_BAIL;
@ -180,7 +182,8 @@ void CommandLine::printHelp(void) {
<< " --ft_packet_window_size\n"
<< "\n"
<< " transfer logic:\n"
<< " TODO\n"
<< " -I <max_incoming_transfers>\n"
<< " -O <max_outgoing_transfers>\n"
;
}

View File

@ -70,9 +70,12 @@ struct CommandLine {
// ---- TODO ----
// advaced dl:
// -I max_incoming_transfers (default 16)
// -O max_outgoing_transfers (default 4)
// -I max_incoming_transfers
size_t max_incoming_transfers {32};
// -O max_outgoing_transfers
size_t max_outgoing_transfers {16};
// -u request chunks only from UDP-direct peers
bool request_only_from_udp_peer {false};
CommandLine(int argc, char** argv);

View File

@ -20,7 +20,7 @@
namespace States {
ReceiveStartSHA1::ReceiveStartSHA1(ToxClient& tcl, const CommandLine& cl) : StateI(tcl), _dump_dir(cl.receive_dump_dir) {
ReceiveStartSHA1::ReceiveStartSHA1(ToxClient& tcl, const CommandLine& cl) : StateI(tcl), _cl(cl), _dump_dir(cl.receive_dump_dir) {
if (cl.receive_id.empty()) {
throw std::runtime_error("receiver missing id");
}
@ -41,7 +41,7 @@ bool ReceiveStartSHA1::iterate(float delta) {
// timout if not heard after 10s
if (time_since_remote_activity >= 10.f) {
std::cerr << "ReceiveStartSHA1 info tansfer timed out " << std::get<0>(*_transfer) << ":" << std::get<1>(*_transfer) << "." << std::get<2>(*_transfer) << "\n";
std::cerr << "ReceiveStartSHA1 info tansfer timed out " << std::get<0>(*_transfer) << ":" << std::get<1>(*_transfer) << "." << int(std::get<2>(*_transfer)) << "\n";
_transfer.reset();
}
@ -114,6 +114,7 @@ std::unique_ptr<StateI> ReceiveStartSHA1::nextState(void) {
std::cout << "ReceiveStartSHA1 switching state to SHA1\n";
return std::make_unique<SHA1>(
_tcl,
_cl,
std::move(file_map),
std::move(sha1_info),
std::move(_sha1_info_data),
@ -148,7 +149,7 @@ bool ReceiveStartSHA1::onFT1ReceiveInitSHA1Info(uint32_t group_number, uint32_t
_sha1_info_data.resize(file_size);
_transfer = std::make_tuple(group_number, peer_number, transfer_id, 0.f);
std::cout << "ReceiveStartSHA1 accepted info transfer" << group_number << ":" << peer_number << "." << transfer_id << "\n";
std::cout << "ReceiveStartSHA1 accepted info transfer" << group_number << ":" << peer_number << "." << int(transfer_id) << "\n";
// accept
return true;
@ -174,7 +175,7 @@ void ReceiveStartSHA1::onFT1ReceiveDataSHA1Info(uint32_t group_number, uint32_t
_sha1_info_data.clear();
}
std::cout << "ReceiveStartSHA1 info tansfer finished " << group_number << ":" << peer_number << "." << transfer_id << "\n";
std::cout << "ReceiveStartSHA1 info tansfer finished " << group_number << ":" << peer_number << "." << int(transfer_id) << "\n";
_done = true;
}
}

View File

@ -33,6 +33,7 @@ struct ReceiveStartSHA1 final : public StateI {
void onFT1SendDataSHA1Chunk(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, uint8_t* data, size_t data_size) override;
private:
const CommandLine& _cl;
std::string _dump_dir;
//FTInfoSHA1 _sha1_info;

View File

@ -17,7 +17,7 @@
namespace States {
SendStartSHA1::SendStartSHA1(ToxClient& tcl, const CommandLine& cl) : StateI(tcl), _file_path(cl.send_path) {
SendStartSHA1::SendStartSHA1(ToxClient& tcl, const CommandLine& cl) : StateI(tcl), _cl(cl), _file_path(cl.send_path) {
std::cout << "SendStartSHA1 start building sha1_info\n";
std::error_code err;
_file_map = mio::make_mmap_source(cl.send_path, 0, mio::map_entire_file, err);
@ -72,6 +72,7 @@ std::unique_ptr<StateI> SendStartSHA1::nextState(void) {
// we are done setting up
return std::make_unique<SHA1>(
_tcl,
_cl,
std::move(new_file_map),
std::move(_sha1_info),
std::move(_sha1_info_data),

View File

@ -33,6 +33,8 @@ struct SendStartSHA1 final : public StateI {
void onFT1SendDataSHA1Chunk(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, uint8_t* data, size_t data_size) override;
private:
const CommandLine& _cl;
std::string _file_path;
mio::mmap_source _file_map;
FTInfoSHA1 _sha1_info;

View File

@ -11,6 +11,7 @@ namespace States {
SHA1::SHA1(
ToxClient& tcl,
const CommandLine& cl,
mio::mmap_sink&& file_map,
const FTInfoSHA1&& sha1_info,
const std::vector<uint8_t>&& sha1_info_data,
@ -27,6 +28,9 @@ SHA1::SHA1(
{
assert(_have_chunk.size() == _sha1_info.chunks.size());
_max_concurrent_in = cl.max_incoming_transfers;
_max_concurrent_out = cl.max_incoming_transfers;
_have_all = true;
_have_count = 0;
for (size_t i = 0; i < _have_chunk.size(); i++) {

View File

@ -3,6 +3,7 @@
#include "../state.hpp"
#include "../ft_sha1_info.hpp"
#include "../command_line.hpp"
#include <mio/mio.hpp>
@ -20,6 +21,7 @@ struct SHA1 final : public StateI {
public: // general interface
SHA1(
ToxClient& tcl,
const CommandLine& cl,
mio::mmap_sink&& file_map,
const FTInfoSHA1&& sha1_info,
const std::vector<uint8_t>&& sha1_info_data,
@ -75,8 +77,8 @@ struct SHA1 final : public StateI {
// chunk_index -> time since request
std::map<size_t, float> _chunks_requested;
const size_t _max_concurrent_out {16};
const size_t _max_concurrent_in {32};
size_t _max_concurrent_in {32};
size_t _max_concurrent_out {16};
std::minstd_rand _rng {1337};
std::uniform_int_distribution<size_t> _distrib;