tokyotyrant (1.1.40-4.1) 005-change-default-port

Summary

 doc/spex.html |   10 ++++++----
 tcrmgr.c      |    2 +-
 ttserver.c    |    5 ++++-
 ttutil.c      |    2 +-
 ttutil.h      |    6 +++++-
 5 files changed, 17 insertions(+), 8 deletions(-)

    
download this patch

Patch contents

Description: Use socket by default
 Tyrant does not have authorization. Upstream opens up the daemon on all
 interfaces and port 1978. Unix sockets are more secure.
 .
 This updates the utilities to more folllow these changes.
Author: Örjan Persson <orange@fobie.net>
Last-Update: 2010-02-14
Index: tokyotyrant/ttutil.h
===================================================================
--- tokyotyrant.orig/ttutil.h	2010-02-14 22:03:04.000000000 +0100
+++ tokyotyrant/ttutil.h	2010-02-14 22:05:52.000000000 +0100
@@ -266,7 +266,7 @@
  *************************************************************************************************/
 
 
-#define TTDEFPORT      1978              /* default port of the server */
+#define TTDEFPORT      0                 /* default port of the server */
 #define TTMAGICNUM     0xc8              /* magic number of each command */
 #define TTCMDPUT       0x10              /* ID of put command */
 #define TTCMDPUTKEEP   0x11              /* ID of putkeep command */
@@ -297,6 +297,10 @@
 
 #define TTTIMERMAX     8                 /* maximum number of timers */
 
+/* Debian addons */
+#define _TTDEFSOCK      "/var/run/tokyotyrant/tokyotyrant.sock"
+#define _TTDEFMPORT     1978              /* default port of master server */
+
 typedef struct _TTTIMER {                /* type of structure for a timer */
   pthread_t thid;                        /* thread ID */
   bool alive;                            /* alive flag */
Index: tokyotyrant/ttutil.c
===================================================================
--- tokyotyrant.orig/ttutil.c	2010-02-14 22:03:04.000000000 +0100
+++ tokyotyrant/ttutil.c	2010-02-14 22:05:52.000000000 +0100
@@ -1235,7 +1235,7 @@
   tcstrtrim(host);
   if(*host == '\0'){
     tcfree(host);
-    host = tcstrdup("127.0.0.1");
+    host = tcstrdup(port ? "127.0.0.1" : _TTDEFSOCK);
   }
   return host;
 }
Index: tokyotyrant/tcrmgr.c
===================================================================
--- tokyotyrant.orig/tcrmgr.c	2010-02-14 22:03:04.000000000 +0100
+++ tokyotyrant/tcrmgr.c	2010-02-14 22:05:52.000000000 +0100
@@ -848,7 +848,7 @@
   char *host = NULL;
   char *mhost = NULL;
   int port = TTDEFPORT;
