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