IBR-DTNSuite
0.8
|
00001 /* 00002 * BundleStorage.cpp 00003 * 00004 * Created on: 24.03.2009 00005 * Author: morgenro 00006 */ 00007 00008 #include "core/BundleCore.h" 00009 #include "storage/BundleStorage.h" 00010 #include "core/CustodyEvent.h" 00011 #include "core/BundleGeneratedEvent.h" 00012 #include <ibrdtn/data/BundleID.h> 00013 00014 namespace dtn 00015 { 00016 namespace storage 00017 { 00018 BundleStorage::BundleStorage() 00019 { 00020 } 00021 00022 BundleStorage::~BundleStorage() 00023 { 00024 } 00025 00026 void BundleStorage::remove(const dtn::data::Bundle &b) 00027 { 00028 remove(dtn::data::BundleID(b)); 00029 }; 00030 00031 dtn::data::MetaBundle BundleStorage::remove(const ibrcommon::BloomFilter&) 00032 { 00033 throw dtn::storage::BundleStorage::NoBundleFoundException(); 00034 }; 00035 00036 const dtn::data::EID BundleStorage::acceptCustody(const dtn::data::MetaBundle &meta) 00037 { 00038 if (!meta.get(Bundle::CUSTODY_REQUESTED)) 00039 throw ibrcommon::Exception("custody transfer is not requested for this bundle."); 00040 00041 if (meta.custodian == EID()) 00042 throw ibrcommon::Exception("no previous custodian is set."); 00043 00044 // create a new bundle 00045 Bundle custody_bundle; 00046 00047 // set priority to HIGH 00048 custody_bundle.set(dtn::data::PrimaryBlock::PRIORITY_BIT1, false); 00049 custody_bundle.set(dtn::data::PrimaryBlock::PRIORITY_BIT2, true); 00050 00051 // send a custody signal with accept flag 00052 CustodySignalBlock &signal = custody_bundle.push_back<CustodySignalBlock>(); 00053 00054 // set the bundle to match 00055 signal.setMatch(meta); 00056 00057 // set accepted 00058 signal._custody_accepted = true; 00059 00060 custody_bundle.set(dtn::data::PrimaryBlock::DESTINATION_IS_SINGLETON, true); 00061 custody_bundle._destination = meta.custodian; 00062 custody_bundle._source = dtn::core::BundleCore::local; 00063 00064 // send the custody accepted bundle 00065 dtn::core::BundleGeneratedEvent::raise(custody_bundle); 00066 00067 // raise the custody accepted event 00068 dtn::core::CustodyEvent::raise(meta, dtn::core::CUSTODY_ACCEPT); 00069 00070 return dtn::core::BundleCore::local; 00071 } 00072 00073 void BundleStorage::rejectCustody(const dtn::data::MetaBundle &meta, dtn::data::CustodySignalBlock::REASON_CODE reason) 00074 { 00075 if (!meta.get(Bundle::CUSTODY_REQUESTED)) 00076 throw ibrcommon::Exception("custody transfer is not requested for this bundle."); 00077 00078 if (meta.custodian == EID()) 00079 throw ibrcommon::Exception("no previous custodian is set."); 00080 00081 // create a new bundle 00082 Bundle b; 00083 00084 // send a custody signal with reject flag 00085 CustodySignalBlock &signal = b.push_back<CustodySignalBlock>(); 00086 00087 // set the bundle to match 00088 signal.setMatch(meta); 00089 00090 // set reason code 00091 signal._reason = reason; 00092 00093 b._destination = meta.custodian; 00094 b._source = dtn::core::BundleCore::local; 00095 00096 // send the custody rejected bundle 00097 dtn::core::BundleGeneratedEvent::raise(b); 00098 00099 // raise the custody rejected event 00100 dtn::core::CustodyEvent::raise(b, dtn::core::CUSTODY_REJECT); 00101 } 00102 } 00103 }