summaryrefslogtreecommitdiff
path: root/other/DHT_bootstrap.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-08-20 16:37:34 -0400
committerirungentoo <irungentoo@gmail.com>2013-08-20 16:37:34 -0400
commit1fde3ce6aa6f763a6b8dc28a31cd5bfb771bb247 (patch)
treedc8039b4083410b87606be4a61d959d008c00fdf /other/DHT_bootstrap.c
parent747c290269db58f68ce05e976af974f3904ac3d0 (diff)
DHT_bootstrap fixed.
Diffstat (limited to 'other/DHT_bootstrap.c')
-rw-r--r--other/DHT_bootstrap.c39
1 files changed, 18 insertions, 21 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 @@
44 44
45 45
46 46
47void manage_keys() 47void manage_keys(DHT * dht)
48{ 48{
49 const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES; 49 const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
50 uint8_t keys[KEYS_SIZE]; 50 uint8_t keys[KEYS_SIZE];
@@ -60,12 +60,12 @@ void manage_keys()
60 exit(1); 60 exit(1);
61 } 61 }
62 62
63 load_keys(keys); 63 load_keys(dht->c, keys);
64 printf("Keys loaded successfully\n"); 64 printf("Keys loaded successfully\n");
65 } else { 65 } else {
66 //otherwise save new keys 66 //otherwise save new keys
67 new_keys(); 67 new_keys(dht->c);
68 save_keys(keys); 68 save_keys(dht->c, keys);
69 keys_file = fopen("key", "w"); 69 keys_file = fopen("key", "w");
70 70
71 if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) { 71 if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) {
@@ -81,7 +81,13 @@ void manage_keys()
81 81
82int main(int argc, char *argv[]) 82int main(int argc, char *argv[])
83{ 83{
84 manage_keys(); 84 //initialize networking
85 //bind to ip 0.0.0.0:PORT
86 IP ip;
87 ip.i = 0;
88 DHT * dht = new_DHT(new_net_crypto(new_networking(ip, PORT)));
89 init_cryptopackets(dht);
90 manage_keys(dht);
85 printf("Public key: "); 91 printf("Public key: ");
86 uint32_t i; 92 uint32_t i;
87 93
@@ -89,22 +95,17 @@ int main(int argc, char *argv[])
89 file = fopen("PUBLIC_ID.txt", "w"); 95 file = fopen("PUBLIC_ID.txt", "w");
90 96
91 for (i = 0; i < 32; i++) { 97 for (i = 0; i < 32; i++) {
92 if (self_public_key[i] < 16) 98 if (dht->c->self_public_key[i] < 16)
93 printf("0"); 99 printf("0");
94 100
95 printf("%hhX", self_public_key[i]); 101 printf("%hhX", dht->c->self_public_key[i]);
96 fprintf(file, "%hhX", self_public_key[i]); 102 fprintf(file, "%hhX", dht->c->self_public_key[i]);
97 } 103 }
98 104
99 fclose(file); 105 fclose(file);
100 106
101 printf("\n"); 107 printf("\n");
102 printf("Port: %u\n", PORT); 108 printf("Port: %u\n", PORT);
103 //initialize networking
104 //bind to ip 0.0.0.0:PORT
105 IP ip;
106 ip.i = 0;
107 init_networking(ip, PORT);
108 109
109 perror("Initialization"); 110 perror("Initialization");
110 111
@@ -114,28 +115,24 @@ int main(int argc, char *argv[])
114 bootstrap_info.ip.i = inet_addr(argv[1]); 115 bootstrap_info.ip.i = inet_addr(argv[1]);
115 bootstrap_info.port = htons(atoi(argv[2])); 116 bootstrap_info.port = htons(atoi(argv[2]));
116 uint8_t *bootstrap_key = hex_string_to_bin(argv[3]); 117 uint8_t *bootstrap_key = hex_string_to_bin(argv[3]);
117 DHT_bootstrap(bootstrap_info, bootstrap_key); 118 DHT_bootstrap(dht, bootstrap_info, bootstrap_key);
118 free(bootstrap_key); 119 free(bootstrap_key);
119 } 120 }
120 121
121 DHT_init();
122 friendreq_init();
123
124 int is_waiting_for_dht_connection = 1; 122 int is_waiting_for_dht_connection = 1;
125 123
126 while (1) { 124 while (1) {
127 if (is_waiting_for_dht_connection && DHT_isconnected()) { 125 if (is_waiting_for_dht_connection && DHT_isconnected(dht)) {
128 printf("Connected to other bootstrap server successfully.\n"); 126 printf("Connected to other bootstrap server successfully.\n");
129 is_waiting_for_dht_connection = 0; 127 is_waiting_for_dht_connection = 0;
130 } 128 }
131 129
132 doDHT(); 130 do_DHT(dht);
133 131
134 networking_poll(); 132 networking_poll(dht->c->lossless_udp->net);
135 133
136 c_sleep(1); 134 c_sleep(1);
137 } 135 }
138 136
139 shutdown_networking();
140 return 0; 137 return 0;
141} 138}