ソースを参照

Add torrent_name function and use it.

master
Richard Nyberg 18年前
コミット
31f0e727df
4個のファイルの変更20行の追加13行の削除
  1. +6
    -7
      btpd/content.c
  2. +8
    -3
      btpd/torrent.c
  3. +1
    -0
      btpd/torrent.h
  4. +5
    -3
      btpd/tracker_req.c

+ 6
- 7
btpd/content.c ファイルの表示

@@ -183,12 +183,11 @@ cm_save(struct torrent *tp)
static void
cm_write_done(struct torrent *tp)
{
int err;
struct content *cm = tp->cm;

if ((err = bts_close(cm->wrs)) != 0)
btpd_err("Error closing write stream for %s (%s).\n", tp->relpath,
strerror(err));
if ((errno = bts_close(cm->wrs)) != 0)
btpd_err("Error closing write stream for '%s' (%s).\n",
torrent_name(tp), strerror(errno));
cm->wrs = NULL;
event_del(&cm->save_timer);
cm_save(tp);
@@ -243,7 +242,7 @@ cm_td_cb(void *arg)
struct content *cm = tp->cm;

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) {
case CM_ALLOC:
@@ -255,8 +254,8 @@ cm_td_cb(void *arg)
assert(!op->u.start.cancel);
if (!cm_full(tp)) {
if ((err = bts_open(&cm->wrs, &tp->meta, fd_cb_wr, tp)) != 0)
btpd_err("Couldn't open write stream for %s (%s).\n",
tp->relpath, strerror(err));
btpd_err("Couldn't open write stream for '%s' (%s).\n",
torrent_name(tp), strerror(err));
event_add(&cm->save_timer, SAVE_INTERVAL);
}
torrent_on_cm_started(tp);


+ 8
- 3
btpd/torrent.c ファイルの表示

@@ -43,6 +43,12 @@ torrent_get(const uint8_t *hash)
return tp;
}

const char *
torrent_name(struct torrent *tp)
{
return tp->meta.name;
}

off_t
torrent_piece_size(struct torrent *tp, uint32_t index)
{
@@ -120,13 +126,12 @@ torrent_start(const uint8_t *hash)
return error;
}

btpd_log(BTPD_L_BTPD, "Starting torrent '%s'.\n", mi->name);

tp = btpd_calloc(1, sizeof(*tp));
bcopy(relpath, tp->relpath, RELPATH_SIZE);
tp->meta = *mi;
free(mi);

btpd_log(BTPD_L_BTPD, "Starting torrent '%s'.\n", torrent_name(tp));
if ((error = tr_create(tp)) == 0) {
net_create(tp);
cm_create(tp);
@@ -161,7 +166,7 @@ torrent_stop(struct torrent *tp)
static void
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);
m_ntorrents--;
BTPDQ_REMOVE(&m_torrents, tp, entry);


+ 1
- 0
btpd/torrent.h ファイルの表示

@@ -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_block_size(struct torrent *tp, uint32_t piece,
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_started(struct torrent *tp);


+ 5
- 3
btpd/tracker_req.c ファイルの表示

@@ -77,7 +77,8 @@ parse_reply(struct torrent *tp, const char *content, size_t size, int parse)
goto bad_data;

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;
}

@@ -109,7 +110,8 @@ parse_reply(struct torrent *tp, const char *content, size_t size, int parse)
return 0;

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;
}

@@ -155,7 +157,7 @@ timer_cb(int fd, short type, void *arg)
switch (tr->ttype) {
case TIMER_TIMEOUT:
btpd_log(BTPD_L_ERROR, "Tracker request timed out for '%s'.\n",
tp->meta.name);
torrent_name(tp));
tr->nerrors++;
if (tr->event == TR_EV_STOPPED && tr->nerrors >= 5) {
tr_set_stopped(tp);


読み込み中…
キャンセル
保存