OverSim
XmlRpcInterface Class Reference

Applicaton that communicates with a realword application via a socket. More...

#include <XmlRpcInterface.h>

Inheritance diagram for XmlRpcInterface:
BaseApp XmlRpc::XmlRpcServer BaseRpc BaseTcpSupport XmlRpc::XmlRpcSource RpcListener

Classes

struct  XmlRpcConnectionState

Public Member Functions

 XmlRpcInterface ()
 ~XmlRpcInterface ()
virtual void initializeApp (int stage)
 initializes derived class-attributes
virtual void handleMessage (cMessage *msg)
 The "main loop".
void handleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, cPolymorphic *context, int rpcId, const OverlayKey &)
 This method is called if an RPC timeout has been reached.
void deliverTunneledMessage (const BinaryValue &payload)
void localLookup (XmlRpc::XmlRpcValue &params, XmlRpc::XmlRpcValue &result)
void lookup (XmlRpc::XmlRpcValue &params, XmlRpc::XmlRpcValue &result)
void p2pnsRegister (XmlRpc::XmlRpcValue &params, XmlRpc::XmlRpcValue &result)
void p2pnsResolve (XmlRpc::XmlRpcValue &params, XmlRpc::XmlRpcValue &result)
void put (XmlRpc::XmlRpcValue &params, XmlRpc::XmlRpcValue &result)
void get (XmlRpc::XmlRpcValue &params, XmlRpc::XmlRpcValue &result)
void dumpDht (XmlRpc::XmlRpcValue &params, XmlRpc::XmlRpcValue &result)
void joinOverlay (XmlRpc::XmlRpcValue &params, XmlRpc::XmlRpcValue &result)
- Public Member Functions inherited from BaseApp
 BaseApp ()
virtual ~BaseApp ()
 virtual destructor
- Public Member Functions inherited from BaseRpc
 BaseRpc ()
const NodeHandlegetThisNode ()
 Returns the NodeHandle of this node.
simtime_t getUdpTimeout ()
- Public Member Functions inherited from RpcListener
virtual ~RpcListener ()
 destructor
- Public Member Functions inherited from BaseTcpSupport
virtual void socketDataArrived (int connId, void *yourPtr, cPacket *msg, bool urgent)
virtual void socketEstablished (int connId, void *yourPtr)
virtual void socketPeerClosed (int connId, void *yourPtr)
virtual void socketFailure (int connId, void *yourPtr, int code)
virtual void socketStatusArrived (int connId, void *yourPtr, TCPStatusInfo *status)
- Public Member Functions inherited from XmlRpc::XmlRpcServer
 XmlRpcServer ()
 Create a server object.
virtual ~XmlRpcServer ()
 Destructor.
void enableIntrospection (bool enabled=true)
 Specify whether introspection is enabled or not. Default is not enabled.
void addMethod (XmlRpcServerMethod *method)
 Add a command to the RPC server.
void removeMethod (XmlRpcServerMethod *method)
 Remove a command from the RPC server.
void removeMethod (const std::string &methodName)
 Remove a command from the RPC server by name.
XmlRpcServerMethodfindMethod (const std::string &name) const
 Look up a method by name.
bool bindAndListen (int port, int backlog=5)
 Create a socket, bind to the specified port, and set it in listen mode to make it available for clients.
int getPort (void) const
 Get the port number this server is listening on.
void work (double msTime)
 Process client requests for the specified time.
void exit ()
 Temporarily stop processing client requests and exit the work() method.
void shutdown ()
 Close all connections with clients and the socket file descriptor.
void listMethods (XmlRpcValue &result)
 Introspection support.
virtual std::string executeRequest (std::string const &request)
 Parses the request xml, runs the method, generates the response (header+xml).
virtual unsigned handleEvent (unsigned eventType)
 Handle client connection requests.
virtual void removeConnection (XmlRpcServerConnection *)
 Remove a connection from the dispatcher.
- Public Member Functions inherited from XmlRpc::XmlRpcSource
 XmlRpcSource (int fd=-1, bool deleteOnClose=false)
 Constructor.
virtual ~XmlRpcSource ()
 Destructor.
int getfd () const
 Return the file descriptor being monitored.
void setfd (int fd)
 Specify the file descriptor to monitor.
bool getKeepOpen () const
 Return whether the file descriptor should be kept open if it is no longer monitored.
void setKeepOpen (bool b=true)
 Specify whether the file descriptor should be kept open if it is no longer monitored.
virtual void close ()
 Close the owned fd. If deleteOnClose was specified at construction, the object is deleted.

Protected Types

enum  ServerConnectionState { READ_HEADER, READ_REQUEST, EXECUTE_REQUEST, WRITE_RESPONSE }
 Possible IO states for the connection. More...
- Protected Types inherited from XmlRpc::XmlRpcServer
typedef std::map< std::string,
XmlRpcServerMethod * > 
MethodMap
 Collection of methods. This could be a set keyed on method name if we wanted...

Protected Member Functions

bool readHeader (char *buf, uint32_t length)
 Reads the http header.
bool readRequest (char *buf, uint32_t length)
 Reads the request (based on the content-length header value)
bool writeResponse ()
 Executes the request and writes the resulting response.
bool isPrivileged ()
 Check if the connected application is allowed to call privileged methods.
void handleAppTunPacket (char *buf, uint32_t len)
void handleRealworldPacket (char *buf, uint32_t len)
void handleCommonAPIPacket (cMessage *msg)
void handleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
 This method is called if an RPC response has been received.
void resetConnectionState ()
 Reset the internal connection state.
void closeConnection ()
void sendInternalRpcWithTimeout (CompType destComp, BaseCallMessage *call)
virtual void handleReadyMessage (CompReadyMessage *msg)
 method to handle ready messages from the overlay
- Protected Member Functions inherited from BaseApp
int numInitStages () const
 method to set InitStage
void initialize (int stage)
 initializes base class-attributes
virtual void receiveChangeNotification (int category, const cPolymorphic *details)
 callback-method for events at the NotificationBoard
virtual void handleTransportAddressChangedNotification ()
 This method gets call if the node has a new TransportAddress (IP address) because he changed his access network.
virtual void handleNodeLeaveNotification ()
 This method gets call **.gracefulLeaveDelay seconds before it is killed.
virtual void handleNodeGracefulLeaveNotification ()
 This method gets call **.gracefulLeaveDelay seconds before it is killed if this node is among the gracefulLeaveProbability nodes.
void finish ()
 collects statistical data
virtual void finishApp ()
 collects statistical data of derived app
void callRoute (const OverlayKey &key, cPacket *msg, const TransportAddress &hint=TransportAddress::UNSPECIFIED_NODE, RoutingType routingType=DEFAULT_ROUTING)
 Common API function: calls route-method in overlay.
