00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <oasys/util/ScratchBuffer.h>
00019
00020 #include "AdminRegistration.h"
00021 #include "RegistrationTable.h"
00022 #include "bundling/BundleDaemon.h"
00023 #include "bundling/BundleProtocol.h"
00024 #include "bundling/CustodySignal.h"
00025 #include "routing/BundleRouter.h"
00026
00027 namespace dtn {
00028
00029 AdminRegistration::AdminRegistration()
00030 : Registration(ADMIN_REGID,
00031 BundleDaemon::instance()->local_eid(),
00032 Registration::DEFER,
00033 0)
00034 {
00035 logpathf("/dtn/reg/admin");
00036 set_active(true);
00037 }
00038
00039 void
00040 AdminRegistration::deliver_bundle(Bundle* bundle)
00041 {
00042 u_char typecode;
00043
00044 size_t payload_len = bundle->payload_.length();
00045 oasys::ScratchBuffer<u_char*, 256> scratch(payload_len);
00046 const u_char* payload_buf =
00047 bundle->payload_.read_data(0, payload_len, scratch.buf(payload_len));
00048
00049 log_debug("got %zu byte bundle", payload_len);
00050
00051 if (payload_len == 0) {
00052 log_err("admin registration got 0 byte *%p", bundle);
00053 goto done;
00054 }
00055
00056 if (!bundle->is_admin_) {
00057 log_warn("non-admin *%p sent to local eid", bundle);
00058 goto done;
00059 }
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 typecode = payload_buf[0] >> 4;
00074
00075 switch(typecode) {
00076 case BundleProtocol::ADMIN_STATUS_REPORT:
00077 {
00078 log_err("status report *%p received at admin registration", bundle);
00079 break;
00080 }
00081
00082 case BundleProtocol::ADMIN_CUSTODY_SIGNAL:
00083 {
00084 log_info("ADMIN_CUSTODY_SIGNAL *%p received", bundle);
00085 CustodySignal::data_t data;
00086
00087 bool ok = CustodySignal::parse_custody_signal(&data, payload_buf, payload_len);
00088 if (!ok) {
00089 log_err("malformed custody signal *%p", bundle);
00090 break;
00091 }
00092
00093 BundleDaemon::post(new CustodySignalEvent(data));
00094
00095 break;
00096 }
00097 case BundleProtocol::ADMIN_ANNOUNCE:
00098 {
00099 log_info("ADMIN_ANNOUNCE from %s", bundle->source_.c_str());
00100 break;
00101 }
00102
00103 default:
00104 log_warn("unexpected admin bundle with type 0x%x *%p",
00105 typecode, bundle);
00106 }
00107
00108 done:
00109 BundleDaemon::post(new BundleDeliveredEvent(bundle, this));
00110 }
00111
00112
00113 }