From 59453ac6ef78f3822d39850fd609272efb49150d Mon Sep 17 00:00:00 2001 From: Roger Dingledine Date: Thu, 4 Nov 2004 06:41:49 +0000 Subject: [PATCH] add a ControlPort and control listener conn. note that print_usage is obsolete. svn:r2671 --- src/or/config.c | 13 ++++++++++--- src/or/connection.c | 6 ++++-- src/or/or.h | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/or/config.c b/src/or/config.c index cd0a9a4a76..257cbfe95b 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -85,6 +85,7 @@ static config_var_t config_vars[] = { VAR("BandwidthBurstBytes", UINT, BandwidthBurstBytes, "50000000"), VAR("ClientOnly", BOOL, ClientOnly, "0"), VAR("ContactInfo", STRING, ContactInfo, NULL), + VAR("ControlPort", UINT, ControlPort, "0"), VAR("DebugLogFile", STRING, DebugLogFile, NULL), VAR("DataDirectory", STRING, DataDirectory, NULL), VAR("DirPort", UINT, DirPort, "0"), @@ -499,10 +500,10 @@ static void print_usage(void) { printf("tor -f [args]\n" - "See man page for more options. This -h is probably obsolete.\n\n" + "See man page for more options. This -h is obsolete.\n"); +#if 0 "-b \t\tbytes/second rate limiting\n" "-d \t\tDebug file\n" -// "-m \t\tMax number of connections\n" "-l \t\tLog level\n" "-r \t\tList of known routers\n"); printf("\nClient options:\n" @@ -512,6 +513,7 @@ print_usage(void) "-n \t\tNickname of router\n" "-o \t\tOR port to bind to\n" "-p \t\tPID file\n"); +#endif } /** @@ -810,7 +812,7 @@ getconfig(int argc, char **argv, or_options_t *options) options->command = CMD_LIST_FINGERPRINT; } else if (!strcmp(argv[i],"--hash-password")) { options->command = CMD_HASH_PASSWORD; - options->command_arg = tor_strdup(argv[i+1]); + options->command_arg = tor_strdup( (i < argc-1) ? argv[i+1] : ""); ++i; } @@ -932,6 +934,11 @@ getconfig(int argc, char **argv, or_options_t *options) result = -1; } + if (options->ControlPort < 0 || options->ControlPort > 65535) { + log(LOG_WARN, "ControlPort option out of bounds."); + result = -1; + } + if (options->DirPort < 0 || options->DirPort > 65535) { log(LOG_WARN, "DirPort option out of bounds."); result = -1; diff --git a/src/or/connection.c b/src/or/connection.c index c996d63841..809e115733 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -471,7 +471,7 @@ static int connection_init_accepted_conn(connection_t *conn) { conn->state = DIR_CONN_STATE_SERVER_COMMAND_WAIT; break; case CONN_TYPE_CONTROL: - /* XXXX009 NM control */ + conn->state = CONTROL_CONN_STATE_NEEDAUTH; break; } return 0; @@ -651,7 +651,9 @@ int retry_all_listeners(int force) { if (retry_listeners(CONN_TYPE_AP_LISTENER, options.SocksBindAddress, options.SocksPort, "127.0.0.1", force)<0) return -1; - /* XXXX009 control NM */ + if (retry_listeners(CONN_TYPE_CONTROL_LISTENER, NULL, + options.ControlPort, "127.0.0.1", force)<0) + return -1; return 0; } diff --git a/src/or/or.h b/src/or/or.h index 648a188975..a84915807b 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -903,6 +903,7 @@ typedef struct { * length (alpha in geometric distribution). */ int ORPort; /**< Port to listen on for OR connections. */ int SocksPort; /**< Port to listen on for SOCKS connections. */ + int ControlPort; /**< Port to listen on for control connections. */ int DirPort; /**< Port to listen on for directory connections. */ int AuthoritativeDir; /**< Boolean: is this an authoritative directory? */ int ClientOnly; /**< Boolean: should we never evolve into a server role? */