void callRoute (const OverlayKey &key, cPacket *msg, const std::vector< TransportAddress > &sourceRoute, RoutingType routingType=DEFAULT_ROUTING)
virtual void deliver (OverlayKey &key, cMessage *msg)
 Common API function: handles delivered messages from overlay.
virtual void forward (OverlayKey *key, cPacket **msg, NodeHandle *nextHopNode)
 Common API function: handles messages from overlay to be forwarded.
virtual void update (const NodeHandle &node, bool joined)
 Common API function: informs application about neighbors and own nodeID.
NodeVectorcallLocalLookup (const OverlayKey &key, int num, bool safe)
 Common API function: produces a list of nodes that can be used as next hops towards key.
NodeVectorcallNeighborSet (int num)
 Common API function: produces a list of neighbor nodes.
bool isSiblingFor (const NodeHandle &node, const OverlayKey &key, int numSiblings, bool *err)
 Query if a node is among the siblings for a given key.
virtual void handleLowerMessage (cMessage *msg)
 processes self-messages
virtual void handleUpperMessage (cMessage *msg)
 handleUpperMessage gets called of handleMessage(cMessage* msg) if msg arrivedOn from_upperTier (currently msg gets deleted in this function)
virtual void handleUDPMessage (cMessage *msg)
 method to handle messages that come directly from the UDP gate
virtual void bindToPort (int port)
 Tells UDP we want to get all packets arriving on the given port.
virtual void sendMessageToUDP (const TransportAddress &destAddr, cPacket *msg, simtime_t delay=SIMTIME_ZERO)
 Sends a packet over UDP.
virtual void handleTraceMessage (cMessage *msg)
 handleTraceMessage gets called of handleMessage(cMessage* msg) if a message arrives at trace_in.
void sendMessageToLowerTier (cPacket *msg)
 sends non-commonAPI message to the lower tier
bool internalHandleRpcCall (BaseCallMessage *msg)
 Handles internal rpc requests.
void internalHandleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
 Handles rpc responses internal in base classes

void internalSendRouteRpc (BaseRpcMessage *message, const OverlayKey &destKey, const std::vector< TransportAddress > &sourceRoute, RoutingType routingType)
virtual CompType getThisCompType ()
 Return the component type of this module.
void sendReadyMessage (bool ready=true, const OverlayKey &nodeId=OverlayKey::UNSPECIFIED_KEY)
- Protected Member Functions inherited from BaseRpc
virtual void internalHandleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, cPolymorphic *context, int rpcId, const OverlayKey &destKey)
 Handles rpc timeouts internal in base classes

void initRpcs ()
 Initializes Remote-Procedure state.
void finishRpcs ()
 Deinitializes Remote-Procedure state.
virtual void internalHandleRpcMessage (BaseRpcMessage *msg)
 Handles incoming rpc messages and delegates them to the corresponding listeners or handlers.
