GlobalNodeList.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #ifndef __GLOBALNODELIST_H__
00025 #define __GLOBALNODELIST_H__
00026
00027 #include <map>
00028 #include <vector>
00029 #include <oversim_mapset.h>
00030
00031 #include <omnetpp.h>
00032
00033 #include <ChurnGenerator.h>
00034 #include <HashFunc.h>
00035 #include <BinaryValue.h>
00036 #include <NodeHandle.h>
00037
00038 class PeerInfo;
00039 class BootstrapList;
00040 class TransportAddress;
00041 class OverlayKey;
00042 class GlobalStatistics;
00043
00050 struct bootstrapEntry
00051 {
00052 TransportAddress* node;
00053 PeerInfo* info;
00054 friend std::ostream& operator<<(std::ostream& Stream, const bootstrapEntry entry);
00055 };
00056
00064 class GlobalNodeList : public cSimpleModule
00065 {
00066 public:
00070 typedef std::vector<OverlayKey> KeyList;
00071
00075 ~GlobalNodeList();
00076
00086 void addPeer(const IPvXAddress& ip, PeerInfo* info);
00087
00093 void sendNotificationToAllPeers(int category);
00094
00103 virtual void killPeer(const IPvXAddress& ip);
00104
00117 virtual const NodeHandle& getRandomNode(uint32_t nodeType = 0,
00118 bool bootstrappedNeeded = true,
00119 bool inoffensiveNeeded = false);
00120
00132 virtual const NodeHandle& getBootstrapNode(const NodeHandle &node =
00133 NodeHandle::UNSPECIFIED_NODE);
00134
00140 virtual void registerPeer(const TransportAddress& peer);
00141
00147 virtual void registerPeer(const NodeHandle& peer);
00148
00149
00155 virtual void refreshEntry(const TransportAddress& peer);
00156
00162 virtual void removePeer(const TransportAddress& peer);
00163
00170 virtual KeyList* getKeyList(uint32_t maximumKeys);
00171
00177 virtual const OverlayKey& getRandomKeyListItem() const;
00178
00185 virtual void setOverlayReadyIcon(const TransportAddress& address, bool ready);
00186
00193 virtual PeerInfo* getPeerInfo(const TransportAddress& peer);
00194
00201 virtual void setMalicious(const TransportAddress& address, bool malicious);
00202
00209 virtual bool isMalicious(const TransportAddress& address);
00210
00211 virtual cObject** getContext(const TransportAddress& address);
00212
00218 void setPreKilled(const TransportAddress& address);
00219
00227 TransportAddress* getRandomAliveNode(uint32_t nodeType = 0);
00228
00236 virtual PeerInfo* getRandomPeerInfo(uint32_t nodeType = 0,
00237 bool bootstrapNeeded = false);
00238
00245 virtual PeerInfo* getPeerInfo(const IPvXAddress& ip);
00246
00247 size_t getNumNodes() { return peerSet.size(); };
00248
00249 bool areNodeTypesConnected(uint32_t a, uint32_t b);
00250 void connectNodeTypes(uint32_t a, uint32_t b);
00251 void disconnectNodeTypes(uint32_t a, uint32_t b);
00252 void mergeBootstrapNodes(int toPartition, int fromPartition, int numNodes);
00253
00254 inline void incLandmarkPeerSize() { landmarkPeerSize++; }
00255 inline uint16_t getLandmarkPeerSize() { return landmarkPeerSize; }
00256 inline void incLandmarkPeerSizePerType(uint16_t type) { landmarkPeerSizePerType[type]++; }
00257 inline uint32_t getBootstrappedPeerSize() { return bootstrappedPeerSize; }
00258
00259 protected:
00260
00264 virtual void initialize();
00265
00271 virtual void handleMessage(cMessage* msg);
00272
00278 virtual void createKeyList(uint32_t size);
00279
00280 KeyList keyList;
00281 uint32_t bootstrappedPeerSize;
00282 uint32_t bootstrappedPeerSizePerType[MAX_NODETYPES];
00283 uint16_t landmarkPeerSize;
00284 uint16_t landmarkPeerSizePerType[MAX_NODETYPES];
00285 uint32_t bootstrappedMaliciousNodes;
00286 uint32_t maliciousNodes;
00287 uint32_t preKilledNodes;
00288 double maliciousNodeRatio;
00289 cOutVector maliciousNodesVector;
00290 typedef UNORDERED_MAP<IPvXAddress, bootstrapEntry> PeerHashMap;
00291 PeerHashMap peerSet;
00293
00294 uint32_t maxNumberOfKeys;
00295 double keyProbability;
00297 private:
00298 uint32 min_ip, max_ip;
00299 GlobalStatistics* globalStatistics;
00300 bool connectionMatrix[MAX_NODETYPES][MAX_NODETYPES];
00301 };
00302
00303 #endif