From ef91ec14fcb14296b471f601b449a7f7e4a835a5 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Wed, 10 Jul 2024 10:41:25 +0200 Subject: [PATCH] explicit and better rng, remove junk and old code --- solanaceae/ngc_ft1_sha1/chunk_picker.cpp | 65 ++---------------------- solanaceae/ngc_ft1_sha1/chunk_picker.hpp | 31 +++-------- solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp | 2 +- 3 files changed, 12 insertions(+), 86 deletions(-) diff --git a/solanaceae/ngc_ft1_sha1/chunk_picker.cpp b/solanaceae/ngc_ft1_sha1/chunk_picker.cpp index 125f4f4..ee92831 100644 --- a/solanaceae/ngc_ft1_sha1/chunk_picker.cpp +++ b/solanaceae/ngc_ft1_sha1/chunk_picker.cpp @@ -49,7 +49,7 @@ struct PickerStrategySequential { struct PickerStrategyRandom { const BitSet& chunk_candidates; const size_t total_chunks; - std::default_random_engine& rng; + std::minstd_rand& rng; size_t count {0u}; size_t i {rng()%total_chunks}; @@ -57,7 +57,7 @@ struct PickerStrategyRandom { PickerStrategyRandom( const BitSet& chunk_candidates_, const size_t total_chunks_, - std::default_random_engine& rng_ + std::minstd_rand& rng_ ) : chunk_candidates(chunk_candidates_), total_chunks(total_chunks_), @@ -94,7 +94,7 @@ struct PickerStrategyRandomSequential { PickerStrategyRandomSequential( const BitSet& chunk_candidates_, const size_t total_chunks_, - std::default_random_engine& rng_ + std::minstd_rand& rng_ ) : psr(chunk_candidates_, total_chunks_, rng_), pssf(chunk_candidates_, total_chunks_) @@ -146,6 +146,7 @@ void ChunkPicker::updateParticipation( } if (!o.get().have_all) { + // TODO: set priority participating_unfinished.emplace(o, ParticipationEntry{}); } } @@ -166,64 +167,6 @@ void ChunkPicker::updateParticipation( } } -void ChunkPicker::validateParticipation( - Contact3Handle c, - ObjectRegistry& objreg -) { -#if 0 - // replaces them in place - participating.clear(); - participating_unfinished.clear(); - - for (const Object ov : objreg.view()) { - const ObjectHandle o {objreg, ov}; - - participating.emplace(o); - - if (!o.all_of()) { - continue; - } - - if (!o.get().have_all) { - participating_unfinished.emplace(o, ParticipationEntry{}); - } - } -#endif - entt::dense_set val_p; - //entt::dense_set val_pu; - //participating_unfinished.clear(); // HACK: rn this update unfished o.o - - for (const Object ov : objreg.view()) { - const ObjectHandle o {objreg, ov}; - - val_p.emplace(o); - - //if (!o.all_of()) { - // continue; - //} - - //if (!o.get().have_all) { - // //val_pu.emplace(o); - // //participating_unfinished.emplace(o, ParticipationEntry{}); - //} - } - - // validate - if (c.all_of()) { - const auto& participating = c.get().participating; - assert(val_p.size() == participating.size()); - //assert(val_pu.size() == participating_unfinished.size()); - - for (const auto& it : val_p) { - assert(participating.contains(it)); - } - } - - //for (const auto& it : val_pu) { - // assert(participating_unfinished.contains(it)); - //} -} - std::vector ChunkPicker::updateChunkRequests( Contact3Handle c, ObjectRegistry& objreg, diff --git a/solanaceae/ngc_ft1_sha1/chunk_picker.hpp b/solanaceae/ngc_ft1_sha1/chunk_picker.hpp index 9854ac3..1557d06 100644 --- a/solanaceae/ngc_ft1_sha1/chunk_picker.hpp +++ b/solanaceae/ngc_ft1_sha1/chunk_picker.hpp @@ -30,27 +30,23 @@ struct ChunkPickerTimer { struct ChunkPicker { // max transfers static constexpr size_t max_tf_info_requests {1}; - static constexpr size_t max_tf_chunk_requests {3}; + static constexpr size_t max_tf_chunk_requests {3}; // TODO: dynamic, function/factor of (window(delay*speed)/chunksize) - std::default_random_engine _rng{std::random_device{}()}; - - //// max outstanding requests - //// TODO: should this include transfers? - //static constexpr size_t max_open_info_requests {1}; - //const size_t max_open_chunk_requests {6}; + // TODO: cheaper init? tls rng for deep seeding? + std::minstd_rand _rng{std::random_device{}()}; // TODO: handle with hash utils? struct ParticipationEntry { ParticipationEntry(void) {} // skips in round robin -> lower should_skip => higher priority + // TODO: replace with enum value uint16_t should_skip {2}; // 0 high, 8 low (double each time? 0,1,2,4,8) uint16_t skips {2}; }; - // TODO: only unfinished? entt::dense_map participating_unfinished; Object participating_in_last {entt::null}; - private: + private: // TODO: properly sort // updates participating_unfinished void updateParticipation( Contact3Handle c, @@ -58,19 +54,11 @@ struct ChunkPicker { ); public: - void validateParticipation( - Contact3Handle c, - ObjectRegistry& objreg - ); + // ---------- tick ---------- - // tick //void sendInfoRequests(); + // is this like a system? - // TODO: only update on: - // - transfer start? - // - transfer done - // - request timed out - // - reset on disconnect? struct ContentChunkR { ObjectHandle object; size_t chunk_index; @@ -83,10 +71,5 @@ struct ChunkPicker { const size_t open_requests //NGCFT1& nft ); - - // - reset on disconnect? - void resetPeer( - Contact3Handle c - ); }; diff --git a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp index 60802c3..adc8cc8 100644 --- a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp +++ b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp @@ -461,7 +461,7 @@ float SHA1_NGCFT1::iterate(float delta) { // updateChunkRequests updates the unfinished // TODO: pull out and check there? if (cp.participating_unfinished.empty()) { - std::cout << "destorying empty useless cp\n"; + std::cout << "destroying empty useless cp\n"; cp_to_remove.push_back(c); } else { // most likely will have something soon