diff options
author | Alberto Compagno <acompagn+fdio@cisco.com> | 2020-02-21 17:30:49 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@fd.io> | 2020-02-21 17:30:49 +0000 |
commit | e1135db42f05a94c6790c8650a3ac20396e0d78c (patch) | |
tree | 65b48490ced07f11597aedc2b752381b0d9e4b30 /libtransport/src/hicn/transport/utils/content_store.cc | |
parent | 1b9512282a5324b2bd2b28b8e5555e15676cb54c (diff) | |
parent | 35058cdfe0134c88f1aa8d23342d1d7b9d39e296 (diff) |
Merge "[HICN-2] Added P2P confidential communication on hICN"
Diffstat (limited to 'libtransport/src/hicn/transport/utils/content_store.cc')
-rw-r--r-- | libtransport/src/hicn/transport/utils/content_store.cc | 56 |
1 files changed, 33 insertions, 23 deletions
diff --git a/libtransport/src/hicn/transport/utils/content_store.cc b/libtransport/src/hicn/transport/utils/content_store.cc index 8e3435507..ba13bef41 100644 --- a/libtransport/src/hicn/transport/utils/content_store.cc +++ b/libtransport/src/hicn/transport/utils/content_store.cc @@ -40,41 +40,48 @@ void ContentStore::insert( content_store_hash_table_.size(), fifo_list_.size()); } - // Check if the content can be cached - if (content_object->getLifetime() > 0) { - if (content_store_hash_table_.size() >= max_content_store_size_) { - content_store_hash_table_.erase(fifo_list_.back()); - fifo_list_.pop_back(); - } - - // Insert new item - - auto it = content_store_hash_table_.find(content_object->getName()); - if (it != content_store_hash_table_.end()) { - fifo_list_.erase(it->second.second); - content_store_hash_table_.erase(content_object->getName()); - } + if (content_store_hash_table_.size() >= max_content_store_size_) { + content_store_hash_table_.erase(fifo_list_.back()); + fifo_list_.pop_back(); + } - fifo_list_.push_front(std::cref(content_object->getName())); - auto pos = fifo_list_.begin(); - content_store_hash_table_[content_object->getName()] = ContentStoreEntry( - ObjectTimeEntry(content_object, std::chrono::steady_clock::now()), pos); + // Insert new item + auto it = content_store_hash_table_.find(content_object->getName()); + if (it != content_store_hash_table_.end()) { + fifo_list_.erase(it->second.second); + content_store_hash_table_.erase(content_object->getName()); } + + fifo_list_.push_front(std::cref(content_object->getName())); + auto pos = fifo_list_.begin(); + content_store_hash_table_[content_object->getName()] = ContentStoreEntry( + ObjectTimeEntry(content_object, std::chrono::steady_clock::now()), pos); } const std::shared_ptr<ContentObject> ContentStore::find( const Interest &interest) { utils::SpinLock::Acquire locked(cs_mutex_); + + std::shared_ptr<ContentObject> ret = empty_reference_; auto it = content_store_hash_table_.find(interest.getName()); if (it != content_store_hash_table_.end()) { - if (std::chrono::duration_cast<std::chrono::milliseconds>( + + auto content_lifetime = it->second.first.first->getLifetime(); + auto time_passed_since_creation = + std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::steady_clock::now() - it->second.first.second) - .count() < it->second.first.first->getLifetime()) { - return it->second.first.first; + .count(); + + if (time_passed_since_creation > content_lifetime) { + fifo_list_.erase(it->second.second); + content_store_hash_table_.erase(it); + } + else { + ret = it->second.first.first; } } - return empty_reference_; + return ret; } void ContentStore::erase(const Name &exact_name) { @@ -103,7 +110,10 @@ void ContentStore::printContent() { for (auto &item : content_store_hash_table_) { if (item.second.first.first->getPayloadType() == transport::core::PayloadType::MANIFEST) { - TRANSPORT_LOGI("Manifest: %s\n", + TRANSPORT_LOGI("Manifest: %s", + item.second.first.first->getName().toString().c_str()); + } else { + TRANSPORT_LOGI("Data Packet: %s", item.second.first.first->getName().toString().c_str()); } } |