XmlRpcInterface.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 _XMLRPCINTERFACE_H__
00025 #define _XMLRPCINTERFACE_H__
00026
00027 #include <omnetpp.h>
00028 #include <CommonMessages_m.h>
00029 #include <DHTMessage_m.h>
00030 #include <BaseOverlay.h>
00031 #include <BaseApp.h>
00032 #include <tunoutscheduler.h>
00033 #include <realtimescheduler.h>
00034 #include <XmlRpc.h>
00035
00036 class P2pns;
00037
00038 const int XMLRPC_TIMEOUT=30;
00039
00040
00044 class XmlRpcInterface : public BaseApp, public XmlRpc::XmlRpcServer
00045 {
00046 protected:
00047 unsigned int mtu;
00048
00049 cMessage* packetNotification;
00050 RealtimeScheduler::PacketBuffer packetBuffer;
00051 RealtimeScheduler* scheduler;
00052
00054 bool readHeader(char *buf, uint32_t length);
00055
00057 bool readRequest(char *buf, uint32_t length);
00058
00060 bool writeResponse();
00061
00063 enum ServerConnectionState { READ_HEADER, READ_REQUEST, EXECUTE_REQUEST,
00064 WRITE_RESPONSE };
00065
00066 struct XmlRpcConnectionState {
00068 ServerConnectionState _connectionState;
00069
00071 std::string _header;
00072
00074 int _contentLength;
00075
00077 std::string _request;
00078
00080 std::string _response;
00081
00083 int _bytesWritten;
00084
00086 bool _keepAlive;
00087
00089 SOCKET appFd;
00090
00092 bool localhost;
00093
00095 uint32_t pendingRpc;
00096 };
00097
00098 std::map<int, XmlRpcConnectionState> state;
00099 SOCKET curAppFd;
00100 bool limitAccess;
00101
00102 XmlRpc::XmlRpcServerMethod* _localLookup;
00103 XmlRpc::XmlRpcServerMethod* _lookup;
00104 XmlRpc::XmlRpcServerMethod* _register;
00105 XmlRpc::XmlRpcServerMethod* _resolve;
00106 XmlRpc::XmlRpcServerMethod* _put;
00107 XmlRpc::XmlRpcServerMethod* _get;
00108 XmlRpc::XmlRpcServerMethod* _dumpDht;
00109 XmlRpc::XmlRpcServerMethod* _joinOverlay;
00110
00118 bool isPrivileged();
00119
00120 void handleAppTunPacket(char *buf, uint32_t len);
00121 void handleRealworldPacket(char *buf, uint32_t len);
00122 void handleCommonAPIPacket(cMessage *msg);
00123 void handleRpcResponse(BaseResponseMessage* msg,
00124 cPolymorphic* context,
00125 int rpcId,
00126 simtime_t rtt);
00131 void resetConnectionState();
00132
00133 void closeConnection();
00134 void sendInternalRpcWithTimeout(CompType destComp, BaseCallMessage *call);
00135 virtual void handleReadyMessage(CompReadyMessage* msg);
00136
00137 SOCKET appTunFd;
00138 P2pns* p2pns;
00140 public:
00141 XmlRpcInterface();
00142 ~XmlRpcInterface();
00143
00144 virtual void initializeApp(int stage);
00145
00150 virtual void handleMessage(cMessage *msg);
00151
00152
00153 void handleRpcTimeout(BaseCallMessage* msg,
00154 const TransportAddress& dest,
00155 cPolymorphic* context, int rpcId,
00156 const OverlayKey&);
00157
00158 void deliverTunneledMessage(const BinaryValue& payload);
00159
00160 void localLookup(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00161 void lookup(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00162 void p2pnsRegister(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00163 void p2pnsResolve(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00164 void put(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00165 void get(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00166 void dumpDht(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00167 void joinOverlay(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00168 };
00169
00170 #endif