summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/info.c33
-rw-r--r--utils/midpoint.c19
2 files changed, 33 insertions, 19 deletions
diff --git a/utils/info.c b/utils/info.c
new file mode 100644
index 0000000..6f082dc
--- /dev/null
+++ b/utils/info.c
@@ -0,0 +1,33 @@
+#include <error.h>
+#include <sys/time.h>
+#include <poll.h>
+#define TORRENT_USERDATA struct dht * dht;
+#define DHT_USERDATA struct pollfd ** pollfds; size_t * pollfds_size; nfds_t * nfds;
+#include <dht.c>
+#define S0(x) (x ? x : "")
+int we_have_disconnected = 0;
+#define DISCONNECTION_MIXIN_BOTTOM we_have_disconnected++;
+#include <tcp.c>
+int main (int argc, char ** argv) {
+ if (argc != 1+3)
+ error_at_line(1, 0, __FILE__, __LINE__, "%s infohash ipv6 port", S0(argv[0]));
+ struct dht * dht = dht_init(NULL);
+ nfds_t nfds = 0;
+ size_t pollfds_size = 1;
+ struct pollfd * pollfds = malloc(sizeof *pollfds);
+ dht->nfds = &nfds;
+ dht->pollfds_size = &pollfds_size;
+ dht->pollfds = &pollfds;
+ dht->connection = connection;
+ dht->verbosity |= incoming_dht | outgoing_dht | expected | debug;
+ dht->torrents = torrent_init();
+ hex2bin(dht->torrents->hash, argv[1], 20);
+ dht->torrents->type = info;
+ dht->torrents->peers = peer_init();
+ inet_pton(AF_INET6, argv[2], dht->torrents->peers->addr.sin6_addr.s6_addr);
+ dht->torrents->peers->addr.sin6_port = htons(atoi(argv[3]));
+ periodic(dht);
+ while (!we_have_disconnected && poll(*dht->pollfds, *dht->nfds, -1) != -1)
+ tcp_work(dht);
+ dht_free(dht);
+}
diff --git a/utils/midpoint.c b/utils/midpoint.c
index 1a2e6f3..c736143 100644
--- a/utils/midpoint.c
+++ b/utils/midpoint.c
@@ -2,25 +2,6 @@
#include <error.h>
#define S0(x) (x ? x : "")
-/**
- * converts a hexadecimal string to bytes
- *
- * b and h may not overlap, unless they are the same address
- *
- * @param b [out] array of bytes to write to with capacity l
- * @param h [in] array of hex to read from with 2l hex digits
- * @param l [in] length of output array
- */
-
-void hex2bin (unsigned char * b, const char * h, int l) {
- for (int i = 0; i < l; i++) {
- char ms = *h++;
- char ls = *h++;
- b[i] = (ms >= 'a' ? ms - 'a' + 10 : (ms >= 'A' ? ms - 'A' + 10 : ms - '0')) << 4;
- b[i] |= (ls >= 'a' ? ls - 'a' + 10 : (ls >= 'A' ? ls - 'A' + 10 : ls - '0'));
- }
-}
-
int main (int argc, char ** argv) {
if (argc < 3)
error_at_line(1, 0, __FILE__, __LINE__, "%s <bin|add|subtract|divide|midpoint> <a> [b]", S0(argv[0]));