00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdio.h>
00023 #include <sys/time.h>
00024 #include <stdarg.h>
00025 #include <time.h>
00026 #include <unistd.h>
00027
00028 #include <ccn/ccn.h>
00029 #include <ccn/ccnd.h>
00030 #include <ccn/charbuf.h>
00031 #include <ccn/hashtb.h>
00032 #include <ccn/uri.h>
00033
00034 #include "ccnd_private.h"
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 void
00045 ccnd_msg(struct ccnd_handle *h, const char *fmt, ...)
00046 {
00047 struct timeval t;
00048 va_list ap;
00049 struct ccn_charbuf *b;
00050 int res;
00051 time_t clock;
00052 if (h == NULL || h->debug == 0 || h->logger == 0)
00053 return;
00054 b = ccn_charbuf_create();
00055 gettimeofday(&t, NULL);
00056 if (((h->debug & 64) != 0) &&
00057 ((h->logbreak-- < 0 && t.tv_sec != h->logtime) ||
00058 t.tv_sec >= h->logtime + 30)) {
00059 clock = t.tv_sec;
00060 ccn_charbuf_putf(b, "%ld.000000 ccnd[%d]: %s ____________________ %s",
00061 (long)t.tv_sec, h->logpid,
00062 h->portstr ? h->portstr : "",
00063 ctime(&clock));
00064 h->logtime = t.tv_sec;
00065 h->logbreak = 30;
00066 }
00067 ccn_charbuf_putf(b, "%ld.%06u ", (long)t.tv_sec, (unsigned)t.tv_usec);
00068 if (h->debug & 32)
00069 ccn_charbuf_putf(b, "%08x.", (unsigned)h->wtnow);
00070 ccn_charbuf_putf(b, "ccnd[%d]: %s\n", h->logpid, fmt);
00071 va_start(ap, fmt);
00072 res = (*h->logger)(h->loggerdata, (const char *)b->buf, ap);
00073 va_end(ap);
00074 ccn_charbuf_destroy(&b);
00075
00076 if (res < 0)
00077 h->debug = 0;
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 void
00091 ccnd_debug_ccnb(struct ccnd_handle *h,
00092 int lineno,
00093 const char *msg,
00094 struct face *face,
00095 const unsigned char *ccnb,
00096 size_t ccnb_size)
00097 {
00098 struct ccn_charbuf *c;
00099 struct ccn_parsed_interest pi;
00100 const unsigned char *nonce = NULL;
00101 size_t nonce_size = 0;
00102 const unsigned char *pubkey = NULL;
00103 size_t pubkey_size = 0;
00104 size_t i;
00105 struct interest_entry *ie = NULL;
00106 int default_lifetime = CCN_INTEREST_LIFETIME_SEC << 12;
00107 intmax_t lifetime = default_lifetime;
00108
00109 if (h != NULL && h->debug == 0)
00110 return;
00111 if (ccn_parse_interest(ccnb, ccnb_size, &pi, NULL) >= 0) {
00112 pubkey_size = (pi.offset[CCN_PI_E_PublisherIDKeyDigest] -
00113 pi.offset[CCN_PI_B_PublisherIDKeyDigest]);
00114 pubkey = ccnb + pi.offset[CCN_PI_B_PublisherIDKeyDigest];
00115 lifetime = ccn_interest_lifetime(ccnb, &pi);
00116 ccn_ref_tagged_BLOB(CCN_DTAG_Nonce, ccnb,
00117 pi.offset[CCN_PI_B_Nonce],
00118 pi.offset[CCN_PI_E_Nonce],
00119 &nonce,
00120 &nonce_size);
00121 ie = hashtb_lookup(h->interest_tab, ccnb, pi.offset[CCN_PI_B_Nonce]);
00122 }
00123 else {
00124 pi.min_suffix_comps = 0;
00125 pi.max_suffix_comps = 32767;
00126 pi.orderpref = 0;
00127 pi.answerfrom = CCN_AOK_DEFAULT;
00128 pi.scope = -1;
00129 }
00130 c = ccn_charbuf_create();
00131 ccn_charbuf_putf(c, "debug.%d %s ", lineno, msg);
00132 if (face != NULL)
00133 ccn_charbuf_putf(c, "%u ", face->faceid);
00134 ccn_uri_append(c, ccnb, ccnb_size, 1);
00135 ccn_charbuf_putf(c, " (%u bytes", (unsigned)ccnb_size);
00136 if (pi.min_suffix_comps != 0 || pi.max_suffix_comps != 32767) {
00137 ccn_charbuf_putf(c, ",c=%d", pi.min_suffix_comps);
00138 if (pi.min_suffix_comps != pi.max_suffix_comps) {
00139 ccn_charbuf_putf(c, ":");
00140 if (pi.max_suffix_comps != 32767)
00141 ccn_charbuf_putf(c, "%d", pi.max_suffix_comps);
00142 }
00143 }
00144 if (pubkey_size >= 3)
00145 ccn_charbuf_putf(c, ",pb=%02X%02X%02X",
00146 pubkey[0], pubkey[1], pubkey[2]);
00147 if (pi.orderpref != 0)
00148 ccn_charbuf_putf(c, ",cs=%d", pi.orderpref);
00149 if (pi.answerfrom != CCN_AOK_DEFAULT)
00150 ccn_charbuf_putf(c, ",aok=%#x", pi.answerfrom);
00151 if (pi.scope != -1)
00152 ccn_charbuf_putf(c, ",scope=%d", pi.scope);
00153 if (lifetime != default_lifetime) {
00154 ccn_charbuf_putf(c, ",life=%d.%04d",
00155 (int)(lifetime >> 12),
00156 (int)(lifetime & 0xFFF) * 10000 / 4096);
00157 }
00158 if (ie != NULL)
00159 ccn_charbuf_putf(c, ",i=%u", ie->serial);
00160 ccn_charbuf_putf(c, ")");
00161 if (nonce_size > 0) {
00162 const char *p = "";
00163 ccn_charbuf_putf(c, " ");
00164 if (nonce_size == 12)
00165 p = "CCC-P-F-T-NN";
00166 for (i = 0; i < nonce_size; i++)
00167 ccn_charbuf_putf(c, "%s%02X", (*p) && (*p++)=='-' ? "-" : "", nonce[i]);
00168 }
00169 ccnd_msg(h, "%s", ccn_charbuf_as_string(c));
00170 ccn_charbuf_destroy(&c);
00171 }
00172
00173
00174
00175
00176 const char *ccnd_usage_message =
00177 "ccnd - CCNx Daemon\n"
00178 " options: none\n"
00179 " arguments: none\n"
00180 " environment variables:\n"
00181 " CCND_DEBUG=\n"
00182 " 0 - no messages\n"
00183 " 1 - basic messages (any non-zero value gets these)\n"
00184 " 2 - interest messages\n"
00185 " 4 - content messages\n"
00186 " 8 - matching details\n"
00187 " 16 - interest details\n"
00188 " 32 - gory interest details\n"
00189 " 64 - log occasional human-readable timestamps\n"
00190 " 128 - face registration debugging\n"
00191 " bitwise OR these together for combinations; -1 gets max logging\n"
00192 " CCN_LOCAL_PORT=\n"
00193 " UDP port for unicast clients (default "CCN_DEFAULT_UNICAST_PORT").\n"
00194 " Also listens on this TCP port for stream connections.\n"
00195 " Also affects name of unix-domain socket.\n"
00196 " CCN_LOCAL_SOCKNAME=\n"
00197 " Name stem of unix-domain socket (default "CCN_DEFAULT_LOCAL_SOCKNAME").\n"
00198 " CCND_CAP=\n"
00199 " Capacity limit, in count of ContentObjects.\n"
00200 " Not an absolute limit.\n"
00201 " CCND_MTU=\n"
00202 " Packet size in bytes.\n"
00203 " If set, interest stuffing is allowed within this budget.\n"
00204 " Single items larger than this are not precluded.\n"
00205 " CCND_DATA_PAUSE_MICROSEC=\n"
00206 " Adjusts content-send delay time for multicast and udplink faces\n"
00207 " CCND_DEFAULT_TIME_TO_STALE=\n"
00208 " Default for content objects without explicit FreshnessSeconds\n"
00209 " CCND_MAX_TIME_TO_STALE=\n"
00210 " Limit, in seconds, until content becomes stale\n"
00211 " CCND_KEYSTORE_DIRECTORY=\n"
00212 " Directory readable only by ccnd where its keystores are kept\n"
00213 " Defaults to a private subdirectory of /var/tmp\n"
00214 " CCND_LISTEN_ON=\n"
00215 " List of ip addresses to listen on; defaults to wildcard\n"
00216 " CCND_AUTOREG=\n"
00217 " List of prefixes to auto-register on new faces initiated by peers\n"
00218 " example: CCND_AUTOREG=ccnx:/like/this,ccnx:/and/this\n"
00219 ;