Bladeren bron

Update the info files regularly. Before they were only updated when a torrent

stopped.
master
Richard Nyberg 18 jaren geleden
bovenliggende
commit
796e706974
3 gewijzigde bestanden met toevoegingen van 33 en 4 verwijderingen
  1. +8
    -2
      btpd/tlib.c
  2. +1
    -1
      btpd/tlib.h
  3. +24
    -1
      btpd/torrent.c

+ 8
- 2
btpd/tlib.c Bestand weergeven

@@ -183,7 +183,8 @@ save_info(struct tlib *tl)
btpd_err("failed to open '%s' (%s).\n", wpath, strerror(errno)); btpd_err("failed to open '%s' (%s).\n", wpath, strerror(errno));
dct_subst_save(fp, "de", iob.buf); dct_subst_save(fp, "de", iob.buf);
buf_free(&iob); buf_free(&iob);
if (ferror(fp) || fclose(fp) != 0)
if ((fflush(fp) == EOF || fsync(fileno(fp)) != 0
|| ferror(fp) || fclose(fp) != 0))
btpd_err("failed to write '%s'.\n", wpath); btpd_err("failed to write '%s'.\n", wpath);
if (rename(wpath, path) != 0) if (rename(wpath, path) != 0)
btpd_err("failed to rename: '%s' -> '%s' (%s).\n", wpath, path, btpd_err("failed to rename: '%s' -> '%s' (%s).\n", wpath, path,
@@ -191,9 +192,14 @@ save_info(struct tlib *tl)
} }


void void
tlib_update_info(struct tlib *tl)
tlib_update_info(struct tlib *tl, int only_file)
{ {
struct tlib tmp;
assert(tl->tp != NULL); assert(tl->tp != NULL);
if (only_file) {
tmp = *tl;
tl = &tmp;
}
tl->tot_down += tl->tp->net->downloaded; tl->tot_down += tl->tp->net->downloaded;
tl->tot_up += tl->tp->net->uploaded; tl->tot_up += tl->tp->net->uploaded;
tl->content_have = cm_content(tl->tp); tl->content_have = cm_content(tl->tp);


+ 1
- 1
btpd/tlib.h Bestand weergeven

@@ -28,7 +28,7 @@ struct tlib *tlib_add(const uint8_t *hash, const char *mi, size_t mi_size,
const char *content, char *name); const char *content, char *name);
int tlib_del(struct tlib *tl); int tlib_del(struct tlib *tl);


void tlib_update_info(struct tlib *tl);
void tlib_update_info(struct tlib *tl, int only_file);


struct tlib *tlib_by_hash(const uint8_t *hash); struct tlib *tlib_by_hash(const uint8_t *hash);
struct tlib *tlib_by_num(unsigned num); struct tlib *tlib_by_num(unsigned num);


+ 24
- 1
btpd/torrent.c Bestand weergeven

@@ -16,9 +16,14 @@
#include "tracker_req.h" #include "tracker_req.h"
#include "stream.h" #include "stream.h"


#define SAVE_INTERVAL 300

static unsigned m_ntorrents; static unsigned m_ntorrents;
static struct torrent_tq m_torrents = BTPDQ_HEAD_INITIALIZER(m_torrents); static struct torrent_tq m_torrents = BTPDQ_HEAD_INITIALIZER(m_torrents);


static unsigned m_tsave;
static struct torrent *m_savetp;

const struct torrent_tq * const struct torrent_tq *
torrent_get_all(void) torrent_get_all(void)
{ {
@@ -113,6 +118,10 @@ torrent_start(struct tlib *tl)
m_ntorrents++; m_ntorrents++;
cm_start(tp, 0); cm_start(tp, 0);
free(mi); free(mi);
if (m_ntorrents == 1) {
m_tsave = btpd_seconds + SAVE_INTERVAL;
m_savetp = tp;
}
return IPC_OK; return IPC_OK;
} else { } else {
mi_free_files(tp->nfiles, tp->files); mi_free_files(tp->nfiles, tp->files);
@@ -137,6 +146,9 @@ torrent_kill(struct torrent *tp)
net_kill(tp); net_kill(tp);
cm_kill(tp); cm_kill(tp);
mi_free_files(tp->nfiles, tp->files); mi_free_files(tp->nfiles, tp->files);
if (m_savetp == tp)
if ((m_savetp = BTPDQ_NEXT(tp, entry)) == NULL)
m_savetp = BTPDQ_FIRST(&m_torrents);
free(tp); free(tp);
} }


@@ -157,7 +169,7 @@ torrent_stop(struct torrent *tp, int delete)
if (cm_active(tp)) if (cm_active(tp))
cm_stop(tp); cm_stop(tp);
if (!delete) if (!delete)
tlib_update_info(tp->tl);
tlib_update_info(tp->tl, 0);
break; break;
case T_STOPPING: case T_STOPPING:
if (tr_active(tp)) if (tr_active(tp))
@@ -211,4 +223,15 @@ torrent_on_tick_all(void)
struct torrent *tp, *next; struct torrent *tp, *next;
BTPDQ_FOREACH_MUTABLE(tp, &m_torrents, entry, next) BTPDQ_FOREACH_MUTABLE(tp, &m_torrents, entry, next)
torrent_on_tick(tp); torrent_on_tick(tp);

if (m_savetp != NULL && m_tsave <= btpd_seconds) {
if (m_savetp->state == T_LEECH || m_savetp->state == T_SEED) {
tlib_update_info(m_savetp->tl, 1);
if ((m_savetp = BTPDQ_NEXT(m_savetp, entry)) == NULL)
m_savetp = BTPDQ_FIRST(&m_torrents);
if (m_ntorrents > 0)
m_tsave = btpd_seconds +
max(m_ntorrents, SAVE_INTERVAL) / m_ntorrents;
}
}
} }

Laden…
Annuleren
Opslaan