Commit 347d3f9d authored by Nick Mathewson's avatar Nick Mathewson 🐚
Browse files

Start implementing control interface.


svn:r2652
parent d63d4209
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ N - Windows installer
   - Review website; make important info more prominent.

Beyond 0.0.9:
   - Check getrlimit(RLIMIT_[N]OFILE), sysconf(OPEN_MAX) on start-up, and
   o Check getrlimit(RLIMIT_[N]OFILE), sysconf(OPEN_MAX) on start-up, and
     warn if we're running as a server with a low limit.
   - Implement If-Modified-Since for directories.
N  - Handle rendezvousing with unverified nodes.
+3 −1
Original line number Diff line number Diff line
@@ -59,6 +59,8 @@ the message.
        0x0005 Unauthorized user
        0x0006 Failed authentication attempt

  The rest of the body should be a human-readable description of the error.

3.2. DONE (Type 0x0001)

  Sent from server to client in response to a request that was successfully
@@ -76,7 +78,7 @@ the message.

  Request the value of a configuration variable.  The body contains a
  nul-terminated string for a configuration key.  The server replies with a
  CONFVALUE message 
  CONFVALUE message.

3.5. CONFVALUE (Type 0x0004)

+2 −2
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ bin_PROGRAMS = tor

tor_SOURCES = buffers.c circuitbuild.c circuitlist.c \
	circuituse.c command.c config.c \
	connection.c connection_edge.c connection_or.c \
	connection.c connection_edge.c connection_or.c control.c \
	cpuworker.c directory.c dirserv.c dns.c hibernate.c main.c \
	onion.c relay.c rendcommon.c rendclient.c rendmid.c \
	rendservice.c rephist.c router.c routerlist.c routerparse.c \
@@ -16,7 +16,7 @@ tor_LDADD = ../common/libor.a ../common/libor-crypto.a -lz -lssl -lcrypto

test_SOURCES = buffers.c circuitbuild.c circuitlist.c \
	circuituse.c command.c config.c \
	connection.c connection_edge.c connection_or.c \
	connection.c connection_edge.c connection_or.c control.c \
	cpuworker.c directory.c dirserv.c dns.c hibernate.c main.c \
	onion.c relay.c rendcommon.c rendclient.c rendmid.c \
	rendservice.c rephist.c router.c routerlist.c routerparse.c \
+32 −0
Original line number Diff line number Diff line
@@ -636,6 +636,38 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) {
  }
}

/* DOCDOC: 1 if complete, 0 if pending, -1 on error. */
int fetch_from_buf_control(buf_t *buf, uint16_t *len_out, uint16_t *type_out,
                           char **body_out)
{
  uint16_t len;

  tor_assert(buf);
  tor_assert(len_out);
  tor_assert(type_out);
  tor_assert(body_out);

  if (buf->datalen < 4)
    return 0;

  len = ntohs(get_uint16(buf->mem));
  if (buf->datalen < 4 + (unsigned)len)
    return 0;

  *len_out = len;
  *type_out = ntohs(get_uint16(buf->mem+2));
  if (len) {
    *body_out = tor_malloc(len);
    memcpy(*body_out, buf->mem+4, len);
  } else {
    *body_out = NULL;
  }

  buf_remove_from_front(buf, 4+len);

  return 1;
}

/** Log an error and exit if <b>buf</b> is corrupted.
 */
void assert_buf_ok(buf_t *buf)
+31 −6
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ const char *conn_type_to_string[] = {
  "Dir",         /* 9 */
  "DNS worker",  /* 10 */
  "CPU worker",  /* 11 */
  "Control listener", /* 12 */
  "Control",     /* 13 */
};

/** Array of string arrays to make {conn-\>type,conn-\>state} human-readable. */
@@ -70,6 +72,10 @@ const char *conn_state_to_string[][_CONN_TYPE_MAX+1] = {
    "idle",                            /* 1 */
    "busy with onion",                 /* 2 */
    "busy with handshake" },           /* 3 */
  { "ready" }, /* control listener, 0 */
  { "",                       /* control, 0 */
    "ready",                           /* 1 */
    "waiting for authentication", },   /* 2 */
};

