diff options
author | irungentoo <irungentoo@gmail.com> | 2013-08-16 13:11:09 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-08-16 13:11:09 -0400 |
commit | 88ff81d9def5efe69cbaf91aa41906177ba7dde9 (patch) | |
tree | cb9f149e438bcd1f18d8c1eb5d8be6b0a22f58a4 /testing/DHT_test.c | |
parent | c5af8f44a9d040a0bbe0442ec074d9fc8562dd32 (diff) |
Passed everything through astyle.
Diffstat (limited to 'testing/DHT_test.c')
-rw-r--r-- | testing/DHT_test.c | 132 |
1 files changed, 74 insertions, 58 deletions
diff --git a/testing/DHT_test.c b/testing/DHT_test.c index c5b367cf..3883f3a7 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c | |||
@@ -1,11 +1,11 @@ | |||
1 | /* DHT test | 1 | /* DHT test |
2 | * A file with a main that runs our DHT for testing. | 2 | * A file with a main that runs our DHT for testing. |
3 | * | 3 | * |
4 | * Compile with: gcc -O2 -Wall -D VANILLA_NACL -o test ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../nacl/build/${HOSTNAME%.*}/lib/amd64/{cpucycles.o,libnacl.a,randombytes.o} DHT_test.c | 4 | * Compile with: gcc -O2 -Wall -D VANILLA_NACL -o test ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../nacl/build/${HOSTNAME%.*}/lib/amd64/{cpucycles.o,libnacl.a,randombytes.o} DHT_test.c |
5 | * | 5 | * |
6 | * Command line arguments are the ip, port and public key of a node. | 6 | * Command line arguments are the ip, port and public key of a node. |
7 | * EX: ./test 127.0.0.1 33445 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA | 7 | * EX: ./test 127.0.0.1 33445 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
8 | * | 8 | * |
9 | * The test will then ask you for the id (in hex format) of the friend you wish to add | 9 | * The test will then ask you for the id (in hex format) of the friend you wish to add |
10 | * | 10 | * |
11 | * Copyright (C) 2013 Tox project All Rights Reserved. | 11 | * Copyright (C) 2013 Tox project All Rights Reserved. |
@@ -24,9 +24,9 @@ | |||
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/network.h" | 30 | //#include "../core/network.h" |
31 | #include "../core/DHT.c" | 31 | #include "../core/DHT.c" |
32 | #include "../core/friend_requests.c" | 32 | #include "../core/friend_requests.c" |
@@ -53,19 +53,22 @@ void print_clientlist() | |||
53 | uint32_t i, j; | 53 | uint32_t i, j; |
54 | IP_Port p_ip; | 54 | IP_Port p_ip; |
55 | printf("___________________CLOSE________________________________\n"); | 55 | printf("___________________CLOSE________________________________\n"); |
56 | for(i = 0; i < 32; i++) { | 56 | |
57 | for (i = 0; i < 32; i++) { | ||
57 | printf("ClientID: "); | 58 | printf("ClientID: "); |
58 | for(j = 0; j < 32; j++) { | 59 | |
60 | for (j = 0; j < 32; j++) { | ||
59 | printf("%02hhX", close_clientlist[i].client_id[j]); | 61 | printf("%02hhX", close_clientlist[i].client_id[j]); |
60 | } | 62 | } |
63 | |||
61 | p_ip = close_clientlist[i].ip_port; | 64 | p_ip = close_clientlist[i].ip_port; |
62 | printf("\nIP: %u.%u.%u.%u Port: %u",p_ip.ip.c[0],p_ip.ip.c[1],p_ip.ip.c[2],p_ip.ip.c[3],ntohs(p_ip.port)); | 65 | printf("\nIP: %u.%u.%u.%u Port: %u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); |
63 | printf("\nTimestamp: %llu",(long long unsigned int) close_clientlist[i].timestamp); | 66 | printf("\nTimestamp: %llu", (long long unsigned int) close_clientlist[i].timestamp); |
64 | printf("\nLast pinged: %llu\n",(long long unsigned int) close_clientlist[i].last_pinged); | 67 | printf("\nLast pinged: %llu\n", (long long unsigned int) close_clientlist[i].last_pinged); |
65 | p_ip = close_clientlist[i].ret_ip_port; | 68 | p_ip = close_clientlist[i].ret_ip_port; |
66 | printf("OUR IP: %u.%u.%u.%u Port: %u\n",p_ip.ip.c[0],p_ip.ip.c[1],p_ip.ip.c[2],p_ip.ip.c[3],ntohs(p_ip.port)); | 69 | printf("OUR IP: %u.%u.%u.%u Port: %u\n", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); |
67 | printf("Timestamp: %llu\n",(long long unsigned int) close_clientlist[i].ret_timestamp); | 70 | printf("Timestamp: %llu\n", (long long unsigned int) close_clientlist[i].ret_timestamp); |
68 | } | 71 | } |
69 | } | 72 | } |
70 | 73 | ||
71 | void print_friendlist() | 74 | void print_friendlist() |
@@ -73,78 +76,91 @@ void print_friendlist() | |||
73 | uint32_t i, j, k; | 76 | uint32_t i, j, k; |
74 | IP_Port p_ip; | 77 | IP_Port p_ip; |
75 | printf("_________________FRIENDS__________________________________\n"); | 78 | printf("_________________FRIENDS__________________________________\n"); |
76 | for(k = 0; k < num_friends; k++) { | 79 | |
80 | for (k = 0; k < num_friends; k++) { | ||
77 | printf("FRIEND %u\n", k); | 81 | printf("FRIEND %u\n", k); |
78 | printf("ID: "); | 82 | printf("ID: "); |
79 | for(j = 0; j < 32; j++) { | 83 | |
84 | for (j = 0; j < 32; j++) { | ||
80 | printf("%c", friends_list[k].client_id[j]); | 85 | printf("%c", friends_list[k].client_id[j]); |
81 | } | 86 | } |
87 | |||
82 | p_ip = DHT_getfriendip(friends_list[k].client_id); | 88 | p_ip = DHT_getfriendip(friends_list[k].client_id); |
83 | printf("\nIP: %u.%u.%u.%u:%u",p_ip.ip.c[0],p_ip.ip.c[1],p_ip.ip.c[2],p_ip.ip.c[3],ntohs(p_ip.port)); | 89 | printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); |
84 | 90 | ||
85 | printf("\nCLIENTS IN LIST:\n\n"); | 91 | printf("\nCLIENTS IN LIST:\n\n"); |
86 | 92 | ||
87 | for(i = 0; i < 4; i++) { | 93 | for (i = 0; i < 4; i++) { |
88 | printf("ClientID: "); | 94 | printf("ClientID: "); |
89 | for(j = 0; j < 32; j++) { | 95 | |
90 | if(friends_list[k].client_list[i].client_id[j] < 16) | 96 | for (j = 0; j < 32; j++) { |
97 | if (friends_list[k].client_list[i].client_id[j] < 16) | ||
91 | printf("0"); | 98 | printf("0"); |
99 | |||
92 | printf("%hhX", friends_list[k].client_list[i].client_id[j]); | 100 | printf("%hhX", friends_list[k].client_list[i].client_id[j]); |
93 | } | 101 | } |
102 | |||
94 | p_ip = friends_list[k].client_list[i].ip_port; | 103 | p_ip = friends_list[k].client_list[i].ip_port; |
95 | printf("\nIP: %u.%u.%u.%u:%u",p_ip.ip.c[0],p_ip.ip.c[1],p_ip.ip.c[2],p_ip.ip.c[3],ntohs(p_ip.port)); | 104 | printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); |
96 | printf("\nTimestamp: %llu",(long long unsigned int) friends_list[k].client_list[i].timestamp); | 105 | printf("\nTimestamp: %llu", (long long unsigned int) friends_list[k].client_list[i].timestamp); |
97 | printf("\nLast pinged: %llu\n",(long long unsigned int) friends_list[k].client_list[i].last_pinged); | 106 | printf("\nLast pinged: %llu\n", (long long unsigned int) friends_list[k].client_list[i].last_pinged); |
98 | p_ip = friends_list[k].client_list[i].ret_ip_port; | 107 | p_ip = friends_list[k].client_list[i].ret_ip_port; |
99 | printf("ret IP: %u.%u.%u.%u:%u\n",p_ip.ip.c[0],p_ip.ip.c[1],p_ip.ip.c[2],p_ip.ip.c[3],ntohs(p_ip.port)); | 108 | printf("ret IP: %u.%u.%u.%u:%u\n", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); |
100 | printf("Timestamp: %llu\n", (long long unsigned int)friends_list[k].client_list[i].ret_timestamp); | 109 | printf("Timestamp: %llu\n", (long long unsigned int)friends_list[k].client_list[i].ret_timestamp); |
101 | } | 110 | } |
102 | } | 111 | } |
103 | } | 112 | } |
104 | 113 | ||
105 | void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) | 114 | void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port) |
106 | { | 115 | { |
107 | uint32_t i; | 116 | uint32_t i; |
108 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); | 117 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); |
109 | printf("--------------------BEGIN-----------------------------\n"); | 118 | printf("--------------------BEGIN-----------------------------\n"); |
110 | for(i = 0; i < length; i++) { | 119 | |
111 | if(data[i] < 16) | 120 | for (i = 0; i < length; i++) { |
121 | if (data[i] < 16) | ||
112 | printf("0"); | 122 | printf("0"); |
113 | printf("%hhX",data[i]); | 123 | |
124 | printf("%hhX", data[i]); | ||
114 | } | 125 | } |
126 | |||
115 | printf("\n--------------------END-----------------------------\n\n\n"); | 127 | printf("\n--------------------END-----------------------------\n\n\n"); |
116 | } | 128 | } |
117 | 129 | ||
118 | int main(int argc, char *argv[]) | 130 | int main(int argc, char *argv[]) |
119 | { | 131 | { |
120 | //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); | 132 | //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); |
121 | 133 | ||
122 | if (argc < 4) { | 134 | if (argc < 4) { |
123 | printf("usage %s ip port public_key\n", argv[0]); | 135 | printf("usage %s ip port public_key\n", argv[0]); |
124 | exit(0); | 136 | exit(0); |
125 | } | 137 | } |
138 | |||
126 | new_keys(); | 139 | new_keys(); |
127 | printf("OUR ID: "); | 140 | printf("OUR ID: "); |
128 | uint32_t i; | 141 | uint32_t i; |
129 | for(i = 0; i < 32; i++) { | 142 | |
130 | if(self_public_key[i] < 16) | 143 | for (i = 0; i < 32; i++) { |
144 | if (self_public_key[i] < 16) | ||
131 | printf("0"); | 145 | printf("0"); |
132 | printf("%hhX",self_public_key[i]); | 146 | |
147 | printf("%hhX", self_public_key[i]); | ||
133 | } | 148 | } |
134 | 149 | ||
135 | char temp_id[128]; | 150 | char temp_id[128]; |
136 | printf("\nEnter the client_id of the friend you wish to add (32 bytes HEX format):\n"); | 151 | printf("\nEnter the client_id of the friend you wish to add (32 bytes HEX format):\n"); |
137 | if(scanf("%s", temp_id) != 1) | 152 | |
153 | if (scanf("%s", temp_id) != 1) | ||
138 | exit(0); | 154 | exit(0); |
139 | 155 | ||
140 | DHT_addfriend(hex_string_to_bin(temp_id)); | 156 | DHT_addfriend(hex_string_to_bin(temp_id)); |
141 | 157 | ||
142 | /* initialize networking */ | 158 | /* initialize networking */ |
143 | /* bind to ip 0.0.0.0:PORT */ | 159 | /* bind to ip 0.0.0.0:PORT */ |
144 | IP ip; | 160 | IP ip; |
145 | ip.i = 0; | 161 | ip.i = 0; |
146 | init_networking(ip, PORT); | 162 | init_networking(ip, PORT); |
147 | 163 | ||
148 | 164 | ||
149 | perror("Initialization"); | 165 | perror("Initialization"); |
150 | IP_Port bootstrap_ip_port; | 166 | IP_Port bootstrap_ip_port; |
@@ -155,37 +171,37 @@ int main(int argc, char *argv[]) | |||
155 | * bootstrap_ip_port.ip.c[3] = 1; */ | 171 | * bootstrap_ip_port.ip.c[3] = 1; */ |
156 | bootstrap_ip_port.ip.i = inet_addr(argv[1]); | 172 | bootstrap_ip_port.ip.i = inet_addr(argv[1]); |
157 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); | 173 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); |
158 | 174 | ||
159 | /* | 175 | /* |
160 | IP_Port ip_port; | 176 | IP_Port ip_port; |
161 | uint8_t data[MAX_UDP_PACKET_SIZE]; | 177 | uint8_t data[MAX_UDP_PACKET_SIZE]; |
162 | uint32_t length; | 178 | uint32_t length; |
163 | */ | 179 | */ |
164 | 180 | ||
165 | DHT_init(); | 181 | DHT_init(); |
166 | friendreq_init(); | 182 | friendreq_init(); |
167 | 183 | ||
168 | while(1) { | 184 | while (1) { |
169 | 185 | ||
170 | doDHT(); | 186 | doDHT(); |
171 | 187 | ||
172 | /* slvrTODO: | 188 | /* slvrTODO: |
173 | while(receivepacket(&ip_port, data, &length) != -1) { | 189 | while(receivepacket(&ip_port, data, &length) != -1) { |
174 | if(DHT_handlepacket(data, length, ip_port) && friendreq_handlepacket(data, length, ip_port)) { | 190 | if(DHT_handlepacket(data, length, ip_port) && friendreq_handlepacket(data, length, ip_port)) { |
175 | //unhandled packet | 191 | //unhandled packet |
176 | printpacket(data, length, ip_port); | 192 | printpacket(data, length, ip_port); |
177 | } else { | 193 | } else { |
178 | printf("Received handled packet with length: %u\n", length); | 194 | printf("Received handled packet with length: %u\n", length); |
179 | } | 195 | } |
180 | } | 196 | } |
181 | */ | 197 | */ |
182 | networking_poll(); | 198 | networking_poll(); |
183 | 199 | ||
184 | print_clientlist(); | 200 | print_clientlist(); |
185 | print_friendlist(); | 201 | print_friendlist(); |
186 | c_sleep(300); | 202 | c_sleep(300); |
187 | } | 203 | } |
188 | 204 | ||
189 | shutdown_networking(); | 205 | shutdown_networking(); |
190 | return 0; | 206 | return 0; |
191 | } | 207 | } |