diff options
author | irungentoo <irungentoo@gmail.com> | 2013-07-13 13:20:12 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-07-13 13:20:12 -0400 |
commit | d63d63de9b17afaa5896929d00fbc1ba04e52491 (patch) | |
tree | bb02c5363dceae82390e545ad4a410d289722021 | |
parent | d4fe483efd3e0062f12430efe9deb66d43d914d7 (diff) |
Simple boostrap server added.
-rw-r--r-- | other/DHT_bootstrap.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c new file mode 100644 index 00000000..6be90875 --- /dev/null +++ b/other/DHT_bootstrap.c | |||
@@ -0,0 +1,60 @@ | |||
1 | /* DHT boostrap | ||
2 | * | ||
3 | * A simple DHT boostrap server for tox. | ||
4 | * | ||
5 | * Build command: 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 | * | ||
7 | */ | ||
8 | |||
9 | #include "../core/DHT.h" | ||
10 | |||
11 | |||
12 | //Sleep function (x = milliseconds) | ||
13 | #ifdef WIN32 | ||
14 | #define c_sleep(x) Sleep(1*x) | ||
15 | #else | ||
16 | #include <unistd.h> | ||
17 | #define c_sleep(x) usleep(1000*x) | ||
18 | #endif | ||
19 | |||
20 | #define PORT 33445 | ||
21 | |||
22 | |||
23 | |||
24 | int main(int argc, char *argv[]) | ||
25 | { | ||
26 | new_keys(); | ||
27 | printf("Public key: "); | ||
28 | uint32_t i; | ||
29 | for(i = 0; i < 32; i++) | ||
30 | { | ||
31 | if(self_public_key[i] < 16) | ||
32 | printf("0"); | ||
33 | printf("%hhX",self_public_key[i]); | ||
34 | } | ||
35 | printf("\n"); | ||
36 | //initialize networking | ||
37 | //bind to ip 0.0.0.0:PORT | ||
38 | IP ip; | ||
39 | ip.i = 0; | ||
40 | init_networking(ip, PORT); | ||
41 | |||
42 | perror("Initialization"); | ||
43 | |||
44 | IP_Port ip_port; | ||
45 | uint8_t data[MAX_UDP_PACKET_SIZE]; | ||
46 | uint32_t length; | ||
47 | |||
48 | while(1) | ||
49 | { | ||
50 | doDHT(); | ||
51 | |||
52 | while(receivepacket(&ip_port, data, &length) != -1) | ||
53 | { | ||
54 | DHT_handlepacket(data, length, ip_port); | ||
55 | } | ||
56 | c_sleep(1); | ||
57 | } | ||
58 | shutdown_networking(); | ||
59 | return 0; | ||
60 | } \ No newline at end of file | ||