diff options
Diffstat (limited to 'other/DHT_bootstrap.c')
-rw-r--r-- | other/DHT_bootstrap.c | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 3e8858dc..deecda87 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c | |||
@@ -1,13 +1,13 @@ | |||
1 | /* DHT boostrap | 1 | /* DHT boostrap |
2 | * | 2 | * |
3 | * A simple DHT boostrap server for tox. | 3 | * A simple DHT boostrap server for tox. |
4 | * | 4 | * |
5 | * Build commands (use one or the other): | 5 | * Build commands (use one or the other): |
6 | * gcc -O2 -Wall -D VANILLA_NACL -o bootstrap_server ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../core/DHT.c ../nacl/build/${HOSTNAME%.*}/lib/amd64/{cpucycles.o,libnacl.a,randombytes.o} DHT_bootstrap.c | 6 | * gcc -O2 -Wall -D VANILLA_NACL -o bootstrap_server ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../core/DHT.c ../nacl/build/${HOSTNAME%.*}/lib/amd64/{cpucycles.o,libnacl.a,randombytes.o} DHT_bootstrap.c |
7 | * | 7 | * |
8 | * gcc -O2 -Wall -o bootstrap_server ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../core/DHT.c -lsodium DHT_bootstrap.c | 8 | * gcc -O2 -Wall -o bootstrap_server ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../core/DHT.c -lsodium DHT_bootstrap.c |
9 | */ | 9 | */ |
10 | 10 | #include <arpa/inet.h> | |
11 | #include "../core/DHT.h" | 11 | #include "../core/DHT.h" |
12 | 12 | ||
13 | 13 | ||
@@ -21,7 +21,19 @@ | |||
21 | 21 | ||
22 | #define PORT 33445 | 22 | #define PORT 33445 |
23 | 23 | ||
24 | 24 | unsigned char * hex_string_to_bin(char hex_string[]) | |
25 | { | ||
26 | unsigned char * val = malloc(strlen(hex_string)); | ||
27 | char * pos = hex_string; | ||
28 | int i=0; | ||
29 | while(i < strlen(hex_string)) | ||
30 | { | ||
31 | sscanf(pos,"%2hhx",&val[i]); | ||
32 | pos+=2; | ||
33 | i++; | ||
34 | } | ||
35 | return val; | ||
36 | } | ||
25 | 37 | ||
26 | int main(int argc, char *argv[]) | 38 | int main(int argc, char *argv[]) |
27 | { | 39 | { |
@@ -42,13 +54,29 @@ int main(int argc, char *argv[]) | |||
42 | init_networking(ip, PORT); | 54 | init_networking(ip, PORT); |
43 | 55 | ||
44 | perror("Initialization"); | 56 | perror("Initialization"); |
57 | |||
58 | if (argc > 3) { | ||
59 | printf("Trying to bootstrap into the network...\n"); | ||
60 | IP_Port bootstrap_info; | ||
61 | bootstrap_info.ip.i = inet_addr(argv[1]); | ||
62 | bootstrap_info.port = htons(atoi(argv[2])); | ||
63 | uint8_t *bootstrap_key = hex_string_to_bin(argv[3]); | ||
64 | DHT_bootstrap(bootstrap_info, bootstrap_key); | ||
65 | free(bootstrap_key); | ||
66 | } | ||
45 | 67 | ||
46 | IP_Port ip_port; | 68 | IP_Port ip_port; |
47 | uint8_t data[MAX_UDP_PACKET_SIZE]; | 69 | uint8_t data[MAX_UDP_PACKET_SIZE]; |
48 | uint32_t length; | 70 | uint32_t length; |
49 | 71 | ||
72 | int is_waiting_for_dht_connection = 1; | ||
50 | while(1) | 73 | while(1) |
51 | { | 74 | { |
75 | if (is_waiting_for_dht_connection && DHT_isconnected()) | ||
76 | { | ||
77 | printf("Connected to other bootstrap server successfully.\n"); | ||
78 | is_waiting_for_dht_connection = 0; | ||
79 | } | ||
52 | doDHT(); | 80 | doDHT(); |
53 | 81 | ||
54 | while(receivepacket(&ip_port, data, &length) != -1) | 82 | while(receivepacket(&ip_port, data, &length) != -1) |
@@ -58,5 +86,5 @@ int main(int argc, char *argv[]) | |||
58 | c_sleep(1); | 86 | c_sleep(1); |
59 | } | 87 | } |
60 | shutdown_networking(); | 88 | shutdown_networking(); |
61 | return 0; | 89 | return 0; |
62 | } \ No newline at end of file | 90 | } \ No newline at end of file |