From 1fde3ce6aa6f763a6b8dc28a31cd5bfb771bb247 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 20 Aug 2013 16:37:34 -0400 Subject: [PATCH] DHT_bootstrap fixed. --- other/DHT_bootstrap.c | 39 ++++++++++++++++++--------------------- testing/DHT_test.c | 2 +- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 299e030c..4a91679c 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -44,7 +44,7 @@ -void manage_keys() +void manage_keys(DHT * dht) { const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES; uint8_t keys[KEYS_SIZE]; @@ -60,12 +60,12 @@ void manage_keys() exit(1); } - load_keys(keys); + load_keys(dht->c, keys); printf("Keys loaded successfully\n"); } else { //otherwise save new keys - new_keys(); - save_keys(keys); + new_keys(dht->c); + save_keys(dht->c, keys); keys_file = fopen("key", "w"); if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) { @@ -81,7 +81,13 @@ void manage_keys() int main(int argc, char *argv[]) { - manage_keys(); + //initialize networking + //bind to ip 0.0.0.0:PORT + IP ip; + ip.i = 0; + DHT * dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); + init_cryptopackets(dht); + manage_keys(dht); printf("Public key: "); uint32_t i; @@ -89,22 +95,17 @@ int main(int argc, char *argv[]) file = fopen("PUBLIC_ID.txt", "w"); for (i = 0; i < 32; i++) { - if (self_public_key[i] < 16) + if (dht->c->self_public_key[i] < 16) printf("0"); - printf("%hhX", self_public_key[i]); - fprintf(file, "%hhX", self_public_key[i]); + printf("%hhX", dht->c->self_public_key[i]); + fprintf(file, "%hhX", dht->c->self_public_key[i]); } fclose(file); printf("\n"); printf("Port: %u\n", PORT); - //initialize networking - //bind to ip 0.0.0.0:PORT - IP ip; - ip.i = 0; - init_networking(ip, PORT); perror("Initialization"); @@ -114,28 +115,24 @@ int main(int argc, char *argv[]) bootstrap_info.ip.i = inet_addr(argv[1]); bootstrap_info.port = htons(atoi(argv[2])); uint8_t *bootstrap_key = hex_string_to_bin(argv[3]); - DHT_bootstrap(bootstrap_info, bootstrap_key); + DHT_bootstrap(dht, bootstrap_info, bootstrap_key); free(bootstrap_key); } - DHT_init(); - friendreq_init(); - int is_waiting_for_dht_connection = 1; while (1) { - if (is_waiting_for_dht_connection && DHT_isconnected()) { + if (is_waiting_for_dht_connection && DHT_isconnected(dht)) { printf("Connected to other bootstrap server successfully.\n"); is_waiting_for_dht_connection = 0; } - doDHT(); + do_DHT(dht); - networking_poll(); + networking_poll(dht->c->lossless_udp->net); c_sleep(1); } - shutdown_networking(); return 0; } diff --git a/testing/DHT_test.c b/testing/DHT_test.c index c128f25c..a9575fd5 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c @@ -136,7 +136,7 @@ int main(int argc, char *argv[]) ip.i = 0; DHT * dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); - + init_cryptopackets(dht); if (argc < 4) { printf("usage %s ip port public_key\n", argv[0]); exit(0);