uint32_t sendRouteRpcCall (CompType destComp, const TransportAddress &dest, const OverlayKey &destKey, BaseCallMessage *msg, cPolymorphic *context=NULL, RoutingType routingType=DEFAULT_ROUTING, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Routes a Remote-Procedure-Call message to an OverlayKey.
uint32_t sendRouteRpcCall (CompType destComp, const OverlayKey &destKey, BaseCallMessage *msg, cPolymorphic *context=NULL, RoutingType routingType=DEFAULT_ROUTING, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Routes a Remote-Procedure-Call message to an OverlayKey.
uint32_t sendRouteRpcCall (CompType destComp, const TransportAddress &dest, BaseCallMessage *msg, cPolymorphic *context=NULL, RoutingType routingType=DEFAULT_ROUTING, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Sends a Remote-Procedure-Call message using the overlay's UDP port
This replaces ROUTE_DIRECT calls!
uint32_t sendUdpRpcCall (const TransportAddress &dest, BaseCallMessage *msg, cPolymorphic *context=NULL, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Sends a Remote-Procedure-Call message to the underlay

uint32_t sendInternalRpcCall (CompType destComp, BaseCallMessage *msg, cPolymorphic *context=NULL, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Sends an internal Remote-Procedure-Call between two tiers

void cancelRpcMessage (uint32_t nonce)
 Cancels a Remote-Procedure-Call.
void cancelAllRpcs ()
 Cancels all RPCs.
void sendRpcResponse (TransportType transportType, CompType destComp, const TransportAddress &dest, const OverlayKey &destKey, BaseCallMessage *call, BaseResponseMessage *response)
 Send Remote-Procedure response message and deletes call message.
void sendRpcResponse (BaseCallMessage *call, BaseResponseMessage *response)
 Send Remote-Procedure response message to UDP and deletes call message.
int pingNode (const TransportAddress &dest, simtime_t timeout=-1, int retries=0, cPolymorphic *context=NULL, const char *caption="PING", RpcListener *rpcListener=NULL, int rpcId=-1, TransportType transportType=INVALID_TRANSPORT)
 ping a node by its TransportAddress
virtual bool handleRpcCall (BaseCallMessage *msg)
 Processes Remote-Procedure-Call invocation messages.
virtual void pingResponse (PingResponse *pingResponse, cPolymorphic *context, int rpcId, simtime_t rtt)
virtual void pingTimeout (PingCall *pingCall, const TransportAddress &dest, cPolymorphic *context, int rpcId)
bool internalHandleMessage (cMessage *msg)
- Protected Member Functions inherited from RpcListener
virtual void handleRpcResponse (BaseResponseMessage *msg, const RpcState &rpcState, simtime_t rtt)
 This method is called if an RPC response has been received.
virtual void handleRpcTimeout (const RpcState &rpcState)
 This method is called if an RPC timeout has been reached.
- Protected Member Functions inherited from BaseTcpSupport
void handleTCPMessage (cMessage *msg)
 Member function to handle incoming TCP messages.
void bindAndListenTcp (int port)
 Member function to bind service to the specified port and listen afterwards.
bool isAlreadyConnected (TransportAddress address)
 Member function to check if the service is already connected.
void establishTcpConnection (TransportAddress address)
 Member function to establish a connection to the specified node.
void sendTcpData (cPacket *msg, TransportAddress address)
 Member function to send TCP data to the specified node.
virtual void handleConnectionEvent (EvCode code, TransportAddress address)
 Member function to handle passive connection events.
virtual void handleDataReceived (TransportAddress address, cPacket *msg, bool urgent)
 Member function to handle incoming data.
virtual void handleIncomingConnection (TransportAddress address)
 Member function to handle newly opened connections.
void closeTcpConnection (TransportAddress address)
 Member function to close an established connection.
void setTcpOut (cGate *gate)
 Member function to set local gate towards the TCP module during init phase.
cGate * getTcpOut ()
 Member function to get local gate towards the TCP module.
- Protected Member Functions inherited from XmlRpc::XmlRpcServer
virtual void acceptConnection ()
 Accept a client connection request.
virtual XmlRpcServerConnectioncreateConnection (int socket)
 Create a new connection object for processing requests from a specific client.
virtual void dispatchConnection (XmlRpcServerConnection *sc)
 Hand off a new connection object to a dispatcher.
std::string parseRequest (std::string const &request, XmlRpcValue &params)
 Parse the methodName and parameters from the request.
bool executeMethod (const std::string &methodName, XmlRpcValue &params, XmlRpcValue &result)
 Execute a named method with the specified params.
bool executeMulticall (const std::string &methodName, XmlRpcValue &params, XmlRpcValue &result)
 Execute multiple calls and return the results in an array.
std::string generateResponse (std::string const &resultXml)
 Construct a response from the result XML.
std::string generateFaultResponse (std::string const &msg, int errorCode=-1)
 Construct a fault response.
std::string generateHeader (std::string const &body)
 Return the appropriate headers for the response.

Protected Attributes

unsigned int mtu
cMessage * packetNotification
PacketBuffer packetBuffer
RealtimeSchedulerscheduler
std::map< int,
XmlRpcConnectionState
state
SOCKET curAppFd
bool limitAccess
XmlRpc::XmlRpcServerMethod_localLookup
XmlRpc::XmlRpcServerMethod_lookup
XmlRpc::XmlRpcServerMethod_register
XmlRpc::XmlRpcServerMethod_resolve
XmlRpc::XmlRpcServerMethod_put
XmlRpc::XmlRpcServerMethod_get
XmlRpc::XmlRpcServerMethod_dumpDht
XmlRpc::XmlRpcServerMethod_joinOverlay
XmlRpc::XmlRpcServerMethod_addContact
XmlRpc::XmlRpcServerMethod_removeContact
XmlRpc::XmlRpcServerMethod_getContacts
XmlRpc::XmlRpcServerMethod_getUserId
XmlRpc::XmlRpcServerMethod_searchContact
XmlRpc::XmlRpcServerMethod_publish
XmlRpc::XmlRpcServerMethod_pull_notification
XmlRpc::XmlRpcServerMethod_subscribe
SOCKET appTunFd
 FD of the application TUN socket used for tunneling.
P2pnsp2pns
 Pointer to the P2PNS module.
- Protected Attributes inherited from BaseApp
UnderlayConfiguratorunderlayConfigurator
 pointer to UnderlayConfigurator in this node
GlobalNodeListglobalNodeList
 pointer to GlobalNodeList in this node
GlobalStatisticsglobalStatistics
 pointer to GlobalStatistics module in this node
NotificationBoard * notificationBoard
 pointer to NotificationBoard in this node
bool debugOutput
 debug output yes/no?
int numOverlaySent
 number of sent packets to overlay
int bytesOverlaySent
 number of sent bytes to overlay
int numOverlayReceived
 number of received packets from overlay
int bytesOverlayReceived
 number of received bytes from overlay
int numUdpSent
 number of sent packets to UDP
int bytesUdpSent
 number of sent bytes to UDP
int numUdpReceived
 number of received packets from UDP
int bytesUdpReceived
 number of received bytes from UDP
simtime_t creationTime
 simTime when the App has been created
- Protected Attributes inherited from BaseRpc
NodeHandle thisNode
 NodeHandle to this node.
BaseOverlayoverlay
bool debugOutput
 debug output ?
GlobalStatisticsglobalStatistics
 pointer to GlobalStatistics module in this node
CompType thisCompType
NeighborCacheneighborCache
 pointer to the neighbor cache
CryptoModulecryptoModule
 pointer to CryptoModule
int numPingSent
int bytesPingSent
int numPingResponseSent
int bytesPingResponseSent
- Protected Attributes inherited from XmlRpc::XmlRpcServer
bool _introspectionEnabled
 Whether the introspection API is supported by this server.
XmlRpcDispatch _disp
 Event dispatcher.
MethodMap _methods
 Registered RPC methods.
XmlRpcServerMethod_listMethods
 List all registered RPC methods (only available if introspection is enabled)
XmlRpcServerMethod_methodHelp
 Return help string for a specified method (only available if introspection is enabled)

Additional Inherited Members

- Public Types inherited from BaseTcpSupport
enum  EvCode {
  NO_EST_CONNECTION, PEER_CLOSED, PEER_TIMEDOUT, PEER_REFUSED,
  CONNECTION_RESET, CONNECTION_SUCC_ClOSED
}
- Public Attributes inherited from XmlRpc::XmlRpcSource
bool _ssl
SSL_CTX_ssl_ctx
SSL_ssl_ssl
SSL_METHOD_ssl_meth
- Static Protected Attributes inherited from XmlRpc::XmlRpcServer
static const char METHODNAME_TAG [] = "<methodName>"
static const char PARAMS_TAG [] = "<params>"
static const char PARAMS_ETAG [] = "</params>"
static const char PARAM_TAG [] = "<param>"
static const char PARAM_ETAG [] = "</param>"
static const std::string SYSTEM_MULTICALL
static const std::string METHODNAME = "methodName"
static const std::string PARAMS = "params"
static const std::string FAULTCODE = "faultCode"
static const std::string FAULTSTRING = "faultString"

Detailed Description

Applicaton that communicates with a realword application via a socket.

Definition at line 44 of file XmlRpcInterface.h.

Member Enumeration Documentation

Possible IO states for the connection.

Enumerator:
READ_HEADER 
READ_REQUEST 
EXECUTE_REQUEST 
WRITE_RESPONSE 

Definition at line 63 of file XmlRpcInterface.h.

Constructor & Destructor Documentation

XmlRpcInterface::XmlRpcInterface ( )

Definition at line 471 of file XmlRpcInterface.cc.

{
p2pns = NULL;
_localLookup = NULL;
_lookup = NULL;
_register = NULL;
_resolve = NULL;
_put = NULL;
_get = NULL;
_dumpDht = NULL;
_joinOverlay = NULL;
_addContact = NULL;
_getContacts = NULL;
_getUserId = NULL;
_subscribe = NULL;
_publish = NULL;
}
XmlRpcInterface::~XmlRpcInterface ( )

Definition at line 495 of file XmlRpcInterface.cc.

{
delete _localLookup;
delete _lookup;
delete _register;
delete _resolve;
delete _put;
delete _get;
delete _dumpDht;
delete _joinOverlay;
delete _addContact;
delete _getContacts;
delete _getUserId;
delete _publish;
delete _subscribe;
cancelAndDelete(packetNotification);
}

Member Function Documentation

void XmlRpcInterface::closeConnection ( )
protected
void XmlRpcInterface::deliverTunneledMessage ( const BinaryValue payload)

Definition at line 742 of file XmlRpcInterface.cc.

{
#if not defined _WIN32 && not defined __APPLE__
Enter_Method_Silent();
if (payload.size() == 0) {
return;
}
int curBytesWritten = scheduler->sendBytes(&payload[0],
payload.size(),
0, 0, true, appTunFd);
if (curBytesWritten <= 0) {
throw cRuntimeError("XmlRpcServerConnection::deliverTunneledMessage(): "
"Error writing to application TUN device.");
}
#endif
}
void XmlRpcInterface::dumpDht ( XmlRpc::XmlRpcValue params,
XmlRpc::XmlRpcValue result 
)

Definition at line 407 of file XmlRpcInterface.cc.

{
if (params.size() != 1) {
throw XmlRpcException("dump_dht(int dummy): Invalid argument type");
}
if (!isPrivileged()) {
throw XmlRpcException("dump_dht(int dummy): Not allowed");
}
throw XmlRpcException("dump_dht(): No DHT service");
state[curAppFd]._connectionState = EXECUTE_REQUEST;
DHTdumpCall* call = new DHTdumpCall();
}
void XmlRpcInterface::get ( XmlRpc::XmlRpcValue params,
XmlRpc::XmlRpcValue result 
)

Definition at line 383 of file XmlRpcInterface.cc.

{
if ((params.size() != 4)
|| (params[0].getType() != XmlRpcValue::TypeBase64)
|| (params[1].getType() != XmlRpcValue::TypeInt)
|| (params[2].getType() != XmlRpcValue::TypeBase64)
|| (params[3].getType() != XmlRpcValue::TypeString))
throw XmlRpcException("get(base64 key, int num, base64 placemark "
", string application): Invalid argument type");
throw XmlRpcException("get(base64 key, int num, base64 placemark "
", string application): No DHT service");
state[curAppFd]._connectionState = EXECUTE_REQUEST;
DHTgetCAPICall* dhtGetMsg = new DHTgetCAPICall();
BinaryValue keyString = (const XmlRpcValue::BinaryData&)params[0];
dhtGetMsg->setKey(OverlayKey::sha1(keyString));
}
void XmlRpcInterface::handleAppTunPacket ( char *  buf,
uint32_t  len 
)
protected

Definition at line 702 of file XmlRpcInterface.cc.

{
#if not defined _WIN32 && not defined __APPLE__
EV << "XmlRpcInterface::handleAppTunPacket(): packet of "
<< "length " << length << endl;
if (!p2pns) {
throw cRuntimeError("XmlRpcInterface::handleAppTunPacket(): "
"P2PNS module missing on tier2!");
}
if (OverlayKey::getLength() < 100) {
throw cRuntimeError("XmlRpcInterface::handleAppTunPacket(): "
"P2PNS needs at least 100 bit nodeIds!");
}
if (length < 40) {
EV << "XmlRpcInterface::handleAppTunPacket(): packet too "
<< "short - discarding packet!" << endl;
return;
}
ip6_hdr* ip_buf = (ip6_hdr*) buf;
if (((ip_buf->ip6_vfc & 0xf0) >> 4) != 6) {
EV << "XmlRpcInterface::handleAppTunPacket(): received packet "
"is no IPv6 - discarding packet!" << endl;
return;
}
OverlayKey destKey = OverlayKey(ntohl(ip_buf->ip6_dst.s6_addr32[0]));
for (int i = 1; i < 4; i++) {
destKey = (destKey << 32) + OverlayKey(ntohl(ip_buf->ip6_dst.s6_addr32[i]));
}
destKey = destKey << (OverlayKey::getLength() - 100);
p2pns->tunnel(destKey, BinaryValue(buf, length));
#endif
}
void XmlRpcInterface::handleCommonAPIPacket ( cMessage *  msg)
protected

Definition at line 956 of file XmlRpcInterface.cc.

{
error("DHTXMLRealworldApp::handleCommonAPIPacket(): Unknown Packet!");
}
void XmlRpcInterface::handleMessage ( cMessage *  msg)
virtual

The "main loop".

Every message that is received or send is handled by this method

Reimplemented from BaseApp.

Definition at line 547 of file XmlRpcInterface.cc.

{
// Packet from the application...
if (msg==packetNotification) {
EV << "[XmlRpcInterface::handleMessage() @ " << overlay->getThisNode().getIp()
<< " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
<< " Message from application. Queue length = " << packetBuffer.size()
<< endl;
while (packetBuffer.size() > 0) {
// get packet from buffer and parse it
*(packetBuffer.begin());
packetBuffer.pop_front();
curAppFd = packet.fd;
switch (packet.func) {
handleAppTunPacket(packet.data, packet.length);
break;
if (state.count(curAppFd) == 0) {
throw cRuntimeError("XmlRpcInterface::handleMessage(): "
"Received packet "
"from unknown socket!");
}
break;
if (state.count(curAppFd)) {
throw cRuntimeError("XmlRpcInterface::handleMessage(): "
"Connection state table corrupt!");
}
if (packet.addr != NULL) {
if (((sockaddr_in*)packet.addr)->sin_addr.s_addr
== inet_addr("127.0.0.1")) {
state[curAppFd].localhost = true;
}
delete packet.addr;
packet.addr = NULL;
}
break;
if (state.count(curAppFd) == 0) {
throw cRuntimeError("XmlRpcInterface::handleMessage(): "
"Trying to close unknown "
"connection!");
}
state.erase(curAppFd);
}
if (packet.data) {
delete[] packet.data;
}
}
} else if (msg->isSelfMessage()) {
// process rpc self-messages
BaseRpcMessage* rpcMessage = dynamic_cast<BaseRpcMessage*>(msg);
if (rpcMessage!=NULL) {
return;
}
delete msg;
} else {
// RPCs
BaseRpcMessage* rpcMessage = dynamic_cast<BaseRpcMessage*>(msg);
if (rpcMessage!=NULL) {
return;
}
// common API
CommonAPIMessage* commonAPIMsg = dynamic_cast<CommonAPIMessage*>(msg);
if (commonAPIMsg != NULL)
handleCommonAPIPacket(commonAPIMsg);
CompReadyMessage* readyMsg = dynamic_cast<CompReadyMessage*>(msg);
if (readyMsg != NULL)
handleReadyMessage(readyMsg);
delete msg;
}
}
void XmlRpcInterface::handleReadyMessage ( CompReadyMessage msg)
protectedvirtual

method to handle ready messages from the overlay

Parameters
msgmessage to handle

Reimplemented from BaseApp.

Definition at line 657 of file XmlRpcInterface.cc.

{
if ((msg->getReady() == false) || (msg->getComp() != OVERLAY_COMP)) {
return;
}
if (appTunFd != INVALID_SOCKET) {
// set TUN interface address using the current NodeId
// TODO: this is ugly
const OverlayKey& key = overlay->getThisNode().getKey();
if (OverlayKey::getLength() < 100) {
throw cRuntimeError("XmlRpcInterface::handleReadyMessage(): "
"P2PNS needs at least 100 bit nodeIds!");
}
std::stringstream addr;
addr << "2001:001";
for (int i = 0; i < 100/4; i++) {
if (((i + 3) % 4) == 0) {
addr << ":";
}
addr << std::hex << key.getBitRange(OverlayKey::getLength() -
4 * (i + 1), 4);
}
std::string cmd = "/sbin/ip addr add " + addr.str() + "/28 dev tun0";
EV << "XmlRpcInterface::handleOverlayReady(): "
"Setting TUN interface address " << addr.str() << endl;
if (system(cmd.c_str()) != 0) {
EV << "XmlRpcInterface::handleOverlayReady(): "
"Failed to set TUN interface address!" << endl;
}
if (system("/sbin/ip link set tun0 up") != 0) {
EV << "XmlRpcInterface::handleOverlayReady(): "
"Failed to set TUN interface up!" << endl;
}
p2pns->registerId(addr.str());
}
}
void XmlRpcInterface::handleRealworldPacket ( char *  buf,
uint32_t  len 
)
protected

Definition at line 762 of file XmlRpcInterface.cc.

{
if (state[curAppFd]._connectionState == READ_HEADER) {
if (!readHeader(buf, length)) {
// discard data, if the header is invalid
state[curAppFd]._header = "";
state[curAppFd]._request = "";
state[curAppFd]._response = "";
state[curAppFd]._connectionState = READ_HEADER;
return;
}
}
if (state[curAppFd]._connectionState == READ_REQUEST)
if (!readRequest(buf, length))
return;
if (state[curAppFd]._connectionState == WRITE_RESPONSE)
if (!writeResponse() ) {
return;
}
return;
}
void XmlRpcInterface::handleRpcResponse ( BaseResponseMessage msg,
cPolymorphic *  context,
int  rpcId,
simtime_t  rtt 
)
protectedvirtual

This method is called if an RPC response has been received.

Parameters
msgThe response message.
contextPointer to an optional state object. The object has to be handled/deleted by the handleRpcResponse() code
rpcIdThe RPC id.
rttThe Round-Trip-Time of this RPC

Reimplemented from RpcListener.

Definition at line 788 of file XmlRpcInterface.cc.

{
curAppFd = rpcId;
if (state.count(curAppFd) == 0) {
return;
}
if (state[curAppFd]._connectionState != EXECUTE_REQUEST) break;
XmlRpcValue resultValue;
resultValue.setSize(_LookupResponse->getSiblingsArraySize());
if (_LookupResponse->getIsValid() == true) {
for (uint32_t i=0; i < _LookupResponse->getSiblingsArraySize();
i++) {
resultValue[i].setSize(3);
resultValue[i][0] =
_LookupResponse->getSiblings(i).getIp().str();
resultValue[i][1] =
_LookupResponse->getSiblings(i).getPort();
resultValue[i][2] =
_LookupResponse->getSiblings(i).getKey().toString(16);
}
state[curAppFd]._response = generateResponse(resultValue.toXml());
} else {
std::cout << "XmlRpcInterface(): lookup() failed!" << endl;
state[curAppFd]._response = generateFaultResponse("lookup() failed", 22);
}
state[curAppFd]._connectionState = WRITE_RESPONSE;
if (!writeResponse()) {
}
break;
}
if (state[curAppFd]._connectionState != EXECUTE_REQUEST)
break;
XmlRpcValue resultValue;
if (_P2pnsRegisterResponse->getIsSuccess() == true) {
resultValue = 0;
state[curAppFd]._response = generateResponse(resultValue.toXml());
} else {
std::cout << "XmlRpcInterface(): register() failed!" << endl;
state[curAppFd]._response = generateFaultResponse("register() failed", 22);
}
state[curAppFd]._connectionState = WRITE_RESPONSE;
if (!writeResponse() ) {
}
break;
}
if (state[curAppFd]._connectionState != EXECUTE_REQUEST)
break;
XmlRpcValue resultValue;
resultValue.setSize(_P2pnsResolveResponse->getAddressArraySize());
if (_P2pnsResolveResponse->getIsSuccess() == true) {
for (uint i=0; i < _P2pnsResolveResponse->getAddressArraySize(); i++) {
resultValue[i].setSize(3);
BinaryValue& addr = _P2pnsResolveResponse->getAddress(i);
resultValue[i][0] = XmlRpcValue(&addr[0], addr.size());
resultValue[i][1] = (int)_P2pnsResolveResponse->getKind(i);
resultValue[i][2] = (int)_P2pnsResolveResponse->getId(i);
}
state[curAppFd]._response = generateResponse(resultValue.toXml());
} else {
std::cout << "XmlRpcInterface(): resolve() failed!" << endl;
state[curAppFd]._response = generateFaultResponse("resolve() failed: Name not found", 9);
}
state[curAppFd]._connectionState = WRITE_RESPONSE;
if (!writeResponse() ) {
}
break;
}
RPC_ON_RESPONSE(DHTputCAPI) {
if (state[curAppFd]._connectionState != EXECUTE_REQUEST)
break;
XmlRpcValue resultValue;
if (_DHTputCAPIResponse->getIsSuccess() == true) {
resultValue = 0;
state[curAppFd]._response = generateResponse(resultValue.toXml());
} else {
std::cout << "XmlRpcInterface(): put() failed!" << endl;
state[curAppFd]._response = generateFaultResponse("put() failed", 22);
}
state[curAppFd]._connectionState = WRITE_RESPONSE;
if (!writeResponse() ) {
}
break;
}
RPC_ON_RESPONSE(DHTgetCAPI) {
if (state[curAppFd]._connectionState != EXECUTE_REQUEST)
break;
XmlRpcValue resultValue;
resultValue.setSize(2);
resultValue[0].setSize(_DHTgetCAPIResponse->getResultArraySize());
if (_DHTgetCAPIResponse->getIsSuccess() == true) {
for (uint i=0; i < _DHTgetCAPIResponse->getResultArraySize(); i++) {
resultValue[i].setSize(2);
DhtDumpEntry& entry = _DHTgetCAPIResponse->getResult(i);
resultValue[0][i] = XmlRpcValue(&(*(entry.getValue().begin())),
entry.getValue().size());
}
resultValue[1] = std::string();
state[curAppFd]._response = generateResponse(resultValue.toXml());
} else {
std::cout << "XmlRpcInterface(): get() failed!" << endl;
state[curAppFd]._response = generateFaultResponse("get() failed", 22);
}
state[curAppFd]._connectionState = WRITE_RESPONSE;
if (!writeResponse() ) {
}
break;
}
RPC_ON_RESPONSE(DHTdump) {
if (state[curAppFd]._connectionState != EXECUTE_REQUEST)
break;
XmlRpcValue resultValue;
resultValue.setSize(_DHTdumpResponse->getRecordArraySize());
for (uint32_t i=0; i < _DHTdumpResponse->getRecordArraySize();
i++) {
resultValue[i].setSize(3);
resultValue[i][0] =
_DHTdumpResponse->getRecord(i).getKey().toString(16);
resultValue[i][1] = XmlRpcValue(
&(*(_DHTdumpResponse->getRecord(i).getValue().begin())),
_DHTdumpResponse->getRecord(i).getValue().size());
resultValue[i][2] =
_DHTdumpResponse->getRecord(i).getTtl();
}
state[curAppFd]._response = generateResponse(resultValue.toXml());
state[curAppFd]._connectionState = WRITE_RESPONSE;
if (!writeResponse()) {
}
break;
}
}
void XmlRpcInterface::handleRpcTimeout ( BaseCallMessage msg,
const TransportAddress dest,
cPolymorphic *  context,
int  rpcId,
const OverlayKey destKey 
)
virtual

This method is called if an RPC timeout has been reached.

Parameters
msgThe original RPC message.
destThe destination node
contextPointer to an optional state object. The object has to be handled/deleted by the handleRpcResponse() code
rpcIdThe RPC id.
destKeythe destination OverlayKey

Reimplemented from RpcListener.

Definition at line 639 of file XmlRpcInterface.cc.

{
curAppFd = rpcId;
if (state.count(curAppFd) == 0)
return;
std::cout << "XmlRpcInterface(): XML-RPC failed!" << endl;
state[curAppFd]._response = generateFaultResponse("XML-RPC timeout", 22);
state[curAppFd]._connectionState = WRITE_RESPONSE;
if (!writeResponse() ) {
}
}
void XmlRpcInterface::initializeApp ( int  stage)
virtual

initializes derived class-attributes

Parameters
stagethe init stage

Reimplemented from BaseApp.

Definition at line 437 of file XmlRpcInterface.cc.

{
// all initialization is done in the first stage
if (stage != MAX_STAGE_APP)
return;
packetNotification = new cMessage("packetNotification");
mtu = par("mtu");
limitAccess = par("limitAccess");
scheduler = check_and_cast<RealtimeScheduler *>(simulation.getScheduler());
true);
_lookup = new Lookup(this);
_register = new P2pnsRegister(this);
_resolve = new P2pnsResolve(this);
_put = new Put(this);
_get = new Get(this);
_dumpDht = new DumpDht(this);
curAppFd = INVALID_SOCKET;
}
bool XmlRpcInterface::isPrivileged ( )
protected

Check if the connected application is allowed to call privileged methods.

Currently this is true for all applications connecting to localhost. If **.limitAccess = false there are no access restrictions.

Returns
true, if the application is allowed to call privileged methods

Definition at line 428 of file XmlRpcInterface.cc.

{
if (limitAccess) {
return state[curAppFd].localhost;
} else {
return true;
}
}
void XmlRpcInterface::joinOverlay ( XmlRpc::XmlRpcValue params,
XmlRpc::XmlRpcValue result 
)

Definition at line 333 of file XmlRpcInterface.cc.

{
if ((params.size() != 1)
|| (params[0].getType() != XmlRpcValue::TypeBase64))
throw XmlRpcException("join(base64 nodeID): Invalid argument type");
if (!isPrivileged()) {
throw XmlRpcException("join(base64 nodeID): Not allowed");
}
BinaryValue nodeID = (const XmlRpcValue::BinaryData&)params[0];
result[0] = 0;
}
void XmlRpcInterface::localLookup ( XmlRpc::XmlRpcValue params,
XmlRpc::XmlRpcValue result 
)

Definition at line 259 of file XmlRpcInterface.cc.

{
if ((params.size() != 3)
|| (params[0].getType() != XmlRpcValue::TypeBase64)
|| (params[1].getType() != XmlRpcValue::TypeInt)
|| (params[2].getType() != XmlRpcValue::TypeBoolean))
throw XmlRpcException("local_lookup(base64 key, int num, "
"boolean safe): Invalid argument type");
BinaryValue keyString = (const XmlRpcValue::BinaryData&)params[0];
NodeVector* nextHops = NULL;
if (keyString.size() > 0) {
nextHops = overlay->local_lookup(OverlayKey::sha1(keyString),
params[1], params[2]);
} else {
params[1], params[2]);
}
for (uint32_t i=0; i < nextHops->size(); i++) {
result[i][0] = (*nextHops)[i].getIp().str();
result[i][1] = (*nextHops)[i].getPort();
result[i][2] = (*nextHops)[i].getKey().toString(16);
}
delete nextHops;
}
void XmlRpcInterface::lookup ( XmlRpc::XmlRpcValue params,
XmlRpc::XmlRpcValue result 
)

