* PrequelD.c
*
* Copyright:
- * Copyright (C) 2012 by Christopher R. Hertel
+ * Copyright (C) 2012-2014 by Christopher R. Hertel
*
* Email: crh@ubiqx.mn.org
*
- * $Id: PrequelD.c; 2014-09-22 17:14:11 -0500; Christopher R. Hertel$
+ * $Id: PrequelD.c; 2014-09-22 18:49:59 -0500; Christopher R. Hertel$
*
* -------------------------------------------------------------------------- **
*
* PeerDist - The protocol and/or encoding format used by Microsoft's
* BranchCacheTM distributed caching system.
*
- * Prequel - The name of an Open Source project aimed at implementing
- * PeerDist for use with Linux, *BSD, and other Unix-like
- * OSes.
+ * Prequel - The name of this Open Source project, which is aimed at
+ * implementing PeerDist for use with Linux, *BSD, and other
+ * Unix-like OSes.
*
* References:
- * [BCOVIEW]: MS W2K8R2 BranchCache Overview
- * http://technet.microsoft.com/en-us/library/dd637832.aspx
+ * [BCOVIEW]: MS W2K8R2 BranchCache Overview
+ * http://technet.microsoft.com/en-us/library/dd637832.aspx
*
- * [MS-CCRSOD]: Content Caching and Retrieval System Overview
- * http://msdn.microsoft.com/en-us/library/ff632262.aspx
+ * [MS-CCROD]: Content Caching and Retrieval Protocols Overview
+ * http://msdn.microsoft.com/en-us/library/hh441913.aspx
*
- * [MS-PCCRC]: Peer Content Caching and Retrieval: Content Identification
- * http://msdn.microsoft.com/en-us/library/dd303704.aspx
+ * [MS-PCCRC]: Peer Content Caching and Retrieval: Content Identification
+ * http://msdn.microsoft.com/en-us/library/dd303704.aspx
*
* To Compile:
* cc -I.. -D_FILE_OFFSET_BITS=64 -o PrequelD PrequelD.c \
* ../ubi_sLinkList.c -lcrypto -lpthread
*
* ToDo:
- * + Add support for Unicode pathnames.
+ * + Combine all mutex-protected global values into a single structure,
+ * with the mutex included. That structure should be viewed as an
+ * object that accessed via methods (that leverage the mutex).
+ *
+ * + Verify support for Unicode pathnames.
+ *
+ * + Get rid of bSIZE.
*
* + The background thread should traverse source directories and generate
* hash caches for any file that meets criteria and does not have an
#define RECV_TIMEOUT { 2, 0 } /* 2 seconds. */
#define POLL_TIMEOUT 30000 /* 30 seconds. */
-#define bSIZE 1024
+#define bSIZE 1024 /* 1K bytes. */
/* -------------------------------------------------------------------------- **
* is true, then the client did provide a value and that value
* is stored in the <val> field.
*
- * WorkItem - A queue entry and a string pointer pointing to the pathname
- * of a source file that is in need of hashing.
- *
+ * WorkItem - A queue entry node and a string pointer pointing to the
+ * pathname of a source file that is in need of hashing.
*/
typedef struct
*/
static const char *Copyright =
- "Copyright (c) 2012 by Christopher R. Hertel";
+ "Copyright (c) 2012, 2013 by Christopher R. Hertel";
static const char *License =
- "License: GNU General Public License version 3 (GPLv3)\n"
- " http://www.gnu.org/licenses/gpl-3.0.html";
-static const char *Revision =
- "$Revision$";
+ "License: GNU General Public License version 3 (GPLv3)\n"
+ " http://www.gnu.org/licenses/gpl-3.0.html";
+static const char *Revision = "$Revision$";
static const char *Id =
- "$Id: PrequelD.c; 2014-09-22 17:14:11 -0500; Christopher R. Hertel$";
+ "$Id: PrequelD.c; 2014-09-22 18:49:59 -0500; Christopher R. Hertel$";
static const char *HelpMsg[] =
{
*/
{
static enum { wNone, wStop, wQueue, wDir } doState; /* What shall we do? */
- static struct timespec ts = { 0, 500000000 }; /* Half a second. */
+ static struct timespec ts = { 0, 500000000 }; /* Half a second. */
WorkItem *srcEntry = NULL;
do
/* Determine which action to take, and collect any required data.
* This requires locking/unlocking the global mutex.
*/
- doState = wNone; /* Default action. */
if( 0 == pthread_mutex_lock( &GlobalMutex ) )
{
/* Note: See pthread_mutex_lock(3). We do not check for an error
* to occurr and, if an error were to occur, we don't have a
* sensible way of handling it (other than to wait and retry).
*/
+ doState = wNone; /* Default action. */
if( Shutdown )
doState = wStop;
else
doState = wDir;
else
{
+ /* Do all of this now, while we have the mutex. */
srcEntry = (WorkItem *)ubi_slDequeue( WorkQueue );
if( (NULL != srcEntry) && (NULL != srcEntry->srcPath) )
{
if( Verbosity > 2 )
Log( "Dequeued: %s\n", srcEntry->srcPath );
}
- else
+ else /* Should never happen. */
Log( "Error: NULL entry in priority queue.\n" );
}
}
break;
case wDir:
/* Hash an entry from a source directory. */
- /* FIX: Need directory traversal. */
+ /* PreCalcHash(); FIX: Write PreCalcHash(); */
break;
default:
break;
switch( c )
{
case 'c':
- ConfigFile = optarg;
+ ConfigFile = optarg;
break;
case 'f':
- Daemonize = false;
+ Daemonize = false;
break;
case 'h':
- SpewHelp = true;
+ SpewHelp = true;
break;
case 'l':
- LogFile = optarg;
+ LogFile = optarg;
break;
case 'q':
- Verbosity = 0;
- VerbSet = true;
+ Verbosity = 0;
+ VerbSet = true;
break;
case 't':
- TestConfig = true;
+ TestConfig = true;
break;
case 'v':
if( Verbosity < 0xFF )
Verbosity++;
- VerbSet = true;
+ VerbSet = true;
break;
case 'V':
SpewVersion = true;
*
* Output: EXIT_SUCCESS or, on failure, EXIT_FAILURE.
*
+ * Notes: The program has two threads. The foreground thread listens for
+ * service requests on a Unix Domain Socket. The background
+ * thread (called the "worker") maintains the hash cache files.
+ *
+ * See the comments at the top of this file for more details.
+ *
* ------------------------------------------------------------------------ **
*/
{
ReadOpts( argc, argv ); /* Get all set up to run. */
ReadKeys(); /* Find the signing keys. */
- /* Become a daemon, unless we were told otherwise. */
+ /* Unless we were told otherwise, let's become a daemon. */
if( Daemonize )
Spawn();
/* Before creating any subthreads, let's try to open the listening socket. */
listenSock = OpenListenSock( Cfg->sockFileName );
- /* Initialize the priority queue and start the worker thread. */
+ /* Initialize the priority queue, and start the worker thread. */
(void)ubi_slInitList( WorkQueue );
StartWorker();