00001 /* 00002 * NeighborDatabase.cpp 00003 * 00004 * Created on: 23.07.2010 00005 * Author: morgenro 00006 */ 00007 00008 #include "routing/NeighborDatabase.h" 00009 #include <ibrdtn/utils/Clock.h> 00010 00011 namespace dtn 00012 { 00013 namespace routing 00014 { 00015 NeighborDatabase::NeighborEntry::NeighborEntry() : _available(false) {}; 00016 00017 NeighborDatabase::NeighborEntry::NeighborEntry(const dtn::data::EID &eid) 00018 : _eid(eid), _available(false) 00019 { } 00020 00021 NeighborDatabase::NeighborEntry::~NeighborEntry() 00022 { } 00023 00024 void NeighborDatabase::NeighborEntry::updateLastSeen() 00025 { 00026 _lastseen = dtn::utils::Clock::getTime(); 00027 } 00028 00029 void NeighborDatabase::NeighborEntry::updateBundles(const ibrcommon::BloomFilter &bf) 00030 { 00031 _filter = bf; 00032 } 00033 00034 NeighborDatabase::NeighborDatabase() 00035 { 00036 } 00037 00038 NeighborDatabase::~NeighborDatabase() 00039 { 00040 } 00041 00042 NeighborDatabase::NeighborEntry& NeighborDatabase::get(const dtn::data::EID &eid) 00043 { 00044 if (_entries.find(eid) == _entries.end()) 00045 { 00046 NeighborEntry entry(eid); 00047 _entries[eid] = entry; 00048 } 00049 00050 return _entries[eid]; 00051 } 00052 00053 void NeighborDatabase::updateLastSeen(const dtn::data::EID &eid) 00054 { 00055 NeighborEntry &entry = get(eid); 00056 entry.updateLastSeen(); 00057 } 00058 void NeighborDatabase::updateBundles(const dtn::data::EID &eid, const ibrcommon::BloomFilter &bf) 00059 { 00060 NeighborEntry &entry = get(eid); 00061 entry.updateBundles(bf); 00062 } 00063 00064 bool NeighborDatabase::knowBundle(const dtn::data::EID &eid, const dtn::data::BundleID &bundle) throw (BloomfilterNotAvailableException) 00065 { 00066 NeighborEntry &entry = get(eid); 00067 return entry._filter.contains(bundle.toString()); 00068 } 00069 00070 void NeighborDatabase::setAvailable(const dtn::data::EID &eid) 00071 { 00072 NeighborEntry &entry = get(eid); 00073 entry.updateLastSeen(); 00074 entry._available = true; 00075 } 00076 00077 void NeighborDatabase::setUnavailable(const dtn::data::EID &eid) 00078 { 00079 NeighborEntry &entry = get(eid); 00080 entry.updateLastSeen(); 00081 entry._available = false; 00082 } 00083 00084 std::set<dtn::data::EID> NeighborDatabase::getAvailable() const 00085 { 00086 std::set<dtn::data::EID> ret; 00087 00088 for (std::map<dtn::data::EID, NeighborDatabase::NeighborEntry>::const_iterator iter = _entries.begin(); iter != _entries.end(); iter++) 00089 { 00090 if ((*iter).second._available) 00091 { 00092 ret.insert((*iter).first); 00093 } 00094 } 00095 00096 return ret; 00097 } 00098 } 00099 }
1.6.3