diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dht.c | 27 | ||||
-rw-r--r-- | src/main.c | 4 |
2 files changed, 19 insertions, 12 deletions
@@ -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; } @@ -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; } |