GlobalNodeList.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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 
00216     void setPreKilled(const TransportAddress& address);
00217 
00225      TransportAddress* getRandomAliveNode(uint32_t nodeType = 0);
00226 
00234     virtual PeerInfo* getRandomPeerInfo(uint32_t nodeType = 0,
00235                                         bool bootstrapNeeded = false);
00236 
00243     virtual PeerInfo* getPeerInfo(const IPvXAddress& ip);
00244 
00245     bool areNodeTypesConnected(uint32_t a, uint32_t b);
00246     void connectNodeTypes(uint32_t a, uint32_t b);
00247     void disconnectNodeTypes(uint32_t a, uint32_t b);
00248     void mergeBootstrapNodes(int toPartition, int fromPartition, int numNodes);
00249 
00250     inline void incLandmarkPeerSize() { landmarkPeerSize++; }
00251     inline uint16_t getLandmarkPeerSize() { return landmarkPeerSize; }
00252     inline void incLandmarkPeerSizePerType(uint16_t type) { landmarkPeerSizePerType[type]++; }
00253     inline uint32_t getBootstrappedPeerSize() { return bootstrappedPeerSize; }
00254 
00255 protected:
00256 
00260     virtual void initialize();
00261 
00267     virtual void handleMessage(cMessage* msg);
00268 
00274     virtual void createKeyList(uint32_t size);
00275 
00276     KeyList keyList; 
00277     uint32_t bootstrappedPeerSize; 
00278     uint32_t bootstrappedPeerSizePerType[MAX_NODETYPES]; 
00279     uint16_t landmarkPeerSize;
00280     uint16_t landmarkPeerSizePerType[MAX_NODETYPES];
00281     uint32_t bootstrappedMaliciousNodes; 
00282     uint32_t maliciousNodes; 
00283     uint32_t preKilledNodes; 
00284     double maliciousNodeRatio; 
00285     cOutVector maliciousNodesVector; 
00286     typedef UNORDERED_MAP<IPvXAddress, bootstrapEntry> PeerHashMap; 
00287     PeerHashMap peerSet; 
00289     // key distribution parameters TODO should be put into an other module
00290     uint32_t maxNumberOfKeys; 
00291     double keyProbability; 
00293 private:
00294     uint32 min_ip, max_ip; 
00295     GlobalStatistics* globalStatistics; 
00296     bool connectionMatrix[MAX_NODETYPES][MAX_NODETYPES]; 
00297 };
00298 
00299 #endif

Generated on Tue Sep 8 17:26:52 2009 for OverSim by  doxygen 1.5.8