summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
Diffstat (limited to 'testing')
-rw-r--r--testing/DHT_test.c53
-rw-r--r--testing/Lossless_UDP_testclient.c32
-rw-r--r--testing/Lossless_UDP_testserver.c19
-rw-r--r--testing/Messenger_test.c33
-rw-r--r--testing/nTox.c56
5 files changed, 114 insertions, 79 deletions
diff --git a/testing/DHT_test.c b/testing/DHT_test.c
index fce9c257..ba8c2f23 100644
--- a/testing/DHT_test.c
+++ b/testing/DHT_test.c
@@ -66,13 +66,11 @@ void print_clientlist(DHT *dht)
66 } 66 }
67 67
68 p_ip = dht->close_clientlist[i].ip_port; 68 p_ip = dht->close_clientlist[i].ip_port;
69 printf("\nIP: %u.%u.%u.%u Port: %u", p_ip.ip.uint8[0], p_ip.ip.uint8[1], p_ip.ip.uint8[2], p_ip.ip.uint8[3], 69 printf("\nIP: %s Port: %u", ip_ntoa(&p_ip.ip), ntohs(p_ip.port));
70 ntohs(p_ip.port));
71 printf("\nTimestamp: %llu", (long long unsigned int) dht->close_clientlist[i].timestamp); 70 printf("\nTimestamp: %llu", (long long unsigned int) dht->close_clientlist[i].timestamp);
72 printf("\nLast pinged: %llu\n", (long long unsigned int) dht->close_clientlist[i].last_pinged); 71 printf("\nLast pinged: %llu\n", (long long unsigned int) dht->close_clientlist[i].last_pinged);
73 p_ip = dht->close_clientlist[i].ret_ip_port; 72 p_ip = dht->close_clientlist[i].ret_ip_port;
74 printf("OUR IP: %u.%u.%u.%u Port: %u\n", p_ip.ip.uint8[0], p_ip.ip.uint8[1], p_ip.ip.uint8[2], p_ip.ip.uint8[3], 73 printf("OUR IP: %s Port: %u\n", ip_ntoa(&p_ip.ip), ntohs(p_ip.port));
75 ntohs(p_ip.port));
76 printf("Timestamp: %llu\n", (long long unsigned int) dht->close_clientlist[i].ret_timestamp); 74 printf("Timestamp: %llu\n", (long long unsigned int) dht->close_clientlist[i].ret_timestamp);
77 } 75 }
78} 76}
@@ -91,9 +89,8 @@ void print_friendlist(DHT *dht)
91 printf("%c", dht->friends_list[k].client_id[j]); 89 printf("%c", dht->friends_list[k].client_id[j]);
92 } 90 }
93 91
94 p_ip = DHT_getfriendip(dht, dht->friends_list[k].client_id); 92 int friendok = DHT_getfriendip(dht, dht->friends_list[k].client_id, &p_ip);
95 printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.uint8[0], p_ip.ip.uint8[1], p_ip.ip.uint8[2], p_ip.ip.uint8[3], 93 printf("\nIP: %s:%u", ip_ntoa(&p_ip.ip), ntohs(p_ip.port));
96 ntohs(p_ip.port));
97 94
98 printf("\nCLIENTS IN LIST:\n\n"); 95 printf("\nCLIENTS IN LIST:\n\n");
99 96
@@ -108,13 +105,11 @@ void print_friendlist(DHT *dht)
108 } 105 }
109 106
110 p_ip = dht->friends_list[k].client_list[i].ip_port; 107 p_ip = dht->friends_list[k].client_list[i].ip_port;
111 printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.uint8[0], p_ip.ip.uint8[1], p_ip.ip.uint8[2], p_ip.ip.uint8[3], 108 printf("\nIP: %s:%u", ip_ntoa(&p_ip.ip), ntohs(p_ip.port));
112 ntohs(p_ip.port));
113 printf("\nTimestamp: %llu", (long long unsigned int) dht->friends_list[k].client_list[i].timestamp); 109 printf("\nTimestamp: %llu", (long long unsigned int) dht->friends_list[k].client_list[i].timestamp);
114 printf("\nLast pinged: %llu\n", (long long unsigned int) dht->friends_list[k].client_list[i].last_pinged); 110 printf("\nLast pinged: %llu\n", (long long unsigned int) dht->friends_list[k].client_list[i].last_pinged);
115 p_ip = dht->friends_list[k].client_list[i].ret_ip_port; 111 p_ip = dht->friends_list[k].client_list[i].ret_ip_port;
116 printf("ret IP: %u.%u.%u.%u:%u\n", p_ip.ip.uint8[0], p_ip.ip.uint8[1], p_ip.ip.uint8[2], p_ip.ip.uint8[3], 112 printf("ret IP: %s:%u\n", ip_ntoa(&p_ip.ip), ntohs(p_ip.port));
117 ntohs(p_ip.port));
118 printf("Timestamp: %llu\n", (long long unsigned int)dht->friends_list[k].client_list[i].ret_timestamp); 113 printf("Timestamp: %llu\n", (long long unsigned int)dht->friends_list[k].client_list[i].ret_timestamp);
119 } 114 }
120 } 115 }
@@ -138,19 +133,25 @@ void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port)
138 133
139int main(int argc, char *argv[]) 134int main(int argc, char *argv[])
140{ 135{
136 if (argc < 4) {
137 printf("Usage: %s [--ipv4|--ipv6] ip port public_key\n", argv[0]);
138 exit(0);
139 }
140
141 /* let user override default by cmdline */
142 uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
143 int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
144 if (argvoffset < 0)
145 exit(1);
146
141 //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); 147 //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32);
142 /* initialize networking */ 148 /* initialize networking */
143 /* bind to ip 0.0.0.0:PORT */ 149 /* bind to ip 0.0.0.0:PORT */
144 IP ip; 150 IP ip;
145 ip.uint32 = 0; 151 ip_init(&ip, ipv6enabled);
146 152
147 DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); 153 DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT)));
148 154
149 if (argc < 4) {
150 printf("usage %s ip port public_key\n", argv[0]);
151 exit(0);
152 }
153
154 new_keys(dht->c); 155 new_keys(dht->c);
155 printf("OUR ID: "); 156 printf("OUR ID: ");
156 uint32_t i; 157 uint32_t i;
@@ -170,16 +171,16 @@ int main(int argc, char *argv[])
170 171
171 DHT_addfriend(dht, hex_string_to_bin(temp_id)); 172 DHT_addfriend(dht, hex_string_to_bin(temp_id));
172 173
173
174 perror("Initialization"); 174 perror("Initialization");
175 IP_Port bootstrap_ip_port; 175
176 bootstrap_ip_port.port = htons(atoi(argv[2])); 176 uint16_t port = htons(atoi(argv[argvoffset + 2]));
177 /* bootstrap_ip_port.ip.c[0] = 127; 177 unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
178 * bootstrap_ip_port.ip.c[1] = 0; 178 int res = DHT_bootstrap_ex(dht, argv[argvoffset + 1], ipv6enabled, port, binary_string);
179 * bootstrap_ip_port.ip.c[2] = 0; 179 free(binary_string);
180 * bootstrap_ip_port.ip.c[3] = 1; */ 180 if (!res) {
181 bootstrap_ip_port.ip.uint32 = inet_addr(argv[1]); 181 printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
182 DHT_bootstrap(dht, bootstrap_ip_port, hex_string_to_bin(argv[3])); 182 return 1;
183 }
183 184
184 /* 185 /*
185 IP_Port ip_port; 186 IP_Port ip_port;
diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c
index d5fb1544..70349204 100644
--- a/testing/Lossless_UDP_testclient.c
+++ b/testing/Lossless_UDP_testclient.c
@@ -66,8 +66,7 @@ void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port)
66 66
67void printip(IP_Port ip_port) 67void printip(IP_Port ip_port)
68{ 68{
69 printf("\nIP: %u.%u.%u.%u Port: %u", ip_port.ip.uint8[0], ip_port.ip.uint8[1], ip_port.ip.uint8[2], ip_port.ip.uint8[3], 69 printf("\nIP: %s Port: %u", ip_ntoa(&ip_port.ip), ntohs(ip_port.port));
70 ntohs(ip_port.port));
71} 70}
72/* 71/*
73void printpackets(Data test) 72void printpackets(Data test)
@@ -152,30 +151,45 @@ void printconnection(int connection_id)
152 151
153int main(int argc, char *argv[]) 152int main(int argc, char *argv[])
154{ 153{
155 if (argc < 4) { 154 /* let user override default by cmdline */
156 printf("usage: %s ip port filename\n", argv[0]); 155 uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
156 int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
157 if (argvoffset < 0)
158 exit(1);
159
160 if (argc < argvoffset + 4) {
161 printf("Usage: %s [--ipv4|--ipv6] ip port filename\n", argv[0]);
157 exit(0); 162 exit(0);
158 } 163 }
159 164
160 uint8_t buffer[512]; 165 uint8_t buffer[512];
161 int read; 166 int read;
162 167
163 FILE *file = fopen(argv[3], "rb"); 168 FILE *file = fopen(argv[argvoffset + 3], "rb");
164 169
165 if (file == NULL) 170 if (file == NULL) {
171 printf("Failed to open file \"%s\".\n", argv[argvoffset + 3]);
166 return 1; 172 return 1;
173 }
167 174
168 175
169 /* initialize networking */ 176 /* initialize networking */
170 /* bind to ip 0.0.0.0:PORT */ 177 /* bind to ip 0.0.0.0:PORT */
171 IP ip; 178 IP ip;
172 ip.uint32 = 0; 179 ip_init(&ip, ipv6enabled);
180
173 Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT)); 181 Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT));
174 perror("Initialization"); 182 perror("Initialization");
183
175 IP_Port serverip; 184 IP_Port serverip;
176 serverip.ip.uint32 = inet_addr(argv[1]); 185 ip_init(&serverip.ip, ipv6enabled);
177 serverip.port = htons(atoi(argv[2])); 186 if (!addr_resolve(argv[argvoffset + 1], &serverip.ip)) {
187 printf("Failed to convert \"%s\" into an IP address.\n", argv[argvoffset + 1]);
188 return 1;
189 }
190 serverip.port = htons(atoi(argv[argvoffset + 2]));
178 printip(serverip); 191 printip(serverip);
192
179 int connection = new_connection(ludp, serverip); 193 int connection = new_connection(ludp, serverip);
180 uint64_t timer = current_time(); 194 uint64_t timer = current_time();
181 195
diff --git a/testing/Lossless_UDP_testserver.c b/testing/Lossless_UDP_testserver.c
index eb506b3d..343a662a 100644
--- a/testing/Lossless_UDP_testserver.c
+++ b/testing/Lossless_UDP_testserver.c
@@ -147,24 +147,33 @@ void printconnection(int connection_id)
147 147
148int main(int argc, char *argv[]) 148int main(int argc, char *argv[])
149{ 149{
150 if (argc < 2) { 150 /* let user override default by cmdline */
151 printf("usage: %s filename\n", argv[0]); 151 uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
152 int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
153 if (argvoffset < 0)
154 exit(1);
155
156 if (argc < argvoffset + 2) {
157 printf("Usage: %s [--ipv4|--ipv6] filename\n", argv[0]);
152 exit(0); 158 exit(0);
153 } 159 }
154 160
155 uint8_t buffer[512]; 161 uint8_t buffer[512];
156 int read; 162 int read;
157 163
158 FILE *file = fopen(argv[1], "wb"); 164 FILE *file = fopen(argv[argvoffset + 1], "wb");
159 165
160 if (file == NULL) 166 if (file == NULL) {
167 printf("Failed to open file \"%s\".\n", argv[argvoffset + 1]);
161 return 1; 168 return 1;
169 }
162 170
163 171
164 //initialize networking 172 //initialize networking
165 //bind to ip 0.0.0.0:PORT 173 //bind to ip 0.0.0.0:PORT
166 IP ip; 174 IP ip;
167 ip.uint32 = 0; 175 ip_init(&ip, ipv6enabled);
176
168 Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT)); 177 Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT));
169 perror("Initialization"); 178 perror("Initialization");
170 179
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c
index e85a85a2..14d9ca20 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -95,27 +95,40 @@ void print_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t len
95 95
96int main(int argc, char *argv[]) 96int main(int argc, char *argv[])
97{ 97{
98 if (argc < 4 && argc != 2) { 98 /* let user override default by cmdline */
99 printf("usage %s ip port public_key (of the DHT bootstrap node)\n or\n %s Save.bak\n", argv[0], argv[0]); 99 uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
100 int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
101 if (argvoffset < 0)
102 exit(1);
103
104 /* with optional --ipvx, now it can be 1-4 arguments... */
105 if ((argc != argvoffset + 2) && (argc != argvoffset + 4)) {
106 printf("Usage: %s [--ipv4|--ipv6] ip port public_key (of the DHT bootstrap node)\n", argv[0]);
107 printf("or\n");
108 printf(" %s [--ipv4|--ipv6] Save.bak (to read Save.bak as state file)\n", argv[0], argv[0]);
100 exit(0); 109 exit(0);
101 } 110 }
102 111
103 m = initMessenger(); 112 m = initMessenger(ipv6enabled);
104 113
105 if ( !m ) { 114 if ( !m ) {
106 fputs("Failed to allocate messenger datastructure\n", stderr); 115 fputs("Failed to allocate messenger datastructure\n", stderr);
107 exit(0); 116 exit(0);
108 } 117 }
109 118
110 if (argc > 3) { 119 if (argc == argvoffset + 4) {
111 IP_Port bootstrap_ip_port; 120 uint16_t port = htons(atoi(argv[argvoffset + 2]));
112 bootstrap_ip_port.port = htons(atoi(argv[2])); 121 uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
113 bootstrap_ip_port.ip.uint32 = inet_addr(argv[1]); 122 int res = DHT_bootstrap_ex(m->dht, argv[argvoffset + 1], ipv6enabled, port, bootstrap_key);
114 DHT_bootstrap(m->dht, bootstrap_ip_port, hex_string_to_bin(argv[3])); 123 free(bootstrap_key);
124 if (!res) {
125 printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
126 exit(1);
127 }
115 } else { 128 } else {
116 FILE *file = fopen(argv[1], "rb"); 129 FILE *file = fopen(argv[argvoffset + 1], "rb");
117
118 if ( file == NULL ) { 130 if ( file == NULL ) {
131 printf("Failed to open \"%s\" - does it exist?\n", argv[argvoffset + 1]);
119 return 1; 132 return 1;
120 } 133 }
121 134
diff --git a/testing/nTox.c b/testing/nTox.c
index 438468bd..750970f9 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -537,6 +537,17 @@ void print_help(void)
537 537
538int main(int argc, char *argv[]) 538int main(int argc, char *argv[])
539{ 539{
540 if (argc < 4) {
541 printf("Usage: %s [--ipv4|--ipv6] IP PORT KEY [-f keyfile]\n", argv[0]);
542 exit(0);
543 }
544
545 /* let user override default by cmdline */
546 uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
547 int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
548 if (argvoffset < 0)
549 exit(1);
550
540 int on = 0; 551 int on = 0;
541 int c = 0; 552 int c = 0;
542 int i = 0; 553 int i = 0;
@@ -544,29 +555,18 @@ int main(int argc, char *argv[])
544 char idstring[200] = {0}; 555 char idstring[200] = {0};
545 Tox *m; 556 Tox *m;
546 557
547 if (argc < 4) { 558 if ((argc == 2) && !strcmp(argv[1], "-h")) {
548 printf("[!] Usage: %s [IP] [port] [public_key] <keyfile>\n", argv[0]); 559 print_help();
549 exit(0); 560 exit(0);
550 } 561 }
551 562
552 for (i = 0; i < argc; i++) { 563 /* [-f keyfile] MUST be last two arguments, no point in walking over the list
553 if (argv[i] == NULL) { 564 * especially not a good idea to accept it anywhere in the middle */
554 break; 565 if (argc > argvoffset + 3)
555 } else if (argv[i][0] == '-') { 566 if (!strcmp(argv[argc - 2], "-f"))
556 if (argv[i][1] == 'h') { 567 filename = argv[argc - 1];
557 print_help();
558 exit(0);
559 } else if (argv[i][1] == 'f') {
560 if (argv[i + 1] != NULL)
561 filename = argv[i + 1];
562 else {
563 fputs("[!] you passed '-f' without giving an argument!\n", stderr);
564 }
565 }
566 }
567 }
568 568
569 m = tox_new(); 569 m = tox_new_ex(ipv6enabled);
570 570
571 if ( !m ) { 571 if ( !m ) {
572 fputs("Failed to allocate Messenger datastructure", stderr); 572 fputs("Failed to allocate Messenger datastructure", stderr);
@@ -590,20 +590,18 @@ int main(int argc, char *argv[])
590 new_lines(idstring); 590 new_lines(idstring);
591 strcpy(line, ""); 591 strcpy(line, "");
592 592
593 tox_IP_Port bootstrap_ip_port; 593 uint16_t port = htons(atoi(argv[argvoffset + 2]));
594 bootstrap_ip_port.port = htons(atoi(argv[2])); 594 unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
595 int resolved_address = resolve_addr(argv[1]); 595 int res = tox_bootstrap_ex(m, argv[argvoffset + 1], ipv6enabled, port, binary_string);
596 free(binary_string);
596 597
597 if (resolved_address != 0) 598 if (!res) {
598 bootstrap_ip_port.ip.i = resolved_address; 599 printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
599 else 600 endwin();
600 exit(1); 601 exit(1);
602 }
601 603
602 unsigned char *binary_string = hex_string_to_bin(argv[3]);
603 tox_bootstrap(m, bootstrap_ip_port, binary_string);
604 free(binary_string);
605 nodelay(stdscr, TRUE); 604 nodelay(stdscr, TRUE);
606
607 while (1) { 605 while (1) {
608 if (on == 0 && tox_isconnected(m)) { 606 if (on == 0 && tox_isconnected(m)) {
609 new_lines("[i] connected to DHT\n[i] define username with /n"); 607 new_lines("[i] connected to DHT\n[i] define username with /n");