00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "BundleOffer.h"
00018
00019 namespace prophet
00020 {
00021
00022 #define LOG(_args...) core_->print_log("offer",BundleCore::LOG_DEBUG,_args)
00023
00024 BundleOffer::BundleOffer(BundleCore* core,
00025 const BundleList& bundles,
00026 FwdStrategyComp* comp,
00027 Decider* decider)
00028 : core_(core), comp_(comp), decider_(decider)
00029 {
00030 for (BundleList::const_iterator i = bundles.begin();
00031 i != bundles.end(); i++)
00032 add_bundle(*i);
00033 }
00034
00035 BundleOffer::~BundleOffer()
00036 {
00037 delete comp_;
00038 delete decider_;
00039 }
00040
00041 void
00042 BundleOffer::add_bundle(const Bundle* b)
00043 {
00044 if (b == NULL) return;
00045
00046 if ((*decider_)(b))
00047 {
00048
00049 List::iterator i = list_.begin();
00050 while (i != list_.end() && (*comp_)(b,*i))
00051 i++;
00052 list_.insert(i,b);
00053 LOG("offering %s %u %u",b->destination_id().c_str(),
00054 b->creation_ts(), b->sequence_num());
00055 }
00056 else
00057 {
00058 LOG("not offering %s %u %u",b->destination_id().c_str(),
00059 b->creation_ts(), b->sequence_num());
00060 }
00061 }
00062
00063 const BundleOfferList&
00064 BundleOffer::get_bundle_offer(const Dictionary& ribd,
00065 const AckList* acks)
00066 {
00067 bolist_.clear();
00068 List::iterator i = list_.begin();
00069 while (i != list_.end())
00070 {
00071 std::string eid = core_->get_route((*i)->destination_id());
00072 u_int16_t sid = ribd.find(eid);
00073 if (sid != Dictionary::INVALID_SID)
00074 bolist_.add_offer(*i,sid);
00075 i++;
00076 }
00077 if (acks != NULL && !acks->empty())
00078 {
00079 PointerList<Ack> list;
00080 acks->clone(list);
00081 for (PointerList<Ack>::iterator ai = list.begin(); ai != list.end(); ai++)
00082 {
00083 std::string eid = core_->get_route((*ai)->dest_id());
00084 u_int16_t sid = ribd.find(eid);
00085 if (sid != Dictionary::INVALID_SID)
00086 bolist_.add_offer((*ai)->cts(),(*ai)->seq(),sid,false,true);
00087 }
00088 }
00089 return bolist_;
00090 }
00091
00092 };