Definition at line 289 of file XmlRpcInterface.cc.

{
if (((params.size() != 2)
|| (params[0].getType() != XmlRpcValue::TypeBase64)
|| (params[1].getType() != XmlRpcValue::TypeInt))
&& ((params.size() != 3)
|| (params[0].getType() != XmlRpcValue::TypeBase64)
|| (params[1].getType() != XmlRpcValue::TypeInt)
|| (params[2].getType() != XmlRpcValue::TypeInt)))
throw XmlRpcException("lookup(base64 key, int numSiblings(, "
"int RoutingType)): Invalid argument type");
if ((int)params[1] > overlay->getMaxNumSiblings())
throw XmlRpcException("lookup(base64 key, int numSiblings(, "
"int RoutingType)): numSibling to big");
if (params.size() == 3) {
if (((int)params[2] != DEFAULT_ROUTING) &&
((int)params[2] != ITERATIVE_ROUTING) &&
((int)params[2] != EXHAUSTIVE_ITERATIVE_ROUTING) &&
((int)params[2] != SEMI_RECURSIVE_ROUTING) &&
((int)params[2] != FULL_RECURSIVE_ROUTING) &&
((int)params[2] != RECURSIVE_SOURCE_ROUTING)) {
throw XmlRpcException("lookup(base64 key, int numSiblings(, "
"int RoutingType)): invalid routingType");
}
}
state[curAppFd]._connectionState = EXECUTE_REQUEST;
LookupCall* lookupCall = new LookupCall();
BinaryValue keyString = (const XmlRpcValue::BinaryData&)params[0];
lookupCall->setKey(OverlayKey::sha1(keyString));
lookupCall->setNumSiblings(params[1]);
if (params.size() == 3) {
lookupCall->setRoutingType(params[2]);
}
}
void XmlRpcInterface::p2pnsRegister ( XmlRpc::XmlRpcValue params,
XmlRpc::XmlRpcValue result 
)

