From c6156989725399a83f4a33384a3c60885ed6f211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Mon, 30 Jan 2023 17:27:57 +0100 Subject: new www, c mods --- src/dht.c | 27 +++++++++------ src/main.c | 4 +-- www/index.php | 108 ++++++++++++++-------------------------------------------- www/info.php | 78 ++++++++++++++++++++++++++++++++++++++++++ www/list.php | 17 +++++++++ 5 files changed, 140 insertions(+), 94 deletions(-) create mode 100644 www/info.php create mode 100644 www/list.php diff --git a/src/dht.c b/src/dht.c index dc3ff77..c20b6ed 100644 --- a/src/dht.c +++ b/src/dht.c @@ -428,7 +428,7 @@ void torrent_print (FILE * s, const struct torrent * t) { char buf[41]; buf[40] = '\0'; bin2hex(buf, t->hash, 20); - printf("magnet:?xt=urn:btih:%s%s%s%s%s%s%s%s\n\t**** PEERS ****\n", buf, t->type & announce ? " announce" : "", t->type & peers ? " peers" : "", t->type & info ? " info" : "", t->state & handshake_sent ? " handshake_sent" : "", t->state & handshake_received ? " handshake_received" : "", t->state & extension_sent ? " extension_sent" : "", t->state & extension_received ? " extension_received" : ""); + printf("magnet:?xt=urn:btih:%s%s%s%s%s%s%s%s ttl=%ld\n\t**** PEERS ****\n", buf, t->type & announce ? " announce" : "", t->type & peers ? " peers" : "", t->type & info ? " info" : "", t->state & handshake_sent ? " handshake_sent" : "", t->state & handshake_received ? " handshake_received" : "", t->state & extension_sent ? " extension_sent" : "", t->state & extension_received ? " extension_received" : "", t->ttl > 0 ? t->ttl-seconds() : -1); struct peer * p = t->peers; while (p) { fprintf(s, "\t"); @@ -559,8 +559,8 @@ void dht_print (FILE * s, const struct dht * d) { char buf[41]; buf[40] = '\0'; bin2hex(buf, d->id, 20); - char secret[17*2]; - secret[17*2+1] = '\0'; + char secret[16*2+1]; + secret[16*2] = '\0'; bin2hex(secret, d->secret, 16); fprintf(s, "id=%s socket=%d t=%u p=%u tmax=%u pmax=%u p/t-max=%u runsec=%ld rxp=%u txp=%u rxb=%u txb=%u secret=%s tt=%u tr=%u p=%u\n", buf, d->socket, d->torrents_num, d->peers_num, d->torrents_max, d->peers_max, d->peers_per_torrent_max, seconds()-d->time, d->rxp, d->txp, d->rxb, d->txb, secret, d->tt, d->tr, d->p); fprintf(s, "**** NODES ****\n"); @@ -587,12 +587,15 @@ void dht_print (FILE * s, const struct dht * d) { fprintf(s, "\t**** COUNT OF %s BUCKETS: %d\n", i ? "IPv6" : "IPv4", buckets); } fprintf(s, "**** COUNT OF NODES: %d\n", nodes); - printf("**** TORRENTS ****\n"); + fprintf(s, "**** TORRENTS ****\n"); struct torrent * t = d->torrents; + unsigned torrents = 0; while (t) { + torrents++; torrent_print(s, t); t = t->next; } + fprintf(s, "**** COUNT OF TORRENTS: %u\n", torrents); } /** @@ -2333,11 +2336,11 @@ void periodic (struct dht * d) { get_peers(d, &n->addr, t->hash); n = n->next; } - if (sent < K) { + if (sent < 1) { #define RTGP(buckets) {struct bucket * b = d->buckets; \ find(t->hash, &b, NULL); \ struct node * n = b->nodes; \ - while (sent < K && n) { \ + while (sent < 1 && n) { \ sent++; \ if (!n->unanswered) \ n->last_sent = seconds(); \ @@ -2348,11 +2351,11 @@ void periodic (struct dht * d) { RTGP(buckets); RTGP(buckets6); } - if (sent < K) { + if (sent < 1) { struct bucket * b = d->buckets; - while (sent < K && b) { + while (sent < 1 && b) { n = b->nodes; - while (sent < K && n) { + while (sent < 1 && n) { sent++; if (!n->unanswered) n->last_sent = seconds(); @@ -2423,7 +2426,11 @@ void periodic (struct dht * d) { t = t->next; } L(debug, d, "txqp=%u rxrp=%u rxqp=%u txrp=%u", d->txqp, d->rxrp, d->rxqp, d->txrp); - assert(!(d->txqp > 16384 || d->rxrp > 16384 || d->rxqp > 16384 || d->txrp > 16384)); +#define TOOMUCH 32727 + if (d->txqp > TOOMUCH || d->rxrp > TOOMUCH || d->rxqp > TOOMUCH || d->txrp > TOOMUCH) { + dht_print(stdout, d); + raise(SIGABRT); + } d->txqp = d->txrp = d->rxqp = d->rxrp = 0; } diff --git a/src/main.c b/src/main.c index b42c873..4e9c188 100644 --- a/src/main.c +++ b/src/main.c @@ -45,10 +45,10 @@ void found_torrent (struct dht * d __attribute__((unused)), const unsigned char L(debug, d, "%s%s", buf, t ? " stored" : " new"); if (t) { if (!t->type) - t->ttl = seconds()+512; + t->ttl = seconds()+128; t->type |= info | peers; } else { - if (last_added + 10 > seconds()) { + if (last_added + 1 > seconds()) { L(debug, d, "not adding a torrent this fast"); return; } diff --git a/www/index.php b/www/index.php index ac4bb50..1fd25a2 100644 --- a/www/index.php +++ b/www/index.php @@ -1,89 +1,33 @@ "; - while (false !== ($entry = readdir($handle))) { - if (preg_match("/torrent$/", $entry)) { - $h = htmlspecialchars(explode(".", $entry)[0]); - echo '
  • ' . $h . ''; - } - } - die(); - closedir($handle); - } else { - die("ne morem brati direktorija"); - } -} -if (!preg_match("/^[a-f0-9A-F]{40}$/", $_REQUEST["h"])) - die('!preg_match("/^[a-f0-9A-F]{40}$/", $_REQUEST["h"])'); -$t = TorrentFile::load("../".$_REQUEST["h"].".torrent"); + require_once "vendor/autoload.php"; + use Rhilip\Bencode\TorrentFile; + use Rhilip\Bencode\ParseException; ?> - - -

    getName()) ?>

    -<?= htmlspecialchars($t->getName()) ?> - - - - - - - - - - - isPrivate()) echo ""; ?> - - - - - - - - - - - - - -getRootData()["source"]["v"]) { ?> - - - - - - - -getSource())) { ?> - - - - -
    pridobljenogetCreationDate()) ?>
    tipgetProtocol() ?>
    datotečni načingetFileMode() ?>
    zaseben
    magnetna povezava
    .torrent>torrent datoteka
    velikostgetSize()/(1024*1024*1024), 6, ",", "") ?> GiB
    število datotekgetFileCount() ?>
    ip naslov viragetRootData()["source"]["ip"]) ?>
    odjemalec viragetRootData()["source"]["v"]) ?>
    velikost koščkagetPieceLength()/1024; ?> kB
    izvorgetSource()) ?>
    + +

    število datotek:

    +

    seznam

    +

    iskalnik

    +
    + " /> + +
    + +

    rezultati

    +
    +
    +
    + diff --git a/www/info.php b/www/info.php new file mode 100644 index 0000000..7ec562a --- /dev/null +++ b/www/info.php @@ -0,0 +1,78 @@ + + + + +

    getName()) ?>

    +<?= htmlspecialchars($t->getName()) ?> + + + + + + + + + + + isPrivate()) echo ""; ?> + + + + + + + + + + + + + + + +getRootData()["source"]["v"]) { ?> + + + + + + + +getSource())) { ?> + + + + +
    pridobljenogetCreationDate()) ?>
    tipgetProtocol() ?>
    datotečni načingetFileMode() ?>
    zaseben
    magnetna povezava
    .torrent>torrent datoteka
    velikostgetSize()/(1024*1024*1024), 6, ",", "") ?> GiB
    število datotekgetFileCount() ?>
    ip naslov viragetRootData()["source"]["ip"]) ?>
    odjemalec viragetRootData()["source"]["v"]) ?>
    velikost koščkagetPieceLength()/1024; ?> kB
    izvorgetSource()) ?>
    + " . htmlspecialchars($k) . ""; + } else { + echo "
  • " . htmlspecialchars($k) . " (" . number_format($v/(1024*1024), 6, ",", "") . " MiB)"; + } +} +echo ""; +?> + +

    interna stran, dostop prepovedan

    + diff --git a/www/list.php b/www/list.php new file mode 100644 index 0000000..6dbeb40 --- /dev/null +++ b/www/list.php @@ -0,0 +1,17 @@ +"; + while (false !== ($entry = readdir($handle))) { + if (preg_match("/torrent$/", $entry)) { + $h = htmlspecialchars(explode(".", $entry)[0]); + echo '
  • ' . $h . ''; + } + } + die(); + closedir($handle); +} else { + die("ne morem brati direktorija"); +} -- cgit v1.2.3