void RibManager::sendErrorResponse(uint32_t code, const std::string& error, const shared_ptr<const Interest>& request) { NFD_LOG_ERROR("NFD returned an error: " << error << " (code: " << code << ")"); if (!static_cast<bool>(request)) { return; } ControlResponse response; if (code == 404) { response.setCode(code); response.setText(error); } else { response.setCode(533); std::ostringstream os; os << "Failure to update NFD " << "(NFD Error: " << code << " " << error << ")"; response.setText(os.str()); } if (static_cast<bool>(request)) { sendResponse(request->getName(), response); } }
void ManagerBase::sendResponse(const Name& name, const ControlResponse& response) { NFD_LOG_DEBUG("responding" << " name: " << name << " code: " << response.getCode() << " text: " << response.getText()); const Block& encodedControl = response.wireEncode(); shared_ptr<Data> responseData(make_shared<Data>(name)); responseData->setContent(encodedControl); m_keyChain.sign(*responseData); m_face->putData(*responseData); }
void RibManager::onUnRegSuccess(const shared_ptr<const Interest>& request, const ControlParameters& parameters, const Route& route) { ControlResponse response; response.setCode(200); response.setText("Success"); response.setBody(parameters.wireEncode()); NFD_LOG_TRACE("onUnRegSuccess: unregistered " << route); if (static_cast<bool>(request)) { sendResponse(request->getName(), response); } }
void Controller::processValidatedCommandResponse(const Data& data, const shared_ptr<ControlCommand>& command, const CommandSucceedCallback& onSuccess, const CommandFailCallback& onFailure) { ControlResponse response; try { response.wireDecode(data.getContent().blockFromValue()); } catch (const tlv::Error& e) { if (onFailure) onFailure(ControlResponse(ERROR_SERVER, e.what())); return; } uint32_t code = response.getCode(); if (code >= ERROR_LBOUND) { if (onFailure) onFailure(response); return; } ControlParameters parameters; try { parameters.wireDecode(response.getBody()); } catch (const tlv::Error& e) { if (onFailure) onFailure(ControlResponse(ERROR_SERVER, e.what())); return; } try { command->validateResponse(parameters); } catch (const ControlCommand::ArgumentError& e) { if (onFailure) onFailure(ControlResponse(ERROR_SERVER, e.what())); return; } if (onSuccess) onSuccess(parameters); }
void RibManager::sendSuccessResponse(const shared_ptr<const Interest>& request, const ControlParameters& parameters) { if (!static_cast<bool>(request)) { return; } ControlResponse response; response.setCode(200); response.setText("Success"); response.setBody(parameters.wireEncode()); if (static_cast<bool>(request)) { sendResponse(request->getName(), response); } }
void RibManager::sendResponse(const Name& name, const ControlResponse& response) { const Block& encodedControl = response.wireEncode(); shared_ptr<Data> responseData = make_shared<Data>(name); responseData->setContent(encodedControl); m_keyChain.sign(*responseData); m_face.put(*responseData); }
void Tlv0_2WireFormat::decodeControlResponse (ControlResponse& controlResponse, const uint8_t *input, size_t inputLength) { struct ndn_NameComponent nameComponents[100]; struct ndn_NameComponent strategyNameComponents[100]; ControlResponseLite controlResponseLite (nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]), strategyNameComponents, sizeof(strategyNameComponents) / sizeof(strategyNameComponents[0])); ndn_Error error; if ((error = Tlv0_2WireFormatLite::decodeControlResponse (controlResponseLite, input, inputLength))) throw runtime_error(ndn_getErrorString(error)); controlResponse.set(controlResponseLite); }
Blob Tlv0_2WireFormat::encodeControlResponse(const ControlResponse& controlResponse) { struct ndn_NameComponent nameComponents[100]; struct ndn_NameComponent strategyNameComponents[100]; ControlResponseLite controlResponseLite (nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]), strategyNameComponents, sizeof(strategyNameComponents) / sizeof(strategyNameComponents[0])); controlResponse.get(controlResponseLite); DynamicUInt8Vector output(256); ndn_Error error; size_t encodingLength; if ((error = Tlv0_2WireFormatLite::encodeControlResponse (controlResponseLite, DynamicUInt8ArrayLite::downCast(output), &encodingLength))) throw runtime_error(ndn_getErrorString(error)); return output.finish(encodingLength); }
void recordCommandFail(const ControlResponse& response) { failCodes.push_back(response.getCode()); }