00001 // 00002 // Copyright (C) 2007 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 __P2PNSCACHE_H_ 00025 #define __P2PNSCACHE_H_ 00026 00027 #include <set> 00028 #include <vector> 00029 #include <deque> 00030 #include <sstream> 00031 00032 #include <omnetpp.h> 00033 00034 #include <NodeHandle.h> 00035 #include <InitStages.h> 00036 #include <BinaryValue.h> 00037 00038 struct P2pnsCacheEntry 00039 { 00040 BinaryValue value; 00041 cMessage* ttlMessage; 00042 friend std::ostream& operator<<(std::ostream& Stream, 00043 const P2pnsCacheEntry entry); 00044 }; 00045 00046 enum P2pnsConnectionStates { 00047 CONNECTION_PENDING = 0, 00048 CONNECTION_ACTIVE = 1 00049 }; 00050 00051 class P2pnsIdCacheEntry 00052 { 00053 public: 00054 P2pnsIdCacheEntry(const OverlayKey& key) : 00055 key(key), state(CONNECTION_PENDING) {}; 00056 00057 public: 00058 OverlayKey key; 00059 TransportAddress addr; 00060 P2pnsConnectionStates state; 00061 simtime_t lastUsage; 00062 std::deque<BinaryValue> payloadQueue; 00063 }; 00064 00065 typedef std::map<OverlayKey, P2pnsIdCacheEntry> P2pnsIdCache; 00066 00075 class P2pnsCache : public cSimpleModule 00076 { 00077 public: 00078 virtual int numInitStages() const 00079 { 00080 return MAX_STAGE_APP; 00081 } 00082 00083 virtual void initialize(int stage); 00084 virtual void handleMessage(cMessage* msg); 00085 00091 virtual uint32_t getSize(); 00092 00096 virtual void clear(); 00097 00103 virtual bool isEmpty(); 00104 00105 00106 virtual P2pnsIdCacheEntry* getIdCacheEntry(const OverlayKey& key); 00107 00108 virtual P2pnsIdCacheEntry* addIdCacheEntry(const OverlayKey& key, 00109 const BinaryValue* payload = NULL); 00110 00111 virtual void removeIdCacheEntry(const OverlayKey& key); 00112 00119 virtual const BinaryValue& getData(const BinaryValue& name); 00120 00127 virtual cMessage* getTtlMessage(const BinaryValue& name); 00128 00135 virtual const BinaryValue& getDataAtPos(uint32_t pos = 0); 00136 00144 virtual void addData(BinaryValue name, BinaryValue value, cMessage* ttlMessage = NULL); 00145 00151 virtual void removeData(const BinaryValue& name); 00152 void display (); 00153 00154 protected: 00155 std::map<BinaryValue, P2pnsCacheEntry> cache; 00156 P2pnsIdCache idCache; 00161 void updateDisplayString(); 00162 00166 void updateTooltip(); 00167 }; 00168 00169 #endif