torrentd

simple torrent daemon
git clone git@git.2f30.org/torrentd.git
Log | Files | Refs | LICENSE

commit cb90595462d6ae257f799a7b9142265f4c61822d
parent 7a74f47a946025e7830aa5d9320864290558f9c1
Author: sin <sin@2f30.org>
Date:   Fri, 18 Dec 2015 15:29:45 +0000

Add dumptorrent() to help debugging

Diffstat:
Msbtd.c | 1+
Msbtd.h | 1+
Mtorrent.c | 22++++++++++++++++++++++
3 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/sbtd.c b/sbtd.c @@ -35,6 +35,7 @@ main(int argc, char *argv[]) if (argc != 2) usage(argv[0]); t = loadtorrent(argv[1]); + dumptorrent(t); unloadtorrent(t); exit(0); } diff --git a/sbtd.h b/sbtd.h @@ -50,6 +50,7 @@ void bfree(struct ben *); void bprint(struct ben *, int); /* torrent.c */ +void dumptorrent(struct torrent *); struct torrent *loadtorrent(char *); void unloadtorrent(struct torrent *); int piecehash(struct torrent *, long long, uint8_t *); diff --git a/torrent.c b/torrent.c @@ -30,6 +30,28 @@ calcinfohash(struct torrent *t) t->info->end - t->info->start, t->infohash); } +void +dumptorrent(struct torrent *t) +{ + uint8_t md[20]; + char hex[41]; + long long i; + + printf("announce: %s\n", t->announce); + printf("filename: %s\n", t->filename); + bin2hex(t->infohash, hex, 20); + printf("infohash: %s\n", hex); + printf("length: %lld\n", t->length); + printf("piecelen: %lld\n", t->piecelen); + printf("npieces: %lld\n", t->npieces); + + for (i = 0; i < t->npieces; i++) { + piecehash(t, i, md); + bin2hex(md, hex, 20); + printf("piece[%lld] hash: %s\n", i, hex); + } +} + struct torrent * loadtorrent(char *f) {