DHT.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 __DHT_H_
00025 #define __DHT_H_
00026
00027 #include <omnetpp.h>
00028
00029 #include <OverlayKey.h>
00030 #include <SHA1.h>
00031 #include <CommonMessages_m.h>
00032
00033 #include "DHTMessage_m.h"
00034 #include "DHTDataStorage.h"
00035
00036 #include "BaseApp.h"
00037 #include <RpcMacros.h>
00038
00044 class DHT : public BaseApp
00045 {
00046 public:
00047 DHT();
00048 virtual ~DHT();
00049
00050 private:
00051 enum PendingRpcsStates {
00052 INIT = 0,
00053 LOOKUP_STARTED = 1,
00054 GET_HASH_SENT = 2,
00055 GET_VALUE_SENT = 3,
00056 PUT_SENT = 4
00057 };
00058
00059 class PendingRpcsEntry
00060 {
00061 public:
00062 PendingRpcsEntry()
00063 {
00064 getCallMsg = NULL;
00065 putCallMsg = NULL;
00066 state = INIT;
00067 hashVector = NULL;
00068 numSent = 0;
00069 numAvailableReplica = 0;
00070 numFailed = 0;
00071 numResponses = 0;
00072 };
00073
00074 DHTgetCAPICall* getCallMsg;
00075 DHTputCAPICall* putCallMsg;
00076 PendingRpcsStates state;
00077 NodeVector replica;
00078 NodeVector* hashVector;
00079 std::map<BinaryValue, NodeVector> hashes;
00080 int numSent;
00081 int numAvailableReplica;
00082 int numFailed;
00083 int numResponses;
00084 };
00085
00086 friend std::ostream& operator<<(std::ostream& Stream,
00087 const PendingRpcsEntry& entry);
00088
00089 void initializeApp(int stage);
00090 void finishApp();
00091 void handleTimerEvent(cMessage* msg);
00092
00093 bool handleRpcCall(BaseCallMessage* msg);
00094 void handleRpcResponse(BaseResponseMessage* msg, cPolymorphic *context,
00095 int rpcId, simtime_t rtt);
00096 void handleRpcTimeout(BaseCallMessage* msg, const TransportAddress& dest,
00097 cPolymorphic* context, int rpcId,
00098 const OverlayKey& destKey);
00099 void handlePutRequest(DHTPutCall* dhtMsg);
00100 void handleGetRequest(DHTGetCall* dhtMsg);
00101 void handlePutResponse(DHTPutResponse* dhtMsg, int rpcId);
00102 void handleGetResponse(DHTGetResponse* dhtMsg, int rpcId);
00103 void handlePutCAPIRequest(DHTputCAPICall* capiPutMsg);
00104 void handleGetCAPIRequest(DHTgetCAPICall* capiPutMsg);
00105 void handleDumpDhtRequest(DHTdumpCall* call);
00106 void update(const NodeHandle& node, bool joined);
00107 void handleLookupResponse(LookupResponse* lookupMsg, int rpcId);
00108 void sendMaintenancePutCall(const TransportAddress& dest,
00109 const OverlayKey& key,
00110 const DhtDataEntry& entry);
00111 int resultValuesBitLength(DHTGetResponse* msg);
00112
00113 uint numReplica;
00114 int numGetRequests;
00115 double ratioIdentical;
00116 double maintenanceMessages;
00117 double normalMessages;
00118 double numBytesMaintenance;
00119 double numBytesNormal;
00120
00121 bool secureMaintenance;
00122 bool invalidDataAttack;
00123 bool maintenanceAttack;
00125 typedef std::map<uint32_t, PendingRpcsEntry> PendingRpcs;
00126 PendingRpcs pendingRpcs;
00128
00129 DHTDataStorage* dataStorage;
00130 };
00131
00132 #endif