Definition at line 205 of file XmlRpcInterface.cc.

{
if ((params.size() != 5) ||
(params[0].getType() != XmlRpcValue::TypeBase64) ||
(params[1].getType() != XmlRpcValue::TypeInt) ||
(params[2].getType() != XmlRpcValue::TypeInt) ||
(params[3].getType() != XmlRpcValue::TypeBase64) ||
(params[4].getType() != XmlRpcValue::TypeInt))
throw XmlRpcException("register(base64 name, int kind, int id, base64 address, int ttl): "
"Invalid argument type");
throw XmlRpcException("register(base64 name, int kind, int id, base64 address, int ttl): "
"No P2PNS service");
if (!isPrivileged()) {
throw XmlRpcException("register(base64 name, int kind, base64 address, "
"int ttl): Not allowed");
}
state[curAppFd]._connectionState = EXECUTE_REQUEST;
P2pnsRegisterCall* registerCall = new P2pnsRegisterCall();
registerCall->setP2pName(((const XmlRpcValue::BinaryData&)params[0]));
registerCall->setKind((int)params[1]);
registerCall->setId((int)params[2]);
registerCall->setAddress(((const XmlRpcValue::BinaryData&)params[3]));
registerCall->setTtl(params[4]);
}
void XmlRpcInterface::p2pnsResolve ( XmlRpc::XmlRpcValue params,
XmlRpc::XmlRpcValue result 
)

