-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperiment.hpp
69 lines (52 loc) · 1.99 KB
/
experiment.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef DHTSIM_EXPERIMENT_HPP
#define DHTSIM_EXPERIMENT_HPP
#include "network.hpp"
#include "callback.hpp"
#include <cstdint>
#include <iostream> //temporary
namespace dhtsim {
template <typename Node>
class Experiment {
public:
using Key = typename Node::Key;
using FetchCallbackSet = CallbackSet<std::vector<unsigned char>, int>;
// there is no way to do that through the generic DHTNode
// interface.
Experiment(CentralizedNetwork<uint32_t>& net,
const std::vector<std::shared_ptr<Application<uint32_t>>>& nodes) :
net(net), nodes(nodes), waiting(nodes.size(), 0), current_epoch(0) {}
virtual void init() = 0;
virtual void run() = 0;
protected:
void addNode(std::shared_ptr<Node> n) {
this->net.add(n);
this->nodes.push_back(n);
this->waiting.push_back(false);
}
CentralizedNetwork<uint32_t> net;
std::vector<std::shared_ptr<Application<uint32_t>>> nodes;
// a bit mask over each node, "is this node waiting for something?"
std::vector<bool> waiting;
// the keys data for each node we stored
std::vector<Key> stored_data_keys;
unsigned int current_epoch;
void recordFind(size_t node_index, size_t target_data_index, Time since) {
this->waiting[node_index] = false;
std::cout << "[E] S " << node_index << " " << target_data_index
<< " " << this->net.current_epoch() - since << std::endl;
}
void recordFail(size_t node_index, size_t target_data_index, Time since) {
this->waiting[node_index] = false;
std::cout << "[E] F " << node_index << " " << target_data_index
<< " " << this->net.current_epoch() - since << std::endl;
}
std::shared_ptr<Node> create();
void introduce(const std::shared_ptr<Application<uint32_t>>& n1,
const std::shared_ptr<Application<uint32_t>>& n2);
Key store(const std::shared_ptr<Application<uint32_t>>& storer,
const std::vector<unsigned char>& data);
void fetch(const std::shared_ptr<Application<uint32_t>>& fetcher,
const Key& data, FetchCallbackSet cb);
};
}
#endif