use config file parameters

This commit is contained in:
Olaf Rempel 2009-02-24 12:49:40 +01:00
parent ed7b11726b
commit 49550a0afa
3 changed files with 18 additions and 5 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -1,3 +1,6 @@
[global]
listen 0.0.0.0:2780
listen-http 0.0.0.0:8080
status-interval 10
seed-timeout 300