IBR-DTNSuite 0.6

daemon/src/CapsuleWorker.cpp

Go to the documentation of this file.
00001 /*
00002  * CapsuleWorker.cpp
00003  *
00004  *  Created on: 26.04.2011
00005  *      Author: morgenro
00006  */
00007 
00008 #include "CapsuleWorker.h"
00009 #include <ibrdtn/data/PayloadBlock.h>
00010 #include "net/BundleReceivedEvent.h"
00011 #include <ibrdtn/data/ScopeControlHopLimitBlock.h>
00012 #include <ibrdtn/utils/Clock.h>
00013 #include <ibrcommon/Logger.h>
00014 
00015 namespace dtn
00016 {
00017         namespace daemon
00018         {
00019                 CapsuleWorker::CapsuleWorker()
00020                 {
00021                         AbstractWorker::initialize("/bundle-in-bundle", true);
00022                 }
00023 
00024                 CapsuleWorker::~CapsuleWorker()
00025                 {
00026                 }
00027 
00028                 void CapsuleWorker::callbackBundleReceived(const dtn::data::Bundle &capsule)
00029                 {
00030                         try {
00031                                 const PayloadBlock &payload = capsule.getBlock<PayloadBlock>();
00032                                 ibrcommon::BLOB::iostream stream = payload.getBLOB().iostream();
00033 
00034                                 // read the number of bundles
00035                                 SDNV nob; (*stream) >> nob;
00036 
00037                                 // read all offsets
00038                                 for (size_t i = 0; i < (nob.getValue() - 1); i++)
00039                                 {
00040                                         SDNV offset; (*stream) >> offset;
00041                                 }
00042 
00043                                 // create a deserializer for all bundles
00044                                 dtn::data::DefaultDeserializer deserializer(*stream);
00045                                 dtn::data::Bundle b;
00046 
00047                                 try {
00048                                         // read all bundles
00049                                         for (size_t i = 0; i < nob.getValue(); i++)
00050                                         {
00051                                                 // deserialize the next bundle
00052                                                 deserializer >> b;
00053 
00054                                                 // increment value in the scope control hop limit block
00055                                                 try {
00056                                                         dtn::data::ScopeControlHopLimitBlock &schl = b.getBlock<dtn::data::ScopeControlHopLimitBlock>();
00057                                                         schl.increment();
00058                                                 } catch (const dtn::data::Bundle::NoSuchBlockFoundException&) { };
00059 
00060                                                 // raise default bundle received event
00061                                                 dtn::net::BundleReceivedEvent::raise(capsule._source, b);
00062                                         }
00063                                 }
00064                                 catch (const dtn::InvalidDataException &ex) {
00065                                         // display the rejection
00066                                         IBRCOMMON_LOGGER(warning) << "invalid bundle-data received: " << ex.what() << IBRCOMMON_LOGGER_ENDL;
00067                                 }
00068                         } catch (const dtn::data::Bundle::NoSuchBlockFoundException&) { };
00069                 }
00070         }
00071 }