36 class RegistrationTable; |
38 class RegistrationTable; |
37 |
39 |
38 class BPQCache : public oasys::Logger { |
40 class BPQCache : public oasys::Logger { |
39 public: |
41 public: |
40 BPQCache() : |
42 BPQCache() : |
41 Logger("BPQCache", "/dtn/bundle/bpq") {} |
43 Logger("BPQCache", "/dtn/bundle/bpq"), |
|
44 cache_size_(0) {} |
42 |
45 |
43 /** |
46 /** |
44 * Add a new BPQ response to the to the cache |
47 * Add a new BPQ response to the to the cache |
45 */ |
48 */ |
46 bool add_response_bundle(Bundle* bundle, BPQBlock* block); |
49 bool add_response_bundle(Bundle* bundle, BPQBlock* block); |
53 bool answer_query(Bundle* bundle, BPQBlock* block); |
56 bool answer_query(Bundle* bundle, BPQBlock* block); |
54 |
57 |
55 /** |
58 /** |
56 * Number of bundles in the cache |
59 * Number of bundles in the cache |
57 */ |
60 */ |
58 size_t size() {return bpq_table_.size();} |
61 size_t size() { return bpq_table_.size();} |
59 |
62 |
60 static const size_t MAX_KEY_SIZE = 4096; |
63 static bool cache_enabled_; |
|
64 static u_int max_cache_size_; |
|
65 static const u_int MAX_KEY_SIZE = 4096; |
61 |
66 |
62 protected: |
67 protected: |
63 |
68 |
64 /** |
69 /** |
65 * Build a new BPQCcacheEntry from this bundle. |
70 * Build a new BPQCcacheEntry from this bundle. |
66 * Copy the bundle into the fragment list |
71 * Copy the bundle into the fragment list |
67 */ |
72 */ |
68 void create_cache_entry(Bundle* bundle, BPQBlock* block, std::string key); |
73 void create_cache_entry(Bundle* bundle, BPQBlock* block, std::string key); |
69 void replace_cache_entry(Bundle* bundle, BPQBlock* block, std::string key); |
74 |
70 void append_cache_entry(Bundle* bundle, std::string key); |
75 /** |
|
76 * Remove existing cache entry along with all bundle fragments |
|
77 * and create a new entry |
|
78 */ |
|
79 void replace_cache_entry(BPQCacheEntry* entry, Bundle* bundle, |
|
80 BPQBlock* block, std::string key); |
|
81 |
|
82 void remove_cache_entry(BPQCacheEntry* entry, std::string key); |
|
83 /** |
|
84 * Add received bundle fragment to the cache entry |
|
85 * @return true if the new fragment completed the cache entry |
|
86 * false otherwise |
|
87 */ |
|
88 bool append_cache_entry(BPQCacheEntry* entry, Bundle* bundle, std::string key); |
|
89 |
|
90 |
|
91 |
|
92 bool bpq_requires_fragment(BPQBlock* block, Bundle* fragment); |
71 int update_bpq_block(Bundle* bundle, BPQBlock* block); |
93 int update_bpq_block(Bundle* bundle, BPQBlock* block); |
72 bool try_to_deliver(BPQCacheEntry* entry); |
94 bool try_to_deliver(BPQCacheEntry* entry); |
|
95 |
|
96 void update_lru_keys(std::string key); |
73 |
97 |
74 /** |
98 /** |
75 * Calculate a hash table key from a bundle |
99 * Calculate a hash table key from a bundle |
76 * This is a SHA256 hash of the concatenation of: |
100 * This is a SHA256 hash of the concatenation of: |
77 * Matching Rule and Query Value |
101 * Matching Rule and Query Value |