summaryrefslogtreecommitdiff
path: root/other/DHT_bootstrap.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-08-16 13:11:09 -0400
committerirungentoo <irungentoo@gmail.com>2013-08-16 13:11:09 -0400
commit88ff81d9def5efe69cbaf91aa41906177ba7dde9 (patch)
treecb9f149e438bcd1f18d8c1eb5d8be6b0a22f58a4 /other/DHT_bootstrap.c
parentc5af8f44a9d040a0bbe0442ec074d9fc8562dd32 (diff)
Passed everything through astyle.
Diffstat (limited to 'other/DHT_bootstrap.c')
-rw-r--r--other/DHT_bootstrap.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c
index 4b0adeff..299e030c 100644
--- a/other/DHT_bootstrap.c
+++ b/other/DHT_bootstrap.c
@@ -6,7 +6,7 @@
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 ../core/friend_requests.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 ../core/friend_requests.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 ../core/friend_requests.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 ../core/friend_requests.c -lsodium DHT_bootstrap.c
9 * 9 *
10 * 10 *
11 * Copyright (C) 2013 Tox project All Rights Reserved. 11 * Copyright (C) 2013 Tox project All Rights Reserved.
12 * 12 *
@@ -24,7 +24,7 @@
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with Tox. If not, see <http://www.gnu.org/licenses/>. 26 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
27 * 27 *
28 */ 28 */
29 29
30#include "../core/DHT.h" 30#include "../core/DHT.h"
@@ -50,13 +50,16 @@ void manage_keys()
50 uint8_t keys[KEYS_SIZE]; 50 uint8_t keys[KEYS_SIZE];
51 51
52 FILE *keys_file = fopen("key", "r"); 52 FILE *keys_file = fopen("key", "r");
53
53 if (keys_file != NULL) { 54 if (keys_file != NULL) {
54 //if file was opened successfully -- load keys 55 //if file was opened successfully -- load keys
55 size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keys_file); 56 size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keys_file);
57
56 if (read_size != KEYS_SIZE) { 58 if (read_size != KEYS_SIZE) {
57 printf("Error while reading the key file\nExiting.\n"); 59 printf("Error while reading the key file\nExiting.\n");
58 exit(1); 60 exit(1);
59 } 61 }
62
60 load_keys(keys); 63 load_keys(keys);
61 printf("Keys loaded successfully\n"); 64 printf("Keys loaded successfully\n");
62 } else { 65 } else {
@@ -64,10 +67,12 @@ void manage_keys()
64 new_keys(); 67 new_keys();
65 save_keys(keys); 68 save_keys(keys);
66 keys_file = fopen("key", "w"); 69 keys_file = fopen("key", "w");
70
67 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) {
68 printf("Error while writing the key file.\nExiting.\n"); 72 printf("Error while writing the key file.\nExiting.\n");
69 exit(1); 73 exit(1);
70 } 74 }
75
71 printf("Keys saved successfully\n"); 76 printf("Keys saved successfully\n");
72 } 77 }
73 78
@@ -83,12 +88,12 @@ int main(int argc, char *argv[])
83 FILE *file; 88 FILE *file;
84 file = fopen("PUBLIC_ID.txt", "w"); 89 file = fopen("PUBLIC_ID.txt", "w");
85 90
86 for(i = 0; i < 32; i++) 91 for (i = 0; i < 32; i++) {
87 { 92 if (self_public_key[i] < 16)
88 if(self_public_key[i] < 16)
89 printf("0"); 93 printf("0");
90 printf("%hhX",self_public_key[i]); 94
91 fprintf(file, "%hhX",self_public_key[i]); 95 printf("%hhX", self_public_key[i]);
96 fprintf(file, "%hhX", self_public_key[i]);
92 } 97 }
93 98
94 fclose(file); 99 fclose(file);
@@ -117,19 +122,20 @@ int main(int argc, char *argv[])
117 friendreq_init(); 122 friendreq_init();
118 123
119 int is_waiting_for_dht_connection = 1; 124 int is_waiting_for_dht_connection = 1;
120 while(1) 125
121 { 126 while (1) {
122 if (is_waiting_for_dht_connection && DHT_isconnected()) 127 if (is_waiting_for_dht_connection && DHT_isconnected()) {
123 {
124 printf("Connected to other bootstrap server successfully.\n"); 128 printf("Connected to other bootstrap server successfully.\n");
125 is_waiting_for_dht_connection = 0; 129 is_waiting_for_dht_connection = 0;
126 } 130 }
131
127 doDHT(); 132 doDHT();
128 133
129 networking_poll(); 134 networking_poll();
130 135
131 c_sleep(1); 136 c_sleep(1);
132 } 137 }
138
133 shutdown_networking(); 139 shutdown_networking();
134 return 0; 140 return 0;
135} 141}