-  int mport = TTDEFPORT;
+  int mport = _TTDEFMPORT;
   uint64_t ts = 0;
   int opts = 0;
   for(int i = 2; i < argc; i++){
Index: tokyotyrant/ttserver.c
===================================================================
--- tokyotyrant.orig/ttserver.c	2010-02-14 22:03:04.000000000 +0100
+++ tokyotyrant/ttserver.c	2010-02-14 22:05:52.000000000 +0100
@@ -224,7 +224,7 @@
   uint64_t ulim = DEFULIMSIZ;
   bool uas = false;
   uint32_t sid = 0;
-  int mport = TTDEFPORT;
+  int mport = _TTDEFMPORT;
   int ropts = 0;
   int mulnum = 0;
   uint64_t mask = 0;
@@ -236,6 +236,9 @@
       } else if(!strcmp(argv[i], "-port")){
         if(++i >= argc) usage();
         port = tcatoi(argv[i]);
+        if(host == NULL) {
+          host = port ? "127.0.0.1" : _TTDEFSOCK;
+        }
       } else if(!strcmp(argv[i], "-thnum")){
         if(++i >= argc) usage();
         thnum = tcatoi(argv[i]);
Index: tokyotyrant/doc/spex.html
===================================================================
--- tokyotyrant.orig/doc/spex.html	2010-02-14 22:05:54.000000000 +0100
+++ tokyotyrant/doc/spex.html	2010-02-14 22:10:12.000000000 +0100
@@ -128,8 +128,8 @@
 <p>Options feature the following.</p>
 
 <ul class="options">
-<li><code>-host <var>name</var></code> : specify the host name or the address of the server.  By default, every network address is bound.</li>
-<li><code>-port <var>num</var></code> : specify the port number.  By default, it is 1978.</li>
+<li><code>-host <var>name</var></code> : specify the host name or the address of the server.  By default, it is /var/run/tokyotyrant/tokyotyrant.sock if port is not specified, else every network address is bound.</li>
+<li><code>-port <var>num</var></code> : specify the port number.  By default, it is 0 (indicates usage of unix socket).</li>
 <li><code>-thnum <var>num</var></code> : specify the number of worker threads.  By default, it is 8.</li>
 <li><code>-tout <var>num</var></code> : specify the timeout of each session in seconds.  By default, no timeout is specified.</li>
 <li><code>-dmn</code> : work as a daemon process.</li>
@@ -154,6 +154,8 @@
 <li><code>-unmask <var>expr</var></code> : specify the names of allowed commands.</li>
 </ul>
 
+<p>The usage of /var/run/tokyotyrant/tokyotyrant.sock is a Debian specific change. The upstream default is to use port 1978 and all network interfaces.</p>
+
 <p>To terminate the server normally, send SIGINT or SIGTERM to the process.  It is okay to press Ctrl-C on the controlling terminal.  To restart the server, send SIGHUP to the process.  If the port number is not more than 0, UNIX domain socket is used and the path of the socket file is specified by the host parameter.  This command returns 0 on success, another on failure.</p>
 
 <p>The naming convention of the database is specified by the abstract API of Tokyo Cabinet.  If the name is "*", the database will be an on-memory hash database.  If it is "+", the database will be an on-memory tree database.  If its suffix is ".tch", the database will be a hash database.  If its suffix is ".tcb", the database will be a B+ tree database.  If its suffix is ".tcf", the database will be a fixed-length database.  If its suffix is ".tct", the database will be a table database.  Otherwise, this function fails.  Tuning parameters can trail the name, separated by "#".  Each parameter is composed of the name and the value, separated by "=".  On-memory hash database supports "bnum", "capnum", and "capsiz".  On-memory tree database supports "capnum" and "capsiz".  Hash database supports "mode", "bnum", "apow", "fpow", "opts", "rcnum", "xmsiz", and "dfunit".  B+ tree database supports "mode", "lmemb", "nmemb", "bnum", "apow", "fpow", "opts", "lcnum", "ncnum", "xmsiz", and "dfunit".  Fixed-length database supports "mode", "width", and "limsiz".  Table database supports "mode", "bnum", "apow", "fpow", "opts", "rcnum", "lcnum", "ncnum", "xmsiz", "dfunit", and "idx".  The tuning parameter "capnum" specifies the capacity number of records.  "capsiz" specifies the capacity size of using memory.  Records spilled the capacity are removed by the storing order.  "mode" can contain "w" of writer, "r" of reader, "c" of creating, "t" of truncating, "e" of no locking, and "f" of non-blocking lock.  The default mode is relevant to "wc".  "opts" can contains "l" of large option, "d" of Deflate option, "b" of BZIP2 option, and "t" of TCBS option.  "idx" specifies the column name of an index and its type separated by ":".  For example, "casket.tch#bnum=1000000#opts=ld" means that the name of the database file is "casket.tch", and the bucket number is 1000000, and the options are large and Deflate.</p>
@@ -1418,7 +1420,7 @@
 
 <h2 id="protocol">Protocol</h2>
 
-<p>The protocol between the server and clients stands on TCP/IP.  By default, the service port is bound to every address of the local host and the port number is 1978.  Each session of the server and a client is composed of a request and a response.  The server speaks three protocols at the same port.</p>
+<p>The protocol between the server and clients stands on TCP/IP.  By default, the service port is 0 and host is /var/run/tokyotyrant/tokyotyrant.sock (upstream default is 1978).  Each session of the server and a client is composed of a request and a response.  The server speaks three protocols at the same port.</p>
 
 <h3 id="protocol_binary">Original Binary Protocol</h3>
 
@@ -1782,7 +1784,7 @@
 
 <h3 id="tutorial_basic">Basic Use</h3>
 
-<p>After installation of Tokyo Tyrant, you can start the server immediately by executing the command `<code>ttserver</code>' in the terminal.  By default, the server listens to the port 1978 and serves as the accessor of an on-memory hash database, which is useful to store cache data.</p>
+<p>After installation of Tokyo Tyrant, you can start the server immediately by executing the command `<code>ttserver</code>' in the terminal.  By default, the server uses a unix socket which is located in /var/run/tokyotyrant/tokyotyrant.sock and uses an on-memory hash database, which is useful to store cache data.</p>
 
 <pre>[terminal-1]$ ttserver
 </pre>