about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard Nyberg <rnyberg@murmeldjur.se>2006-02-05 11:29:01 +0000
committerRichard Nyberg <rnyberg@murmeldjur.se>2006-02-05 11:29:01 +0000
commit53c3ba32cf834840ae2fdcb38aca3a7f99a42cbd (patch)
tree2c4cdc32575b45f6e1159129c6b397ee4034c6ac
parent886fb651d8666d6fad9c847b93cf43cf945e25c6 (diff)
downloadbtpd-53c3ba32cf834840ae2fdcb38aca3a7f99a42cbd.tar.gz
btpd-53c3ba32cf834840ae2fdcb38aca3a7f99a42cbd.zip
Each torrent now gets a number. This number is used to select which torrent
to operate on from btcli.

-rw-r--r--btpd/torrent.c11
-rw-r--r--btpd/torrent.h1
2 files changed, 12 insertions, 0 deletions
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;