#include <XmlRpcInterface.h>
Public Member Functions | |
virtual void | initializeApp (int stage) |
initializes derived class-attributes | |
virtual void | handleMessage (cMessage *msg) |
The "main loop". | |
void | localLookup (XmlRpc::XmlRpcValue ¶ms, XmlRpc::XmlRpcValue &result) |
void | lookup (XmlRpc::XmlRpcValue ¶ms, XmlRpc::XmlRpcValue &result) |
void | p2pnsRegister (XmlRpc::XmlRpcValue ¶ms, XmlRpc::XmlRpcValue &result) |
void | p2pnsResolve (XmlRpc::XmlRpcValue ¶ms, XmlRpc::XmlRpcValue &result) |
void | put (XmlRpc::XmlRpcValue ¶ms, XmlRpc::XmlRpcValue &result) |
void | get (XmlRpc::XmlRpcValue ¶ms, XmlRpc::XmlRpcValue &result) |
void | joinOverlay (XmlRpc::XmlRpcValue ¶ms, XmlRpc::XmlRpcValue &result) |
Protected Types | |
enum | ServerConnectionState { READ_HEADER, READ_REQUEST, EXECUTE_REQUEST, WRITE_RESPONSE } |
Possible IO states for the connection. More... | |
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. | |
void | handleRealworldPacket (char *buf, uint32_t len) |
void | handleCommonAPIPacket (cMessage *msg) |
void | handleRpcResponse (BaseResponseMessage *msg, int rpcId, simtime_t rtt) |
This method is called if an RPC response has been received. | |
Protected Attributes | |
unsigned int | mtu |
cMessage * | timeout_msg |
cMessage * | packetNotification |
RealtimeScheduler::PacketBuffer | packetBuffer |
RealtimeScheduler * | scheduler |
ServerConnectionState | _connectionState |
Current IO state for the connection. | |
std::string | _header |
Request headers. | |
int | _contentLength |
Number of bytes expected in the request body (parsed from header). | |
std::string | _request |
Request body. | |
std::string | _response |
Response. | |
int | _bytesWritten |
Number of bytes of the response written so far. | |
bool | _keepAlive |
Whether to keep the current client connection open for further requests. | |
int | appFd |
the fd for the current app socket | |
XmlRpc::XmlRpcServerMethod * | _localLookup |
XmlRpc::XmlRpcServerMethod * | _lookup |
XmlRpc::XmlRpcServerMethod * | _register |
XmlRpc::XmlRpcServerMethod * | _resolve |
XmlRpc::XmlRpcServerMethod * | _put |
XmlRpc::XmlRpcServerMethod * | _get |
XmlRpc::XmlRpcServerMethod * | _joinOverlay |
enum XmlRpcInterface::ServerConnectionState [protected] |
Possible IO states for the connection.
00041 { READ_HEADER, READ_REQUEST, EXECUTE_REQUEST, 00042 WRITE_RESPONSE };
bool XmlRpcInterface::readHeader | ( | char * | buf, | |
uint32_t | length | |||
) | [protected] |
Reads the http header.
00611 { 00612 // Read available data 00613 bool eof = false; 00614 00615 _header.append(std::string(buf, length)); 00616 00617 if (length <= 0) { 00618 // Its only an error if we already have read some data 00619 if (_header.length() > 0) 00620 XmlRpcUtil::error("XmlRpcServerConnection::readHeader: error " 00621 "while reading header."); 00622 return false; 00623 } 00624 00625 XmlRpcUtil::log(4, "XmlRpcServerConnection::readHeader: read %d bytes.", 00626 _header.length()); 00627 char *hp = (char*)_header.c_str(); // Start of header 00628 char *ep = hp + _header.length(); // End of string 00629 char *bp = 0; // Start of body 00630 char *lp = 0; // Start of content-length value 00631 char *kp = 0; // Start of connection value 00632 00633 for (char *cp = hp; (bp == 0) && (cp < ep); ++cp) { 00634 if ((ep - cp > 16) && (strncasecmp(cp, "Content-length: ", 16) == 0)) 00635 lp = cp + 16; 00636 else if ((ep - cp > 12) && (strncasecmp(cp, "Connection: ", 12) == 0)) 00637 kp = cp + 12; 00638 else if ((ep - cp > 4) && (strncmp(cp, "\r\n\r\n", 4) == 0)) 00639 bp = cp + 4; 00640 else if ((ep - cp > 2) && (strncmp(cp, "\n\n", 2) == 0)) 00641 bp = cp + 2; 00642 } 00643 00644 // If we haven't gotten the entire header yet, return (keep reading) 00645 if (bp == 0) { 00646 // EOF in the middle of a request is an error, otherwise its ok 00647 if (eof) { 00648 XmlRpcUtil::log(4, "XmlRpcServerConnection::readHeader: EOF"); 00649 if (_header.length() > 0) 00650 XmlRpcUtil::error("XmlRpcServerConnection::readHeader: EOF while reading header"); 00651 return false; // Either way we close the connection 00652 } 00653 00654 return true; // Keep reading 00655 } 00656 00657 // Decode content length 00658 if (lp == 0) { 00659 XmlRpcUtil::error("XmlRpcServerConnection::readHeader: No Content-length specified"); 00660 return false; // We could try to figure it out by parsing as we read, but for now... 00661 } 00662 00663 _contentLength = atoi(lp); 00664 if (_contentLength <= 0) { 00665 XmlRpcUtil::error( 00666 "XmlRpcServerConnection::readHeader: Invalid Content-length specified (%d).", 00667 _contentLength); 00668 return false; 00669 } 00670 00671 XmlRpcUtil::log( 00672 3, 00673 "XmlRpcServerConnection::readHeader: specified content length is %d.", 00674 _contentLength); 00675 00676 // Otherwise copy non-header data to request buffer and set state to read request. 00677 _request = bp; 00678 00679 // Parse out any interesting bits from the header (HTTP version, connection) 00680 _keepAlive = true; 00681 if (_header.find("HTTP/1.0") != std::string::npos) { 00682 if (kp == 0 || strncasecmp(kp, "keep-alive", 10) != 0) 00683 _keepAlive = false; // Default for HTTP 1.0 is to close the connection 00684 } else { 00685 if (kp != 0 && strncasecmp(kp, "close", 5) == 0) 00686 _keepAlive = false; 00687 } 00688 XmlRpcUtil::log(3, "KeepAlive: %d", _keepAlive); 00689 00690 _header = ""; 00691 _connectionState = READ_REQUEST; 00692 return true; // Continue monitoring this source 00693 }
bool XmlRpcInterface::readRequest | ( | char * | buf, | |
uint32_t | length | |||
) | [protected] |
Reads the request (based on the content-length header value).
00696 { 00697 // If we dont have the entire request yet, read available data 00698 if (int(_request.length()) < _contentLength) { 00699 bool eof = false; 00700 00701 _request.append(std::string(buf, length)); 00702 00703 if (length <= 0) { 00704 XmlRpcUtil::error("XmlRpcServerConnection::readRequest: read error."); 00705 return false; 00706 } 00707 00708 // If we haven't gotten the entire request yet, return (keep reading) 00709 if (int(_request.length()) < _contentLength) { 00710 if (eof) { 00711 XmlRpcUtil::error("XmlRpcServerConnection::readRequest: EOF while reading request"); 00712 return false; // Either way we close the connection 00713 } 00714 return true; 00715 } 00716 } 00717 00718 // Otherwise, parse and dispatch the request 00719 XmlRpcUtil::log(3, "XmlRpcServerConnection::readRequest read %d bytes.", 00720 _request.length()); 00721 //XmlRpcUtil::log(5, "XmlRpcServerConnection::readRequest:\n%s\n", _request.c_str()); 00722 00723 _connectionState = WRITE_RESPONSE; 00724 00725 return true; // Continue monitoring this source 00726 }
bool XmlRpcInterface::writeResponse | ( | ) | [protected] |
Executes the request and writes the resulting response.
00729 { 00730 cancelEvent(timeout_msg); 00731 00732 if (_response.length() == 0) { 00733 _response = executeRequest(_request); 00734 _bytesWritten = 0; 00735 00736 if (_connectionState == EXECUTE_REQUEST) 00737 return true; 00738 00739 if (_response.length() == 0) { 00740 XmlRpcUtil::error("XmlRpcServerConnection::writeResponse: empty response."); 00741 return false; 00742 } 00743 } 00744 00745 // Try to write the response 00746 int curBytesWritten = scheduler->sendBytes(_response.c_str(), 00747 _response.length(), 0, 0, true, appFd); 00748 00749 if (curBytesWritten <= 0) { 00750 XmlRpcUtil::error("XmlRpcServerConnection::writeResponse: write error."); 00751 return false; 00752 } else { 00753 _bytesWritten += curBytesWritten; 00754 } 00755 00756 XmlRpcUtil::log( 00757 3, 00758 "XmlRpcServerConnection::writeResponse: wrote %d of %d bytes.", 00759 _bytesWritten, _response.length()); 00760 00761 // Prepare to read the next request 00762 if (_bytesWritten == int(_response.length())) { 00763 _header = ""; 00764 _request = ""; 00765 _response = ""; 00766 _connectionState = READ_HEADER; 00767 } 00768 00769 return _keepAlive; // Continue monitoring this source if true 00770 }
void XmlRpcInterface::handleRealworldPacket | ( | char * | buf, | |
uint32_t | len | |||
) | [protected] |
00456 { 00457 if (_connectionState == READ_HEADER) { 00458 if (!readHeader(buf, length)) { 00459 // discard data, if the header is invalid 00460 _header = ""; 00461 _request = ""; 00462 _response = ""; 00463 _connectionState = READ_HEADER; 00464 return; 00465 } 00466 } 00467 00468 if (_connectionState == READ_REQUEST) 00469 if (!readRequest(buf, length)) 00470 return; 00471 00472 if (_connectionState == WRITE_RESPONSE) 00473 if (!writeResponse() ) { 00474 scheduler->closeAppSocket(appFd); 00475 return; 00476 } 00477 00478 return; 00479 }
void XmlRpcInterface::handleCommonAPIPacket | ( | cMessage * | msg | ) | [protected] |
void XmlRpcInterface::handleRpcResponse | ( | BaseResponseMessage * | msg, | |
int | rpcId, | |||
simtime_t | rtt | |||
) | [protected, virtual] |
This method is called if an RPC response has been received.
msg | The response message. | |
rpcId | The RPC id. | |
rtt | The Round-Trip-Time of this RPC |
Reimplemented from RpcListener.
00483 { 00484 RPC_SWITCH_START(msg) 00485 RPC_ON_RESPONSE( Lookup ) { 00486 if (_connectionState != EXECUTE_REQUEST) break; 00487 00488 XmlRpcValue resultValue; 00489 resultValue.setSize(_LookupResponse->getSiblingsArraySize()); 00490 00491 if (_LookupResponse->getIsValid() == true) { 00492 for (uint i=0; i < _LookupResponse->getSiblingsArraySize(); 00493 i++) { 00494 resultValue[i].setSize(3); 00495 resultValue[i][0] = 00496 _LookupResponse->getSiblings(i).ip.str(); 00497 resultValue[i][1] = 00498 _LookupResponse->getSiblings(i).port; 00499 resultValue[i][2] = 00500 _LookupResponse->getSiblings(i).key.toString(16); 00501 } 00502 _response = generateResponse(resultValue.toXml()); 00503 } else { 00504 std::cout << "XmlRpcInterface(): lookup() failed!" << endl; 00505 _response = generateFaultResponse("lookup() failed", 22); 00506 } 00507 00508 _connectionState = WRITE_RESPONSE; 00509 if (! writeResponse() ) { 00510 scheduler->closeAppSocket(appFd); 00511 } 00512 break; 00513 } 00514 RPC_ON_RESPONSE(P2pnsRegister) { 00515 if (_connectionState != EXECUTE_REQUEST) 00516 break; 00517 00518 XmlRpcValue resultValue; 00519 00520 if (_P2pnsRegisterResponse->getIsSuccess() == true) { 00521 resultValue = 0; 00522 _response = generateResponse(resultValue.toXml()); 00523 } else { 00524 std::cout << "XmlRpcInterface(): register() failed!" << endl; 00525 _response = generateFaultResponse("register() failed", 22); 00526 } 00527 00528 _connectionState = WRITE_RESPONSE; 00529 if (!writeResponse() ) { 00530 scheduler->closeAppSocket(appFd); 00531 } 00532 break; 00533 } 00534 RPC_ON_RESPONSE(P2pnsResolve) { 00535 if (_connectionState != EXECUTE_REQUEST) 00536 break; 00537 00538 XmlRpcValue resultValue; 00539 resultValue.setSize(1); 00540 00541 if (_P2pnsResolveResponse->getIsSuccess() == true) { 00542 resultValue[0] = XmlRpcValue( 00543 &(*(_P2pnsResolveResponse->getAddress().begin())), 00544 _P2pnsResolveResponse->getAddress().size()); 00545 _response = generateResponse(resultValue.toXml()); 00546 } else { 00547 std::cout << "XmlRpcInterface(): resolve() failed!" << endl; 00548 _response = generateFaultResponse("resolve() failed", 22); 00549 } 00550 00551 _connectionState = WRITE_RESPONSE; 00552 if (!writeResponse() ) { 00553 scheduler->closeAppSocket(appFd); 00554 } 00555 break; 00556 } 00557 RPC_ON_RESPONSE(DHTputCAPI) { 00558 if (_connectionState != EXECUTE_REQUEST) 00559 break; 00560 00561 XmlRpcValue resultValue; 00562 00563 if (_DHTputCAPIResponse->getIsSuccess() == true) { 00564 resultValue = 0; 00565 _response = generateResponse(resultValue.toXml()); 00566 } else { 00567 std::cout << "XmlRpcInterface(): put() failed!" << endl; 00568 _response = generateFaultResponse("put() failed", 22); 00569 } 00570 00571 _connectionState = WRITE_RESPONSE; 00572 if (!writeResponse() ) { 00573 scheduler->closeAppSocket(appFd); 00574 } 00575 break; 00576 } 00577 RPC_ON_RESPONSE(DHTgetCAPI) { 00578 if (_connectionState != EXECUTE_REQUEST) 00579 break; 00580 00581 XmlRpcValue resultValue; 00582 resultValue.setSize(2); 00583 resultValue[0].setSize(1); 00584 00585 if (_DHTgetCAPIResponse->getIsSuccess() == true) { 00586 resultValue[0][0] = XmlRpcValue( 00587 &(*(_DHTgetCAPIResponse->getValue().begin())), 00588 _DHTgetCAPIResponse->getValue().size()); 00589 resultValue[1] = std::string(); 00590 _response = generateResponse(resultValue.toXml()); 00591 } else { 00592 std::cout << "XmlRpcInterface(): get() failed!" << endl; 00593 _response = generateFaultResponse("get() failed", 22); 00594 } 00595 00596 _connectionState = WRITE_RESPONSE; 00597 if (!writeResponse() ) { 00598 scheduler->closeAppSocket(appFd); 00599 } 00600 break; 00601 } 00602 RPC_SWITCH_END( ) 00603 }
void XmlRpcInterface::initializeApp | ( | int | stage | ) | [virtual] |
initializes derived class-attributes
stage | the init stage |
Reimplemented from BaseApp.
00341 { 00342 // all initialization is done in the first stage 00343 if (stage != MIN_STAGE_APP) 00344 return; 00345 00346 packetNotification = new cMessage("packetNotification"); 00347 mtu = par("mtu"); 00348 00349 scheduler = check_and_cast<RealtimeScheduler *>(simulation.scheduler()); 00350 scheduler->setInterfaceModule(this, packetNotification, &packetBuffer, mtu, 00351 true); 00352 00353 XmlRpc::setVerbosity(1); 00354 00355 _localLookup = new LocalLookup(this); 00356 _lookup = new Lookup(this); 00357 _register = new P2pnsRegister(this); 00358 _resolve = new P2pnsResolve(this); 00359 _put = new Put(this); 00360 _get = new Get(this); 00361 _joinOverlay = new JoinOverlay(this); 00362 00363 enableIntrospection(true); 00364 00365 appFd = -1; 00366 00367 _connectionState = READ_HEADER; 00368 _keepAlive = true; 00369 00370 timeout_msg = new cMessage("timeout_msg"); 00371 }
void XmlRpcInterface::handleMessage | ( | cMessage * | msg | ) | [virtual] |
The "main loop".
Every message that is received or send is handled by this method
Reimplemented from BaseApp.
00374 { 00375 // Packet from the application... 00376 if (msg==packetNotification) { 00377 EV << "[DHTXMLRealworldApp::handleMessage() @ " << thisNode.ip 00378 << " (" << thisNode.key.toString(16) << ")]\n" 00379 << " Message from application. Queue length = " << packetBuffer.size() 00380 << endl; 00381 while (packetBuffer.size() > 0) { 00382 // get packet from buffer and parse it 00383 RealtimeScheduler::PacketBufferEntry packet = 00384 *(packetBuffer.begin()); 00385 packetBuffer.pop_front(); 00386 switch (packet.func) { 00387 00388 case RealtimeScheduler::PacketBufferEntry::DATA: 00389 00390 if (packet.fd != appFd) { 00391 error("XmlRpcInterface::handleMessage(): Received packet " 00392 "from unknown socket!"); 00393 } 00394 handleRealworldPacket(packet.data, packet.length); 00395 break; 00396 00397 case RealtimeScheduler::PacketBufferEntry::FD_NEW: 00398 if (appFd != -1) { 00399 error("XmlRpcInterface::handleMessage(): Multiple connections " 00400 "not supported yet!"); 00401 } 00402 appFd = packet.fd; 00403 break; 00404 00405 case RealtimeScheduler::PacketBufferEntry::FD_CLOSE: 00406 if (packet.fd != appFd) { 00407 error("XmlRpcInterface::handleMessage(): Trying to close unknown " 00408 "connection!"); 00409 } 00410 00411 appFd = -1; 00412 _header = ""; 00413 _request = ""; 00414 _response = ""; 00415 _connectionState = READ_HEADER; 00416 } 00417 if (packet.data) { 00418 delete[] packet.data; 00419 } 00420 } 00421 } else if (msg->isSelfMessage()) { 00422 // process rpc self-messages 00423 BaseRpcMessage* rpcMessage = dynamic_cast<BaseRpcMessage*>(msg); 00424 if (rpcMessage!=NULL) { 00425 internalHandleRpcMessage(rpcMessage); 00426 return; 00427 } 00428 // process all other self-messages 00429 if (msg == timeout_msg) { 00430 std::cout << "DHTXMLRealworldApp(): XML-RPC failed!" << endl; 00431 _response = generateFaultResponse("XML-RPC timeout", 22); 00432 _connectionState = WRITE_RESPONSE; 00433 if (!writeResponse() ) { 00434 scheduler->closeAppSocket(appFd); 00435 } 00436 return; 00437 } 00438 } else { 00439 // RPCs 00440 BaseRpcMessage* rpcMessage = dynamic_cast<BaseRpcMessage*>(msg); 00441 if (rpcMessage!=NULL) { 00442 internalHandleRpcMessage(rpcMessage); 00443 return; 00444 } 00445 // common API 00446 CommonAPIMessage* commonAPIMsg = dynamic_cast<CommonAPIMessage*>(msg); 00447 if (commonAPIMsg != NULL) 00448 handleCommonAPIPacket(commonAPIMsg); 00449 00450 delete msg; 00451 } 00452 00453 }
void XmlRpcInterface::localLookup | ( | XmlRpc::XmlRpcValue & | params, | |
XmlRpc::XmlRpcValue & | result | |||
) |
00221 { 00222 if ((params.size() != 3) 00223 || (params[0].getType() != XmlRpcValue::TypeBase64) 00224 || (params[1].getType() != XmlRpcValue::TypeInt) 00225 || (params[2].getType() != XmlRpcValue::TypeBoolean)) 00226 throw XmlRpcException("local_lookup(base64 key, int num, " 00227 "boolean safe): Invalid argument type"); 00228 00229 BinaryValue keyString = (const XmlRpcValue::BinaryData&)params[0]; 00230 00231 NodeVector* nextHops = overlay->local_lookup(OverlayKey::sha1(keyString), 00232 params[1], params[2]); 00233 00234 for (uint i=0; i < nextHops->size(); i++) { 00235 result[i][0] = (*nextHops)[0].ip.str(); 00236 result[i][1] = (*nextHops)[0].port; 00237 result[i][2] = (*nextHops)[0].key.toString(16); 00238 } 00239 00240 delete nextHops; 00241 }
void XmlRpcInterface::lookup | ( | XmlRpc::XmlRpcValue & | params, | |
XmlRpc::XmlRpcValue & | result | |||
) |
00244 { 00245 if ((params.size() != 2) 00246 || (params[0].getType() != XmlRpcValue::TypeBase64) 00247 || (params[1].getType() != XmlRpcValue::TypeInt)) 00248 throw XmlRpcException("lookup(base64 key, int numSiblings): " 00249 "Invalid argument type"); 00250 00251 if ((int)params[1] > overlay->getMaxNumSiblings()) 00252 throw XmlRpcException("lookup(base64 key, int numSiblings): " 00253 "numSibling to big"); 00254 00255 _connectionState = EXECUTE_REQUEST; 00256 00257 LookupCall* lookupCall = new LookupCall(); 00258 00259 BinaryValue keyString = (const XmlRpcValue::BinaryData&)params[0]; 00260 lookupCall->setKey(OverlayKey::sha1(keyString)); 00261 lookupCall->setNumSiblings(params[1]); 00262 00263 sendInternalRpcCall(OVERLAY_COMP, lookupCall); 00264 00265 cancelEvent(timeout_msg); 00266 scheduleAt(simulation.simTime() + XMLRPC_TIMEOUT, timeout_msg); 00267 }
void XmlRpcInterface::p2pnsRegister | ( | XmlRpc::XmlRpcValue & | params, | |
XmlRpc::XmlRpcValue & | result | |||
) |
00173 { 00174 if ((params.size() != 3) || 00175 (params[0].getType() != XmlRpcValue::TypeBase64) || 00176 (params[1].getType() != XmlRpcValue::TypeBase64) || 00177 (params[2].getType() != XmlRpcValue::TypeInt)) 00178 throw XmlRpcException("register(base64 name, base64 address, int ttl): " 00179 "Invalid argument type"); 00180 00181 if (overlay->getCompModule(TIER2_COMP) == NULL) 00182 throw XmlRpcException("register(base64 name, base64 address, int ttl): " 00183 "No P2PNS service"); 00184 00185 _connectionState = EXECUTE_REQUEST; 00186 00187 P2pnsRegisterCall* registerCall = new P2pnsRegisterCall(); 00188 00189 registerCall->setName(((const XmlRpcValue::BinaryData&)params[0])); 00190 registerCall->setAddress(((const XmlRpcValue::BinaryData&)params[1])); 00191 registerCall->setTtl(params[2]); 00192 00193 sendInternalRpcCall(TIER2_COMP, registerCall); 00194 00195 cancelEvent(timeout_msg); 00196 scheduleAt(simulation.simTime() + XMLRPC_TIMEOUT, timeout_msg); 00197 }
void XmlRpcInterface::p2pnsResolve | ( | XmlRpc::XmlRpcValue & | params, | |
XmlRpc::XmlRpcValue & | result | |||
) |
00200 { 00201 if ((params.size() != 1) || 00202 (params[0].getType() != XmlRpcValue::TypeBase64)) 00203 throw XmlRpcException("resolve(base64 name): Invalid argument type"); 00204 00205 if (overlay->getCompModule(TIER2_COMP) == NULL) 00206 throw XmlRpcException("resolve(base64 name): No P2PNS service"); 00207 00208 _connectionState = EXECUTE_REQUEST; 00209 00210 P2pnsResolveCall* resolveCall = new P2pnsResolveCall(); 00211 00212 resolveCall->setName(((const XmlRpcValue::BinaryData&)params[0])); 00213 00214 sendInternalRpcCall(TIER2_COMP, resolveCall); 00215 00216 cancelEvent(timeout_msg); 00217 scheduleAt(simulation.simTime() + XMLRPC_TIMEOUT, timeout_msg); 00218 }
void XmlRpcInterface::put | ( | XmlRpc::XmlRpcValue & | params, | |
XmlRpc::XmlRpcValue & | result | |||
) |
00283 { 00284 if ((params.size() != 4) 00285 || (params[0].getType() != XmlRpcValue::TypeBase64) 00286 || (params[1].getType() != XmlRpcValue::TypeBase64) 00287 || (params[2].getType() != XmlRpcValue::TypeInt) 00288 || (params[3].getType() != XmlRpcValue::TypeString)) 00289 throw XmlRpcException("put(base64 key, base64 value, int ttl " 00290 ", string application): Invalid argument type"); 00291 00292 if (overlay->getCompModule(TIER1_COMP) == NULL) 00293 throw XmlRpcException("put(base64 key, base64 value, int ttl " 00294 ", string application): No DHT service"); 00295 00296 _connectionState = EXECUTE_REQUEST; 00297 00298 DHTputCAPICall* dhtPutMsg = new DHTputCAPICall(); 00299 00300 BinaryValue keyString = (const XmlRpcValue::BinaryData&)params[0]; 00301 00302 dhtPutMsg->setKey(OverlayKey::sha1(keyString)); 00303 dhtPutMsg->setValue(((const XmlRpcValue::BinaryData&)params[1])); 00304 dhtPutMsg->setTtl(params[2]); 00305 dhtPutMsg->setIsModifiable(true); 00306 00307 sendInternalRpcCall(TIER1_COMP, dhtPutMsg); 00308 00309 cancelEvent(timeout_msg); 00310 scheduleAt(simulation.simTime() + XMLRPC_TIMEOUT, timeout_msg); 00311 }
void XmlRpcInterface::get | ( | XmlRpc::XmlRpcValue & | params, | |
XmlRpc::XmlRpcValue & | result | |||
) |
00314 { 00315 if ((params.size() != 4) 00316 || (params[0].getType() != XmlRpcValue::TypeBase64) 00317 || (params[1].getType() != XmlRpcValue::TypeInt) 00318 || (params[2].getType() != XmlRpcValue::TypeBase64) 00319 || (params[3].getType() != XmlRpcValue::TypeString)) 00320 throw XmlRpcException("get(base64 key, int num, base64 placemark " 00321 ", string application): Invalid argument type"); 00322 00323 if (overlay->getCompModule(TIER1_COMP) == NULL) 00324 throw XmlRpcException("get(base64 key, int num, base64 placemark " 00325 ", string application): No DHT service"); 00326 00327 _connectionState = EXECUTE_REQUEST; 00328 00329 DHTgetCAPICall* dhtGetMsg = new DHTgetCAPICall(); 00330 00331 BinaryValue keyString = (const XmlRpcValue::BinaryData&)params[0]; 00332 dhtGetMsg->setKey(OverlayKey::sha1(keyString)); 00333 00334 sendInternalRpcCall(TIER1_COMP, dhtGetMsg); 00335 00336 cancelEvent(timeout_msg); 00337 scheduleAt(simulation.simTime() + XMLRPC_TIMEOUT, timeout_msg); 00338 }
void XmlRpcInterface::joinOverlay | ( | XmlRpc::XmlRpcValue & | params, | |
XmlRpc::XmlRpcValue & | result | |||
) |
00270 { 00271 if ((params.size() != 1) 00272 || (params[0].getType() != XmlRpcValue::TypeBase64)) 00273 throw XmlRpcException("join(base64 nodeID): Invalid argument type"); 00274 00275 BinaryValue nodeID = (const XmlRpcValue::BinaryData&)params[0]; 00276 00277 overlay->join(OverlayKey::sha1(nodeID)); 00278 00279 result[0] = 0; 00280 }
unsigned int XmlRpcInterface::mtu [protected] |
cMessage* XmlRpcInterface::timeout_msg [protected] |
cMessage* XmlRpcInterface::packetNotification [protected] |
RealtimeScheduler* XmlRpcInterface::scheduler [protected] |
Current IO state for the connection.
std::string XmlRpcInterface::_header [protected] |
Request headers.
int XmlRpcInterface::_contentLength [protected] |
Number of bytes expected in the request body (parsed from header).
std::string XmlRpcInterface::_request [protected] |
Request body.
std::string XmlRpcInterface::_response [protected] |
Response.
int XmlRpcInterface::_bytesWritten [protected] |
Number of bytes of the response written so far.
bool XmlRpcInterface::_keepAlive [protected] |
Whether to keep the current client connection open for further requests.
int XmlRpcInterface::appFd [protected] |
the fd for the current app socket
XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_localLookup [protected] |
XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_lookup [protected] |
XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_register [protected] |
XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_resolve [protected] |
XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_put [protected] |
XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_get [protected] |
XmlRpc::XmlRpcServerMethod* XmlRpcInterface::_joinOverlay [protected] |