ccnd_msg.c

Go to the documentation of this file.
00001 /**
00002  * @file ccnd_msg.c
00003  *
00004  * Logging support for ccnd.
00005  *
00006  * Part of ccnd - the CCNx Daemon.
00007  *
00008  * Copyright (C) 2008, 2009 Palo Alto Research Center, Inc.
00009  *
00010  * This work is free software; you can redistribute it and/or modify it under
00011  * the terms of the GNU General Public License version 2 as published by the
00012  * Free Software Foundation.
00013  * This work is distributed in the hope that it will be useful, but WITHOUT ANY
00014  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
00016  * for more details. You should have received a copy of the GNU General Public
00017  * License along with this program; if not, write to the
00018  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
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  *  Produce ccnd debug output.
00037  *  Output is produced via h->logger under the control of h->debug;
00038  *  prepends decimal timestamp and process identification.
00039  *  Caller should not supply newlines.
00040  *  @param      h  the ccnd handle
00041  *  @param      fmt  printf-like format string
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     /* if there's no one to hear, don't make a sound */
00073     if (res < 0)
00074         h->debug = 0;
00075 }
00076 
00077 /**
00078  *  Produce a ccnd debug trace entry.
00079  *  Output is produced by calling ccnd_msg.
00080  *  @param      h  the ccnd handle
00081  *  @param      lineno  caller's source line number (usually __LINE__)
00082  *  @param      msg  a short text tag to identify the entry
00083  *  @param      face    handle of associated face; may be NULL
00084  *  @param      ccnb    points to ccnb-encoded Interest or ContentObject
00085  *  @param      ccnb_size   is in bytes
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  * CCND Usage message
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     ;
Generated on Fri May 13 16:27:01 2011 for Content-Centric Networking in C by  doxygen 1.6.3