From 2626851f4846829e7cfa993a75dfbeab17fc9371 Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Sun, 19 May 2019 11:31:41 +0200 Subject: [HICN-201] Do not reply to interests requesting non-existent data. Change-Id: I7acd1d86e71f3670068b102bd24cd475d8092fb1 Signed-off-by: Mauro Sardara --- apps/http-proxy/src/IcnReceiver.cc | 39 ++++++++++++++++++++++++++++++-------- apps/http-proxy/src/IcnReceiver.h | 11 +++++++++-- 2 files changed, 40 insertions(+), 10 deletions(-) (limited to 'apps') diff --git a/apps/http-proxy/src/IcnReceiver.cc b/apps/http-proxy/src/IcnReceiver.cc index fc6837a2c..d4e922c11 100644 --- a/apps/http-proxy/src/IcnReceiver.cc +++ b/apps/http-proxy/src/IcnReceiver.cc @@ -126,20 +126,37 @@ void AsyncConsumerProducer::doReceive() { void AsyncConsumerProducer::manageIncomingInterest( core::Name& name, core::Packet::MemBufPtr& packet, utils::MemBuf* payload) { - // auto seg = name.getSuffix(); + auto seg = name.getSuffix(); name.setSuffix(0); auto _it = chunk_number_map_.find(name); auto _end = chunk_number_map_.end(); if (_it != _end) { - return; + if (_it->second.second) { + // Content is in production + return; + } + + if (seg >= _it->second.first) { + TRANSPORT_LOGD( + "Ignoring interest with name %s for a content object which does not " + "exist. (Request: %u, max: %u)", + name.toString().c_str(), (uint32_t)seg, (uint32_t)_it->second.first); + return; + } } bool is_mpd = HTTPMessageFastParser::isMpdRequest(payload->data(), payload->length()); - chunk_number_map_.emplace(name, 0); - response_name_queue_.emplace(std::move(name), is_mpd ? 1000 : 10000); + auto pair = chunk_number_map_.emplace(name, std::pair(0, 0)); + if (!pair.second) { + pair.first->second.first = 0; + } + + pair.first->second.second = true; + + response_name_queue_.emplace(std::move(name), is_mpd ? 1000 : 100000); connector_.send(payload, [packet = std::move(packet)]() {}); } @@ -166,17 +183,23 @@ void AsyncConsumerProducer::publishContent(const uint8_t* data, const interface::Name& name = options.getName(); - start_suffix = chunk_number_map_[name]; + auto it = chunk_number_map_.find(name); + if (it == chunk_number_map_.end()) { + std::cerr << "Aborting due to response not found in ResposeInfo map." + << std::endl; + abort(); + } + + start_suffix = it->second.first; if (headers) { request_counter_++; } - - chunk_number_map_[name] += + it->second.first += producer_socket_.produce(name, data, size, is_last, start_suffix); if (is_last) { - chunk_number_map_.erase(name); + it->second.second = false; response_name_queue_.pop(); } } diff --git a/apps/http-proxy/src/IcnReceiver.h b/apps/http-proxy/src/IcnReceiver.h index 61ca4333a..ea4eeb010 100644 --- a/apps/http-proxy/src/IcnReceiver.h +++ b/apps/http-proxy/src/IcnReceiver.h @@ -28,6 +28,10 @@ namespace transport { class AsyncConsumerProducer { + using SegmentProductionPair = std::pair; + using ResponseInfoMap = std::unordered_map; + using RequestQueue = std::queue; + public: explicit AsyncConsumerProducer(const std::string& prefix, std::string& ip_address, std::string& port, @@ -63,8 +67,11 @@ class AsyncConsumerProducer { // std::unordered_map> // connection_map_; ATSConnector connector_; - std::unordered_map chunk_number_map_; - std::queue response_name_queue_; + + // ResponseInfoMap --> max_seq_number + bool indicating whether request is in + // production + ResponseInfoMap chunk_number_map_; + RequestQueue response_name_queue_; }; } // namespace transport -- cgit 1.2.3-korg