From 2d7d9c33aff7a72d53ec47b977e1bfa120c9f8b1 Mon Sep 17 00:00:00 2001 From: Richard Nyberg Date: Tue, 3 Feb 2009 17:09:43 +0100 Subject: [PATCH] More tracker logging, and use switch for log type. --- btpd/btpd.h | 2 +- btpd/tracker_req.c | 14 ++++++++++++-- btpd/util.c | 20 ++++++++------------ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/btpd/btpd.h b/btpd/btpd.h index 3b7ecc7..c473b7f 100644 --- a/btpd/btpd.h +++ b/btpd/btpd.h @@ -53,7 +53,7 @@ #define BTPD_L_ALL 0xffffffff #define BTPD_L_ERROR 0x00000001 -#define BTPD_L_TRACKER 0x00000002 +#define BTPD_L_TR 0x00000002 #define BTPD_L_CONN 0x00000004 #define BTPD_L_MSG 0x00000008 #define BTPD_L_BTPD 0x00000010 diff --git a/btpd/tracker_req.c b/btpd/tracker_req.c index 9debcf5..5d302ed 100644 --- a/btpd/tracker_req.c +++ b/btpd/tracker_req.c @@ -62,6 +62,8 @@ all_failed(struct tr_tier *t) static void * req_send(struct tr_tier *t) { + btpd_log(BTPD_L_TR, "sending event %d to '%s' for '%s'.\n", + t->event, t->cur->url, torrent_name(t->tp)); switch (t->cur->type) { case TR_HTTP: return httptr_req(t->tp, t, t->cur->url, t->event); @@ -166,8 +168,11 @@ add_tracker(struct tr_tier *t, const char *url) if ((e->url = strdup(url)) == NULL) btpd_err("Out of memory.\n"); e->type = TR_HTTP; - } else + } else { + btpd_log(BTPD_L_TR, "skipping unsupported tracker '%s' for '%s'.\n", + url, torrent_name(t->tp)); return; + } BTPDQ_INSERT_TAIL(&t->trackers, e, entry); } @@ -175,11 +180,11 @@ static struct tr_tier * tier_create(struct torrent *tp, struct mi_tier *tier) { struct tr_tier *t = btpd_calloc(1, sizeof(*t)); + t->tp = tp; BTPDQ_INIT(&t->trackers); for (int i = 0; i < tier->nurls; i++) add_tracker(t, tier->urls[i]); if (!BTPDQ_EMPTY(&t->trackers)) { - t->tp = tp; t->interval = -1; t->event = TR_EV_STOPPED; evtimer_init(&t->timer, tier_timer_cb, t); @@ -292,6 +297,8 @@ tr_result(struct tr_tier *t, struct tr_response *res) break; } case TR_RES_CONN: + btpd_log(BTPD_L_TR, "connection to '%s' failed for '%s'.\n", + t->cur->url, torrent_name(t->tp)); e = t->cur; while ((e = BTPDQ_NEXT(e, entry)) != NULL && e->failure != NULL) ; @@ -313,6 +320,9 @@ tr_result(struct tr_tier *t, struct tr_response *res) btpd_log(BTPD_L_ERROR, "bad data from tracker '%s' for '%s'.\n", t->cur->url, torrent_name(t->tp)); case TR_RES_OK: + if (TR_RES_OK) + btpd_log(BTPD_L_TR, "response from '%s' for '%s'.\n", + t->cur->url, torrent_name(t->tp)); if (t->event == TR_EV_STOPPED) t->active = 0; else { diff --git a/btpd/util.c b/btpd/util.c index 700b0e6..9019bfd 100644 --- a/btpd/util.c +++ b/btpd/util.c @@ -65,18 +65,14 @@ btpd_timer_del(struct timeout *to) static const char * logtype_str(uint32_t type) { - if (type & BTPD_L_BTPD) - return "btpd"; - else if (type & BTPD_L_ERROR) - return "error"; - else if (type & BTPD_L_CONN) - return "conn"; - else if (type & BTPD_L_TRACKER) - return "tracker"; - else if (type & BTPD_L_MSG) - return "msg"; - else - return ""; + switch (type) { + case BTPD_L_BTPD: return "btpd"; + case BTPD_L_ERROR: return "error"; + case BTPD_L_CONN: return "conn"; + case BTPD_L_TR: return "tracker"; + case BTPD_L_MSG: return "msg"; + } + return ""; } static void