-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsvs.hpp
93 lines (69 loc) · 2.41 KB
/
svs.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
#include <deque>
#include <iostream>
#include <ndn-cxx/util/scheduler.hpp>
#include <random>
#include <thread>
#include <mutex>
#include "svs_common.hpp"
#include "svs_helper.hpp"
namespace ndn {
namespace svs {
class SVS {
public:
SVS(NodeID id, std::function<void(const std::string &)> onMsg_)
: onMsg(onMsg_),
m_id(id),
m_scheduler(m_face.getIoService()),
rengine_(rdevice_()) {
// Bootstrap with knowledge of itself only
m_vv[id] = 0;
}
void run();
void registerPrefix();
void publishMsg(const std::string &msg);
private:
void asyncSendPacket();
void onSyncInterest(const Interest &interest);
void onDataInterest(const Interest &interest);
void onSyncAck(const Data &data);
void onDataReply(const Data &data);
void onNack(const Interest &interest, const lp::Nack &nack);
void onTimeout(const Interest &interest);
void retxSyncInterest();
void sendSyncInterest();
void sendSyncACK(const Name &n);
std::pair<bool, bool> mergeStateVector(const VersionVector &vv_other);
std::function<void(const std::string &)> onMsg;
// Members
NodeID m_id;
Face m_face;
KeyChain m_keyChain;
VersionVector m_vv;
Scheduler m_scheduler; // Use io_service from face
std::unordered_map<Name, std::shared_ptr<const Data>> m_data_store;
// Mult-level queues
std::deque<std::shared_ptr<Packet>> pending_ack;
std::deque<std::shared_ptr<Packet>> pending_sync_interest;
std::deque<std::shared_ptr<Packet>> pending_data_reply;
std::deque<std::shared_ptr<Packet>> pending_data_interest_forwarded;
std::deque<std::shared_ptr<Packet>> pending_data_interest;
std::mutex pending_sync_interest_mutex;
// Microseconds between sending two packets in the queues
std::uniform_int_distribution<> packet_dist =
std::uniform_int_distribution<>(10000, 15000);
// Microseconds between sending two sync interests
std::uniform_int_distribution<> retx_dist =
std::uniform_int_distribution<>(1000000 * 0.9, 1000000 * 1.1);
// Microseconds for sending ACK if local vector isn't newer
std::uniform_int_distribution<> ack_dist =
std::uniform_int_distribution<>(20000, 40000);
// Random engine
std::random_device rdevice_;
std::mt19937 rengine_;
// Events
scheduler::EventId retx_event; // will send retx next sync intrest
scheduler::EventId packet_event; // Will send next packet async
};
} // namespace svs
} // namespace ndn