update tf with lossy and print up/down stats every 15s

This commit is contained in:
Green Sky 2023-01-17 19:34:36 +01:00
parent 83dcf2af82
commit 92dcc81731
No known key found for this signature in database
4 changed files with 31 additions and 2 deletions

@ -1 +1 @@
Subproject commit aa9c7c44bab594cd03b0ad5af70fd5c39a34cf6b
Subproject commit 3675c2a1a8dc01e3a892d4f487f98657a9ea0ce6

View File

@ -182,6 +182,25 @@ bool SHA1::iterate(float delta) {
}
}
// log
_io_log_timer += delta;
static const float log_interval {15.f};
if (_io_log_timer >= log_interval) {
_io_log_timer = 0.f;
size_t bytes_up_since {_bytes_up - _bytes_up_last_log};
_bytes_up_last_log = _bytes_up;
size_t bytes_down_since {_bytes_down - _bytes_down_last_log};
_bytes_down_last_log = _bytes_down;
float up_kibs {(bytes_up_since / 1024.f) / log_interval};
float down_kibs {(bytes_down_since / 1024.f) / log_interval};
std::cout << "SHA1 speed down: " << down_kibs << "KiB/s up: " << up_kibs << "KiB/s\n";
std::cout << "SHA1 total down: " << _bytes_down / 1024 << "KiB up: " << _bytes_up / 1024 << "KiB\n";
}
// TODO: unmap and remap the file every couple of minutes to keep ram usage down?
// TODO: when to stop?
return false;
@ -324,6 +343,8 @@ void SHA1::onFT1ReceiveDataSHA1Chunk(uint32_t group_number, uint32_t peer_number
// check transfers
for (auto it = _transfers_receiving_chunk.begin(); it != _transfers_receiving_chunk.end(); it++) {
if (std::get<0>(*it) == group_number && std::get<1>(*it) == peer_number && std::get<2>(*it) == transfer_id) {
_bytes_down += data_size;
std::get<float>(*it) = 0.f; // time
const size_t chunk_index = std::get<4>(*it);
@ -364,6 +385,8 @@ void SHA1::onFT1SendDataSHA1Chunk(uint32_t group_number, uint32_t peer_number, u
// TODO: sub optimal
for (auto it = _transfers_sending_chunk.begin(); it != _transfers_sending_chunk.end(); it++) {
if (std::get<0>(*it) == group_number && std::get<1>(*it) == peer_number && std::get<2>(*it) == transfer_id) {
_bytes_up += data_size;
std::get<float>(*it) = 0.f; // time
const size_t chunk_index = std::get<4>(*it);

View File

@ -61,6 +61,12 @@ struct SHA1 final : public StateI {
const std::vector<uint8_t> _sha1_info_data;
const SHA1Digest _sha1_info_hash;
float _io_log_timer {0.f};
size_t _bytes_up {0};
size_t _bytes_up_last_log {0};
size_t _bytes_down {0};
size_t _bytes_down_last_log {0};
// index is the same as for info
std::vector<bool> _have_chunk;
bool _have_all {false};

View File

@ -278,7 +278,7 @@ void ToxClient::onToxGroupPeerJoin(uint32_t group_number, uint32_t peer_id) {
}
void ToxClient::onToxGroupPeerExit(uint32_t group_number, uint32_t peer_id, Tox_Group_Exit_Type exit_type, std::string_view name, std::string_view part_message) {
std::cout << "TCL group peer exit " << group_number << ":" << peer_id << "\n";
std::cout << "TCL group peer exit " << group_number << ":" << peer_id << " " << name << "\n";
_groups[group_number].erase(peer_id);
_tox_profile_dirty = true;
}