Commit 36484f87 authored by Roger Dingledine's avatar Roger Dingledine
Browse files

convert some more source files to the new log convention


svn:r6002
parent 7d80921a
Loading
Loading
Loading
Loading
+93 −85
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ buf_normalize(buf_t *buf)
  } else {
    char *newmem, *oldmem;
    size_t sz = (buf->mem+buf->len)-buf->cur;
    warn(LD_BUG, "Unexpected non-normalized buffer.");
    log_warn(LD_BUG, "Unexpected non-normalized buffer.");
    newmem = GUARDED_MEM(tor_malloc(ALLOC_LEN(buf->len)));
    SET_GUARDS(newmem, buf->len);
    memcpy(newmem, buf->cur, sz);
@@ -262,7 +262,7 @@ buf_ensure_capacity(buf_t *buf, size_t capacity)
  while (new_len < capacity)
    new_len *= 2;
  /* Resize the buffer. */
  debug(LD_MM,"Growing buffer from %d to %d bytes.",
  log_debug(LD_MM,"Growing buffer from %d to %d bytes.",
            (int)buf->len, (int)new_len);
  buf_resize(buf,new_len);
  return 0;
@@ -287,7 +287,7 @@ buf_shrink(buf_t *buf)
  if (new_len == buf->len)
    return;

  debug(LD_MM,"Shrinking buffer from %d to %d bytes.",
  log_debug(LD_MM,"Shrinking buffer from %d to %d bytes.",
            (int)buf->len, (int)new_len);
  buf_resize(buf, new_len);
}
@@ -407,7 +407,7 @@ read_to_buf_impl(int s, size_t at_most, buf_t *buf,
    }
    return 0; /* would block. */
  } else if (read_result == 0) {
    debug(LD_NET,"Encountered eof");
    log_debug(LD_NET,"Encountered eof");
    *reached_eof = 1;
    return 0;
  } else { /* we read some bytes */
@@ -415,7 +415,7 @@ read_to_buf_impl(int s, size_t at_most, buf_t *buf,
    buf_total_used += read_result;
    if (buf->datalen > buf->highwater)
      buf->highwater = buf->datalen;
    debug(LD_NET,"Read %d bytes. %d on inbuf.",read_result,
    log_debug(LD_NET,"Read %d bytes. %d on inbuf.",read_result,
              (int)buf->datalen);
    return read_result;
  }
@@ -481,7 +481,7 @@ read_to_buf_tls_impl(tor_tls_t *tls, size_t at_most, buf_t *buf, char *next)
{
  int r;

  debug(LD_NET,"before: %d on buf, %d pending, at_most %d.",
  log_debug(LD_NET,"before: %d on buf, %d pending, at_most %d.",
            (int)buf_datalen(buf), (int)tor_tls_get_pending_bytes(tls),
            (int)at_most);
  r = tor_tls_read(tls, next, at_most);
@@ -491,7 +491,7 @@ read_to_buf_tls_impl(tor_tls_t *tls, size_t at_most, buf_t *buf, char *next)
  buf_total_used += r;
  if (buf->datalen > buf->highwater)
    buf->highwater = buf->datalen;
  debug(LD_NET,"Read %d bytes. %d on inbuf; %d pending",r,
  log_debug(LD_NET,"Read %d bytes. %d on inbuf; %d pending",r,
            (int)buf->datalen,(int)tor_tls_get_pending_bytes(tls));
  return r;
}
@@ -525,7 +525,7 @@ read_to_buf_tls(tor_tls_t *tls, size_t at_most, buf_t *buf)
  tor_assert(tls);
  assert_buf_ok(buf);

  debug(LD_NET,"start: %d on buf, %d pending, at_most %d.",
  log_debug(LD_NET,"start: %d on buf, %d pending, at_most %d.",
            (int)buf_datalen(buf), (int)tor_tls_get_pending_bytes(tls),
            (int)at_most);

@@ -575,7 +575,7 @@ flush_buf_impl(int s, buf_t *buf, size_t sz, size_t *buf_flushlen)
    if (!ERRNO_IS_EAGAIN(e)) { /* it's a real error */
      return -1;
    }
    debug(LD_NET,"write() would block, returning.");
    log_debug(LD_NET,"write() would block, returning.");
    return 0;
  } else {
    *buf_flushlen -= write_result;
@@ -612,7 +612,7 @@ flush_buf(int s, buf_t *buf, size_t sz, size_t *buf_flushlen)
  r = flush_buf_impl(s, buf, flushlen0, buf_flushlen);
  check();

  debug(LD_NET,"%d: flushed %d bytes, %d ready to flush, %d remain.",
  log_debug(LD_NET,"%d: flushed %d bytes, %d ready to flush, %d remain.",
            s,r,(int)*buf_flushlen,(int)buf->datalen);
  if (r < 0 || (size_t)r < flushlen0)
    return r; /* Error, or can't flush any more now. */
@@ -622,7 +622,7 @@ flush_buf(int s, buf_t *buf, size_t sz, size_t *buf_flushlen)
    tor_assert(buf->cur == buf->mem);
    r = flush_buf_impl(s, buf, flushlen1, buf_flushlen);
    check();
    debug(LD_NET,"%d: flushed %d bytes, %d ready to flush, %d remain.",
    log_debug(LD_NET,"%d: flushed %d bytes, %d ready to flush, %d remain.",
              s,r,(int)*buf_flushlen,(int)buf->datalen);
    if (r<0)
      return r;
@@ -647,7 +647,7 @@ flush_buf_tls_impl(tor_tls_t *tls, buf_t *buf, size_t sz, size_t *buf_flushlen)
  }
  *buf_flushlen -= r;
  buf_remove_from_front(buf, r);
  debug(LD_NET,"flushed %d bytes, %d ready to flush, %d remain.",
  log_debug(LD_NET,"flushed %d bytes, %d ready to flush, %d remain.",
            r,(int)*buf_flushlen,(int)buf->datalen);
  return r;
}
@@ -709,7 +709,7 @@ write_to_buf(const char *string, size_t string_len, buf_t *buf)
  /* assert_buf_ok(buf); */

  if (buf_ensure_capacity(buf, buf->datalen+string_len)) {
    warn(LD_MM, "buflen too small, can't hold %d bytes.",
    log_warn(LD_MM, "buflen too small, can't hold %d bytes.",
             (int)(buf->datalen+string_len));
    return -1;
  }
@@ -729,7 +729,7 @@ write_to_buf(const char *string, size_t string_len, buf_t *buf)
  }
  if (buf->datalen > buf->highwater)
    buf->highwater = buf->datalen;
  debug(LD_NET,"added %d bytes to buf (now %d total).",
  log_debug(LD_NET,"added %d bytes to buf (now %d total).",
            (int)string_len, (int)buf->datalen);
  check();
  return buf->datalen;
@@ -812,27 +812,27 @@ fetch_from_buf_http(buf_t *buf,
  buf_normalize(buf);

  if (buf_nul_terminate(buf)<0) {
    warn(LD_BUG,"Couldn't nul-terminate buffer");
    log_warn(LD_BUG,"Couldn't nul-terminate buffer");
    return -1;
  }
  headers = buf->cur;
  body = strstr(headers,"\r\n\r\n");
  if (!body) {
    debug(LD_HTTP,"headers not all here yet.");
    log_debug(LD_HTTP,"headers not all here yet.");
    return 0;
  }
  body += 4; /* Skip the the CRLFCRLF */
  headerlen = body-headers; /* includes the CRLFCRLF */
  bodylen = buf->datalen - headerlen;
  debug(LD_HTTP,"headerlen %d, bodylen %d.", (int)headerlen, (int)bodylen);
  log_debug(LD_HTTP,"headerlen %d, bodylen %d.", (int)headerlen, (int)bodylen);

  if (max_headerlen <= headerlen) {
    warn(LD_HTTP,"headerlen %d larger than %d. Failing.",
    log_warn(LD_HTTP,"headerlen %d larger than %d. Failing.",
             (int)headerlen, (int)max_headerlen-1);
    return -1;
  }
  if (max_bodylen <= bodylen) {
    warn(LD_HTTP,"bodylen %d larger than %d. Failing.",
    log_warn(LD_HTTP,"bodylen %d larger than %d. Failing.",
             (int)bodylen, (int)max_bodylen-1);
    return -1;
  }
@@ -843,22 +843,22 @@ fetch_from_buf_http(buf_t *buf,
    int i;
    i = atoi(p+strlen(CONTENT_LENGTH));
    if (i < 0) {
      warn(LD_PROTOCOL, "Content-Length is less than zero; it looks like "
      log_warn(LD_PROTOCOL, "Content-Length is less than zero; it looks like "
               "someone is trying to crash us.");
      return -1;
    }
    contentlen = i;
    /* if content-length is malformed, then our body length is 0. fine. */
    debug(LD_HTTP,"Got a contentlen of %d.",(int)contentlen);
    log_debug(LD_HTTP,"Got a contentlen of %d.",(int)contentlen);
    if (bodylen < contentlen) {
      if (!force_complete) {
        debug(LD_HTTP,"body not all here yet.");
        log_debug(LD_HTTP,"body not all here yet.");
        return 0; /* not all there yet */
      }
    }
    if (bodylen > contentlen) {
      bodylen = contentlen;
      debug(LD_HTTP,"bodylen reduced to %d.",(int)bodylen);
      log_debug(LD_HTTP,"bodylen reduced to %d.",(int)bodylen);
    }
  }
  /* all happy. copy into the appropriate places, and return 1 */
@@ -929,8 +929,9 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req, int log_sockstype)
        if (buf->datalen < 2u+nummethods)
          return 0;
        if (!nummethods || !memchr(buf->cur+2, 0, nummethods)) {
          warn(LD_APP,
               "socks5: offered methods don't include 'no auth'. Rejecting.");
          log_warn(LD_APP,
                   "socks5: offered methods don't include 'no auth'. "
                   "Rejecting.");
          req->replylen = 2; /* 2 bytes of response */
          req->reply[0] = 5;
          req->reply[1] = '\xFF'; /* reject all methods */
@@ -942,24 +943,24 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req, int log_sockstype)
        req->reply[0] = 5; /* socks5 reply */
        req->reply[1] = SOCKS5_SUCCEEDED;
        req->socks_version = 5; /* remember we've already negotiated auth */
        debug(LD_APP,"socks5: accepted method 0");
        log_debug(LD_APP,"socks5: accepted method 0");
        return 0;
      }
      /* we know the method; read in the request */
      debug(LD_APP,"socks5: checking request");
      log_debug(LD_APP,"socks5: checking request");
      if (buf->datalen < 8) /* basic info plus >=2 for addr plus 2 for port */
        return 0; /* not yet */
      req->command = (unsigned char) *(buf->cur+1);
      if (req->command != SOCKS_COMMAND_CONNECT &&
          req->command != SOCKS_COMMAND_RESOLVE) {
        /* not a connect or resolve? we don't support it. */
        warn(LD_APP,"socks5: command %d not recognized. Rejecting.",
        log_warn(LD_APP,"socks5: command %d not recognized. Rejecting.",
                 req->command);
        return -1;
      }
      switch (*(buf->cur+3)) { /* address type */
        case 1: /* IPv4 address */
          debug(LD_APP,"socks5: ipv4 address type");
          log_debug(LD_APP,"socks5: ipv4 address type");
          if (buf->datalen < 10) /* ip/port there? */
            return 0; /* not yet */

@@ -967,8 +968,9 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req, int log_sockstype)
          in.s_addr = htonl(destip);
          tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
          if (strlen(tmpbuf)+1 > MAX_SOCKS_ADDR_LEN) {
            warn(LD_APP,
               "socks5 IP takes %d bytes, which doesn't fit in %d. Rejecting.",
            log_warn(LD_APP,
                     "socks5 IP takes %d bytes, which doesn't fit in %d. "
                     "Rejecting.",
                     (int)strlen(tmpbuf)+1,(int)MAX_SOCKS_ADDR_LEN);
            return -1;
          }
@@ -977,7 +979,8 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req, int log_sockstype)
          buf_remove_from_front(buf, 10);
          if (!address_is_in_virtual_range(req->address) &&
              !have_warned_about_unsafe_socks) {
            warn(LD_APP,"Your application (using socks5 on port %d) is giving "
            log_warn(LD_APP,
                "Your application (using socks5 on port %d) is giving "
                "Tor only an IP address. Applications that do DNS resolves "
                "themselves may leak information. Consider using Socks4A "
                "(e.g. via privoxy or socat) instead.  For more information, "
@@ -987,12 +990,13 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req, int log_sockstype)
          }
          return 1;
        case 3: /* fqdn */
          debug(LD_APP,"socks5: fqdn address type");
          log_debug(LD_APP,"socks5: fqdn address type");
          len = (unsigned char)*(buf->cur+4);
          if (buf->datalen < 7u+len) /* addr/port there? */
            return 0; /* not yet */
          if (len+1 > MAX_SOCKS_ADDR_LEN) {
            warn(LD_APP, "socks5 hostname is %d bytes, which doesn't fit in "
            log_warn(LD_APP,
                     "socks5 hostname is %d bytes, which doesn't fit in "
                     "%d. Rejecting.", len+1,MAX_SOCKS_ADDR_LEN);
            return -1;
          }
@@ -1001,12 +1005,13 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req, int log_sockstype)
          req->port = ntohs(get_uint16(buf->cur+5+len));
          buf_remove_from_front(buf, 5+len+2);
          if (log_sockstype)
            notice(LD_APP, "Your application (using socks5 on port %d) gave "
            log_notice(LD_APP,
                  "Your application (using socks5 on port %d) gave "
                  "Tor a hostname, which means Tor will do the DNS resolve "
                  "for you. This is good.", req->port);
          return 1;
        default: /* unsupported */
          warn(LD_APP,"socks5: unsupported address type %d. Rejecting.",
          log_warn(LD_APP,"socks5: unsupported address type %d. Rejecting.",
                   *(buf->cur+3));
          return -1;
      }
@@ -1023,7 +1028,7 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req, int log_sockstype)
      if (req->command != SOCKS_COMMAND_CONNECT &&
          req->command != SOCKS_COMMAND_RESOLVE) {
        /* not a connect or resolve? we don't support it. */
        warn(LD_APP,"socks4: command %d not recognized. Rejecting.",
        log_warn(LD_APP,"socks4: command %d not recognized. Rejecting.",
                 req->command);
        return -1;
      }
@@ -1031,26 +1036,27 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req, int log_sockstype)
      req->port = ntohs(*(uint16_t*)(buf->cur+2));
      destip = ntohl(*(uint32_t*)(buf->mem+4));
      if ((!req->port && req->command!=SOCKS_COMMAND_RESOLVE) || !destip) {
        warn(LD_APP,"socks4: Port or DestIP is zero. Rejecting.");
        log_warn(LD_APP,"socks4: Port or DestIP is zero. Rejecting.");
        return -1;
      }
      if (destip >> 8) {
        debug(LD_APP,"socks4: destip not in form 0.0.0.x.");
        log_debug(LD_APP,"socks4: destip not in form 0.0.0.x.");
        in.s_addr = htonl(destip);
        tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
        if (strlen(tmpbuf)+1 > MAX_SOCKS_ADDR_LEN) {
          debug(LD_APP,"socks4 addr (%d bytes) too long. Rejecting.",
          log_debug(LD_APP,"socks4 addr (%d bytes) too long. Rejecting.",
                    (int)strlen(tmpbuf));
          return -1;
        }
        debug(LD_APP,"socks4: successfully read destip (%s)",safe_str(tmpbuf));
        log_debug(LD_APP,
                  "socks4: successfully read destip (%s)",safe_str(tmpbuf));
        socks4_prot = socks4;
      }

      next = memchr(buf->cur+SOCKS4_NETWORK_LEN, 0,
                    buf->datalen-SOCKS4_NETWORK_LEN);
      if (!next) {
        debug(LD_APP,"socks4: Username not here yet.");
        log_debug(LD_APP,"socks4: Username not here yet.");
        return 0;
      }
      tor_assert(next < buf->cur+buf->datalen);
@@ -1059,34 +1065,36 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req, int log_sockstype)
      if (socks4_prot != socks4a &&
          !address_is_in_virtual_range(tmpbuf) &&
          !have_warned_about_unsafe_socks) {
        warn(LD_APP,"Your application (using socks4 on port %d) is giving Tor "
        log_warn(LD_APP,
                 "Your application (using socks4 on port %d) is giving Tor "
                 "only an IP address. Applications that do DNS resolves "
             "themselves may leak information. Consider using Socks4A (e.g. "
             "via privoxy or socat) instead.", req->port);
                 "themselves may leak information. Consider using Socks4A "
                 "(e.g. via privoxy or socat) instead.", req->port);
//      have_warned_about_unsafe_socks = 1; // (for now, warn every time)
      }
      if (socks4_prot == socks4a) {
        if (next+1 == buf->cur+buf->datalen) {
          debug(LD_APP,"socks4: No part of destaddr here yet.");
          log_debug(LD_APP,"socks4: No part of destaddr here yet.");
          return 0;
        }
        startaddr = next+1;
        next = memchr(startaddr, 0, buf->cur+buf->datalen-startaddr);
        if (!next) {
          debug(LD_APP,"socks4: Destaddr not all here yet.");
          log_debug(LD_APP,"socks4: Destaddr not all here yet.");
          return 0;
        }
        if (MAX_SOCKS_ADDR_LEN <= next-startaddr) {
          warn(LD_APP,"socks4: Destaddr too long. Rejecting.");
          log_warn(LD_APP,"socks4: Destaddr too long. Rejecting.");
          return -1;
        }
        tor_assert(next < buf->cur+buf->datalen);
        if (log_sockstype)
          notice(LD_APP, "Your application (using socks4a on port %d) gave "
          log_notice(LD_APP,
                     "Your application (using socks4a on port %d) gave "
                     "Tor a hostname, which means Tor will do the DNS resolve "
                     "for you. This is good.", req->port);
      }
      debug(LD_APP,"socks4: Everything is here. Success.");
      log_debug(LD_APP,"socks4: Everything is here. Success.");
      strlcpy(req->address, startaddr ? startaddr : tmpbuf,
              sizeof(req->address));
      /* next points to the final \0 on inbuf */
@@ -1125,7 +1133,7 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req, int log_sockstype)
      req->replylen = strlen(req->reply)+1;
      /* fall through */
    default: /* version is not socks4 or socks5 */
      warn(LD_APP,
      log_warn(LD_APP,
               "Socks version %d not recognized. (Tor is not an http proxy.)",
               *(buf->cur));
      return -1;
+118 −112

File changed.

Preview size limit exceeded, changes collapsed.

+17 −14
Original line number Diff line number Diff line
@@ -218,7 +218,7 @@ circuit_state_to_string(int state)
    case CIRCUIT_STATE_OR_WAIT: return "connecting to server";
    case CIRCUIT_STATE_OPEN: return "open";
    default:
      warn(LD_BUG, "Bug: unknown circuit state %d", state);
      log_warn(LD_BUG, "Bug: unknown circuit state %d", state);
      tor_snprintf(buf, sizeof(buf), "unknown state [%d]", state);
      return buf;
  }
@@ -408,11 +408,13 @@ circuit_get_by_circid_orconn_impl(uint16_t circ_id, connection_t *conn)
    circuit_t *circ;
    for (circ=global_circuitlist;circ;circ = circ->next) {
      if (circ->p_conn == conn && circ->p_circ_id == circ_id) {
        warn(LD_BUG, "circuit matches p_conn, but not in hash table (Bug!)");
        log_warn(LD_BUG,
                 "circuit matches p_conn, but not in hash table (Bug!)");
        return circ;
      }
      if (circ->n_conn == conn && circ->n_circ_id == circ_id) {
        warn(LD_BUG, "circuit matches n_conn, but not in hash table (Bug!)");
        log_warn(LD_BUG,
                 "circuit matches n_conn, but not in hash table (Bug!)");
        return circ;
      }
    }
@@ -565,7 +567,8 @@ circuit_find_to_cannibalize(uint8_t purpose, extend_info_t *info,
  circuit_t *circ;
  circuit_t *best=NULL;

  debug(LD_CIRC,"Hunting for a circ to cannibalize: purpose %d, uptime %d, "
  log_debug(LD_CIRC,
            "Hunting for a circ to cannibalize: purpose %d, uptime %d, "
            "capacity %d, internal %d",
            purpose, need_uptime, need_capacity, internal);

@@ -666,7 +669,7 @@ _circuit_mark_for_close(circuit_t *circ, int reason, int line,
  }
  if (reason == END_CIRC_AT_ORIGIN) {
    if (!CIRCUIT_IS_ORIGIN(circ)) {
      warn(LD_BUG, "Specified 'at-origin' non-reason for ending circuit, "
      log_warn(LD_BUG, "Specified 'at-origin' non-reason for ending circuit, "
               "but circuit was not at origin. (called %s:%d, purpose=%d)",
               file, line, circ->purpose);
    }
@@ -677,7 +680,7 @@ _circuit_mark_for_close(circuit_t *circ, int reason, int line,
    reason = END_CIRC_REASON_NONE;
  }
  if (reason < _END_CIRC_REASON_MIN || reason > _END_CIRC_REASON_MAX) {
    warn(LD_BUG, "Reason %d out of range at %s:%d", reason, file, line);
    log_warn(LD_BUG, "Reason %d out of range at %s:%d", reason, file, line);
    reason = END_CIRC_REASON_NONE;
  }

@@ -706,7 +709,7 @@ _circuit_mark_for_close(circuit_t *circ, int reason, int line,
    tor_assert(circ->state == CIRCUIT_STATE_OPEN);
    tor_assert(circ->build_state->chosen_exit);
    /* treat this like getting a nack from it */
    info(LD_REND, "Failed intro circ %s to %s (awaiting ack). "
    log_info(LD_REND, "Failed intro circ %s to %s (awaiting ack). "
             "Removing from descriptor.",
             safe_str(circ->rend_query),
             safe_str(build_state_get_exit_nickname(circ->build_state)));
+107 −89

File changed.

Preview size limit exceeded, changes collapsed.

+33 −28
Original line number Diff line number Diff line
@@ -52,10 +52,10 @@ command_time_process_cell(cell_t *cell, connection_t *conn, int *time,
  time_passed = tv_udiff(&start, &end) ;

  if (time_passed > 10000) { /* more than 10ms */
    debug(LD_OR,"That call just took %ld ms.",time_passed/1000);
    log_debug(LD_OR,"That call just took %ld ms.",time_passed/1000);
  }
  if (time_passed < 0) {
    info(LD_GENERAL,"That call took us back in time!");
    log_info(LD_GENERAL,"That call took us back in time!");
    time_passed = 0;
  }
  *time += time_passed;
@@ -82,7 +82,8 @@ command_process_cell(cell_t *cell, connection_t *conn)

  if (now > current_second) { /* the second has rolled over */
    /* print stats */
    info(LD_OR,"At end of second: %d creates (%d ms), %d createds (%d ms), "
    log_info(LD_OR,
         "At end of second: %d creates (%d ms), %d createds (%d ms), "
         "%d relays (%d ms), %d destroys (%d ms)",
         num_create, create_time/1000,
         num_created, created_time/1000,
@@ -164,7 +165,8 @@ command_process_create_cell(cell_t *cell, connection_t *conn)
  int id_is_high;

  if (we_are_hibernating()) {
    info(LD_OR,"Received create cell but we're shutting down. Sending back "
    log_info(LD_OR,
             "Received create cell but we're shutting down. Sending back "
             "destroy.");
    connection_or_send_destroy(cell->circ_id, conn,
                               END_CIRC_REASON_HIBERNATING);
@@ -179,12 +181,12 @@ command_process_create_cell(cell_t *cell, connection_t *conn)
   */
  id_is_high = cell->circ_id & (1<<15);
  if (id_is_high && conn->circ_id_type == CIRC_ID_TYPE_HIGHER) {
    info(LD_OR, "Got a high circuit ID from %s (%d); switching to "
    log_info(LD_OR, "Got a high circuit ID from %s (%d); switching to "
             "low circuit IDs.",
             conn->nickname ? conn->nickname : "client", conn->s);
    conn->circ_id_type = CIRC_ID_TYPE_LOWER;
  } else if (!id_is_high && conn->circ_id_type == CIRC_ID_TYPE_LOWER) {
    info(LD_OR, "Got a low circuit ID from %s (%d); switching to "
    log_info(LD_OR, "Got a low circuit ID from %s (%d); switching to "
             "high circuit IDs.",
             conn->nickname ? conn->nickname : "client", conn->s);
    conn->circ_id_type = CIRC_ID_TYPE_HIGHER;
@@ -214,11 +216,11 @@ command_process_create_cell(cell_t *cell, connection_t *conn)

    /* hand it off to the cpuworkers, and then return */
    if (assign_to_cpuworker(NULL, CPUWORKER_TASK_ONION, circ) < 0) {
      warn(LD_GENERAL,"Failed to hand off onionskin. Closing.");
      log_warn(LD_GENERAL,"Failed to hand off onionskin. Closing.");
      circuit_mark_for_close(circ, END_CIRC_REASON_INTERNAL);
      return;
    }
    debug(LD_OR,"success: handed off onionskin.");
    log_debug(LD_OR,"success: handed off onionskin.");
  } else {
    /* This is a CREATE_FAST cell; we can handle it immediately without using
     * a CPU worker.*/
@@ -226,12 +228,12 @@ command_process_create_cell(cell_t *cell, connection_t *conn)
    char reply[DIGEST_LEN*2];
    tor_assert(cell->command == CELL_CREATE_FAST);
    if (fast_server_handshake(cell->payload, reply, keys, sizeof(keys))<0) {
      warn(LD_OR,"Failed to generate key material. Closing.");
      log_warn(LD_OR,"Failed to generate key material. Closing.");
      circuit_mark_for_close(circ, END_CIRC_REASON_INTERNAL);
      return;
    }
    if (onionskin_answer(circ, CELL_CREATED_FAST, reply, keys)<0) {
      warn(LD_OR,"Failed to reply to CREATE_FAST cell. Closing.");
      log_warn(LD_OR,"Failed to reply to CREATE_FAST cell. Closing.");
      circuit_mark_for_close(circ, END_CIRC_REASON_INTERNAL);
      return;
    }
@@ -254,7 +256,8 @@ command_process_created_cell(cell_t *cell, connection_t *conn)
  circ = circuit_get_by_circid_orconn(cell->circ_id, conn);

  if (!circ) {
    info(LD_OR,"(circID %d) unknown circ (probably got a destroy earlier). "
    log_info(LD_OR,
             "(circID %d) unknown circ (probably got a destroy earlier). "
             "Dropping.", cell->circ_id);
    return;
  }
@@ -267,21 +270,22 @@ command_process_created_cell(cell_t *cell, connection_t *conn)
  }

  if (CIRCUIT_IS_ORIGIN(circ)) { /* we're the OP. Handshake this. */
    debug(LD_OR,"at OP. Finishing handshake.");
    log_debug(LD_OR,"at OP. Finishing handshake.");
    if (circuit_finish_handshake(circ, cell->command, cell->payload) < 0) {
      warn(LD_OR,"circuit_finish_handshake failed.");
      log_warn(LD_OR,"circuit_finish_handshake failed.");
      circuit_mark_for_close(circ, END_CIRC_AT_ORIGIN);
      return;
    }
    debug(LD_OR,"Moving to next skin.");
    log_debug(LD_OR,"Moving to next skin.");
    if (circuit_send_next_onion_skin(circ) < 0) {
      info(LD_OR,"circuit_send_next_onion_skin failed.");
      log_info(LD_OR,"circuit_send_next_onion_skin failed.");
      /* XXX push this circuit_close lower */
      circuit_mark_for_close(circ, END_CIRC_AT_ORIGIN);
      return;
    }
  } else { /* pack it into an extended relay cell, and send it. */
    debug(LD_OR,"Converting created cell to extended relay cell, sending.");
    log_debug(LD_OR,
              "Converting created cell to extended relay cell, sending.");
    connection_edge_send_command(NULL, circ, RELAY_COMMAND_EXTENDED,
                                 cell->payload, ONIONSKIN_REPLY_LEN, NULL);
  }
@@ -300,7 +304,8 @@ command_process_relay_cell(cell_t *cell, connection_t *conn)
  circ = circuit_get_by_circid_orconn(cell->circ_id, conn);

  if (!circ) {
    debug(LD_OR,"unknown circuit %d on connection from %s:%d. Dropping.",
    log_debug(LD_OR,
              "unknown circuit %d on connection from %s:%d. Dropping.",
              cell->circ_id, conn->address, conn->port);
    return;
  }
@@ -352,11 +357,11 @@ command_process_destroy_cell(cell_t *cell, connection_t *conn)
  circ = circuit_get_by_circid_orconn(cell->circ_id, conn);
  reason = (uint8_t)cell->payload[0];
  if (!circ) {
    info(LD_OR,"unknown circuit %d on connection from %s:%d. Dropping.",
    log_info(LD_OR,"unknown circuit %d on connection from %s:%d. Dropping.",
             cell->circ_id, conn->address, conn->port);
    return;
  }
  debug(LD_OR,"Received for circID %d.",cell->circ_id);
  log_debug(LD_OR,"Received for circID %d.",cell->circ_id);

  if (cell->circ_id == circ->p_circ_id) {
    /* the destroy came from behind */
@@ -368,7 +373,7 @@ command_process_destroy_cell(cell_t *cell, connection_t *conn)
      circuit_mark_for_close(circ, reason);
    } else {
      char payload[1];
      debug(LD_OR, "Delivering 'truncated' back.");
      log_debug(LD_OR, "Delivering 'truncated' back.");
      payload[0] = (char)reason;
      connection_edge_send_command(NULL, circ, RELAY_COMMAND_TRUNCATED,
                                   payload, sizeof(payload), NULL);