Definition at line 237 of file XmlRpcInterface.cc.

{
if ((params.size() != 2) ||
(params[0].getType() != XmlRpcValue::TypeBase64) ||
(params[1].getType() != XmlRpcValue::TypeInt))
throw XmlRpcException("resolve(base64 name, int kind): Invalid argument type");
throw XmlRpcException("resolve(base64 name, int kind): No P2PNS service");
state[curAppFd]._connectionState = EXECUTE_REQUEST;
P2pnsResolveCall* resolveCall = new P2pnsResolveCall();
resolveCall->setP2pName(((const XmlRpcValue::BinaryData&)params[0]));
resolveCall->setKind((int)params[1]);
resolveCall->setId(0);
}
void XmlRpcInterface::put ( XmlRpc::XmlRpcValue params,
XmlRpc::XmlRpcValue result 
)

Definition at line 350 of file XmlRpcInterface.cc.

{
if ((params.size() != 4)
|| (params[0].getType() != XmlRpcValue::TypeBase64)
|| (params[1].getType() != XmlRpcValue::TypeBase64)
|| (params[2].getType() != XmlRpcValue::TypeInt)
|| (params[3].getType() != XmlRpcValue::TypeString))
throw XmlRpcException("put(base64 key, base64 value, int ttl "
", string application): Invalid argument type");
if (!isPrivileged()) {
throw XmlRpcException("put(base64 key, base64 value, int ttl "
", string application): Not allowed");
}
throw XmlRpcException("put(base64 key, base64 value, int ttl "
", string application): No DHT service");
state[curAppFd]._connectionState = EXECUTE_REQUEST;
DHTputCAPICall* dhtPutMsg = new DHTputCAPICall();
BinaryValue keyString = (const XmlRpcValue::BinaryData&)params[0];
dhtPutMsg->setKey(OverlayKey::sha1(keyString));
dhtPutMsg->setValue(((const XmlRpcValue::BinaryData&)params[1]));
dhtPutMsg->setTtl(params[2]);
dhtPutMsg->setIsModifiable(true);
}
bool XmlRpcInterface::readHeader ( char *  buf,
uint32_t  length 
)
protected

