void NodeHandshakeExtension::HandshakeEndpoint::query(const dtn::data::EID &origin) { { ibrcommon::MutexLock l(_blacklist_lock); // only query once each 60 seconds if (_blacklist[origin] > dtn::utils::Clock::getUnixTimestamp()) return; _blacklist[origin] = dtn::utils::Clock::getUnixTimestamp() + 60; } // create a new request for the summary vector of the neighbor NodeHandshake request(NodeHandshake::HANDSHAKE_REQUEST); // walk through all extensions to generate a request (*_callback).requestHandshake(origin, request); IBRCOMMON_LOGGER_DEBUG_TAG(NodeHandshakeExtension::TAG, 15) << "handshake query from " << origin.getString() << ": " << request.toString() << IBRCOMMON_LOGGER_ENDL; // create a new bundle dtn::data::Bundle req; // set the source of the bundle req.source = getWorkerURI(); // set the destination of the bundle req.set(dtn::data::PrimaryBlock::DESTINATION_IS_SINGLETON, true); if (origin.isCompressable()) req.destination = origin.add(origin.getDelimiter() + "50"); else req.destination = origin.add(origin.getDelimiter() + "routing"); // limit the lifetime to 60 seconds req.lifetime = 60; // set high priority req.set(dtn::data::PrimaryBlock::PRIORITY_BIT1, false); req.set(dtn::data::PrimaryBlock::PRIORITY_BIT2, true); dtn::data::PayloadBlock &p = req.push_back<PayloadBlock>(); ibrcommon::BLOB::Reference ref = p.getBLOB(); // serialize the request into the payload { ibrcommon::BLOB::iostream ios = ref.iostream(); (*ios) << request; } // add a schl block dtn::data::ScopeControlHopLimitBlock &schl = req.push_front<dtn::data::ScopeControlHopLimitBlock>(); schl.setLimit(1); // add an age block (to prevent expiring due to wrong clocks) req.push_front<dtn::data::AgeBlock>(); // send the bundle transmit(req); }
void DeliveryPredictabilityMap::update(const dtn::data::EID &host_b, const DeliveryPredictabilityMap &dpm, const float &p_encounter_first) { float p_ab = 0.0f; try { p_ab = get(host_b); } catch (const DeliveryPredictabilityMap::ValueNotFoundException&) { p_ab = p_encounter_first; } /** * Calculate transitive values */ for (predictmap::const_iterator it = dpm._predictmap.begin(); it != dpm._predictmap.end(); ++it) { const dtn::data::EID &host_c = it->first; const float &p_bc = it->second; // do not update values for the origin host if (host_b.sameHost(host_c)) continue; // do not process values with our own EID if (dtn::core::BundleCore::local.sameHost(host_c)) continue; predictmap::iterator dp_it; if ((dp_it = _predictmap.find(host_c)) != _predictmap.end()) { dp_it->second = std::max(dp_it->second, p_ab * p_bc * _beta); } else { _predictmap[host_c] = p_ab * p_bc * _beta; } } }
bool ForwardingStrategy::isBackrouteValid(const DeliveryPredictabilityMap& neighbor_dpm, const dtn::data::EID& source) const { ibrcommon::MutexLock dpm_lock(_prophet_router->_deliveryPredictabilityMap); // check if we know a way to the source try { if (_prophet_router->_deliveryPredictabilityMap.get(source.getNode()) > 0.0) return true; } catch (const dtn::routing::DeliveryPredictabilityMap::ValueNotFoundException&) { } // check if the peer know a way to the source try { if (neighbor_dpm.get(source.getNode()) > 0.0) return true; } catch (const dtn::routing::DeliveryPredictabilityMap::ValueNotFoundException&) { } return false; }
bool ForwardingStrategy::neighborDPIsGreater(const DeliveryPredictabilityMap& neighbor_dpm, const dtn::data::EID& destination) const { const dtn::data::EID destnode = destination.getNode(); try { float local_pv = 0.0f; // get the local value { ibrcommon::MutexLock dpm_lock(_prophet_router->_deliveryPredictabilityMap); const DeliveryPredictabilityMap& dp_map = _prophet_router->_deliveryPredictabilityMap; local_pv = dp_map.get(destnode); } try { // retrieve the value from the DeliveryPredictabilityMap of the neighbor float foreign_pv = neighbor_dpm.get(destnode); return (foreign_pv > local_pv); } catch (const DeliveryPredictabilityMap::ValueNotFoundException&) { // if the foreign router has no entry for the destination // then compare the local value with a fictitious initial value return (_prophet_router->_p_first_threshold > local_pv); } } catch (const DeliveryPredictabilityMap::ValueNotFoundException&) { // always forward if the destination is not in our own predictability map } return false; }
std::string KeyExchangeSession::getSessionKey(const dtn::data::EID &peer, unsigned int uniqueId) { // generate session key std::stringstream sstm; sstm << uniqueId << "." << peer.getString(); return sstm.str(); }
KeyExchangeSession::KeyExchangeSession(int protocol, const dtn::data::EID &peer, unsigned int uniqueId, SessionState *state) : _protocol(protocol), _unique_id(uniqueId), _peer(peer.getNode()), _state(state), _expiration(0) { // generate session key _session_key = getSessionKey(_peer, _unique_id); // set a expiration time (10 minutes) _expiration = dtn::utils::Clock::getMonotonicTimestamp() + 600; }
dtn::security::SecurityKey SecurityKeyManager::get(const dtn::data::EID &ref, const dtn::security::SecurityKey::KeyType type) const throw (SecurityKey::KeyNotFoundException) { dtn::security::SecurityKey keydata; keydata.reference = ref.getNode(); keydata.type = type; keydata.file = getKeyFile(keydata.reference, type); // load security key load(keydata); return keydata; }
void dtn::dht::DHTNameService::lookup(const dtn::data::EID &eid) { if (!dtn::core::BundleCore::local.sameHost(eid)) { if (this->_announced) { std::string eid_ = eid.getNode().getString(); IBRCOMMON_LOGGER_DEBUG_TAG("DHTNameService", 30) << "DHT Lookup: " << eid_ << IBRCOMMON_LOGGER_ENDL; ibrcommon::MutexLock l(this->_libmutex); dtn_dht_lookup(&_context, eid_.c_str(), eid_.size()); } else { this->cachedLookups.push_front(eid); } } }
void NativeSession::removeRegistration(const dtn::data::EID &eid) throw (NativeSessionException) { // error checking if (eid == dtn::data::EID()) { throw NativeSessionException("given endpoint is not acceptable"); } else { _registration.unsubscribe(eid); } IBRCOMMON_LOGGER_DEBUG_TAG(NativeSession::TAG, 20) << "Registration " << eid.getString() << " removed" << IBRCOMMON_LOGGER_ENDL; }
void PayloadIntegrityBlock::sign(dtn::data::Bundle &bundle, const SecurityKey &key, const dtn::data::EID& destination) { PayloadIntegrityBlock& pib = bundle.push_front<PayloadIntegrityBlock>(); pib.set(REPLICATE_IN_EVERY_FRAGMENT, true); // check if this is a fragment if (bundle.get(dtn::data::PrimaryBlock::FRAGMENT)) { dtn::data::PayloadBlock& plb = bundle.find<dtn::data::PayloadBlock>(); ibrcommon::BLOB::Reference blobref = plb.getBLOB(); ibrcommon::BLOB::iostream stream = blobref.iostream(); addFragmentRange(pib._ciphersuite_params, bundle.fragmentoffset, stream.size()); } // set the source and destination address of the new block if (!key.reference.sameHost(bundle.source)) pib.setSecuritySource( key.reference ); if (!destination.sameHost(bundle.destination)) pib.setSecurityDestination( destination ); pib.setResultSize(key); pib.setCiphersuiteId(SecurityBlock::PIB_RSA_SHA256); pib._ciphersuite_flags |= CONTAINS_SECURITY_RESULT; std::string sign = calcHash(bundle, key, pib); pib._security_result.set(SecurityBlock::integrity_signature, sign); }
/** * Transfer one bundle to another node. * @param destination The EID of the other node. * @param id The ID of the bundle to transfer. This bundle must be stored in the storage. */ void RoutingExtension::transferTo(const dtn::data::EID &destination, const dtn::data::MetaBundle &meta) { // acquire the transfer of this bundle, could throw already in transit or no resource left exception { // lock the list of neighbors ibrcommon::MutexLock l((**this).getNeighborDB()); // get the neighbor entry for the next hop NeighborDatabase::NeighborEntry &entry = (**this).getNeighborDB().get(destination, true); // acquire the transfer, could throw already in transit or no resource left exception entry.acquireTransfer(meta); } try { // create a new bundle transfer object dtn::net::BundleTransfer transfer(destination, meta); // transfer the bundle to the next hop dtn::core::BundleCore::getInstance().getConnectionManager().queue(transfer); IBRCOMMON_LOGGER_DEBUG_TAG(RoutingExtension::TAG, 20) << "bundle " << meta.toString() << " queued for " << destination.getString() << IBRCOMMON_LOGGER_ENDL; } catch (const dtn::core::P2PDialupException&) { // lock the list of neighbors ibrcommon::MutexLock l((**this).getNeighborDB()); // get the neighbor entry for the next hop NeighborDatabase::NeighborEntry &entry = (**this).getNeighborDB().get(destination); // release the transfer entry.releaseTransfer(meta); // and abort the query throw NeighborDatabase::NeighborNotAvailableException(); } catch (const ibrcommon::Exception &e) { // ignore any other error } }
void KeyExchangeEvent::raise(const dtn::data::EID &eid, const dtn::security::KeyExchangeData &data) { // raise the new event dtn::core::EventDispatcher<KeyExchangeEvent>::queue( new KeyExchangeEvent(eid.getNode(), data) ); }
void NodeHandshakeExtension::HandshakeEndpoint::query(const dtn::data::EID &origin) { { ibrcommon::MutexLock l(_blacklist_lock); // only query once each 60 seconds if (_blacklist[origin] > dtn::utils::Clock::getMonotonicTimestamp()) return; _blacklist[origin] = dtn::utils::Clock::getMonotonicTimestamp() + 60; } // create a new request for the summary vector of the neighbor NodeHandshake request(NodeHandshake::HANDSHAKE_REQUEST); #ifdef IBRDTN_SUPPORT_COMPRESSION // request compressed answer request.addRequest(NodeHandshakeItem::REQUEST_COMPRESSED_ANSWER); #endif // walk through all extensions to generate a request (*_callback).requestHandshake(origin, request); IBRCOMMON_LOGGER_DEBUG_TAG(NodeHandshakeExtension::TAG, 15) << "handshake query from " << origin.getString() << ": " << request.toString() << IBRCOMMON_LOGGER_ENDL; // create a new bundle with a zero timestamp (+age block) dtn::data::Bundle req(true); // set the source of the bundle req.source = getWorkerURI(); // set the destination of the bundle req.set(dtn::data::PrimaryBlock::DESTINATION_IS_SINGLETON, true); req.destination = origin; // set destination application req.destination.setApplication("routing"); // limit the lifetime to 60 seconds req.lifetime = 60; // set high priority req.set(dtn::data::PrimaryBlock::PRIORITY_BIT1, false); req.set(dtn::data::PrimaryBlock::PRIORITY_BIT2, true); dtn::data::PayloadBlock &p = req.push_back<PayloadBlock>(); ibrcommon::BLOB::Reference ref = p.getBLOB(); // serialize the request into the payload { ibrcommon::BLOB::iostream ios = ref.iostream(); (*ios) << request; } // add a schl block dtn::data::ScopeControlHopLimitBlock &schl = req.push_front<dtn::data::ScopeControlHopLimitBlock>(); schl.setLimit(1); // send the bundle transmit(req); }