servlib/bundling/BPQCache.h
changeset 66 e1101c5d54a1
parent 64 1296a0283271
child 67 cfe2328ba1c6
--- a/servlib/bundling/BPQCache.h	Wed Oct 26 13:33:11 2011 +0100
+++ b/servlib/bundling/BPQCache.h	Fri Jan 06 17:28:36 2012 +0000
@@ -26,6 +26,8 @@
 #include <oasys/util/StringUtils.h>
 #include "../reg/Registration.h"
 #include "../reg/RegistrationTable.h"
+#include <list>
+
 namespace dtn {
 
 class BPQBlock;
@@ -38,7 +40,8 @@
 class BPQCache : public oasys::Logger {
 public:
 	BPQCache() :
-        Logger("BPQCache", "/dtn/bundle/bpq") {}
+        Logger("BPQCache", "/dtn/bundle/bpq"),
+        cache_size_(0) {}
 
 	/**
 	 * Add a new BPQ response to the to the cache
@@ -55,9 +58,11 @@
     /**
      * Number of bundles in the cache
      */
-    size_t size() {return bpq_table_.size();}
+    size_t size() { return bpq_table_.size();}
 
-    static const size_t MAX_KEY_SIZE = 4096;
+    static 			bool  cache_enabled_;
+    static 			u_int max_cache_size_;
+    static const 	u_int MAX_KEY_SIZE = 4096;
 
 protected:
 
@@ -66,11 +71,30 @@
      * Copy the bundle into the fragment list
      */
     void create_cache_entry(Bundle* bundle, BPQBlock* block, std::string key);
-    void replace_cache_entry(Bundle* bundle, BPQBlock* block, std::string key);
-    void append_cache_entry(Bundle* bundle, std::string key);
+
+    /**
+	 * Remove existing cache entry along with all bundle fragments
+	 * and create a new entry
+	 */
+    void replace_cache_entry(BPQCacheEntry* entry, Bundle* bundle,
+    						 BPQBlock* block, std::string key);
+
+    void remove_cache_entry(BPQCacheEntry* entry, std::string key);
+    /**
+     * Add received bundle fragment to the cache entry
+     * @return  true if the new fragment completed the cache entry
+     * 			false otherwise
+     */
+    bool append_cache_entry(BPQCacheEntry* entry, Bundle* bundle, std::string key);
+
+
+
+    bool bpq_requires_fragment(BPQBlock* block, Bundle* fragment);
     int  update_bpq_block(Bundle* bundle, BPQBlock* block);
     bool try_to_deliver(BPQCacheEntry* entry);
 
+    void update_lru_keys(std::string key);
+
     /**
      * Calculate a hash table key from a bundle
      * This is a  SHA256 hash of the concatenation of:
@@ -86,6 +110,8 @@
     typedef oasys::StringHashMap<BPQCacheEntry*> Cache;
     Cache bpq_table_;
 
+    std::list<std::string> lru_keys_;
+    size_t cache_size_;
 };
 
 } // namespace dtn