diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2023-03-15 20:26:21 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2023-03-15 20:26:21 +0100 |
commit | 5aed85d8cdc3301c9f9a68d89d21ae7b1bf1658f (patch) | |
tree | 3d1b3be214f43b57763eda2149b5cc9bea7dbe5e /src/main.c | |
parent | infloop fix 2 (diff) | |
download | travnik-5aed85d8cdc3301c9f9a68d89d21ae7b1bf1658f.tar travnik-5aed85d8cdc3301c9f9a68d89d21ae7b1bf1658f.tar.gz travnik-5aed85d8cdc3301c9f9a68d89d21ae7b1bf1658f.tar.bz2 travnik-5aed85d8cdc3301c9f9a68d89d21ae7b1bf1658f.tar.lz travnik-5aed85d8cdc3301c9f9a68d89d21ae7b1bf1658f.tar.xz travnik-5aed85d8cdc3301c9f9a68d89d21ae7b1bf1658f.tar.zst travnik-5aed85d8cdc3301c9f9a68d89d21ae7b1bf1658f.zip |
Diffstat (limited to '')
-rw-r--r-- | src/main.c | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -9,6 +9,7 @@ #include <poll.h> #include <sys/time.h> #define S0(x) (x ? x : "") +#define So(x, o) (x ? x : o) #define TORRENT_USERDATA struct dht * dht; #define DHT_USERDATA struct pollfd ** pollfds; size_t * pollfds_size; nfds_t * nfds; #include <dht.c> @@ -45,10 +46,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()+256; + t->ttl = seconds()+atoi(So(getenv("TTL"), "256")); t->type |= info | peers; } else { - if (last_added + 2 > seconds()) { + if (last_added + atoi(So(getenv("COOLDOWN"), "2")) > seconds()) { L(debug, d, "not adding a torrent this fast"); return; } @@ -56,7 +57,7 @@ void found_torrent (struct dht * d __attribute__((unused)), const unsigned char t = torrent_init(); memcpy(t->hash, h, 20); t->type |= info | peers; - t->ttl = seconds()+256; + t->ttl = seconds()+atoi(So(getenv("TTL"), "256")); add_torrent(d, t); } } @@ -121,6 +122,20 @@ int main (int argc, char ** argv) { dht = dht_init(config); free_bencoding(config); config = NULL; + if (getenv("INSERT_PEER")) { + dht->insert_peer.sin6_family = AF_INET6; + dht->insert_peer.sin6_port = htons(atoi(So(getenv("INSERT_PEER_PORT"), "1337"))); + if (inet_pton(AF_INET6, getenv("INSERT_PEER"), dht->insert_peer.sin6_addr.s6_addr) != 1) { + error_at_line(0, 0, __FILE__, __LINE__, "inet_pton(AF_INET6, getenv(INSERT_PEER)) != 1"); + r = 14; + goto r; + } + error_at_line(0, 0, __FILE__, __LINE__, "feature INSERT_PEER not implemented completely -- bugs: travnik somehow starts sending packets to inserted peer ... perhaps he sends get_peers to himself?"); + r = 15; + goto r; + } + if (getenv("TOOMUCH")) + dht->toomuch = atoi(getenv("TOOMUCH")); dht->possible_torrent = found_torrent; dht->connection = connection; pollfds = malloc(sizeof *pollfds); |