Reads the http header.

Definition at line 961 of file XmlRpcInterface.cc.

{
// Read available data
bool eof = false;
state[curAppFd]._header.append(std::string(buf, length));
if (length <= 0) {
// Its only an error if we already have read some data
if (state[curAppFd]._header.length() > 0)
XmlRpcUtil::error("XmlRpcServerConnection::readHeader: error "
"while reading header.");
return false;
}
XmlRpcUtil::log(4, "XmlRpcServerConnection::readHeader: read %d bytes.",
state[curAppFd]._header.length());
char *hp = (char*)state[curAppFd]._header.c_str(); // Start of header
char *ep = hp + state[curAppFd]._header.length(); // End of string
char *bp = 0; // Start of body
char *lp = 0; // Start of content-length value
char *kp = 0; // Start of connection value
for (char *cp = hp; (bp == 0) && (cp < ep); ++cp) {
if ((ep - cp > 16) && (strncasecmp(cp, "Content-length: ", 16) == 0))
lp = cp + 16;
else if ((ep - cp > 12) && (strncasecmp(cp, "Connection: ", 12) == 0))
kp = cp + 12;
else if ((ep - cp > 4) && (strncmp(cp, "\r\n\r\n", 4) == 0))
bp = cp + 4;
else if ((ep - cp > 2) && (strncmp(cp, "\n\n", 2) == 0))
bp = cp + 2;
}
// If we haven't gotten the entire header yet, return (keep reading)
if (bp == 0) {
// EOF in the middle of a request is an error, otherwise its ok
if (eof) {
XmlRpcUtil::log(4, "XmlRpcServerConnection::readHeader: EOF");
if (state[curAppFd]._header.length() > 0)
XmlRpcUtil::error("XmlRpcServerConnection::readHeader: EOF while reading header");
return false; // Either way we close the connection
}
return true; // Keep reading
}
// Decode content length
if (lp == 0) {
XmlRpcUtil::error("XmlRpcServerConnection::readHeader: No Content-length specified");
return false; // We could try to figure it out by parsing as we read, but for now...
}
state[curAppFd]._contentLength = atoi(lp);
if (state[curAppFd]._contentLength <= 0) {
"XmlRpcServerConnection::readHeader: Invalid Content-length specified (%d).",
state[curAppFd]._contentLength);
return false;
}
XmlRpcUtil::log(
3,
"XmlRpcServerConnection::readHeader: specified content length is %d.",
state[curAppFd]._contentLength);
// Otherwise copy non-header data to request buffer and set state to read request.
state[curAppFd]._request = bp;
// Parse out any interesting bits from the header (HTTP version, connection)
state[curAppFd]._keepAlive = true;
if (state[curAppFd]._header.find("HTTP/1.0") != std::string::npos) {
if (kp == 0 || strncasecmp(kp, "keep-alive", 10) != 0)
state[curAppFd]._keepAlive = false; // Default for HTTP 1.0 is to close the connection
} else {
if (kp != 0 && strncasecmp(kp, "close", 5) == 0)
state[curAppFd]._keepAlive = false;
}
XmlRpcUtil::log(3, "KeepAlive: %d", state[curAppFd]._keepAlive);
state[curAppFd]._header = "";
state[curAppFd]._connectionState = READ_REQUEST;
return true; // Continue monitoring this source
}
bool XmlRpcInterface::readRequest ( char *  buf,
uint32_t  length 
)
protected

