summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index 199bfab..0949e4b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);