00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef MACEDON_CACHE_H
00034
00035 #define MACEDON_CACHE_H
00036 #define MAX_CACHE_SIZE 100
00037 #define MAX_CACHE_LIFE 10 * 1000 * 1000 //usec
00038
00044 #include "MaceTypes.h"
00045 #include "NodeCollection.h"
00046 #include "Printable.h"
00047 #include "TimeUtil.h"
00048
00049 namespace mace {
00050
00052 class AddressCacheEntry : public mace::PrintPrintable, public mace::Serializable {
00053 private:
00054 MaceKey _id;
00055
00056 public:
00057 MaceKey start;
00058 MaceKey end;
00059 uint64_t time;
00060
00061 void print(std::ostream&) const;
00062 MaceKey getId() const { return _id; }
00063 double getScore() const { return time; }
00064 AddressCacheEntry() : _id(), start(), end(), time() {}
00065 AddressCacheEntry(const MaceKey& id) : _id(id), start(), end(), time(TimeUtil::timeu()) {}
00066 AddressCacheEntry(const MaceKey& id, const MaceKey& b, const MaceKey& e) : _id(id), start(b), end(e), time(TimeUtil::timeu()) {}
00067 virtual ~AddressCacheEntry() {}
00069 int deserialize(std::istream& in) throw(SerializationException) {
00070 ABORT("deserialize not supported");
00071 }
00073 void serialize(std::string& str) const {
00074 ABORT("serialize not supported");
00075 }
00076
00077 };
00078
00085 class AddressCache
00086 {
00087 public:
00088 AddressCache () : entries() {}
00089 ~AddressCache () {}
00099 void insert(const MaceKey& start, const MaceKey& end, const MaceKey& address);
00101 void remove(const MaceKey& address);
00103 MaceKey query(const MaceKey&);
00105 void verify(const MaceKey& hash, const MaceKey& address);
00106 private:
00107 typedef NodeCollection<AddressCacheEntry, MAX_CACHE_SIZE> cachemap;
00108 void consistency();
00109 cachemap entries;
00110 };
00111
00112 }
00113
00114 #endif