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 const int XMLRPC_TIMEOUT=30;
00037
00038
00042 class XmlRpcInterface : public BaseApp, public XmlRpc::XmlRpcServer
00043 {
00044 protected:
00045 unsigned int mtu;
00046
00047 cMessage* packetNotification;
00048 RealtimeScheduler::PacketBuffer packetBuffer;
00049 RealtimeScheduler* scheduler;
00050
00052 bool readHeader(char *buf, uint32_t length);
00053
00055 bool readRequest(char *buf, uint32_t length);
00056
00058 bool writeResponse();
00059
00061 enum ServerConnectionState { READ_HEADER, READ_REQUEST, EXECUTE_REQUEST,
00062 WRITE_RESPONSE };
00063
00064 struct XmlRpcConnectionState {
00066 ServerConnectionState _connectionState;
00067
00069 std::string _header;
00070
00072 int _contentLength;
00073
00075 std::string _request;
00076
00078 std::string _response;
00079
00081 int _bytesWritten;
00082
00084 bool _keepAlive;
00085
00087 SOCKET appFd;
00088
00090 bool localhost;
00091
00093 uint32_t pendingRpc;
00094 };
00095
00096 std::map<int, XmlRpcConnectionState> state;
00097 SOCKET curAppFd;
00098 bool limitAccess;
00099
00100 XmlRpc::XmlRpcServerMethod* _localLookup;
00101 XmlRpc::XmlRpcServerMethod* _lookup;
00102 XmlRpc::XmlRpcServerMethod* _register;
00103 XmlRpc::XmlRpcServerMethod* _resolve;
00104 XmlRpc::XmlRpcServerMethod* _put;
00105 XmlRpc::XmlRpcServerMethod* _get;
00106 XmlRpc::XmlRpcServerMethod* _dumpDht;
00107 XmlRpc::XmlRpcServerMethod* _joinOverlay;
00108
00116 bool isPrivileged();
00117
00118 void handleRealworldPacket(char *buf, uint32_t len);
00119 void handleCommonAPIPacket(cMessage *msg);
00120 void handleRpcResponse(BaseResponseMessage* msg,
00121 cPolymorphic* context,
00122 int rpcId,
00123 simtime_t rtt);
00128 void resetConnectionState();
00129
00130 void closeConnection();
00131 void sendInternalRpcWithTimeout(CompType destComp, BaseCallMessage *call);
00132
00133
00134 public:
00135 XmlRpcInterface();
00136 ~XmlRpcInterface();
00137
00138 virtual void initializeApp(int stage);
00139
00144 virtual void handleMessage(cMessage *msg);
00145
00146
00147 void handleRpcTimeout(BaseCallMessage* msg,
00148 const TransportAddress& dest,
00149 cPolymorphic* context, int rpcId,
00150 const OverlayKey&);
00151
00152 void localLookup(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00153 void lookup(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00154 void p2pnsRegister(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00155 void p2pnsResolve(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00156 void put(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00157 void get(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00158 void dumpDht(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00159 void joinOverlay(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00160 };
00161
00162 #endif