commit b84463502c6806ff07078402d6123067f5eeb597
parent f53778c44deacd990d4447564de134ce4f2dd6ce
Author: sin <sin@2f30.org>
Date: Sat, 26 Dec 2015 16:40:21 +0000
add ev types
Diffstat:
3 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/storrent.c b/storrent.c
@@ -22,7 +22,7 @@ main(int argc, char *argv[])
if (!(t = loadtorrent(argv[1])))
exit(1);
dumptorrent(t);
- getpeers(t);
+ trackerget(t, EVSTARTED);
unloadtorrent(t);
exit(0);
}
diff --git a/storrent.h b/storrent.h
@@ -1,4 +1,10 @@
/* See LICENSE file for copyright and license details. */
+enum {
+ EVSTARTED,
+ EVCOMPLETED,
+ EVSTOPPED
+};
+
struct ben {
int type;
struct ben *k;
@@ -65,7 +71,7 @@ int piecehash(struct torrent *, long long, uint8_t *);
char *peerid(void);
/* tracker.c */
-int getpeers(struct torrent *);
+int trackerget(struct torrent *, int);
/* util.c */
void *emalloc(size_t);
diff --git a/tracker.c b/tracker.c
@@ -94,14 +94,28 @@ parsepeers(struct torrent *t, struct buf *b)
}
int
-getpeers(struct torrent *t)
+trackerget(struct torrent *t, int event)
{
CURL *curl;
CURLcode res;
- char buf[8192], *infohash, *id;
+ char buf[8192], *infohash, *id, *ev;
struct buf reply;
int r;
+ switch (event) {
+ case EVSTARTED:
+ ev = "started";
+ break;
+ case EVCOMPLETED:
+ ev = "completed";
+ break;
+ case EVSTOPPED:
+ ev = "stopped";
+ break;
+ default:
+ return -1;
+ }
+
if (!(curl = curl_easy_init()))
return -1;
@@ -117,8 +131,8 @@ getpeers(struct torrent *t)
r = snprintf(buf, sizeof(buf),
"%s?info_hash=%s&peer_id=%s&port=6881&uploaded=0&"
- "downloaded=0&left=%zu&compact=1&event=started",
- t->announcers[0].urls[0], infohash, id, t->totallen);
+ "downloaded=0&left=%zu&compact=1&event=%s",
+ t->announcers[0].urls[0], infohash, id, t->totallen, ev);
if (r < 0 || (size_t)r >= sizeof(buf)) {
r = -1;
goto err2;