AnnounceBundle.cc

Go to the documentation of this file.
00001 #include <oasys/util/ScratchBuffer.h>
00002 #include "AnnounceBundle.h"
00003 #include "BundleProtocol.h"
00004 
00005 namespace dtn {
00006 
00007 void
00008 AnnounceBundle::create_announce_bundle(Bundle* announce,
00009                                        const EndpointID& route_eid)
00010 {
00011     // only meant for DTN admin consumption
00012     announce->is_admin_ = true;
00013 
00014     // assign router's local EID as bundle source
00015     announce->source_.assign(route_eid);
00016 
00017     // null out the rest
00018     announce->dest_.assign(EndpointID::NULL_EID());
00019     announce->replyto_.assign(EndpointID::NULL_EID());
00020     announce->custodian_.assign(EndpointID::NULL_EID());
00021 
00022     // non-zero expire time
00023     announce->expiration_ = 3600;
00024 
00025     // one byte payload:  admin type
00026     u_char buf = (BundleProtocol::ADMIN_ANNOUNCE << 4);
00027     announce->payload_.set_data(&buf,1);
00028 }
00029 
00030 bool
00031 AnnounceBundle::parse_announce_bundle(Bundle* bundle,
00032                                       EndpointID *route_eid)
00033 {
00034     if (bundle->is_admin_ == false)
00035         return false;
00036 
00037     size_t payload_len = bundle->payload_.length();
00038     if (payload_len <= 0) return false;
00039 
00040     oasys::ScratchBuffer<u_char*, 256> scratch(payload_len);
00041     const u_char* payload_buf =
00042             bundle->payload_.read_data(0, payload_len, scratch.buf(payload_len));
00043 
00044     if ((*payload_buf >> 4) == BundleProtocol::ADMIN_ANNOUNCE) {
00045 
00046         if(route_eid != NULL)
00047             route_eid->assign(bundle->source_);
00048 
00049         return true;
00050     }
00051 
00052     return false;
00053 }
00054 
00055 } // dtn

Generated on Fri Dec 22 14:47:57 2006 for DTN Reference Implementation by  doxygen 1.5.1