/********* END VARIABLES ************/
@@ -459,6 +465,9 @@ static int connection_init_accepted_conn(connection_t *conn) {
      conn->purpose = DIR_PURPOSE_SERVER;
      conn->state = DIR_CONN_STATE_SERVER_COMMAND_WAIT;
      break;
    case CONN_TYPE_CONTROL:
      /* XXXX009 NM control */
      break;
  }
  return 0;
}
@@ -543,7 +552,8 @@ static void listener_close_if_present(int type) {
  int i,n;
  tor_assert(type == CONN_TYPE_OR_LISTENER ||
             type == CONN_TYPE_AP_LISTENER ||
             type == CONN_TYPE_DIR_LISTENER);
             type == CONN_TYPE_DIR_LISTENER ||
             type == CONN_TYPE_CONTROL_LISTENER);
  get_connection_array(&carray,&n);
  for(i=0;i<n;i++) {
    conn = carray[i];
@@ -636,6 +646,7 @@ 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 */

  return 0;
}
@@ -787,6 +798,8 @@ int connection_handle_read(connection_t *conn) {
      return connection_handle_listener_read(conn, CONN_TYPE_AP);
    case CONN_TYPE_DIR_LISTENER:
      return connection_handle_listener_read(conn, CONN_TYPE_DIR);
    case CONN_TYPE_CONTROL_LISTENER:
      return connection_handle_listener_read(conn, CONN_TYPE_CONTROL);
  }

  if(connection_read_to_buf(conn) < 0) {
@@ -1151,7 +1164,8 @@ connection_t *connection_get_by_type_rendquery(int type, const char *rendquery)
int connection_is_listener(connection_t *conn) {
  if(conn->type == CONN_TYPE_OR_LISTENER ||
     conn->type == CONN_TYPE_AP_LISTENER ||
     conn->type == CONN_TYPE_DIR_LISTENER)
     conn->type == CONN_TYPE_DIR_LISTENER ||
     conn->type == CONN_TYPE_CONTROL_LISTENER)
    return 1;
  return 0;
}
@@ -1167,7 +1181,8 @@ int connection_state_is_open(connection_t *conn) {

  if((conn->type == CONN_TYPE_OR && conn->state == OR_CONN_STATE_OPEN) ||
     (conn->type == CONN_TYPE_AP && conn->state == AP_CONN_STATE_OPEN) ||
     (conn->type == CONN_TYPE_EXIT && conn->state == EXIT_CONN_STATE_OPEN))
     (conn->type == CONN_TYPE_EXIT && conn->state == EXIT_CONN_STATE_OPEN) ||
     (conn->type == CONN_TYPE_CONTROL && conn->state ==CONTROL_CONN_STATE_OPEN))
    return 1;

  return 0;
@@ -1232,6 +1247,8 @@ static int connection_process_inbuf(connection_t *conn) {
      return connection_dns_process_inbuf(conn);
    case CONN_TYPE_CPUWORKER:
      return connection_cpu_process_inbuf(conn);
    case CONN_TYPE_CONTROL:
      return connection_control_process_inbuf(conn);
    default:
      log_fn(LOG_WARN,"got unexpected conn->type %d.", conn->type);
      return -1;
@@ -1262,6 +1279,8 @@ static int connection_finished_flushing(connection_t *conn) {
      return connection_dns_finished_flushing(conn);
    case CONN_TYPE_CPUWORKER:
      return connection_cpu_finished_flushing(conn);
    case CONN_TYPE_CONTROL:
      return connection_control_finished_flushing(conn);
    default:
      log_fn(LOG_WARN,"got unexpected conn->type %d.", conn->type);
      return -1;
@@ -1384,6 +1403,7 @@ void assert_connection_ok(connection_t *conn, time_t now)
    case CONN_TYPE_OR_LISTENER:
    case CONN_TYPE_AP_LISTENER:
    case CONN_TYPE_DIR_LISTENER:
    case CONN_TYPE_CONTROL_LISTENER:
      tor_assert(conn->state == LISTENER_STATE_READY);
      break;
    case CONN_TYPE_OR:
@@ -1413,6 +1433,11 @@ void assert_connection_ok(connection_t *conn, time_t now)
      tor_assert(conn->state >= _CPUWORKER_STATE_MIN);
      tor_assert(conn->state <= _CPUWORKER_STATE_MAX);
      break;
    case CONN_TYPE_CONTROL:
      tor_assert(conn->state >= _CONTROL_CONN_STATE_MIN);
      tor_assert(conn->state <= _CONTROL_CONN_STATE_MAX);
      /* XXXX009 NM */
      break;
    default:
      tor_assert(0);
  }
Loading