explicit and better rng, remove junk and old code

This commit is contained in:
Green Sky 2024-07-10 10:41:25 +02:00
parent 699957f79a
commit ef91ec14fc
No known key found for this signature in database
3 changed files with 12 additions and 86 deletions

View File

@ -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<Components::FT1ChunkSHA1Cache>().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<Components::SuspectedParticipants>()) {
const ObjectHandle o {objreg, ov};
participating.emplace(o);
if (!o.all_of<Components::FT1ChunkSHA1Cache, Components::FT1InfoSHA1>()) {
continue;
}
if (!o.get<Components::FT1ChunkSHA1Cache>().have_all) {
participating_unfinished.emplace(o, ParticipationEntry{});
}
}
#endif
entt::dense_set<Object> val_p;
//entt::dense_set<Object> val_pu;
//participating_unfinished.clear(); // HACK: rn this update unfished o.o
for (const Object ov : objreg.view<Components::SuspectedParticipants>()) {
const ObjectHandle o {objreg, ov};
val_p.emplace(o);
//if (!o.all_of<Components::FT1ChunkSHA1Cache, Components::FT1InfoSHA1>()) {
// continue;
//}
//if (!o.get<Components::FT1ChunkSHA1Cache>().have_all) {
// //val_pu.emplace(o);
// //participating_unfinished.emplace(o, ParticipationEntry{});
//}
}
// validate
if (c.all_of<Contact::Components::FT1Participation>()) {
const auto& participating = c.get<Contact::Components::FT1Participation>().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::ContentChunkR> ChunkPicker::updateChunkRequests(
Contact3Handle c,
ObjectRegistry& objreg,

View File

@ -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<Object, ParticipationEntry> 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
);
};

View File

@ -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