Merge remote-tracking branch 'upstream/refactor' into refactor

This commit is contained in:
Simon Levermann 2013-08-20 22:46:39 +02:00
commit ffa01f8def
2 changed files with 19 additions and 22 deletions

View File

@ -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;
}

View File

@ -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);