summaryrefslogtreecommitdiff
path: root/src/or/dns.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-10-25 17:52:14 +0000
committerNick Mathewson <nickm@torproject.org>2005-10-25 17:52:14 +0000
commit049f6c01310006e9c30fedd46ecda44b7d1d5570 (patch)
treecaf005ba74ea6df0d52b1cd8740c080483979cb5 /src/or/dns.c
parent7a9774eff0e8f05c1adb65f90a539986d50c40bd (diff)
downloadtor-049f6c01310006e9c30fedd46ecda44b7d1d5570.tar.gz
tor-049f6c01310006e9c30fedd46ecda44b7d1d5570.zip
Switch remaining files to new log interface.
svn:r5315
Diffstat (limited to 'src/or/dns.c')
-rw-r--r--src/or/dns.c84
1 files changed, 44 insertions, 40 deletions
diff --git a/src/or/dns.c b/src/or/dns.c
index 87815c312e..2cd64acc70 100644
--- a/src/or/dns.c
+++ b/src/or/dns.c
@@ -17,6 +17,7 @@ const char dns_c_id[] = "$Id$";
* them becomes more commonly available.
*/
+#define NEW_LOG_INTERFACE
#include "or.h"
#include "tree.h"
@@ -149,14 +150,14 @@ purge_expired_resolves(uint32_t now)
*/
while (oldest_cached_resolve && (oldest_cached_resolve->expire < now)) {
resolve = oldest_cached_resolve;
- log(LOG_DEBUG,"Forgetting old cached resolve (address %s, expires %lu)",
+ debug(LD_EXIT,"Forgetting old cached resolve (address %s, expires %lu)",
safe_str(resolve->address), (unsigned long)resolve->expire);
if (resolve->state == CACHE_STATE_PENDING) {
- log_fn(LOG_WARN,"Bug: Expiring a dns resolve ('%s') that's still pending. Forgot to cull it?", safe_str(resolve->address));
+ debug(LD_EXIT,"Bug: Expiring a dns resolve ('%s') that's still pending. Forgot to cull it?", safe_str(resolve->address));
tor_fragile_assert();
}
if (resolve->pending_connections) {
- log_fn(LOG_WARN, "Closing pending connections on expiring DNS resolve!");
+ debug(LD_EXIT, "Closing pending connections on expiring DNS resolve!");
tor_fragile_assert();
while (resolve->pending_connections) {
pend = resolve->pending_connections;
@@ -283,19 +284,19 @@ dns_resolve(connection_t *exitconn)
pending_connection->conn = exitconn;
pending_connection->next = resolve->pending_connections;
resolve->pending_connections = pending_connection;
- log_fn(LOG_DEBUG,"Connection (fd %d) waiting for pending DNS resolve of '%s'",
+ debug(LD_EXIT,"Connection (fd %d) waiting for pending DNS resolve of '%s'",
exitconn->s, safe_str(exitconn->address));
exitconn->state = EXIT_CONN_STATE_RESOLVING;
return 0;
case CACHE_STATE_VALID:
exitconn->addr = resolve->addr;
- log_fn(LOG_DEBUG,"Connection (fd %d) found cached answer for '%s'",
+ debug(LD_EXIT,"Connection (fd %d) found cached answer for '%s'",
exitconn->s, safe_str(exitconn->address));
if (exitconn->purpose == EXIT_PURPOSE_RESOLVE)
send_resolved_cell(exitconn, RESOLVED_TYPE_IPV4);
return 1;
case CACHE_STATE_FAILED:
- log_fn(LOG_DEBUG,"Connection (fd %d) found cached error for '%s'",
+ debug(LD_EXIT,"Connection (fd %d) found cached error for '%s'",
exitconn->s, safe_str(exitconn->address));
if (exitconn->purpose == EXIT_PURPOSE_RESOLVE)
send_resolved_cell(exitconn, RESOLVED_TYPE_ERROR);
@@ -344,14 +345,15 @@ assign_to_dnsworker(connection_t *exitconn)
dnsconn = connection_get_by_type_state(CONN_TYPE_DNSWORKER, DNSWORKER_STATE_IDLE);
if (!dnsconn) {
- log_fn(LOG_WARN,"no idle dns workers. Failing.");
+ warn(LD_EXIT,"no idle dns workers. Failing.");
if (exitconn->purpose == EXIT_PURPOSE_RESOLVE)
send_resolved_cell(exitconn, RESOLVED_TYPE_ERROR_TRANSIENT);
goto err;
}
- log_fn(LOG_DEBUG, "Connection (fd %d) needs to resolve '%s'; assigning to DNSWorker (fd %d)",
- exitconn->s, safe_str(exitconn->address), dnsconn->s);
+ debug(LD_EXIT,
+ "Connection (fd %d) needs to resolve '%s'; assigning to DNSWorker (fd %d)",
+ exitconn->s, safe_str(exitconn->address), dnsconn->s);
tor_free(dnsconn->address);
dnsconn->address = tor_strdup(exitconn->address);
@@ -384,7 +386,8 @@ connection_dns_remove(connection_t *conn)
resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
if (!resolve) {
- log_fn(LOG_NOTICE,"Address '%s' is not pending. Dropping.", safe_str(conn->address));
+ /* XXXX RD This *is* a bug, right? -NM */
+ notice(LD_BUG,"Address '%s' is not pending. Dropping.", safe_str(conn->address));
return;
}
@@ -396,7 +399,7 @@ connection_dns_remove(connection_t *conn)
if (pend->conn == conn) {
resolve->pending_connections = pend->next;
tor_free(pend);
- log_fn(LOG_DEBUG, "First connection (fd %d) no longer waiting for resolve of '%s'",
+ debug(LD_EXIT, "First connection (fd %d) no longer waiting for resolve of '%s'",
conn->s, safe_str(conn->address));
return;
} else {
@@ -405,7 +408,7 @@ connection_dns_remove(connection_t *conn)
victim = pend->next;
pend->next = victim->next;
tor_free(victim);
- log_fn(LOG_DEBUG, "Connection (fd %d) no longer waiting for resolve of '%s'",
+ debug(LD_EXIT, "Connection (fd %d) no longer waiting for resolve of '%s'",
conn->s, safe_str(conn->address));
return; /* more are pending */
}
@@ -467,13 +470,14 @@ dns_cancel_pending_resolve(char *address)
resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
if (!resolve) {
- log_fn(LOG_NOTICE,"Address '%s' is not pending. Dropping.", safe_str(address));
+ /* XXXX RD This *is* a bug, right? -NM */
+ notice(LD_BUG,"Address '%s' is not pending. Dropping.", safe_str(address));
return;
}
if (!resolve->pending_connections) {
/* XXX this should never trigger, but sometimes it does */
- log_fn(LOG_WARN,"Bug: Address '%s' is pending but has no pending connections!",
+ warn(LD_BUG,"Bug: Address '%s' is pending but has no pending connections!",
safe_str(address));
tor_fragile_assert();
return;
@@ -481,8 +485,8 @@ dns_cancel_pending_resolve(char *address)
tor_assert(resolve->pending_connections);
/* mark all pending connections to fail */
- log_fn(LOG_DEBUG, "Failing all connections waiting on DNS resolve of '%s'",
- safe_str(address));
+ debug(LD_EXIT, "Failing all connections waiting on DNS resolve of '%s'",
+ safe_str(address));
while (resolve->pending_connections) {
pend = resolve->pending_connections;
pend->conn->state = EXIT_CONN_STATE_RESOLVEFAILED;
@@ -551,8 +555,8 @@ dns_found_answer(char *address, uint32_t addr, char outcome)
resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
if (!resolve) {
- log_fn(LOG_INFO,"Resolved unasked address '%s'; caching anyway.",
- safe_str(address));
+ info(LD_EXIT,"Resolved unasked address '%s'; caching anyway.",
+ safe_str(address));
resolve = tor_malloc_zero(sizeof(cached_resolve_t));
resolve->state = (outcome == DNS_RESOLVE_SUCCEEDED) ?
CACHE_STATE_VALID : CACHE_STATE_FAILED;
@@ -565,7 +569,7 @@ dns_found_answer(char *address, uint32_t addr, char outcome)
if (resolve->state != CACHE_STATE_PENDING) {
/* XXXX Maybe update addr? or check addr for consistency? Or let
* VALID replace FAILED? */
- log_fn(LOG_NOTICE, "Resolved '%s' which was already resolved; ignoring",
+ notice(LD_EXIT, "Resolved '%s' which was already resolved; ignoring",
safe_str(address));
tor_assert(resolve->pending_connections == NULL);
return;
@@ -656,7 +660,7 @@ connection_dns_finished_flushing(connection_t *conn)
int
connection_dns_reached_eof(connection_t *conn)
{
- log_fn(LOG_WARN,"Read eof. Worker died unexpectedly.");
+ warn(LD_EXIT,"Read eof. Worker died unexpectedly.");
if (conn->state == DNSWORKER_STATE_BUSY) {
/* don't cancel the resolve here -- it would be cancelled in
* connection_about_to_close_connection(), since conn is still
@@ -682,8 +686,8 @@ connection_dns_process_inbuf(connection_t *conn)
tor_assert(conn->type == CONN_TYPE_DNSWORKER);
if (conn->state != DNSWORKER_STATE_BUSY && buf_datalen(conn->inbuf)) {
- log_fn(LOG_WARN,"Bug: read data (%d bytes) from an idle dns worker (fd %d, address '%s'). Please report.",
- (int)buf_datalen(conn->inbuf), conn->s, safe_str(conn->address));
+ warn(LD_BUG,"Bug: read data (%d bytes) from an idle dns worker (fd %d, address '%s'). Please report.",
+ (int)buf_datalen(conn->inbuf), conn->s, safe_str(conn->address));
tor_fragile_assert();
/* Pull it off the buffer anyway, or it will just stay there.
@@ -692,7 +696,7 @@ connection_dns_process_inbuf(connection_t *conn)
while (buf_datalen(conn->inbuf)) {
connection_fetch_from_buf(&success,1,conn);
connection_fetch_from_buf((char *)&addr,sizeof(uint32_t),conn);
- log_fn(LOG_WARN,"Discarding idle dns answer (success %d, addr %d.)",
+ warn(LD_EXIT,"Discarding idle dns answer (success %d, addr %d.)",
success, addr); // XXX safe_str
}
return 0;
@@ -705,8 +709,8 @@ connection_dns_process_inbuf(connection_t *conn)
connection_fetch_from_buf(&success,1,conn);
connection_fetch_from_buf((char *)&addr,sizeof(uint32_t),conn);
- log_fn(LOG_DEBUG, "DNSWorker (fd %d) returned answer for '%s'",
- conn->s, safe_str(conn->address));
+ debug(LD_EXIT, "DNSWorker (fd %d) returned answer for '%s'",
+ conn->s, safe_str(conn->address));
tor_assert(success >= DNS_RESOLVE_FAILED_TRANSIENT);
tor_assert(success <= DNS_RESOLVE_SUCCEEDED);
@@ -784,17 +788,17 @@ dnsworker_main(void *data)
if ((r = recv(fd, &address_len, 1, 0)) != 1) {
if (r == 0) {
- log_fn(LOG_INFO,"DNS worker exiting because Tor process closed connection (either pruned idle dnsworker or died).");
+ info(LD_EXIT,"DNS worker exiting because Tor process closed connection (either pruned idle dnsworker or died).");
} else {
- log_fn(LOG_INFO,"DNS worker exiting 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_EXIT,"DNS worker exiting because of error on connection to Tor process.");
+ info(LD_EXIT,"(Error on %d was %s)", fd, tor_socket_strerror(tor_socket_errno(fd)));
}
tor_close_socket(fd);
spawn_exit();
}
if (address_len && read_all(fd, address, address_len, 1) != address_len) {
- log_fn(LOG_ERR,"read hostname failed. Child exiting.");
+ err(LD_BUG,"read hostname failed. Child exiting.");
tor_close_socket(fd);
spawn_exit();
}
@@ -807,21 +811,21 @@ dnsworker_main(void *data)
switch (result) {
case 1:
/* XXX result can never be 1, because we set it to -1 above on error */
- log_fn(LOG_INFO,"Could not resolve dest addr %s (transient).",safe_str(address));
+ info(LD_NET,"Could not resolve dest addr %s (transient).",safe_str(address));
answer[0] = DNS_RESOLVE_FAILED_TRANSIENT;
break;
case -1:
- log_fn(LOG_INFO,"Could not resolve dest addr %s (permanent).",safe_str(address));
+ info(LD_NET,"Could not resolve dest addr %s (permanent).",safe_str(address));
answer[0] = DNS_RESOLVE_FAILED_PERMANENT;
break;
case 0:
- log_fn(LOG_INFO,"Resolved address '%s'.",safe_str(address));
+ info(LD_NET,"Resolved address '%s'.",safe_str(address));
answer[0] = DNS_RESOLVE_SUCCEEDED;
break;
}
set_uint32(answer+1, ip);
if (write_all(fd, answer, 5, 1) != 5) {
- log_fn(LOG_ERR,"writing answer failed. Child exiting.");
+ err(LD_NET,"writing answer failed. Child exiting.");
tor_close_socket(fd);
spawn_exit();
}
@@ -841,7 +845,7 @@ spawn_dnsworker(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;
}
@@ -850,7 +854,7 @@ spawn_dnsworker(void)
fd = fdarray[0]; /* We copy this out here, since dnsworker_main may free fdarray */
spawn_func(dnsworker_main, (void*)fdarray);
- log_fn(LOG_DEBUG,"just spawned a worker.");
+ debug(LD_EXIT,"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);
@@ -865,7 +869,7 @@ spawn_dnsworker(void)
conn->address = tor_strdup("<unused>");
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;
}
@@ -903,8 +907,8 @@ spawn_enough_dnsworkers(void)
DNSWORKER_STATE_BUSY);
tor_assert(dnsconn);
- log_fn(LOG_WARN, "%d DNS workers are spawned; all are busy. Killing one.",
- MAX_DNSWORKERS);
+ warn(LD_EXIT, "%d DNS workers are spawned; all are busy. Killing one.",
+ MAX_DNSWORKERS);
connection_mark_for_close(dnsconn);
num_dnsworkers_busy--;
@@ -918,7 +922,7 @@ spawn_enough_dnsworkers(void)
while (num_dnsworkers < num_dnsworkers_needed) {
if (spawn_dnsworker() < 0) {
- log_fn(LOG_WARN,"Spawn failed. Will try again later.");
+ warn(LD_EXIT,"Spawn failed. Will try again later.");
return -1;
}
num_dnsworkers++;
@@ -927,7 +931,7 @@ spawn_enough_dnsworkers(void)
while (num_dnsworkers > num_dnsworkers_busy+MAX_IDLE_DNSWORKERS) {
/* too many idle? */
/* cull excess workers */
- log_fn(LOG_INFO,"%d of %d dnsworkers are idle. Killing one.",
+ info(LD_EXIT,"%d of %d dnsworkers are idle. Killing one.",
num_dnsworkers-num_dnsworkers_busy, num_dnsworkers);
dnsconn = connection_get_by_type_state(CONN_TYPE_DNSWORKER, DNSWORKER_STATE_IDLE);
tor_assert(dnsconn);