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/uri.h>
00032
00033 #include "ccnd_private.h"
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 void
00044 ccnd_msg(struct ccnd_handle *h, const char *fmt, ...)
00045 {
00046 struct timeval t;
00047 va_list ap;
00048 struct ccn_charbuf *b;
00049 int res;
00050 const char *portstr;
00051 if (h == NULL || h->debug == 0 || h->logger == 0)
00052 return;
00053 b = ccn_charbuf_create();
00054 gettimeofday(&t, NULL);
00055 if (((h->debug & 64) != 0) &&
00056 ((h->logbreak-- < 0 && t.tv_sec != h->logtime) ||
00057 t.tv_sec >= h->logtime + 30)) {
00058 portstr = h->portstr;
00059 if (portstr == NULL)
00060 portstr = "";
00061 ccn_charbuf_putf(b, "%ld.000000 ccnd[%d]: %s ____________________ %s",
00062 (long)t.tv_sec, h->logpid, h->portstr, ctime(&t.tv_sec));
00063 h->logtime = t.tv_sec;
00064 h->logbreak = 30;
00065 }
00066 ccn_charbuf_putf(b, "%ld.%06u ccnd[%d]: %s\n",
00067 (long)t.tv_sec, (unsigned)t.tv_usec, h->logpid, fmt);
00068 va_start(ap, fmt);
00069 res = (*h->logger)(h->loggerdata, (const char *)b->buf, ap);
00070 va_end(ap);
00071 ccn_charbuf_destroy(&b);
00072
00073 if (res < 0)
00074 h->debug = 0;
00075 }
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 void
00088 ccnd_debug_ccnb(struct ccnd_handle *h,
00089 int lineno,
00090 const char *msg,
00091 struct face *face,
00092 const unsigned char *ccnb,
00093 size_t ccnb_size)
00094 {
00095 struct ccn_charbuf *c;
00096 struct ccn_parsed_interest pi;
00097 const unsigned char *nonce = NULL;
00098 size_t nonce_size = 0;
00099 size_t i;
00100
00101
00102 if (h != NULL && h->debug == 0)
00103 return;
00104 c = ccn_charbuf_create();
00105 ccn_charbuf_putf(c, "debug.%d %s ", lineno, msg);
00106 if (face != NULL)
00107 ccn_charbuf_putf(c, "%u ", face->faceid);
00108 ccn_uri_append(c, ccnb, ccnb_size, 1);
00109 ccn_charbuf_putf(c, " (%u bytes)", (unsigned)ccnb_size);
00110 if (ccn_parse_interest(ccnb, ccnb_size, &pi, NULL) >= 0) {
00111 const char *p = "";
00112 ccn_ref_tagged_BLOB(CCN_DTAG_Nonce, ccnb,
00113 pi.offset[CCN_PI_B_Nonce],
00114 pi.offset[CCN_PI_E_Nonce],
00115 &nonce,
00116 &nonce_size);
00117 if (nonce_size > 0) {
00118 ccn_charbuf_putf(c, " ");
00119 if (nonce_size == 12)
00120 p = "CCC-P-F-T-NN";
00121 for (i = 0; i < nonce_size; i++)
00122 ccn_charbuf_putf(c, "%s%02X", (*p) && (*p++)=='-' ? "-" : "", nonce[i]);
00123 }
00124 }
00125 ccnd_msg(h, "%s", ccn_charbuf_as_string(c));
00126 ccn_charbuf_destroy(&c);
00127 }
00128
00129
00130
00131
00132 const char *ccnd_usage_message =
00133 "ccnd - CCNx Daemon\n"
00134 " options: none\n"
00135 " arguments: none\n"
00136 " environment variables:\n"
00137 " CCND_DEBUG=\n"
00138 " 0 - no messages\n"
00139 " 1 - basic messages (any non-zero value gets these)\n"
00140 " 2 - interest messages\n"
00141 " 4 - content messages\n"
00142 " 8 - matching details\n"
00143 " 16 - interest details\n"
00144 " 32 - gory interest details\n"
00145 " 64 - log occasional human-readable timestamps\n"
00146 " 128 - face registration debugging\n"
00147 " bitwise OR these together for combinations; -1 gets max logging\n"
00148 " CCN_LOCAL_PORT=\n"
00149 " UDP port for unicast clients (default "CCN_DEFAULT_UNICAST_PORT").\n"
00150 " Also listens on this TCP port for stream connections.\n"
00151 " Also affects name of unix-domain socket.\n"
00152 " CCN_LOCAL_SOCKNAME=\n"
00153 " Name stem of unix-domain socket (default "CCN_DEFAULT_LOCAL_SOCKNAME").\n"
00154 " CCND_CAP=\n"
00155 " Capacity limit, in count of ContentObjects.\n"
00156 " Not an absolute limit.\n"
00157 " CCND_MTU=\n"
00158 " Packet size in bytes.\n"
00159 " If set, interest stuffing is allowed within this budget.\n"
00160 " Single items larger than this are not precluded.\n"
00161 " CCND_DATA_PAUSE_MICROSEC=\n"
00162 " Adjusts content-send delay time for multicast and udplink faces\n"
00163 " CCND_KEYSTORE_DIRECTORY=\n"
00164 " Directory readable only by ccnd where its keystores are kept\n"
00165 " Defaults to a private subdirectory of /var/tmp\n"
00166 " CCND_LISTEN_ON=\n"
00167 " List of ip addresses to listen on; defaults to wildcard\n"
00168 " CCND_AUTOREG=\n"
00169 " List of prefixes to auto-register on new faces initiated by peers\n"
00170 " example: CCND_AUTOREG=ccnx:/like/this,ccnx:/and/this\n"
00171 ;