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 if (h == NULL || h->debug == 0 || h->logger == 0)
00051 return;
00052 b = ccn_charbuf_create();
00053 gettimeofday(&t, NULL);
00054 if (((h->debug & 64) != 0) &&
00055 ((h->logbreak-- < 0 && t.tv_sec != h->logtime) ||
00056 t.tv_sec >= h->logtime + 30)) {
00057 ccn_charbuf_putf(b, "%ld.000000 ccnd[%d]: %s ____________________ %s",
00058 (long)t.tv_sec, h->logpid, h->portstr ? h->portstr : "", ctime(&t.tv_sec));
00059 h->logtime = t.tv_sec;
00060 h->logbreak = 30;
00061 }
00062 ccn_charbuf_putf(b, "%ld.%06u ccnd[%d]: %s\n",
00063 (long)t.tv_sec, (unsigned)t.tv_usec, h->logpid, fmt);
00064 va_start(ap, fmt);
00065 res = (*h->logger)(h->loggerdata, (const char *)b->buf, ap);
00066 va_end(ap);
00067 ccn_charbuf_destroy(&b);
00068
00069 if (res < 0)
00070 h->debug = 0;
00071 }
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 void
00084 ccnd_debug_ccnb(struct ccnd_handle *h,
00085 int lineno,
00086 const char *msg,
00087 struct face *face,
00088 const unsigned char *ccnb,
00089 size_t ccnb_size)
00090 {
00091 struct ccn_charbuf *c;
00092 struct ccn_parsed_interest pi;
00093 const unsigned char *nonce = NULL;
00094 size_t nonce_size = 0;
00095 size_t i;
00096
00097 if (h != NULL && h->debug == 0)
00098 return;
00099 if (ccn_parse_interest(ccnb, ccnb_size, &pi, NULL) >= 0) {
00100 ccn_ref_tagged_BLOB(CCN_DTAG_Nonce, ccnb,
00101 pi.offset[CCN_PI_B_Nonce],
00102 pi.offset[CCN_PI_E_Nonce],
00103 &nonce,
00104 &nonce_size);
00105 }
00106 else
00107 pi.scope = -1;
00108 c = ccn_charbuf_create();
00109 ccn_charbuf_putf(c, "debug.%d %s ", lineno, msg);
00110 if (face != NULL)
00111 ccn_charbuf_putf(c, "%u ", face->faceid);
00112 ccn_uri_append(c, ccnb, ccnb_size, 1);
00113 ccn_charbuf_putf(c, " (%u bytes", (unsigned)ccnb_size);
00114 if (pi.scope != -1)
00115 ccn_charbuf_putf(c, ",scope=%d", pi.scope);
00116 ccn_charbuf_putf(c, ")");
00117 if (nonce_size > 0) {
00118 const char *p = "";
00119 ccn_charbuf_putf(c, " ");
00120 if (nonce_size == 12)
00121 p = "CCC-P-F-T-NN";
00122 for (i = 0; i < nonce_size; i++)
00123 ccn_charbuf_putf(c, "%s%02X", (*p) && (*p++)=='-' ? "-" : "", nonce[i]);
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 ;