diff options
| author | Richard Nyberg <rnyberg@murmeldjur.se> | 2006-02-10 15:41:55 +0000 |
|---|---|---|
| committer | Richard Nyberg <rnyberg@murmeldjur.se> | 2006-02-10 15:41:55 +0000 |
| commit | b43809ba555622797d2acaf0a6a58628983b8946 (patch) | |
| tree | 54f616810388a821d8ef7b68e5438d6523088d7f /cli | |
| parent | bf75d6af1c573fea1043c81cdeb2c634dedb240c (diff) | |
| download | btpd-b43809ba555622797d2acaf0a6a58628983b8946.tar.gz btpd-b43809ba555622797d2acaf0a6a58628983b8946.zip | |
Mostly name changes. Add a missing include. Changed the torrent status
characters displayed by btcli.
Diffstat (limited to 'cli')
| -rw-r--r-- | cli/btcli.c | 55 | ||||
| -rw-r--r-- | cli/btpd_if.c | 25 | ||||
| -rw-r--r-- | cli/btpd_if.h | 11 |
3 files changed, 52 insertions, 39 deletions
diff --git a/cli/btcli.c b/cli/btcli.c index 95139a0..306df1c 100644 --- a/cli/btcli.c +++ b/cli/btcli.c @@ -5,6 +5,7 @@ #include <errno.h> #include <fcntl.h> #include <getopt.h> +#include <inttypes.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> @@ -46,24 +47,37 @@ handle_ipc_res(enum ipc_code code, const char *target) void print_state_name(struct tpstat *ts) { - char statec[] = ">*<U"; - int state = min(ts->state, 3); - printf("%c. %s", statec[state], ts->name); + char c; + switch (ts->state) { + case T_STARTING: + c = '+'; + break; + case T_ACTIVE: + c = ts->pieces_got == ts->torrent_pieces ? 'S' : 'L'; + break; + case T_STOPPING: + c = '-'; + break; + default: + c = 'U'; + break; + } + printf("%c. %s", c, ts->name); } void -print_stat(struct tpstat *cur) +print_stat(struct tpstat *ts) { printf("%5.1f%% %6.1fM %7.2fkB/s %6.1fM %7.2fkB/s %4u %5.1f%%", - 100.0 * cur->have / cur->total, - (double)cur->downloaded / (1 << 20), - (double)cur->rate_down / (20 << 10), - (double)cur->uploaded / (1 << 20), - (double)cur->rate_up / (20 << 10), - cur->npeers, - 100.0 * cur->nseen / cur->npieces); - if (cur->errors > 0) - printf(" E%u", cur->errors); + 100.0 * ts->content_got / ts->content_size, + (double)ts->downloaded / (1 << 20), + (double)ts->rate_down / (20 << 10), + (double)ts->uploaded / (1 << 20), + (double)ts->rate_up / (20 << 10), + ts->peers, + 100.0 * ts->pieces_seen / ts->torrent_pieces); + if (ts->tr_errors > 0) + printf(" E%u", ts->tr_errors); printf("\n"); } @@ -156,7 +170,7 @@ cmd_add(int argc, char **argv) && strcmp(mi->name, mi->files[0].path) == 0))) snprintf(dpath, PATH_MAX, "%s/%s", bdir, mi->name); else if (dir != NULL) - strlcpy(dpath, bdir, PATH_MAX); + strncpy(dpath, bdir, PATH_MAX); else { if (content_link(mi->info_hash, dpath) != 0) { warnx("unknown content dir for %s", argv[i]); @@ -307,7 +321,6 @@ do_stat(int individual, int seconds, int hash_count, uint8_t (*hashes)[20]) struct tpstat tot; again: bzero(&tot, sizeof(tot)); - tot.state = T_ACTIVE; if (handle_ipc_res(btpd_stat(ipc, &st), "stat") != IPC_OK) exit(1); for (int i = 0; i < st->ntorrents; i++) { @@ -324,11 +337,11 @@ again: tot.downloaded += cur->downloaded; tot.rate_up += cur->rate_up; tot.rate_down += cur->rate_down; - tot.npeers += cur->npeers; - tot.nseen += cur->nseen; - tot.npieces += cur->npieces; - tot.have += cur->have; - tot.total += cur->total; + tot.peers += cur->peers; + tot.pieces_seen += cur->pieces_seen; + tot.torrent_pieces += cur->torrent_pieces; + tot.content_got += cur->content_got; + tot.content_size += cur->content_size; if (individual) { print_state_name(cur); printf(":\n"); @@ -355,7 +368,7 @@ cmd_stat(int argc, char **argv) { int ch; int wflag = 0, iflag = 0, seconds = 0; - uint8_t (*hashes)[20]; + uint8_t (*hashes)[20] = NULL; char *endptr; while ((ch = getopt_long(argc, argv, "iw:", stat_opts, NULL)) != -1) { switch (ch) { diff --git a/cli/btpd_if.c b/cli/btpd_if.c index f33851f..c15ce08 100644 --- a/cli/btpd_if.c +++ b/cli/btpd_if.c @@ -154,19 +154,20 @@ parse_btstat(const uint8_t *res, struct btstat **out) int i = 0; for (const char *tp = benc_first(tlst); tp != NULL; tp = benc_next(tp)) { struct tpstat *ts = &st->torrents[i]; - ts->hash = benc_dget_mema(tp, "hash", NULL); - ts->name = benc_dget_str(tp, "path", NULL); + ts->hash = benc_dget_mema(tp, "info hash", NULL); + ts->name = benc_dget_str(tp, "name", NULL); ts->state = benc_dget_int(tp, "state"); - ts->errors = benc_dget_int(tp, "errors"); - ts->npieces = benc_dget_int(tp, "npieces"); - ts->nseen = benc_dget_int(tp, "seen npieces"); - ts->npeers = benc_dget_int(tp, "npeers"); - ts->downloaded = benc_dget_int(tp, "down"); - ts->uploaded = benc_dget_int(tp, "up"); - ts->rate_down = benc_dget_int(tp, "rd"); - ts->rate_up = benc_dget_int(tp, "ru"); - ts->have = benc_dget_int(tp, "have"); - ts->total = benc_dget_int(tp, "total"); + ts->peers = benc_dget_int(tp, "peers"); + ts->tr_errors = benc_dget_int(tp, "tracker errors"); + ts->content_got = benc_dget_int(tp, "content got"); + ts->content_size = benc_dget_int(tp, "content size"); + ts->pieces_got = benc_dget_int(tp, "pieces got"); + ts->pieces_seen = benc_dget_int(tp, "pieces seen"); + ts->torrent_pieces = benc_dget_int(tp, "torrent pieces"); + ts->downloaded = benc_dget_int(tp, "downloaded"); + ts->uploaded = benc_dget_int(tp, "uploaded"); + ts->rate_down = benc_dget_int(tp, "rate down"); + ts->rate_up = benc_dget_int(tp, "rate up"); i++; } *out = st; diff --git a/cli/btpd_if.h b/cli/btpd_if.h index b7096aa..1cc51d9 100644 --- a/cli/btpd_if.h +++ b/cli/btpd_if.h @@ -22,12 +22,11 @@ struct btstat { uint8_t *hash; char *name; enum torrent_state state; - - unsigned errors; - unsigned npeers; - uint32_t npieces, nseen; - off_t have, total; - long long downloaded, uploaded; + unsigned tr_errors; + unsigned peers; + uint32_t pieces_got, pieces_seen, torrent_pieces; + off_t content_got, content_size; + unsigned long long downloaded, uploaded; unsigned long rate_up, rate_down; } torrents[]; }; |