From 53c3ba32cf834840ae2fdcb38aca3a7f99a42cbd Mon Sep 17 00:00:00 2001 From: Richard Nyberg <rnyberg@murmeldjur.se> Date: Sun, 5 Feb 2006 11:29:01 +0000 Subject: [PATCH] Each torrent now gets a number. This number is used to select which torrent to operate on from btcli. --- btpd/torrent.c | 11 +++++++++++ btpd/torrent.h | 1 + 2 files changed, 12 insertions(+) diff --git a/btpd/torrent.c b/btpd/torrent.c index 5c8ff89..b65b481 100644 --- a/btpd/torrent.c +++ b/btpd/torrent.c @@ -19,6 +19,16 @@ #include "tracker_req.h" #include "stream.h" +static unsigned m_next_num; + +static unsigned +num_get_next(void) +{ + if (m_next_num == UINT_MAX) + btpd_err("Reached maximum torrent number.\n"); + return m_next_num++; +} + off_t torrent_piece_size(struct torrent *tp, uint32_t index) { @@ -107,6 +117,7 @@ torrent_load(struct torrent **res, const char *path) *res = btpd_calloc(1, sizeof(**res)); (*res)->relpath = strdup(path); (*res)->meta = *mi; + (*res)->num = num_get_next(); free(mi); } else { clear_metainfo(mi); diff --git a/btpd/torrent.h b/btpd/torrent.h index c84c9be..4a1542e 100644 --- a/btpd/torrent.h +++ b/btpd/torrent.h @@ -11,6 +11,7 @@ enum torrent_state { }; struct torrent { + unsigned num; const char *relpath; struct metainfo meta;