00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifdef HAVE_CONFIG_H
00018 # include <dtn-config.h>
00019 #endif
00020
00021 #include "BundleInfoCache.h"
00022
00023 namespace dtn {
00024
00025
00026 BundleInfoCache::BundleInfoCache(const std::string& logpath, size_t capacity)
00027 : cache_(logpath, CacheCapacityHelper(capacity),
00028 false )
00029 {
00030 }
00031
00032
00033 bool
00034 BundleInfoCache::add_entry(const Bundle* bundle, const EndpointID& prevhop)
00035 {
00036 GbofId id(bundle->source(),
00037 bundle->creation_ts(),
00038 bundle->is_fragment(),
00039 bundle->payload().length(),
00040 bundle->frag_offset());
00041
00042 Cache::Handle h;
00043 bool ok = cache_.put_and_pin(id, prevhop, &h);
00044 if (!ok) {
00045 return false;
00046 }
00047
00048 h.unpin();
00049 return true;
00050 }
00051
00052
00053 bool
00054 BundleInfoCache::lookup(const Bundle* bundle, EndpointID* prevhop)
00055 {
00056 GbofId id(bundle->source(),
00057 bundle->creation_ts(),
00058 bundle->is_fragment(),
00059 bundle->payload().length(),
00060 bundle->frag_offset());
00061
00062 return cache_.get(id, prevhop);
00063 }
00064
00065
00066 void
00067 BundleInfoCache::evict_all()
00068 {
00069 cache_.evict_all();
00070 }
00071
00072 }