// A validator is called on the incoming data, and if the data // passes the validator's description/definitions, this function is // called. Set the neighbor's status to active and refresh its // LSA. If there was a change in status, we schedule an adjacency // LSA build. void HelloProtocol::onContentValidated(const ndn::shared_ptr<const ndn::Data>& data) { /* data name: /<neighbor>/NLSR/INFO/<router>/<version> */ ndn::Name dataName = data->getName(); _LOG_DEBUG("Data validation successful for INFO(name): " << dataName); if (dataName.get(-3).toUri() == INFO_COMPONENT) { ndn::Name neighbor = dataName.getPrefix(-4); Adjacent::Status oldStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor); m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, Adjacent::STATUS_ACTIVE); m_nlsr.getAdjacencyList().setTimedOutInterestCount(neighbor, 0); Adjacent::Status newStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor); _LOG_DEBUG("Neighbor : " << neighbor); _LOG_DEBUG("Old Status: " << oldStatus << " New Status: " << newStatus); // change in Adjacency list if ((oldStatus - newStatus) != 0) { if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) { m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); } else { m_nlsr.getLsdb().scheduleAdjLsaBuild(); } } } }
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; }
void HelloProtocol::processInterestTimedOut(const ndn::Interest& interest) { /* interest name: /<neighbor>/NLSR/INFO/<router> */ const ndn::Name interestName(interest.getName()); _LOG_DEBUG("Interest timed out for Name: " << interestName); if (interestName.get(-2).toUri() != INFO_COMPONENT) { return; } ndn::Name neighbor = interestName.getPrefix(-3); _LOG_DEBUG("Neighbor: " << neighbor); m_nlsr.getAdjacencyList().incrementTimedOutInterestCount(neighbor); Adjacent::Status status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor); uint32_t infoIntTimedOutCount = m_nlsr.getAdjacencyList().getTimedOutInterestCount(neighbor); _LOG_DEBUG("Status: " << status); _LOG_DEBUG("Info Interest Timed out: " << infoIntTimedOutCount); if ((infoIntTimedOutCount < m_nlsr.getConfParameter().getInterestRetryNumber())) { /* interest name: /<neighbor>/NLSR/INFO/<router> */ ndn::Name interestName(neighbor); interestName.append(NLSR_COMPONENT); interestName.append(INFO_COMPONENT); interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode()); expressInterest(interestName, m_nlsr.getConfParameter().getInterestResendTime()); } else if ((status == Adjacent::STATUS_ACTIVE) && (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber())) { m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, Adjacent::STATUS_INACTIVE); m_nlsr.getLsdb().scheduleAdjLsaBuild(); } }
void connect() { if(redisContext_) { throw IllegalStateException("Error redisContext already created"); } state_ = REDISREQUEST_CONNECTING; ScopedMutexLock(lockRedis_); redisContext_ = redisAsyncConnect(host_.c_str(), port_); if (redisContext_->err) { _LOG_DEBUG("REDIS CONNECT FAILED (CREATE ERROR): %s:%d, err = %x, this = %p" , host_.c_str(), port_, redisContext_->err, this); state_ = REDISREQUEST_CONNECTFAILED; //fire_onRedisRequest_Error(redisContext_->err, "connect error", NULL); // disconnectCallback() is called later soon.. // error process will be executed by that function. } redisContext_->data = this; redisLibeventAttach(redisContext_, (struct event_base *)ioService_->coreHandle()); redisAsyncSetConnectCallback(redisContext_, connectCallback); redisAsyncSetDisconnectCallback(redisContext_, disconnectCallback); timerObj_->setTimer(TIMER_ID_CONNECTION_TIMEOUT, DEFAULT_CONNECT_TIMEOUT, false); _LOG_DEBUG("redis connect start : %s:%d, flag = 0x%x, fd = %d, context = %p, this = %p" , host_.c_str(), port_, redisContext_->c.flags, redisContext_->c.fd, redisContext_, this); }
void HelloProtocol::onContentValidated(const ndn::shared_ptr<const ndn::Data>& data) { /* data name: /<neighbor>/NLSR/INFO/<router>/<version> */ ndn::Name dataName = data->getName(); _LOG_DEBUG("Data received for name: " << dataName); if (dataName.get(-3).toUri() == INFO_COMPONENT) { ndn::Name neighbor = dataName.getPrefix(-4); int oldStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor); m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, 1); m_nlsr.getAdjacencyList().setTimedOutInterestCount(neighbor, 0); int newStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor); _LOG_DEBUG("Neighbor : " << neighbor); _LOG_DEBUG("Old Status: " << oldStatus << " New Status: " << newStatus); // change in Adjacency list if ((oldStatus - newStatus) != 0) { m_nlsr.incrementAdjBuildCount(); // Need to schedule event for Adjacency LSA building if (m_nlsr.getIsBuildAdjLsaSheduled() == false) { _LOG_DEBUG("Scheduling scheduledAdjLsaBuild"); m_nlsr.setIsBuildAdjLsaSheduled(true); // event here m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5), ndn::bind(&Lsdb::scheduledAdjLsaBuild, ndn::ref(m_nlsr.getLsdb()))); } } } }
bool DigestTree::update(const std::string& dataPrefix, int sessionNo, int sequenceNo) { int index = find(dataPrefix, sessionNo); _LOG_DEBUG(dataPrefix << ", " << sessionNo); _LOG_DEBUG("DigestTree::update session " << sessionNo << ", index " << index); if (index >= 0) { // only update the newer status if (digestNode_[index]->getSequenceNo() < sequenceNo) digestNode_[index]->setSequenceNo(sequenceNo); else return false; } else { _LOG_DEBUG("new comer " << dataPrefix << ", session " << sessionNo << ", sequence " << sequenceNo); // Insert into digestnode_ sorted. ptr_lib::shared_ptr<Node> temp(new Node(dataPrefix, sessionNo, sequenceNo)); digestNode_.insert (std::lower_bound(digestNode_.begin(), digestNode_.end(), temp, nodeCompare_), temp); } recomputeRoot(); return true; }
void cancel(ticket_t ticket) { ScopedMutexLock(lockRedis_); _LOG_DEBUG("redis request canceled : ticket = %d, count = %d/%d <START>" , ticket, mapCallback_.size(), reservedCommands_.size()); _removeContext(ticket); _LOG_DEBUG("redis request canceled : ticket = %d, count = %d/%d <END>" , ticket, mapCallback_.size(), reservedCommands_.size()); }
void FaceMap::writeLog() { _LOG_DEBUG("------- Face Map-----------"); for (const auto& it : m_table) { _LOG_DEBUG("Face Map Entry (FaceUri: " << (it.second).getFaceUri() << " Face Id: " << (it.second).getFaceId() << ")"); } }
void ProfileEditor::onCloseDBModule() { _LOG_DEBUG("close db module"); if(m_tableModel) { delete m_tableModel; _LOG_DEBUG("tableModel closed"); } }
void FaceMap::writeLog() { _LOG_DEBUG("------- Face Map-----------"); for(std::list<FaceMapEntry>::iterator it = m_table.begin(); it != m_table.end(); ++it) { _LOG_DEBUG("Face Map Entry (FaceUri: " << (*it).getFaceUri() << " Face Id: " << (*it).getFaceId() << ")"); } }
void NamePrefixTableEntry::writeLog() { _LOG_DEBUG("Name: " << m_namePrefix); for (auto it = m_rteList.begin(); it != m_rteList.end(); ++it) { _LOG_DEBUG("Destination: " << (*it)->getDestination()); _LOG_DEBUG("Nexthops: "); (*it)->getNexthopList().writeLog(); } m_nexthopList.writeLog(); }
// This is the first function that incoming Hello data will // see. This checks if the data appears to be signed, and passes it // on to validate the content of the data. void HelloProtocol::onContent(const ndn::Interest& interest, const ndn::Data& data) { _LOG_DEBUG("Received data for INFO(name): " << data.getName()); if (data.getSignature().hasKeyLocator()) { if (data.getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) { _LOG_DEBUG("Data signed with: " << data.getSignature().getKeyLocator().getName()); } } m_nlsr.getValidator().validate(data, ndn::bind(&HelloProtocol::onContentValidated, this, _1), ndn::bind(&HelloProtocol::onContentValidationFailed, 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 RegisteredPrefixTable::removeRegisteredPrefix(uint64_t registeredPrefixId) { int count = 0; // Go backwards through the list so we can erase entries. // Remove all entries even though registeredPrefixId should be unique. for (int i = (int)table_.size() - 1; i >= 0; --i) { Entry& entry = *table_[i]; if (entry.getRegisteredPrefixId() == registeredPrefixId) { ++count; if (entry.getRelatedInterestFilterId() > 0) // Remove the related interest filter. interestFilterTable_.unsetInterestFilter(entry.getRelatedInterestFilterId()); table_.erase(table_.begin() + i); } } if (count == 0) _LOG_DEBUG("removeRegisteredPrefix: Didn't find registeredPrefixId " << registeredPrefixId); if (count == 0) { // The registeredPrefixId was not found. Perhaps this has been called before // the callback in registerPrefix can add to the registered prefix table. // Add this removal request which will be checked before adding to the // registered prefix table. if (::find(removeRequests_.begin(), removeRequests_.end(), registeredPrefixId) == removeRequests_.end()) // Not already requested, so add the request. removeRequests_.push_back(registeredPrefixId); } }
FsWatcher::FsWatcher(boost::asio::io_service& io, QString dirPath, LocalFile_Change_Callback onChange, LocalFile_Change_Callback onDelete, QObject* parent) : QObject(parent) , m_watcher(new QFileSystemWatcher(this)) , m_scheduler(io) , m_dirPath(dirPath) , m_onChange(onChange) , m_onDelete(onDelete) { _LOG_DEBUG("Monitor dir: " << m_dirPath.toStdString()); // add main directory to monitor initFileStateDb(); m_watcher->addPath(m_dirPath); // register signals(callback functions) connect(m_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(DidDirectoryChanged(QString))); connect(m_watcher, SIGNAL(fileChanged(QString)), this, SLOT(DidFileChanged(QString))); rescheduleEvent("rescan", m_dirPath.toStdString(), time::seconds(0), bind(&FsWatcher::ScanDirectory_NotifyUpdates_Execute, this, m_dirPath)); rescheduleEvent("rescan-r", m_dirPath.toStdString(), time::seconds(0), bind(&FsWatcher::ScanDirectory_NotifyRemovals_Execute, this, m_dirPath)); }
ActionItemPtr ActionLog::AddRemoteAction(shared_ptr<Data> actionData) { Name name = actionData->getName(); // action name: /<device_name>/<appname>/action/<shared-folder>/<action-seq> uint64_t seqno = name.get(-1).toNumber(); std::string sharedFolder = name.get(-2).toUri(); if (sharedFolder != m_sharedFolderName) { _LOG_ERROR("Action doesn't belong to this shared folder"); return ActionItemPtr(); } if (name.get(-3).toUri() != "action") { _LOG_ERROR("not an action"); return ActionItemPtr(); } if (name.get(-4) != m_appName) { _LOG_ERROR("Action doesn't belong to this application"); return ActionItemPtr(); } Name deviceName = name.getSubName(0, name.size() - 4); _LOG_DEBUG("From [" << name << "] extracted deviceName: " << deviceName << ", sharedFolder: " << sharedFolder << ", seqno: " << seqno); return AddRemoteAction(deviceName, seqno, actionData); }
bool MySQLConnection::Execute(const char* sql) { if (!m_Mysql) return false; { boost::timer _s; if (mysql_query(m_Mysql, sql)) { uint32 lErrno = mysql_errno(m_Mysql); _LOG_INFO(LOG_FILTER_SQL, "SQL: %s", sql); _LOG_ERROR(LOG_FILTER_SQL, "[%u] %s", lErrno, mysql_error(m_Mysql)); if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled successfully (i.e. reconnection) return Execute(sql); // Try again return false; } else _LOG_DEBUG(LOG_FILTER_SQL, "[%u ms] SQL: %s",(uint32) _s.elapsed(), sql); } return true; }
void HelloProtocol::onRegistrationFailure(const ndn::nfd::ControlResponse& response, const ndn::Name& name) { _LOG_DEBUG(response.getText() << " (code: " << response.getCode() << ")"); /* * If NLSR can not create face for given faceUri then it will treat this * failure as one INFO interest timed out. So that NLSR can move on with * building Adj Lsa and calculate routing table. NLSR does not build Adj * Lsa unless all the neighbors are ACTIVE or DEAD. For considering the * missconfigured(link) neighbour dead this is required. */ Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(name); if (adjacent != 0) { adjacent->setInterestTimedOutNo(adjacent->getInterestTimedOutNo() + 1); Adjacent::Status status = adjacent->getStatus(); uint32_t infoIntTimedOutCount = adjacent->getInterestTimedOutNo(); if (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber()) { if (status == Adjacent::STATUS_ACTIVE) { adjacent->setStatus(Adjacent::STATUS_INACTIVE); } m_nlsr.getLsdb().scheduleAdjLsaBuild(); } } }
void PrefixUpdateProcessor::startListening() { _LOG_DEBUG("Setting Interest filter for: " << COMMAND_PREFIX); m_face.setInterestFilter(COMMAND_PREFIX, bind(&PrefixUpdateProcessor::onInterest, this, _2)); }
void HelloProtocol::scheduleInterest(uint32_t seconds) { _LOG_DEBUG("Scheduling HELLO Interests in " << ndn::time::seconds(seconds)); m_scheduler.scheduleEvent(ndn::time::seconds(seconds), ndn::bind(&HelloProtocol::sendScheduledInterest, this, seconds)); }
void HelloProtocol::processInterest(const ndn::Name& name, const ndn::Interest& interest) { /* interest name: /<neighbor>/NLSR/INFO/<router> */ const ndn::Name interestName = interest.getName(); _LOG_DEBUG("Interest Received for Name: " << interestName); if (interestName.get(-2).toUri() != INFO_COMPONENT) { return; } ndn::Name neighbor; neighbor.wireDecode(interestName.get(-1).blockFromValue()); _LOG_DEBUG("Neighbor: " << neighbor); if (m_nlsr.getAdjacencyList().isNeighbor(neighbor)) { ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>(); data->setName(ndn::Name(interest.getName()).appendVersion()); data->setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec data->setContent(reinterpret_cast<const uint8_t*>(INFO_COMPONENT.c_str()), INFO_COMPONENT.size()); m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName()); _LOG_DEBUG("Sending out data for name: " << interest.getName()); m_nlsr.getNlsrFace().put(*data); Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor); // If this neighbor was previously inactive, send our own hello interest, too if (adjacent->getStatus() == Adjacent::STATUS_INACTIVE) { // We can only do that if the neighbor currently has a face. if(adjacent->getFaceId() != 0){ /* interest name: /<neighbor>/NLSR/INFO/<router> */ ndn::Name interestName(neighbor); interestName.append(NLSR_COMPONENT); interestName.append(INFO_COMPONENT); interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode()); expressInterest(interestName, m_nlsr.getConfParameter().getInterestResendTime()); } // If the originator of the Interest currently lacks a Face, we // need to give it one. else { registerPrefixes(adjacent->getName(), adjacent->getConnectingFaceUri(), adjacent->getLinkCost(), ndn::time::milliseconds::max()); } } } }
bool MySQLConnection::_Query(PreparedStatement* stmt, MYSQL_RES **pResult, uint64* pRowCount, uint32* pFieldCount) { if (!m_Mysql) return false; uint32 index = stmt->m_index; { MySQLPreparedStatement* m_mStmt = GetPreparedStatement(index); ASSERT(m_mStmt); // Can only be null if preparation failed, server side error or bad query m_mStmt->m_stmt = stmt; // Cross reference them for debug output stmt->m_stmt = m_mStmt; /// @todo Cleaner way stmt->BindParameters(); MYSQL_STMT* msql_STMT = m_mStmt->GetSTMT(); MYSQL_BIND* msql_BIND = m_mStmt->GetBind(); boost::timer _s; if (mysql_stmt_bind_param(msql_STMT, msql_BIND)) { uint32 lErrno = mysql_errno(m_Mysql); _LOG_ERROR(LOG_FILTER_SQL, "SQL(p): %s\n [ERROR]: [%u] %s", m_mStmt->getQueryString(m_queries[index].first).c_str(), lErrno, mysql_stmt_error(msql_STMT)); if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled successfully (i.e. reconnection) return _Query(stmt, pResult, pRowCount, pFieldCount); // Try again m_mStmt->ClearParameters(); return false; } if (mysql_stmt_execute(msql_STMT)) { uint32 lErrno = mysql_errno(m_Mysql); _LOG_ERROR(LOG_FILTER_SQL, "SQL(p): %s\n [ERROR]: [%u] %s", m_mStmt->getQueryString(m_queries[index].first).c_str(), lErrno, mysql_stmt_error(msql_STMT)); if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled successfully (i.e. reconnection) return _Query(stmt, pResult, pRowCount, pFieldCount); // Try again m_mStmt->ClearParameters(); return false; } _LOG_DEBUG(LOG_FILTER_SQL, "[%u ms] SQL(p): %s",(uint32)_s.elapsed(), m_mStmt->getQueryString(m_queries[index].first).c_str()); m_mStmt->ClearParameters(); *pResult = mysql_stmt_result_metadata(msql_STMT); *pRowCount = mysql_stmt_num_rows(msql_STMT); *pFieldCount = mysql_stmt_field_count(msql_STMT); return true; } }
void Socket::fetchData(const Name& sessionName, const SeqNo& seqNo, const ndn::OnDataValidated& dataCallback, const ndn::OnDataValidationFailed& failureCallback, const ndn::OnTimeout& onTimeout, int nRetries) { _LOG_DEBUG(">> Socket::fetchData"); Name interestName; interestName.append(sessionName).appendNumber(seqNo); Interest interest(interestName); interest.setMustBeFresh(true); m_face.expressInterest(interest, bind(&Socket::onData, this, _1, _2, dataCallback, failureCallback), onTimeout); _LOG_DEBUG("<< Socket::fetchData"); }
void Node::RegisterResponse::operator()(const ptr_lib::shared_ptr<const Interest>& interest, const ptr_lib::shared_ptr<Data>& responseData) { // Decode responseData->getContent() and check for a success code. // TODO: Move this into the TLV code. struct ndn_TlvDecoder decoder; ndn_TlvDecoder_initialize (&decoder, responseData->getContent().buf(), responseData->getContent().size()); ndn_Error error; size_t endOffset; if ((error = ndn_TlvDecoder_readNestedTlvsStart (&decoder, ndn_Tlv_NfdCommand_ControlResponse, &endOffset))) { _LOG_DEBUG ("Register prefix failed: Error decoding the NFD response: " << ndn_getErrorString(error)); info_->onRegisterFailed_(info_->prefix_); return; } uint64_t statusCode; if ((error = ndn_TlvDecoder_readNonNegativeIntegerTlv (&decoder, ndn_Tlv_NfdCommand_StatusCode, &statusCode))) { _LOG_DEBUG ("Register prefix failed: Error decoding the NFD response: " << ndn_getErrorString(error)); info_->onRegisterFailed_(info_->prefix_); return; } // Status code 200 is "OK". if (statusCode != 200) { _LOG_DEBUG ("Register prefix failed: Expected NFD status code 200, got: " << statusCode); info_->onRegisterFailed_(info_->prefix_); return; } _LOG_DEBUG("Register prefix succeeded with the NFD forwarder for prefix " << info_->prefix_->toUri()); }
void Socket::onData(const Interest& interest, Data& data, const ndn::OnDataValidated& onValidated, const ndn::OnDataValidationFailed& onFailed) { _LOG_DEBUG("Socket::onData"); if (static_cast<bool>(m_validator)) m_validator->validate(data, onValidated, onFailed); else onValidated(data.shared_from_this()); }
void HelloProtocol::processInterestTimedOut(const ndn::Interest& interest) { /* interest name: /<neighbor>/NLSR/INFO/<router> */ const ndn::Name interestName(interest.getName()); _LOG_DEBUG("Interest timed out for Name: " << interestName); if (interestName.get(-2).toUri() != INFO_COMPONENT) { return; } ndn::Name neighbor = interestName.getPrefix(-3); _LOG_DEBUG("Neighbor: " << neighbor); m_nlsr.getAdjacencyList().incrementTimedOutInterestCount(neighbor); int status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor); uint32_t infoIntTimedOutCount = m_nlsr.getAdjacencyList().getTimedOutInterestCount(neighbor); _LOG_DEBUG("Status: " << status); _LOG_DEBUG("Info Interest Timed out: " << infoIntTimedOutCount); if ((infoIntTimedOutCount < m_nlsr.getConfParameter().getInterestRetryNumber())) { /* interest name: /<neighbor>/NLSR/INFO/<router> */ ndn::Name interestName(neighbor); interestName.append(NLSR_COMPONENT); interestName.append(INFO_COMPONENT); interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode()); expressInterest(interestName, m_nlsr.getConfParameter().getInterestResendTime()); } else if ((status == 1) && (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber())) { m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, 0); m_nlsr.incrementAdjBuildCount(); if (m_nlsr.getIsBuildAdjLsaSheduled() == false) { _LOG_DEBUG("Scheduling scheduledAdjLsaBuild"); m_nlsr.setIsBuildAdjLsaSheduled(true); // event here m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5), ndn::bind(&Lsdb::scheduledAdjLsaBuild, &m_nlsr.getLsdb())); } } }
void HelloProtocol::processInterest(const ndn::Name& name, const ndn::Interest& interest) { /* interest name: /<neighbor>/NLSR/INFO/<router> */ const ndn::Name interestName = interest.getName(); _LOG_DEBUG("Interest Received for Name: " << interestName); if (interestName.get(-2).toUri() != INFO_COMPONENT) { return; } ndn::Name neighbor; neighbor.wireDecode(interestName.get(-1).blockFromValue()); _LOG_DEBUG("Neighbor: " << neighbor); if (m_nlsr.getAdjacencyList().isNeighbor(neighbor)) { ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>(); data->setName(ndn::Name(interest.getName()).appendVersion()); data->setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec data->setContent(reinterpret_cast<const uint8_t*>(INFO_COMPONENT.c_str()), INFO_COMPONENT.size()); m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName()); _LOG_DEBUG("Sending out data for name: " << interest.getName()); m_nlsr.getNlsrFace().put(*data); Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor); if (adjacent->getStatus() == 0) { if(adjacent->getFaceId() != 0){ /* interest name: /<neighbor>/NLSR/INFO/<router> */ ndn::Name interestName(neighbor); interestName.append(NLSR_COMPONENT); interestName.append(INFO_COMPONENT); interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode()); expressInterest(interestName, m_nlsr.getConfParameter().getInterestResendTime()); } else { registerPrefixes(adjacent->getName(), adjacent->getConnectingFaceUri(), adjacent->getLinkCost(), ndn::time::milliseconds::max()); } } } }
void DigestTree::recomputeRoot() { SHA256_CTX sha256; SHA256_Init(&sha256); for (size_t i = 0; i < digestNode_.size(); ++i) SHA256_UpdateHex(&sha256, digestNode_[i]->getDigest()); uint8_t digestRoot[ndn_SHA256_DIGEST_SIZE]; SHA256_Final(&digestRoot[0], &sha256); root_ = toHex(digestRoot, sizeof(digestRoot)); _LOG_DEBUG("update root to: " + root_); }
void FileState::DeleteFile(const std::string& filename) { sqlite3_stmt* stmt; sqlite3_prepare_v2(m_db, "DELETE FROM FileState WHERE type=0 AND filename=?", -1, &stmt, 0); sqlite3_bind_text(stmt, 1, filename.c_str(), -1, SQLITE_STATIC); _LOG_DEBUG("Delete " << filename); sqlite3_step(stmt); _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_DONE, sqlite3_errmsg(m_db)); sqlite3_finalize(stmt); }
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); }