void ActionLog::apply_action_xFun(sqlite3_context* context, int argc, sqlite3_value** argv) { ActionLog* the = reinterpret_cast<ActionLog*>(sqlite3_user_data(context)); if (argc != 11) { sqlite3_result_error(context, "``apply_action'' expects 10 arguments", -1); return; } Buffer device_name(sqlite3_value_blob(argv[0]), sqlite3_value_bytes(argv[0])); sqlite3_int64 seq_no = sqlite3_value_int64(argv[1]); int action = sqlite3_value_int(argv[2]); std::string filename = reinterpret_cast<const char*>(sqlite3_value_text(argv[3])); sqlite3_int64 version = sqlite3_value_int64(argv[4]); _LOG_TRACE("apply_function called with " << argc); _LOG_TRACE("device_name: " << Name(Block(reinterpret_cast<const char*>(device_name.buf()), device_name.size())) << ", action: " << action << ", file: " << filename); if (action == 0) // update { Buffer hash(sqlite3_value_blob(argv[5]), sqlite3_value_bytes(argv[5])); time_t atime = static_cast<time_t>(sqlite3_value_int64(argv[6])); time_t mtime = static_cast<time_t>(sqlite3_value_int64(argv[7])); time_t ctime = static_cast<time_t>(sqlite3_value_int64(argv[8])); int mode = sqlite3_value_int(argv[9]); int seg_num = sqlite3_value_int(argv[10]); _LOG_DEBUG("Update " << filename << " " << atime << " " << mtime << " " << ctime << " " << toHex(hash)); the->m_fileState->UpdateFile(filename, version, hash, device_name, seq_no, atime, mtime, ctime, mode, seg_num); // no callback here } else if (action == 1) // delete { the->m_fileState->DeleteFile(filename); the->m_onFileRemoved(filename); } sqlite3_result_null(context); }
shared_ptr<Data> ActionLog::LookupActionData(const Name& deviceName, sqlite3_int64 seqno) { sqlite3_stmt* stmt; sqlite3_prepare_v2(m_db, "SELECT action_content_object FROM ActionLog WHERE device_name=? AND seq_no=?", -1, &stmt, 0); sqlite3_bind_blob(stmt, 1, deviceName.wireEncode().wire(), deviceName.wireEncode().size(), SQLITE_STATIC); // ndn version sqlite3_bind_int64(stmt, 2, seqno); shared_ptr<Data> retval; if (sqlite3_step(stmt) == SQLITE_ROW) { // _LOG_DEBUG(sqlite3_column_blob(stmt, 0) << ", " << sqlite3_column_bytes(stmt, 0)); retval = make_shared<Data>(); retval->wireDecode(Block(reinterpret_cast<const uint8_t*>(sqlite3_column_blob(stmt, 0)), sqlite3_column_bytes(stmt, 0))); } else { _LOG_TRACE("No action found for deviceName [" << deviceName << "] and seqno:" << seqno); } // _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK && sqlite3_errcode(m_db) != SQLITE_ROW, // sqlite3_errmsg(m_db)); sqlite3_finalize(stmt); return retval; }
shared_ptr<Data> ActionLog::LookupActionData(const Name& actionName) { sqlite3_stmt* stmt; sqlite3_prepare_v2(m_db, "SELECT action_content_object FROM ActionLog WHERE action_name=?", -1, &stmt, 0); _LOG_DEBUG(actionName); _LOG_DEBUG(" LookActionData <<<<<<< " << actionName << " " << actionName.wireEncode().size()); sqlite3_bind_blob(stmt, 1, actionName.wireEncode().wire(), actionName.wireEncode().size(), SQLITE_STATIC); shared_ptr<Data> retval; // = make_shared<Data>(); if (sqlite3_step(stmt) == SQLITE_ROW) { // _LOG_DEBUG(sqlite3_column_blob(stmt, 0) << ", " << sqlite3_column_bytes(stmt, 0)); retval = make_shared<Data>(); retval->wireDecode(Block(reinterpret_cast<const uint8_t*>(sqlite3_column_blob(stmt, 0)), sqlite3_column_bytes(stmt, 0))); } else { _LOG_TRACE("No action found for name: " << actionName); } _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_ROW, sqlite3_errmsg(m_db)); sqlite3_finalize(stmt); return retval; }
ptr_lib::shared_ptr<CertificateV2> ValidationState::verifyCertificateChain (const ptr_lib::shared_ptr<CertificateV2>& trustedCertificate) { ptr_lib::shared_ptr<CertificateV2> validatedCertificate = trustedCertificate; for (size_t i = 0; i < certificateChain_.size(); ++i) { ptr_lib::shared_ptr<CertificateV2> certificateToValidate = certificateChain_[i]; if (!VerificationHelpers::verifyDataSignature (*certificateToValidate, *validatedCertificate)) { fail(ValidationError(ValidationError::INVALID_SIGNATURE, "Invalid signature of certificate `" + certificateToValidate->getName().toUri() + "`")); certificateChain_.erase (certificateChain_.begin() + i, certificateChain_.end()); return ptr_lib::shared_ptr<CertificateV2>(); } else { _LOG_TRACE("OK signature for certificate `" << certificateToValidate->getName() << "`"); validatedCertificate = certificateToValidate; } } return validatedCertificate; }
void KeyChain::verifyInterest (const ptr_lib::shared_ptr<Interest>& interest, const OnVerifiedInterest& onVerified, const OnVerifyInterestFailed& onVerifyFailed, int stepCount, WireFormat& wireFormat) { _LOG_TRACE("Enter Verify"); if (policyManager_->requireVerify(*interest)) { ptr_lib::shared_ptr<ValidationRequest> nextStep = policyManager_->checkVerificationPolicy (interest, stepCount, onVerified, onVerifyFailed, wireFormat); if (nextStep) #if 0 face_->expressInterest (*nextStep->interest_, bind(&KeyChain::onCertificateData, this, _1, _2, nextStep), bind(&KeyChain::onCertificateInterestTimeout, this, _1, nextStep->retry_, onVerifyFailed, data, nextStep)); #else throw SecurityException("verifyInterest: ValidationRequest not implemented yet"); #endif } else if (policyManager_->skipVerifyAndTrust(*interest)) onVerified(interest); else onVerifyFailed(interest); }
void NamePrefixTable::addEntry(const ndn::Name& name, RoutingTableEntry& rte) { NptEntryList::iterator it = std::find_if(m_table.begin(), m_table.end(), bind(&npteCompare, _1, name)); if (it == m_table.end()) { _LOG_TRACE("Adding origin: " << rte.getDestination() << " to new name prefix: " << name); NamePrefixTableEntry entry(name); entry.addRoutingTableEntry(rte); entry.generateNhlfromRteList(); entry.getNexthopList().sort(); m_table.push_back(entry); if (rte.getNexthopList().getSize() > 0) { _LOG_TRACE("Updating FIB with next hops for " << entry); m_nlsr.getFib().update(name, entry.getNexthopList()); } } else { _LOG_TRACE("Adding origin: " << rte.getDestination() << " to existing prefix: " << *it); it->addRoutingTableEntry(rte); it->generateNhlfromRteList(); it->getNexthopList().sort(); if (it->getNexthopList().getSize() > 0) { _LOG_TRACE("Updating FIB with next hops for " << *it); m_nlsr.getFib().update(name, it->getNexthopList()); } else { // The routing table may recalculate and add a routing table entry with no next hops to // replace an existing routing table entry. In this case, the name prefix is no longer // reachable through a next hop and should be removed from the FIB. But, the prefix // should remain in the Name Prefix Table as a future routing table calculation may // add next hops. _LOG_TRACE(*it << " has no next hops; removing from FIB"); m_nlsr.getFib().remove(name); } } }
void InterestValidationState::fail(const ValidationError& error) { _LOG_TRACE(error); try { failureCallback_(interest_, error); } catch (const std::exception& ex) { _LOG_ERROR("InterestValidationState::fail: Error in failureCallback: " << ex.what()); } catch (...) { _LOG_ERROR("InterestValidationState::fail: Error in failureCallback."); } setOutcome(false); }
void DataValidationState::bypassValidation() { _LOG_TRACE("Signature verification bypassed for data `" << data_.getName() << "`"); try { successCallback_(data_); } catch (const std::exception& ex) { _LOG_ERROR("DataValidationState::fail: Error in successCallback: " << ex.what()); } catch (...) { _LOG_ERROR("DataValidationState::fail: Error in successCallback."); } setOutcome(true); }
void PrefixUpdateProcessor::onInterest(const ndn::Interest& request) { _LOG_TRACE("Received Interest: " << request); if (!m_isEnabled) { sendNack(request); return; } m_validator.validate(request, bind(&PrefixUpdateProcessor::onCommandValidated, this, _1), bind(&PrefixUpdateProcessor::onCommandValidationFailed, this, _1, _2)); }
void FsWatcher::ScanDirectory_NotifyUpdates_Execute(QString dirPath) { _LOG_TRACE(" >> ScanDirectory_NotifyUpdates_Execute"); // exclude working only on last component, not the full path; iterating through all directories, // even excluded from monitoring QRegExp exclude("^(\\.|\\.\\.|\\.chronoshare|.*~|.*\\.swp)$"); QDirIterator dirIterator(dirPath, QDir::Dirs | QDir::Files | /*QDir::Hidden |*/ QDir::NoSymLinks | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); // directory iterator(recursive) // iterate through directory recursively while (dirIterator.hasNext()) { dirIterator.next(); // Get FileInfo QFileInfo fileInfo = dirIterator.fileInfo(); QString name = fileInfo.fileName(); _LOG_DEBUG("+++ Scanning: " << name.toStdString()); if (!exclude.exactMatch(name)) { _LOG_DEBUG("Not excluded file/dir: " << fileInfo.absoluteFilePath().toStdString()); QString absFilePath = fileInfo.absoluteFilePath(); // _LOG_DEBUG("Attempt to add path to watcher: " << absFilePath.toStdString()); m_watcher->removePath(absFilePath); m_watcher->addPath(absFilePath); if (fileInfo.isFile()) { QString relFile = absFilePath; relFile.remove(0, m_dirPath.size()); fs::path aFile(relFile.toStdString()); if ( //!m_fileState->LookupFile(aFile.relative_path().generic_string()) ///* file does not exist there, but exists locally: added */) !fileExists(aFile.relative_path()) /*file does not exist in db, but exists in fs: add */) { addFile(aFile.relative_path()); DidFileChanged(absFilePath); } } } else { // _LOG_DEBUG("Excluded file/dir: " << fileInfo.filePath().toStdString()); } } }
void NamePrefixTable::removeEntry(const ndn::Name& name, RoutingTableEntry& rte) { NptEntryList::iterator it = std::find_if(m_table.begin(), m_table.end(), bind(&npteCompare, _1, name)); if (it != m_table.end()) { _LOG_TRACE("Removing origin: " << rte.getDestination() << " from prefix: " << *it); it->removeRoutingTableEntry(rte); // If the prefix is a router prefix and it does not have any other routing table entries, // the Adjacency/Coordinate LSA associated with that origin router has been removed from // the LSDB and so the router prefix should be removed from the Name Prefix Table. // // If the prefix is an advertised name prefix: // If another router advertises this name prefix, the RteList should have another entry // for that router; the next hops should be recalculated and installed in the FIB. // // If no other router advertises this name prefix, the RteList should be empty and the // prefix can be removed from the Name Prefix Table. Once a new Name LSA advertises this // prefix, a new entry for the prefix will be created. // if (it->getRteListSize() == 0) { _LOG_TRACE(*it << " has no routing table entries; removing from table and FIB"); m_table.erase(it); m_nlsr.getFib().remove(name); } else { _LOG_TRACE(*it << " has other routing table entries; updating FIB with next hops"); it->generateNhlfromRteList(); it->getNexthopList().sort(); m_nlsr.getFib().update(name, it->getNexthopList()); } } }
void InterestValidationState::bypassValidation() { _LOG_TRACE("Signature verification bypassed for interest `" << interest_.getName() << "`"); for (size_t i = 0; i < successCallbacks_.size(); ++i) { try { successCallbacks_[i](interest_); } catch (const std::exception& ex) { _LOG_ERROR("InterestValidationState::fail: Error in successCallback: " << ex.what()); } catch (...) { _LOG_ERROR("InterestValidationState::fail: Error in successCallback."); } } setOutcome(true); }
void ClientController::onSocket_ReadFrom(const void *data, int size, struct sockaddr_in * sin) { if(protocolFactory_) { if(!protocol_ || protocol_->isReadComplete()) { protocol_ = protocolFactory_->makeProtocol(); _LOG_TRACE("New Protocol make\n"); } // already received from socket to "data" buffer.. protocol_->resetBuffer(); protocol_->addToReadingBuffer(data, size); if(protocol_->processReadFromReadingBuffer() == true) { onReceivedProtocol(protocol_); } } else { onReceivedDatagram(data, size, sin); } }
void DataValidationState::verifyOriginalPacket (const CertificateV2& trustedCertificate) { if (VerificationHelpers::verifyDataSignature(data_, trustedCertificate)) { _LOG_TRACE("OK signature for data `" << data_.getName() << "`"); try { successCallback_(data_); } catch (const std::exception& ex) { _LOG_ERROR("DataValidationState::fail: Error in successCallback: " << ex.what()); } catch (...) { _LOG_ERROR("DataValidationState::fail: Error in successCallback."); } setOutcome(true); } else fail(ValidationError(ValidationError::INVALID_SIGNATURE, "Invalid signature of data `" + data_.getName().toUri() + "`")); }
void KeyChain::verifyData (const ptr_lib::shared_ptr<Data>& data, const OnVerified& onVerified, const OnVerifyFailed& onVerifyFailed, int stepCount) { _LOG_TRACE("Enter Verify"); if (policyManager_->requireVerify(*data)) { ptr_lib::shared_ptr<ValidationRequest> nextStep = policyManager_->checkVerificationPolicy (data, stepCount, onVerified, onVerifyFailed); if (nextStep) face_->expressInterest (*nextStep->interest_, bind(&KeyChain::onCertificateData, this, _1, _2, nextStep), bind(&KeyChain::onCertificateInterestTimeout, this, _1, nextStep->retry_, onVerifyFailed, data, nextStep)); } else if (policyManager_->skipVerifyAndTrust(*data)) onVerified(data); else onVerifyFailed(data); }
void InterestValidationState::verifyOriginalPacket (const CertificateV2& trustedCertificate) { if (VerificationHelpers::verifyInterestSignature(interest_, trustedCertificate)) { _LOG_TRACE("OK signature for interest `" << interest_.getName() << "`"); for (size_t i = 0; i < successCallbacks_.size(); ++i) { try { successCallbacks_[i](interest_); } catch (const std::exception& ex) { _LOG_ERROR("InterestValidationState::fail: Error in successCallback: " << ex.what()); } catch (...) { _LOG_ERROR("InterestValidationState::fail: Error in successCallback."); } } setOutcome(true); } else fail(ValidationError(ValidationError::INVALID_SIGNATURE, "Invalid signature of interest `" + interest_.getName().toUri() + "`")); }
void NamePrefixTable::updateWithNewRoute() { _LOG_DEBUG("Updating table with newly calculated routes"); // Update each name prefix entry in the Name Prefix Table with newly calculated next hops for (const NamePrefixTableEntry& prefixEntry : m_table) { for (const RoutingTableEntry& routingEntry : prefixEntry.getRteList()) { _LOG_TRACE("Updating next hops to origin: " << routingEntry.getDestination() << " for prefix: " << prefixEntry); RoutingTableEntry* rteCheck = m_nlsr.getRoutingTable().findRoutingTableEntry(routingEntry.getDestination()); if (rteCheck != nullptr) { addEntry(prefixEntry.getNamePrefix(), *rteCheck); } else { RoutingTableEntry rte(routingEntry.getDestination()); addEntry(prefixEntry.getNamePrefix(), rte); } } } }
JSONProtocol::JSONProtocol(boost::shared_ptr<BaseProtocol> protocol) { _LOG_TRACE("JSONProtocol with parent_protocol_shared_ptr : %p", this); parent_protocol_shared_ptr_ = protocol; impl_ = new JSONProtocolImpl(this); }
HttpRequest::~HttpRequest() { _LOG_TRACE("~HttpRequest() : this = %p", this); }
void LineController::onReceivedProtocol(boost::shared_ptr<protocol::BaseProtocol> protocol) { boost::shared_ptr<LineProtocol> line = boost::static_pointer_cast<LineProtocol>(protocol); _LOG_TRACE("LineController line received : %s", line->linePtr()); onLineReceived(line->linePtr()); }
ClientController::~ClientController() { _LOG_TRACE("~ClientController() : %p\n", this); }
void ClientController::onSocket_ReadEvent(coconut_socket_t fd) { if(protocolFactory_) { //#define PROTOCOL_READ_FROM_SOCKET #ifdef PROTOCOL_READ_FROM_SOCKET do { if(!protocol_ || protocol_->isReadComplete()) { _LOG_TRACE("New Protocol make #1 in %p\n", this); protocol_ = protocolFactory_->makeProtocol(); } if(protocol_->processRead(socket()) == true) { onReceivedProtocol(protocol_); } else { break; } } while(1); #else char chunk[IOBUF_LEN]; int nread = socket()->read(chunk, IOBUF_LEN); if(nread <= 0) return; //logger::hexdump( (unsigned char*)chunk, nread, stdout); if(!protocol_ || protocol_->isReadComplete()) { _LOG_TRACE("New Protocol make #1 in this = %p\n", this); protocol_ = protocolFactory_->makeProtocol(); } _LOG_DEBUG("ClientController read socket fd = %d, readSize = %d in %p\n", socket()->socketFD(), nread, this); protocol_->addToReadingBuffer(chunk, nread); int index = -1; while(true) { index++; if(protocol_->processReadFromReadingBuffer() == true) { // fire! eventGotProtocol()->fireObservers(shared_from_this(), protocol_); onReceivedProtocol(protocol_); _LOG_TRACE("ClientController Protocol receved completed. readSize = %d, remainBufferSize = %d in %p, index = %d\n", nread, protocol_->remainingBufferSize(), this, index); if(protocol_->remainingBufferSize() > 0) { #define ALWAS_MAKE_PROTOCOL #ifdef ALWAS_MAKE_PROTOCOL // new protocol _LOG_TRACE("New Protocol make #2 in this = %p\n", this); boost::shared_ptr<protocol::BaseProtocol> protocolTemp = protocolFactory_->makeProtocol(); protocolTemp->addToReadingBuffer(protocol_->remainingBufferPtr(), protocol_->remainingBufferSize()); protocol_ = protocolTemp; #else protocol_->resetReadingBufferToRemainingBuffer(); #endif continue; // one more processing.. } } // --> parsing failed.. if(protocol_->isInvalidPacketReceived()) { // this session close! _LOG_ERROR("Invalid Packet Recved.. this = %p, size = \n", this, protocol_->payloadBuffer()->totalSize()); socket()->close(); } break; } #endif } else { char buffer[IOBUF_LEN]; int res = socket()->read(buffer, IOBUF_LEN); if(res > 0) onReceivedData(buffer, res); } }
HttpRequest::HttpRequest(HttpServer *server, coconut_http_request_handle_t req) : serverInst_(server), native_handle_(req) { _LOG_TRACE("HttpRequest() : this = %p", this); impl_ = BaseIOSystemFactory::instance()->createHttpRequestImpl(); impl_->initialize(this); }
BufferedTransport::BufferedTransport() : readPos_(0) { _LOG_TRACE("BufferedTransport() : %p", this); }
JSONProtocol::JSONProtocol(BaseProtocol *protocol) { _LOG_TRACE("JSONProtocol with parent_protocol : %p", this); parent_protocol_ = protocol; impl_ = new JSONProtocolImpl(this); }
JSONProtocol::JSONProtocol() { _LOG_TRACE("JSONProtocol : %p", this); impl_ = new JSONProtocolImpl(this); }
BufferedTransport::~BufferedTransport() { _LOG_TRACE("~BufferedTransport() : %p", this); }
JSONProtocol::~JSONProtocol() { _LOG_TRACE("~JSONProtocol : %p", this); delete impl_; }