IBR-DTNSuite
0.8
|
00001 #include "EchoWorker.h" 00002 #include "net/ConvergenceLayer.h" 00003 #include "ibrdtn/utils/Utils.h" 00004 #include <ibrcommon/Logger.h> 00005 00006 using namespace dtn::core; 00007 using namespace dtn::data; 00008 00009 namespace dtn 00010 { 00011 namespace daemon 00012 { 00013 EchoWorker::EchoWorker() 00014 { 00015 AbstractWorker::initialize("/echo", 11, true); 00016 } 00017 00018 void EchoWorker::callbackBundleReceived(const Bundle &b) 00019 { 00020 try { 00021 const PayloadBlock &payload = b.getBlock<PayloadBlock>(); 00022 00023 // generate a echo 00024 Bundle echo; 00025 00026 // make a copy of the payload block 00027 ibrcommon::BLOB::Reference ref = payload.getBLOB(); 00028 echo.push_back(ref); 00029 00030 // set destination and mark the bundle as singleton destination 00031 echo._destination = b._source; 00032 echo.set(dtn::data::PrimaryBlock::DESTINATION_IS_SINGLETON, true); 00033 00034 // set the source of the bundle 00035 echo._source = getWorkerURI(); 00036 00037 // set the lifetime to the same value as the received bundle 00038 echo._lifetime = b._lifetime; 00039 00040 IBRCOMMON_LOGGER_DEBUG(5) << "echo request received, replying!" << IBRCOMMON_LOGGER_ENDL; 00041 00042 // send it 00043 transmit( echo ); 00044 } catch (const dtn::data::Bundle::NoSuchBlockFoundException&) { 00045 00046 } 00047 } 00048 } 00049 }