00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef QOLYESTER_DAEMON_SET_DUPLICATE_HXX
00020 # define QOLYESTER_DAEMON_SET_DUPLICATE_HXX 1
00021
00022 # include "duplicate.hh"
00023
00024 namespace olsr {
00025
00026 extern sch::Scheduler scheduler;
00027
00028 namespace set {
00029
00030 DuplicateEntry::DuplicateEntry() :
00031 addr_(),
00032 seqnum_(),
00033 retransmitted_(false),
00034 ifaces_(),
00035 time_(0)
00036 {}
00037
00038 DuplicateEntry::DuplicateEntry(const address_t& a, u_int16_t s,
00039 const address_t& i, bool r) :
00040 addr_(a),
00041 seqnum_(s),
00042 retransmitted_(r),
00043 ifaces_(),
00044 time_(timeval_t::in(cst::dup_hold_time)) {
00045 ifaces_.insert(i);
00046 }
00047
00048 bool
00049 DuplicateEntry::in_ifaces(const address_t& a) const {
00050 return ifaces_.find(a) != ifaces_.end();
00051 }
00052
00053 void
00054 DuplicateEntry::add_iface(const address_t& a) {
00055 ifaces_.insert(a);
00056 }
00057
00058 bool
00059 DuplicateEntry::operator<(const This& rhs) const {
00060 if (addr_ == rhs.addr_)
00061 return seqnum_ < rhs.seqnum_;
00062 return addr_ < rhs.addr_;
00063 }
00064
00065 DuplicateEntry
00066 DuplicateEntry::make_key(const address_t& a, u_int16_t s) {
00067 This tmp = dummy_for_find_;
00068 const_cast<address_t&>(tmp.addr_) = a;
00069 const_cast<u_int16_t&>(tmp.seqnum_) = s;
00070 return tmp;
00071 }
00072
00073 DuplicateSet::DuplicateSet()
00074 : dset_(),
00075 dupset_(*this, dset_)
00076 {}
00077
00078 void
00079 DuplicateSet::insert(const DuplicateEntry& x) {
00080 std::pair<dset_t::iterator, bool> p = dset_.insert(x);
00081 if (!p.second) {
00082 sch::TimedEvent* e = p.first->updater();
00083 scheduler.erase(e);
00084 e->set_next(x.time());
00085 scheduler.insert(e);
00086
00087 const_cast<elem_t&>(*p.first).set_time(x.time());
00088 const_cast<elem_t&>(*p.first).ifaces().insert(x.ifaces().begin(),
00089 x.ifaces().end());
00090 if (x.retransmitted())
00091 const_cast<elem_t&>(*p.first).set_retransmitted();
00092 } else {
00093 updater_t* e = new updater_t(x.time(), eraser_t(*this, p.first));
00094 const_cast<elem_t&>(*p.first).set_updater(e);
00095 scheduler.insert(e);
00096 }
00097 }
00098
00099 void
00100 DuplicateSet::erase(const dset_t::iterator& pos) {
00101 sch::TimedEvent* e = pos->updater();
00102 dset_.erase(pos);
00103 scheduler.destroy(e);
00104 }
00105
00106 }
00107
00108 }
00109
00110 #endif // ! QOLYESTER_DAEMON_SET_DUPLICATE_HXX