@@ -183,12 +183,11 @@ cm_save(struct torrent *tp) | |||||
static void | static void | ||||
cm_write_done(struct torrent *tp) | cm_write_done(struct torrent *tp) | ||||
{ | { | ||||
int err; | |||||
struct content *cm = tp->cm; | struct content *cm = tp->cm; | ||||
if ((err = bts_close(cm->wrs)) != 0) | if ((errno = bts_close(cm->wrs)) != 0) | ||||
btpd_err("Error closing write stream for %s (%s).\n", tp->relpath, | btpd_err("Error closing write stream for '%s' (%s).\n", | ||||
strerror(err)); | torrent_name(tp), strerror(errno)); | ||||
cm->wrs = NULL; | cm->wrs = NULL; | ||||
event_del(&cm->save_timer); | event_del(&cm->save_timer); | ||||
cm_save(tp); | cm_save(tp); | ||||
@@ -243,7 +242,7 @@ cm_td_cb(void *arg) | |||||
struct content *cm = tp->cm; | struct content *cm = tp->cm; | ||||
if (op->error) | if (op->error) | ||||
btpd_err("IO error for %s.\n", tp->relpath); | btpd_err("IO error for '%s'.\n", torrent_name(tp)); | ||||
switch (op->type) { | switch (op->type) { | ||||
case CM_ALLOC: | case CM_ALLOC: | ||||
@@ -255,8 +254,8 @@ cm_td_cb(void *arg) | |||||
assert(!op->u.start.cancel); | assert(!op->u.start.cancel); | ||||
if (!cm_full(tp)) { | if (!cm_full(tp)) { | ||||
if ((err = bts_open(&cm->wrs, &tp->meta, fd_cb_wr, tp)) != 0) | if ((err = bts_open(&cm->wrs, &tp->meta, fd_cb_wr, tp)) != 0) | ||||
btpd_err("Couldn't open write stream for %s (%s).\n", | btpd_err("Couldn't open write stream for '%s' (%s).\n", | ||||
tp->relpath, strerror(err)); | torrent_name(tp), strerror(err)); | ||||
event_add(&cm->save_timer, SAVE_INTERVAL); | event_add(&cm->save_timer, SAVE_INTERVAL); | ||||
} | } | ||||
torrent_on_cm_started(tp); | torrent_on_cm_started(tp); | ||||
@@ -43,6 +43,12 @@ torrent_get(const uint8_t *hash) | |||||
return tp; | return tp; | ||||
} | } | ||||
const char * | |||||
torrent_name(struct torrent *tp) | |||||
{ | |||||
return tp->meta.name; | |||||
} | |||||
off_t | off_t | ||||
torrent_piece_size(struct torrent *tp, uint32_t index) | torrent_piece_size(struct torrent *tp, uint32_t index) | ||||
{ | { | ||||
@@ -120,13 +126,12 @@ torrent_start(const uint8_t *hash) | |||||
return error; | return error; | ||||
} | } | ||||
btpd_log(BTPD_L_BTPD, "Starting torrent '%s'.\n", mi->name); | |||||
tp = btpd_calloc(1, sizeof(*tp)); | tp = btpd_calloc(1, sizeof(*tp)); | ||||
bcopy(relpath, tp->relpath, RELPATH_SIZE); | bcopy(relpath, tp->relpath, RELPATH_SIZE); | ||||
tp->meta = *mi; | tp->meta = *mi; | ||||
free(mi); | free(mi); | ||||
btpd_log(BTPD_L_BTPD, "Starting torrent '%s'.\n", torrent_name(tp)); | |||||
if ((error = tr_create(tp)) == 0) { | if ((error = tr_create(tp)) == 0) { | ||||
net_create(tp); | net_create(tp); | ||||
cm_create(tp); | cm_create(tp); | ||||
@@ -161,7 +166,7 @@ torrent_stop(struct torrent *tp) | |||||
static void | static void | ||||
torrent_kill(struct torrent *tp) | torrent_kill(struct torrent *tp) | ||||
{ | { | ||||
btpd_log(BTPD_L_BTPD, "Removed torrent '%s'.\n", tp->meta.name); | btpd_log(BTPD_L_BTPD, "Removed torrent '%s'.\n", torrent_name(tp)); | ||||
assert(m_ntorrents > 0); | assert(m_ntorrents > 0); | ||||
m_ntorrents--; | m_ntorrents--; | ||||
BTPDQ_REMOVE(&m_torrents, tp, entry); | BTPDQ_REMOVE(&m_torrents, tp, entry); | ||||
@@ -38,6 +38,7 @@ off_t torrent_piece_size(struct torrent *tp, uint32_t piece); | |||||
uint32_t torrent_piece_blocks(struct torrent *tp, uint32_t piece); | uint32_t torrent_piece_blocks(struct torrent *tp, uint32_t piece); | ||||
uint32_t torrent_block_size(struct torrent *tp, uint32_t piece, | uint32_t torrent_block_size(struct torrent *tp, uint32_t piece, | ||||
uint32_t nblocks, uint32_t block); | uint32_t nblocks, uint32_t block); | ||||
const char *torrent_name(struct torrent *tp); | |||||
void torrent_on_cm_stopped(struct torrent *tp); | void torrent_on_cm_stopped(struct torrent *tp); | ||||
void torrent_on_cm_started(struct torrent *tp); | void torrent_on_cm_started(struct torrent *tp); | ||||
@@ -77,7 +77,8 @@ parse_reply(struct torrent *tp, const char *content, size_t size, int parse) | |||||
goto bad_data; | goto bad_data; | ||||
if ((buf = benc_dget_mem(content, "failure reason", &len)) != NULL) { | if ((buf = benc_dget_mem(content, "failure reason", &len)) != NULL) { | ||||
btpd_log(BTPD_L_ERROR, "Tracker failure: %.*s.\n", (int)len, buf); | btpd_log(BTPD_L_ERROR, "Tracker failure: '%.*s' for '%s'.\n", | ||||
(int)len, buf, torrent_name(tp)); | |||||
return 1; | return 1; | ||||
} | } | ||||
@@ -109,7 +110,8 @@ parse_reply(struct torrent *tp, const char *content, size_t size, int parse) | |||||
return 0; | return 0; | ||||
bad_data: | bad_data: | ||||
btpd_log(BTPD_L_ERROR, "Bad data from tracker.\n"); | btpd_log(BTPD_L_ERROR, "Bad data from tracker for '%s'.\n", | ||||
torrent_name(tp)); | |||||
return 1; | return 1; | ||||
} | } | ||||
@@ -155,7 +157,7 @@ timer_cb(int fd, short type, void *arg) | |||||
switch (tr->ttype) { | switch (tr->ttype) { | ||||
case TIMER_TIMEOUT: | case TIMER_TIMEOUT: | ||||
btpd_log(BTPD_L_ERROR, "Tracker request timed out for '%s'.\n", | btpd_log(BTPD_L_ERROR, "Tracker request timed out for '%s'.\n", | ||||
tp->meta.name); | torrent_name(tp)); | ||||
tr->nerrors++; | tr->nerrors++; | ||||
if (tr->event == TR_EV_STOPPED && tr->nerrors >= 5) { | if (tr->event == TR_EV_STOPPED && tr->nerrors >= 5) { | ||||
tr_set_stopped(tp); | tr_set_stopped(tp); | ||||