Reads the request (based on the content-length header value)

Definition at line 1046 of file XmlRpcInterface.cc.

{
// If we dont have the entire request yet, read available data
if (int(state[curAppFd]._request.length()) < state[curAppFd]._contentLength) {
bool eof = false;
state[curAppFd]._request.append(std::string(buf, length));
if (length <= 0) {
XmlRpcUtil::error("XmlRpcServerConnection::readRequest: read error.");
return false;
}
// If we haven't gotten the entire request yet, return (keep reading)
if (int(state[curAppFd]._request.length()) < state[curAppFd]._contentLength) {
if (eof) {
XmlRpcUtil::error("XmlRpcServerConnection::readRequest: EOF while reading request");
return false; // Either way we close the connection
}
return true;
}
}
// Otherwise, parse and dispatch the request
XmlRpcUtil::log(3, "XmlRpcServerConnection::readRequest read %d bytes.",
state[curAppFd]._request.length());
//XmlRpcUtil::log(5, "XmlRpcServerConnection::readRequest:\n%s\n", state[curAppFd]._request.c_str());
state[curAppFd]._connectionState = WRITE_RESPONSE;
return true; // Continue monitoring this source
}
void XmlRpcInterface::resetConnectionState ( )
protected

Reset the internal connection state.

This is called after a RPC has finished and the socket was closed.

Definition at line 517 of file XmlRpcInterface.cc.

{
if (state.count(curAppFd) && state[curAppFd].pendingRpc) {
}
state[curAppFd].appFd = INVALID_SOCKET;
state[curAppFd].localhost = false;
state[curAppFd]._header = "";
state[curAppFd]._request = "";
state[curAppFd]._response = "";
state[curAppFd]._connectionState = READ_HEADER;
state[curAppFd]._keepAlive = true;
state[curAppFd].pendingRpc = 0;
}
void XmlRpcInterface::sendInternalRpcWithTimeout ( CompType  destComp,
BaseCallMessage call 
)
protected

Definition at line 539 of file XmlRpcInterface.cc.

{
state[curAppFd].pendingRpc = sendInternalRpcCall(destComp, call, NULL,
}
bool XmlRpcInterface::writeResponse ( )
protected

Executes the request and writes the resulting response.

Definition at line 1079 of file XmlRpcInterface.cc.

{
if (state[curAppFd]._response.length() == 0) {
state[curAppFd]._response = executeRequest(state[curAppFd]._request);
state[curAppFd]._bytesWritten = 0;
if (state[curAppFd]._connectionState == EXECUTE_REQUEST)
return true;
if (state[curAppFd]._response.length() == 0) {
XmlRpcUtil::error("XmlRpcServerConnection::writeResponse: empty response.");
return false;
}
}
// Try to write the response
int curBytesWritten = scheduler->sendBytes(state[curAppFd]._response.c_str(),
state[curAppFd]._response.length(),
0, 0, true, curAppFd);
if (curBytesWritten <= 0) {
XmlRpcUtil::error("XmlRpcServerConnection::writeResponse: write error.");
return false;
} else {
state[curAppFd]._bytesWritten += curBytesWritten;
}
XmlRpcUtil::log(3,
"XmlRpcServerConnection::writeResponse: wrote %d of %d bytes.",
state[curAppFd]._bytesWritten, state[curAppFd]._response.length());
// Prepare to read the next request
if (state[curAppFd]._bytesWritten == int(state[curAppFd]._response.length())) {
state[curAppFd]._header = "";
state[curAppFd]._request = "";
state[curAppFd]._response = "";
state[curAppFd]._connectionState = READ_HEADER;
}
return state[curAppFd]._keepAlive; // Continue monitoring this source if true
}

Member Data Documentation

XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_addContact
protected

Definition at line 112 of file XmlRpcInterface.h.

XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_dumpDht
protected

Definition at line 108 of file XmlRpcInterface.h.

XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_get
protected

Definition at line 107 of file XmlRpcInterface.h.

XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_getContacts
protected

Definition at line 114 of file XmlRpcInterface.h.

XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_getUserId
protected

Definition at line 115 of file XmlRpcInterface.h.

XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_joinOverlay
protected

Definition at line 109 of file XmlRpcInterface.h.

XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_localLookup
protected

Definition at line 102 of file XmlRpcInterface.h.

XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_lookup
protected

Definition at line 103 of file XmlRpcInterface.h.

XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_publish
protected

Definition at line 117 of file XmlRpcInterface.h.

XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_pull_notification
protected

Definition at line 118 of file XmlRpcInterface.h.

XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_put
protected

Definition at line 106 of file XmlRpcInterface.h.

XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_register
protected

Definition at line 104 of file XmlRpcInterface.h.

XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_removeContact
protected

Definition at line 113 of file XmlRpcInterface.h.

XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_resolve
protected

Definition at line 105 of file XmlRpcInterface.h.

XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_searchContact
protected

Definition at line 116 of file XmlRpcInterface.h.

XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_subscribe
protected

Definition at line 119 of file XmlRpcInterface.h.

SOCKET XmlRpcInterface::appTunFd
protected

FD of the application TUN socket used for tunneling.

Definition at line 147 of file XmlRpcInterface.h.

SOCKET XmlRpcInterface::curAppFd
protected

Definition at line 99 of file XmlRpcInterface.h.

bool XmlRpcInterface::limitAccess
protected

Definition at line 100 of file XmlRpcInterface.h.

unsigned int XmlRpcInterface::mtu
protected

Definition at line 47 of file XmlRpcInterface.h.

P2pns* XmlRpcInterface::p2pns
protected

Pointer to the P2PNS module.

Definition at line 148 of file XmlRpcInterface.h.

PacketBuffer XmlRpcInterface::packetBuffer
protected

Definition at line 50 of file XmlRpcInterface.h.

cMessage* XmlRpcInterface::packetNotification
protected

Definition at line 49 of file XmlRpcInterface.h.

RealtimeScheduler* XmlRpcInterface::scheduler
protected

Definition at line 51 of file XmlRpcInterface.h.

std::map<int, XmlRpcConnectionState> XmlRpcInterface::state
protected

Definition at line 98 of file XmlRpcInterface.h.


The documentation for this class was generated from the following files: