OverSim
DHT.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #ifndef __DHT_H_
25 #define __DHT_H_
26 
27 #include <omnetpp.h>
28 
29 #include <OverlayKey.h>
30 #include <SHA1.h>
31 #include <CommonMessages_m.h>
32 
33 #include "DHTMessage_m.h"
34 #include "DHTDataStorage.h"
35 
36 #include "BaseApp.h"
37 #include <RpcMacros.h>
38 
44 class DHT : public BaseApp
45 {
46 public:
47  DHT();
48  virtual ~DHT();
49 
50 private:
52  INIT = 0,
57  };
58 
60  {
61  public:
63  {
64  getCallMsg = NULL;
65  putCallMsg = NULL;
66  state = INIT;
67  hashVector = NULL;
68  numSent = 0;
70  numFailed = 0;
71  numResponses = 0;
72  };
73 
79  std::map<BinaryValue, NodeVector> hashes;
80  int numSent;
82  int numFailed;
84  };
85 
86  friend std::ostream& operator<<(std::ostream& Stream,
87  const PendingRpcsEntry& entry);
88 
89  void initializeApp(int stage);
90  void finishApp();
91  void handleTimerEvent(cMessage* msg);
92 
93  bool handleRpcCall(BaseCallMessage* msg);
94  void handleRpcResponse(BaseResponseMessage* msg, cPolymorphic *context,
95  int rpcId, simtime_t rtt);
96  void handleRpcTimeout(BaseCallMessage* msg, const TransportAddress& dest,
97  cPolymorphic* context, int rpcId,
98  const OverlayKey& destKey);
99  void handlePutRequest(DHTPutCall* dhtMsg);
100  void handleGetRequest(DHTGetCall* dhtMsg);
101  void handlePutResponse(DHTPutResponse* dhtMsg, int rpcId);
102  void handleGetResponse(DHTGetResponse* dhtMsg, int rpcId);
103  void handlePutCAPIRequest(DHTputCAPICall* capiPutMsg);
104  void handleGetCAPIRequest(DHTgetCAPICall* capiPutMsg);
105  void handleDumpDhtRequest(DHTdumpCall* call);
106  void update(const NodeHandle& node, bool joined);
107  void handleLookupResponse(LookupResponse* lookupMsg, int rpcId);
108  void sendMaintenancePutCall(const TransportAddress& dest,
109  const OverlayKey& key,
110  const DhtDataEntry& entry);
112 
120 
125  typedef std::map<uint32_t, PendingRpcsEntry> PendingRpcs;
128  // module references
130 };
131 
132 #endif