diff --git a/connection.c b/connection.c index 7220ccd..6551b5f 100644 --- a/connection.c +++ b/connection.c @@ -68,8 +68,15 @@ struct client_con { struct torrent_file *torrent; }; -static struct torrent_file * find_create_torrent(const char *filename) +static struct torrent_file * find_create_torrent(const char *fullpath) { + /* strip directory from filename */ + const char *filename = strrchr(fullpath, '/'); + if (filename == NULL || *(filename +1) == '\0') + filename = fullpath; + else + filename++; + /* search for this torrent */ struct torrent_file *torrent; list_for_each_entry(torrent, &torrent_list, list) { @@ -135,7 +142,7 @@ static int data_cb(int fd, void *privdata) con->bw_dn = bwdn; } - /* status update */ + /* status update (assume protocol v2) */ } else if (strncmp(line, "CTSTATUS ", 9) == 0) { int seeds1 = 0, seeds2 = 0, leech1 = 0, leech2 = 0, count = 0; int chunk1 = 0, chunk2 = 0, chunk3 = 0, bwdn = 0, bwup = 0; @@ -193,7 +200,7 @@ static int data_cb(int fd, void *privdata) int ctcs_trigger_status(void *privdata) { - long timeout = time(NULL) - 300; + long timeout = time(NULL) - (int)privdata; struct torrent_file *torrent; list_for_each_entry(torrent, &torrent_list, list) { diff --git a/torrent-stats.c b/torrent-stats.c index 20266cf..aea9036 100644 --- a/torrent-stats.c +++ b/torrent-stats.c @@ -99,8 +99,11 @@ int main(int argc, char *argv[]) httpd_add_cb("/quit", 0, ctcs_httpd_quit, NULL); httpd_add_cb("/", 1, ctcs_httpd_show, NULL); - struct timeval tv = { .tv_sec = 10, .tv_usec = 0 }; - event_add_timeout(&tv, ctcs_trigger_status, NULL); + int interval = config_get_int("global", "status-interval", 10); + int timeout = config_get_int("global", "seed-timeout", 300); + + struct timeval tv = { .tv_sec = interval, .tv_usec = 0 }; + event_add_timeout(&tv, ctcs_trigger_status, (void *)timeout); event_loop(); return 0; diff --git a/torrent-stats.conf b/torrent-stats.conf index 175af47..b07a034 100644 --- a/torrent-stats.conf +++ b/torrent-stats.conf @@ -1,3 +1,6 @@ [global] listen 0.0.0.0:2780 listen-http 0.0.0.0:8080 + +status-interval 10 +seed-timeout 300