mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
DHT_bootstrap fixed.
This commit is contained in:
parent
747c290269
commit
1fde3ce6aa
|
@ -44,7 +44,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void manage_keys()
|
void manage_keys(DHT * dht)
|
||||||
{
|
{
|
||||||
const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
|
const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
|
||||||
uint8_t keys[KEYS_SIZE];
|
uint8_t keys[KEYS_SIZE];
|
||||||
|
@ -60,12 +60,12 @@ void manage_keys()
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
load_keys(keys);
|
load_keys(dht->c, keys);
|
||||||
printf("Keys loaded successfully\n");
|
printf("Keys loaded successfully\n");
|
||||||
} else {
|
} else {
|
||||||
//otherwise save new keys
|
//otherwise save new keys
|
||||||
new_keys();
|
new_keys(dht->c);
|
||||||
save_keys(keys);
|
save_keys(dht->c, keys);
|
||||||
keys_file = fopen("key", "w");
|
keys_file = fopen("key", "w");
|
||||||
|
|
||||||
if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) {
|
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[])
|
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: ");
|
printf("Public key: ");
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
|
@ -89,22 +95,17 @@ int main(int argc, char *argv[])
|
||||||
file = fopen("PUBLIC_ID.txt", "w");
|
file = fopen("PUBLIC_ID.txt", "w");
|
||||||
|
|
||||||
for (i = 0; i < 32; i++) {
|
for (i = 0; i < 32; i++) {
|
||||||
if (self_public_key[i] < 16)
|
if (dht->c->self_public_key[i] < 16)
|
||||||
printf("0");
|
printf("0");
|
||||||
|
|
||||||
printf("%hhX", self_public_key[i]);
|
printf("%hhX", dht->c->self_public_key[i]);
|
||||||
fprintf(file, "%hhX", self_public_key[i]);
|
fprintf(file, "%hhX", dht->c->self_public_key[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("Port: %u\n", PORT);
|
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");
|
perror("Initialization");
|
||||||
|
|
||||||
|
@ -114,28 +115,24 @@ int main(int argc, char *argv[])
|
||||||
bootstrap_info.ip.i = inet_addr(argv[1]);
|
bootstrap_info.ip.i = inet_addr(argv[1]);
|
||||||
bootstrap_info.port = htons(atoi(argv[2]));
|
bootstrap_info.port = htons(atoi(argv[2]));
|
||||||
uint8_t *bootstrap_key = hex_string_to_bin(argv[3]);
|
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);
|
free(bootstrap_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
DHT_init();
|
|
||||||
friendreq_init();
|
|
||||||
|
|
||||||
int is_waiting_for_dht_connection = 1;
|
int is_waiting_for_dht_connection = 1;
|
||||||
|
|
||||||
while (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");
|
printf("Connected to other bootstrap server successfully.\n");
|
||||||
is_waiting_for_dht_connection = 0;
|
is_waiting_for_dht_connection = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
doDHT();
|
do_DHT(dht);
|
||||||
|
|
||||||
networking_poll();
|
networking_poll(dht->c->lossless_udp->net);
|
||||||
|
|
||||||
c_sleep(1);
|
c_sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
shutdown_networking();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,7 +136,7 @@ int main(int argc, char *argv[])
|
||||||
ip.i = 0;
|
ip.i = 0;
|
||||||
|
|
||||||
DHT * dht = new_DHT(new_net_crypto(new_networking(ip, PORT)));
|
DHT * dht = new_DHT(new_net_crypto(new_networking(ip, PORT)));
|
||||||
|
init_cryptopackets(dht);
|
||||||
if (argc < 4) {
|
if (argc < 4) {
|
||||||
printf("usage %s ip port public_key\n", argv[0]);
|
printf("usage %s ip port public_key\n", argv[0]);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user