aboutsummaryrefslogtreecommitdiff
path: root/src/or/cpuworker.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-10-25 08:20:10 +0000
committerNick Mathewson <nickm@torproject.org>2005-10-25 08:20:10 +0000
commite7e170a59ec8db6d5dc39cfbff193a107ac78220 (patch)
treeac0142e44e5dd186732037686405b17228377b3c /src/or/cpuworker.c
parent932106f54c35b815756d518b236448b9884d6bde (diff)
downloadtor-e7e170a59ec8db6d5dc39cfbff193a107ac78220.tar
tor-e7e170a59ec8db6d5dc39cfbff193a107ac78220.tar.gz
Change more files to new loggin interface. 3 left.
svn:r5310
Diffstat (limited to 'src/or/cpuworker.c')
-rw-r--r--src/or/cpuworker.c50
1 files changed, 26 insertions, 24 deletions
diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c
index a6ef430e6..a6bb9d932 100644
--- a/src/or/cpuworker.c
+++ b/src/or/cpuworker.c
@@ -13,6 +13,7 @@ const char cpuworker_c_id[] = "$Id$";
* Right now, we only use this for processing onionskins.
**/
+#define NEW_LOG_INTERFACE
#include "or.h"
/** The maximum number of cpuworker processes we will keep around. */
@@ -83,7 +84,7 @@ tag_unpack(const char *tag, uint32_t *addr, uint16_t *port, uint16_t *circ_id)
in.s_addr = htonl(*addr);
tor_inet_ntoa(&in, addrbuf, sizeof(addrbuf));
- log_fn(LOG_DEBUG,"onion was from %s:%d, circ_id %d.", addrbuf, *port, *circ_id);
+ debug(LD_OR,"onion was from %s:%d, circ_id %d.", addrbuf, *port, *circ_id);
}
/** Called when the onion key has changed and we need to spawn new
@@ -109,12 +110,12 @@ cpuworkers_rotate(void)
int
connection_cpu_reached_eof(connection_t *conn)
{
- log_fn(LOG_WARN,"Read eof. Worker died unexpectedly.");
+ warn(LD_GENERAL,"Read eof. Worker died unexpectedly.");
if (conn->state != CPUWORKER_STATE_IDLE) {
/* the circ associated with this cpuworker will have to wait until
* it gets culled in run_connection_housekeeping(), since we have
* no way to find out which circ it was. */
- log_fn(LOG_WARN,"...and it left a circuit queued; abandoning circ.");
+ warn(LD_GENERAL,"...and it left a circuit queued; abandoning circ.");
num_cpuworkers_busy--;
}
num_cpuworkers--;
@@ -163,22 +164,23 @@ connection_cpu_process_inbuf(connection_t *conn)
circ = circuit_get_by_circid_orconn(circ_id, p_conn);
if (success == 0) {
- log_fn(LOG_DEBUG,"decoding onionskin failed. Closing.");
+ debug(LD_OR,"decoding onionskin failed. (Old key or bad sw.) Closing.");
if (circ)
circuit_mark_for_close(circ);
goto done_processing;
}
if (!circ) {
- log_fn(LOG_INFO,"processed onion for a circ that's gone. Dropping.");
+ /*XXXX Why does this happen?*/
+ debug(LD_OR,"processed onion for a circ that's gone. Dropping.");
goto done_processing;
}
tor_assert(circ->p_conn);
if (onionskin_answer(circ, CELL_CREATED, buf+TAG_LEN, buf+TAG_LEN+ONIONSKIN_REPLY_LEN) < 0) {
- log_fn(LOG_WARN,"onionskin_answer failed. Closing.");
+ warn(LD_OR,"onionskin_answer failed. Closing.");
circuit_mark_for_close(circ);
goto done_processing;
}
- log_fn(LOG_DEBUG,"onionskin_answer succeeded. Yay.");
+ debug(LD_OR,"onionskin_answer succeeded. Yay.");
} else {
tor_assert(0); /* don't ask me to do handshakes yet */
}
@@ -243,22 +245,22 @@ cpuworker_main(void *data)
if ((r = recv(fd, &question_type, 1, 0)) != 1) {
// log_fn(LOG_ERR,"read type failed. Exiting.");
if (r == 0) {
- log_fn(LOG_INFO,"CPU worker exiting because Tor process closed connection (either rotated keys or died).");
+ info(LD_OR,"CPU worker exiting because Tor process closed connection (either rotated keys or died).");
} else {
- log_fn(LOG_INFO,"CPU worker editing because of error on connection to Tor process.");
- log_fn(LOG_INFO,"(Error on %d was %s)", fd, tor_socket_strerror(tor_socket_errno(fd)));
+ info(LD_OR,"CPU worker editing because of error on connection to Tor process.");
+ info(LD_OR,"(Error on %d was %s)", fd, tor_socket_strerror(tor_socket_errno(fd)));
}
goto end;
}
tor_assert(question_type == CPUWORKER_TASK_ONION);
if (read_all(fd, tag, TAG_LEN, 1) != TAG_LEN) {
- log_fn(LOG_ERR,"read tag failed. Exiting.");
+ err(LD_BUG,"read tag failed. Exiting.");
goto end;
}
if (read_all(fd, question, ONIONSKIN_CHALLENGE_LEN, 1) != ONIONSKIN_CHALLENGE_LEN) {
- log_fn(LOG_ERR,"read question failed. Exiting.");
+ info(LD_BUG,"read question failed. Exiting.");
goto end;
}
@@ -266,21 +268,21 @@ cpuworker_main(void *data)
if (onion_skin_server_handshake(question, onion_key, last_onion_key,
reply_to_proxy, keys, CPATH_KEY_MATERIAL_LEN) < 0) {
/* failure */
- log_fn(LOG_DEBUG,"onion_skin_server_handshake failed.");
+ debug(LD_OR,"onion_skin_server_handshake failed.");
memset(buf,0,LEN_ONION_RESPONSE); /* send all zeros for failure */
} else {
/* success */
- log_fn(LOG_DEBUG,"onion_skin_server_handshake succeeded.");
+ debug(LD_OR,"onion_skin_server_handshake succeeded.");
buf[0] = 1; /* 1 means success */
memcpy(buf+1,tag,TAG_LEN);
memcpy(buf+1+TAG_LEN,reply_to_proxy,ONIONSKIN_REPLY_LEN);
memcpy(buf+1+TAG_LEN+ONIONSKIN_REPLY_LEN,keys,CPATH_KEY_MATERIAL_LEN);
}
if (write_all(fd, buf, LEN_ONION_RESPONSE, 1) != LEN_ONION_RESPONSE) {
- log_fn(LOG_ERR,"writing response buf failed. Exiting.");
+ err(LD_BUG,"writing response buf failed. Exiting.");
goto end;
}
- log_fn(LOG_DEBUG,"finished writing response.");
+ debug(LD_OR,"finished writing response.");
}
}
end:
@@ -305,14 +307,14 @@ spawn_cpuworker(void)
fdarray = tor_malloc(sizeof(int)*2);
if ((err = tor_socketpair(AF_UNIX, SOCK_STREAM, 0, fdarray)) < 0) {
- log(LOG_WARN, "Couldn't construct socketpair: %s", tor_socket_strerror(-err));
+ warn(LD_NET, "Couldn't construct socketpair: %s", tor_socket_strerror(-err));
tor_free(fdarray);
return -1;
}
fd = fdarray[0];
spawn_func(cpuworker_main, (void*)fdarray);
- log_fn(LOG_DEBUG,"just spawned a worker.");
+ debug(LD_OR,"just spawned a worker.");
#ifndef TOR_IS_MULTITHREADED
tor_close_socket(fdarray[1]); /* we don't need the worker's side of the pipe */
tor_free(fdarray);
@@ -327,7 +329,7 @@ spawn_cpuworker(void)
conn->address = tor_strdup("localhost");
if (connection_add(conn) < 0) { /* no space, forget it */
- log_fn(LOG_WARN,"connection_add failed. Giving up.");
+ warn(LD_NET,"connection_add failed. Giving up.");
connection_free(conn); /* this closes fd */
return -1;
}
@@ -353,7 +355,7 @@ spawn_enough_cpuworkers(void)
while (num_cpuworkers < num_cpuworkers_needed) {
if (spawn_cpuworker() < 0) {
- log_fn(LOG_WARN,"Spawn failed. Will try again later.");
+ warn(LD_GENERAL,"Spawn failed. Will try again later.");
return;
}
num_cpuworkers++;
@@ -374,7 +376,7 @@ process_pending_task(connection_t *cpuworker)
if (!circ)
return;
if (assign_to_cpuworker(cpuworker, CPUWORKER_TASK_ONION, circ) < 0)
- log_fn(LOG_WARN,"assign_to_cpuworker failed. Ignoring.");
+ warn(LD_OR,"assign_to_cpuworker failed. Ignoring.");
}
#define CPUWORKER_BUSY_TIMEOUT 3600 /* seconds */
@@ -398,7 +400,7 @@ cull_wedged_cpuworkers(void)
conn->type == CONN_TYPE_CPUWORKER &&
conn->state == CPUWORKER_STATE_BUSY_ONION &&
conn->timestamp_lastwritten + CPUWORKER_BUSY_TIMEOUT < now) {
- log_fn(LOG_NOTICE,"Bug: closing wedged cpuworker. Can somebody find the bug?");
+ notice(LD_BUG,"Bug: closing wedged cpuworker. Can somebody find the bug?");
num_cpuworkers_busy--;
num_cpuworkers--;
connection_mark_for_close(conn);
@@ -428,7 +430,7 @@ assign_to_cpuworker(connection_t *cpuworker, uint8_t question_type,
circ = task;
if (num_cpuworkers_busy == num_cpuworkers) {
- log_fn(LOG_DEBUG,"No idle cpuworkers. Queuing.");
+ debug(LD_OR,"No idle cpuworkers. Queuing.");
if (onion_pending_add(circ) < 0)
return -1;
return 0;
@@ -440,7 +442,7 @@ assign_to_cpuworker(connection_t *cpuworker, uint8_t question_type,
tor_assert(cpuworker);
if (!circ->p_conn) {
- log_fn(LOG_INFO,"circ->p_conn gone. Failing circ.");
+ info(LD_OR,"circ->p_conn gone. Failing circ.");
return -1;
}
tag_pack(tag, circ->p_conn->addr, circ->p_conn->port, circ->p_circ_id);