-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNode.h
184 lines (142 loc) · 4.65 KB
/
Node.h
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//
// This file is part of an OMNeT++/OMNEST simulation example.
//
// Copyright (C) 2003 Ahmet Sekercioglu
// Copyright (C) 2003-2015 Andras Varga
//
// This file is distributed WITHOUT ANY WARRANTY. See the file
// `license' for details on this and other legal matters.
//
#include <string.h>
#include <omnetpp.h>
#include <string>
#include <gmp.h>
#include <stdio.h>
#include "ChordMessages_m.h"
class SuccessorList;
class FingerTable;
class NodeHandle;
class GlobalNodeList;
using namespace omnetpp;
using namespace std;
#ifndef NODE_H_INCLUDED__
#define NODE_H_INCLUDED__
class Node : public cSimpleModule
{
public:
const std::string& getIp() const {
return IP;
}
void setIp(const std::string& ip) {
IP = ip;
}
const std::string& getOverlayKey() const {
return overlayKey;
}
void setOverlayKey(const std::string& overlayKey) {
this->overlayKey = overlayKey;
}
Node& operator=(const Node& rhs)
{
this->overlayKey = rhs.overlayKey;
this->IP = rhs.IP;
return *this;
}
const Node* getBoostrapNode() const {
return bootstrapNode;
}
void setBoostrapNode(Node* boostrapNode) {
this->bootstrapNode = boostrapNode;
}
public:
std::string IP;
std::string overlayKey;
Node* bootstrapNode;
Node* predecessor;
Node* thisNode = this;
enum States {
INIT = 0,
BOOTSTRAP = 1,
DISCOVERY = 2,
PREJOIN = 3,
JOIN = 4,
POSTJOIN = 5,
READY = 6,
REFRESH = 7,
SHUTDOWN = 8,
FAILED = 9,
};
States state;
GlobalNodeList* boostrapListNode;
static Node* UNSPECIFIED_NODE;
FingerTable* fingertable;
SuccessorList* successorlist;
protected:
Node * failedSuccessor;
// timer messages
cMessage* join_timer; /**< */
cMessage* stabilize_timer; /**< */
cMessage* fixfingers_timer; /**< */
cMessage* checkPredecessor_timer;
PingTimeout* timeout_stabilize;
PingTimeout* timeout_notify;
PingTimeout* ping_timeout;
cMessage * failed;
cMessage * stabilization_check;
//delays
double stabilizeDelay;
double fixfingersDelay;
double firstJoinDelay;
double checkPredecessorDelay;
double ping_timeoutdelay;
double stabilization_check_delay;
double failing_delay;
double timeout_stabilize_delay;
double timeout_notify_delay;
int joinretry;
bool failed_check;
int successorListSize;
int countFIxFinger = 0;
void initializeNodeinfo();
void send_chord(cMessage* msg, cModule* targetModule);
double compute_distance(string ip, bool debug = false);
virtual void initialize() override;
virtual void changeState(int toState);
void initializeFriendModules();
void findFriendModules();
~Node();
void joinOverlay();
void findSuccessor(string key, cMessage* msg);
void findPredecessor(string key, cMessage* msg);
string closestPrecedingNode(string key);
// handle message : from this all following methods are called
virtual void handleMessage(cMessage *msg) override; // base
//void handleFirstNode(cMessage* msg); // TODO
void handleTimerEvent(cMessage* msg); //base (self message)
void handleJoinTimerExpired(cMessage* msg);
void handleStabilizeTimerExpired(cMessage* msg);
virtual void handleFixFingersTimerExpired(cMessage* msg);
void handleCheckPredecessorTimerExpired(cMessage* msg);
void handlePingTimeoutExpired(cMessage * msg); // da call deve essere in grado di capire qual'era il dst e così chiamare handleFailedNode
//call or forward of actions to be performed by this node, eventually this must be performed by other nodes
void handleCall(BaseCallMessage* msg); // base method
void handleFixfingers(FixFingerCall* call);
virtual void handleJoin(JoinCall* call);
void handleNotify(NotifyCall* call);
void handleStabilize(StabilizeCall* call);
void handlePingCall(PingCall * pc);
//responses to calls
virtual void handleResponse(BaseResponseMessage* msg);
virtual void handleJoinResponse(JoinResponse* joinResponse);
virtual void handleNotifyResponse(NotifyResponse* notifyResponse);
virtual void handleStabilizeResponse(StabilizeResponse* stabilizeResponse);
virtual void handleFixfingersResponse(FixFingerResponse* fixfingersResponse);
void handlePingResponse(PingResponse * pr);
bool handleFailedNode(Node* failed);
void handleStabilizationMsg(BaseNetworkPacket* ms);
public:
bool isUnspecified(Node* nhandle);
bool isUnspecified();
bool isBetweenNodes(Node* n1, Node* n2, Node* n3);
};
#endif