P2pns.h

Go to the documentation of this file.
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 __P2PNS_H_
00025 #define __P2PNS_H_
00026 
00027 #include <omnetpp.h>
00028 
00029 #include <OverlayKey.h>
00030 #include <SHA1.h>
00031 #include <CommonMessages_m.h>
00032 
00033 #include <BaseApp.h>
00034 #include <RpcMacros.h>
00035 
00036 class XmlRpcInterface;
00037 
00038 #include "P2pnsCache.h"
00039 
00045 class P2pns : public BaseApp
00046 {
00047 public:
00048     P2pns();
00049     virtual ~P2pns();
00050 
00051     void tunnel(const OverlayKey& destKey, const BinaryValue& payload);
00052     void registerId(const std::string& addr);
00053 
00054     void handleReadyMessage(CompReadyMessage* msg);
00055 
00056 private:
00057     enum LookupRpcId {
00058         RESOLVE_LOOKUP = 0,
00059         TUNNEL_LOOKUP = 1,
00060         REFRESH_LOOKUP = 2
00061     };
00062 
00063     class OverlayKeyObject : public OverlayKey, public cObject {
00064     public:
00065         OverlayKeyObject(const OverlayKey& key) : OverlayKey(key) {};
00066     };
00067 
00068     void initializeApp(int stage);
00069     void finishApp();
00070     void handleTimerEvent(cMessage* msg);
00071     void deliver(OverlayKey& key, cMessage* msg);
00072 
00073     void sendTunnelMessage(const TransportAddress& addr,
00074                            const BinaryValue& payload);
00075 
00076     void updateIdCacheWithNewTransport(cMessage* msg);
00077 
00078     void handleTunnelLookupResponse(LookupResponse* lookupResponse);
00079 
00080     bool handleRpcCall(BaseCallMessage* msg);
00081     void handleRpcResponse(BaseResponseMessage* msg,
00082                            cPolymorphic* context, int rpcId, simtime_t rtt);
00083 
00084     void pingRpcResponse(PingResponse* response, cPolymorphic* context,
00085                          int rpcId, simtime_t rtt);
00086     void pingTimeout(PingCall* call, const TransportAddress& dest,
00087                      cPolymorphic* context, int rpcId);
00088 
00089     void p2pnsRegisterRpc(P2pnsRegisterCall* registerCall);
00090     void p2pnsResolveRpc(P2pnsResolveCall* registerCall);
00091 
00092     void handleDHTputCAPIResponse(DHTputCAPIResponse* putResponse,
00093                                   P2pnsRegisterCall* registerCall);
00094     void handleDHTgetCAPIResponse(DHTgetCAPIResponse* gettResponse,
00095                                   P2pnsResolveCall* resolveCall);
00096     void handleLookupResponse(LookupResponse* lookupResponse,
00097                               cObject* context, int rpcId);
00098 
00099     P2pnsCache *p2pnsCache; 
00100     XmlRpcInterface *xmlRpcInterface; 
00101     bool twoStageResolution; 
00102     simtime_t keepaliveInterval; 
00103     simtime_t idCacheLifetime; 
00104     OverlayKey thisId; 
00105 };
00106 
00107 #endif
Generated on Wed May 26 16:21:14 2010 for OverSim by  doxygen 1.6.3