diff options
Diffstat (limited to 'testing')
-rw-r--r-- | testing/DHT_test.c | 2 | ||||
-rw-r--r-- | testing/Messenger_test.c | 2 | ||||
-rw-r--r-- | testing/experiment/group_chats_test.c | 105 | ||||
-rw-r--r-- | testing/experiment/group_chats_test1.c | 107 | ||||
-rw-r--r-- | testing/misc_tools.c | 12 | ||||
-rw-r--r-- | testing/tox_sync.c | 2 |
6 files changed, 9 insertions, 221 deletions
diff --git a/testing/DHT_test.c b/testing/DHT_test.c index 5ddb5945..cae88ce4 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c | |||
@@ -205,7 +205,7 @@ int main(int argc, char *argv[]) | |||
205 | 205 | ||
206 | if (scanf("%s", temp_id) != 1) | 206 | if (scanf("%s", temp_id) != 1) |
207 | exit(0); | 207 | exit(0); |
208 | 208 | ||
209 | uint8_t *bin_id = hex_string_to_bin(temp_id); | 209 | uint8_t *bin_id = hex_string_to_bin(temp_id); |
210 | DHT_addfriend(dht, bin_id); | 210 | DHT_addfriend(dht, bin_id); |
211 | free(bin_id); | 211 | free(bin_id); |
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index 707bb8db..895a23d9 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c | |||
@@ -167,7 +167,7 @@ int main(int argc, char *argv[]) | |||
167 | if (scanf("%s", temp_hex_id) != 1) { | 167 | if (scanf("%s", temp_hex_id) != 1) { |
168 | return 1; | 168 | return 1; |
169 | } | 169 | } |
170 | 170 | ||
171 | uint8_t *bin_id = hex_string_to_bin(temp_hex_id); | 171 | uint8_t *bin_id = hex_string_to_bin(temp_hex_id); |
172 | int num = m_addfriend(m, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); | 172 | int num = m_addfriend(m, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); |
173 | free(bin_id); | 173 | free(bin_id); |
diff --git a/testing/experiment/group_chats_test.c b/testing/experiment/group_chats_test.c deleted file mode 100644 index 04fee327..00000000 --- a/testing/experiment/group_chats_test.c +++ /dev/null | |||
@@ -1,105 +0,0 @@ | |||
1 | #include "../../toxcore/group_chats.h" | ||
2 | #define NUM_CHATS 8 | ||
3 | |||
4 | #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) | ||
5 | #define c_sleep(x) Sleep(1*x) | ||
6 | #else | ||
7 | #define c_sleep(x) usleep(1000*x) | ||
8 | #endif | ||
9 | Group_Chat *chats[NUM_CHATS]; | ||
10 | |||
11 | void print_close(Group_Close *close) | ||
12 | { | ||
13 | uint32_t i, j; | ||
14 | IP_Port p_ip; | ||
15 | printf("___________________CLOSE________________________________\n"); | ||
16 | |||
17 | for (i = 0; i < GROUP_CLOSE_CONNECTIONS; i++) { | ||
18 | printf("ClientID: "); | ||
19 | |||
20 | for (j = 0; j < CLIENT_ID_SIZE; j++) { | ||
21 | printf("%02hhX", close[i].client_id[j]); | ||
22 | } | ||
23 | |||
24 | p_ip = close[i].ip_port; | ||
25 | 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], | ||
26 | ntohs(p_ip.port)); | ||
27 | printf("\nTimestamp: %llu", (long long unsigned int) close[i].last_recv); | ||
28 | printf("\n"); | ||
29 | } | ||
30 | } | ||
31 | |||
32 | void print_group(Group_Chat *chat) | ||
33 | { | ||
34 | uint32_t i, j; | ||
35 | printf("-----------------\nClientID: "); | ||
36 | |||
37 | for (j = 0; j < CLIENT_ID_SIZE; j++) { | ||
38 | printf("%02hhX", chat->self_public_key[j]); | ||
39 | } | ||
40 | |||
41 | printf("\n___________________GROUP________________________________\n"); | ||
42 | |||
43 | for (i = 0; i < chat->numpeers; i++) { | ||
44 | printf("ClientID: "); | ||
45 | |||
46 | for (j = 0; j < CLIENT_ID_SIZE; j++) { | ||
47 | printf("%02hhX", chat->group[i].client_id[j]); | ||
48 | } | ||
49 | |||
50 | printf("\nTimestamp: %llu", (long long unsigned int) chat->group[i].last_recv); | ||
51 | printf("\nlast_pinged: %llu", (long long unsigned int) chat->group[i].last_pinged); | ||
52 | printf("\npingid: %llu", (long long unsigned int) chat->group[i].pingid); | ||
53 | printf("\n"); | ||
54 | } | ||
55 | } | ||
56 | |||
57 | void print_message(Group_Chat *chat, int peer_number, uint8_t *message, uint16_t length, void *userdata) | ||
58 | { | ||
59 | printf("%u: %s | %u\n", peer_number, message, length); | ||
60 | } | ||
61 | |||
62 | int main() | ||
63 | { | ||
64 | IP ip; | ||
65 | ip.uint32 = 0; | ||
66 | uint32_t i; | ||
67 | |||
68 | |||
69 | for (i = 0; i < NUM_CHATS; ++i) { | ||
70 | chats[i] = new_groupchat(new_networking(ip, 12745)); | ||
71 | |||
72 | if (chats[i] == 0) | ||
73 | exit(1); | ||
74 | |||
75 | networking_registerhandler(chats[i]->net, 48, &handle_groupchatpacket, chats[i]); | ||
76 | callback_groupmessage(chats[i], &print_message, 0); | ||
77 | } | ||
78 | |||
79 | printf("ok\n"); | ||
80 | IP_Port ip_port; | ||
81 | ip_port.ip.uint32 = 0; | ||
82 | ip_port.ip.uint8[0] = 127; | ||
83 | ip_port.ip.uint8[3] = 1; | ||
84 | ip_port.port = htons(12745); | ||
85 | |||
86 | for (i = 0; i < NUM_CHATS; ++i) { | ||
87 | group_newpeer(chats[0], chats[i]->self_public_key); | ||
88 | chat_bootstrap(chats[i], ip_port, chats[0]->self_public_key); | ||
89 | printf("%u\n", i); | ||
90 | } | ||
91 | |||
92 | while (1) { | ||
93 | for (i = 0; i < NUM_CHATS; ++i) { | ||
94 | networking_poll(chats[i]->net); | ||
95 | do_groupchat(chats[i]); | ||
96 | printf("%u\n", chats[i]->numpeers); | ||
97 | print_close(chats[i]->close); | ||
98 | print_group(chats[i]); | ||
99 | } | ||
100 | |||
101 | c_sleep(100); | ||
102 | } | ||
103 | |||
104 | return 0; | ||
105 | } | ||
diff --git a/testing/experiment/group_chats_test1.c b/testing/experiment/group_chats_test1.c deleted file mode 100644 index fc10ab64..00000000 --- a/testing/experiment/group_chats_test1.c +++ /dev/null | |||
@@ -1,107 +0,0 @@ | |||
1 | #include "../../toxcore/group_chats.h" | ||
2 | #include "../misc_tools.c" // hex_string_to_bin | ||
3 | |||
4 | #define NUM_CHATS 8 | ||
5 | |||
6 | #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) | ||
7 | #define c_sleep(x) Sleep(1*x) | ||
8 | #else | ||
9 | #define c_sleep(x) usleep(1000*x) | ||
10 | #endif | ||
11 | Group_Chat *chat; | ||
12 | |||
13 | void print_close(Group_Close *close) | ||
14 | { | ||
15 | uint32_t i, j; | ||
16 | IP_Port p_ip; | ||
17 | printf("___________________CLOSE________________________________\n"); | ||
18 | |||
19 | for (i = 0; i < GROUP_CLOSE_CONNECTIONS; i++) { | ||
20 | printf("ClientID: "); | ||
21 | |||
22 | for (j = 0; j < CLIENT_ID_SIZE; j++) { | ||
23 | printf("%02hhX", close[i].client_id[j]); | ||
24 | } | ||
25 | |||
26 | p_ip = close[i].ip_port; | ||
27 | 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], | ||
28 | ntohs(p_ip.port)); | ||
29 | printf("\nTimestamp: %llu", (long long unsigned int) close[i].last_recv); | ||
30 | printf("\n"); | ||
31 | } | ||
32 | } | ||
33 | |||
34 | void print_group(Group_Chat *chat) | ||
35 | { | ||
36 | uint32_t i, j; | ||
37 | printf("-----------------\nClientID: "); | ||
38 | |||
39 | for (j = 0; j < CLIENT_ID_SIZE; j++) { | ||
40 | printf("%02hhX", chat->self_public_key[j]); | ||
41 | } | ||
42 | |||
43 | printf("\n___________________GROUP________________________________\n"); | ||
44 | |||
45 | for (i = 0; i < chat->numpeers; i++) { | ||
46 | printf("ClientID: "); | ||
47 | |||
48 | for (j = 0; j < CLIENT_ID_SIZE; j++) { | ||
49 | printf("%02hhX", chat->group[i].client_id[j]); | ||
50 | } | ||
51 | |||
52 | printf("\nTimestamp: %llu", (long long unsigned int) chat->group[i].last_recv); | ||
53 | printf("\nlast_pinged: %llu", (long long unsigned int) chat->group[i].last_pinged); | ||
54 | printf("\npingid: %llu", (long long unsigned int) chat->group[i].pingid); | ||
55 | printf("\n"); | ||
56 | } | ||
57 | } | ||
58 | |||
59 | void print_message(Group_Chat *chat, int peer_number, uint8_t *message, uint16_t length, void *userdata) | ||
60 | { | ||
61 | printf("%u: %s | %u\n", peer_number, message, length); | ||
62 | } | ||
63 | |||
64 | int main(int argc, char *argv[]) | ||
65 | { | ||
66 | IP ip; | ||
67 | ip.uint32 = 0; | ||
68 | uint32_t i; | ||
69 | |||
70 | chat = new_groupchat(new_networking(ip, 12745)); | ||
71 | |||
72 | if (chat == 0) | ||
73 | exit(1); | ||
74 | |||
75 | networking_registerhandler(chat->net, 48, &handle_groupchatpacket, chat); | ||
76 | |||
77 | callback_groupmessage(chat, &print_message, 0); | ||
78 | |||
79 | printf("ok\n"); | ||
80 | IP_Port bootstrap_ip_port; | ||
81 | bootstrap_ip_port.port = htons(atoi(argv[2])); | ||
82 | /* bootstrap_ip_port.ip.c[0] = 127; | ||
83 | * bootstrap_ip_port.ip.c[1] = 0; | ||
84 | * bootstrap_ip_port.ip.c[2] = 0; | ||
85 | * bootstrap_ip_port.ip.c[3] = 1; */ | ||
86 | bootstrap_ip_port.ip.uint32 = inet_addr(argv[1]); | ||
87 | |||
88 | uint8_t *bootstrap_id = hex_string_to_bin(argv[3]); | ||
89 | |||
90 | chat_bootstrap(chat, bootstrap_ip_port, bootstrap_id); | ||
91 | |||
92 | free(bootstrap_id); | ||
93 | |||
94 | while (1) { | ||
95 | |||
96 | networking_poll(chat->net); | ||
97 | do_groupchat(chat); | ||
98 | printf("%u ", chat->numpeers); | ||
99 | printf("%u\n", group_sendmessage(chat, "Install Gentoo", sizeof("Install Gentoo"))); | ||
100 | //print_close(chat->close); | ||
101 | // print_group(chat); | ||
102 | |||
103 | c_sleep(100); | ||
104 | } | ||
105 | |||
106 | return 0; | ||
107 | } | ||
diff --git a/testing/misc_tools.c b/testing/misc_tools.c index 5e322a90..ad6b2bff 100644 --- a/testing/misc_tools.c +++ b/testing/misc_tools.c | |||
@@ -37,12 +37,12 @@ | |||
37 | // You are responsible for freeing the return value! | 37 | // You are responsible for freeing the return value! |
38 | uint8_t *hex_string_to_bin(char *hex_string) | 38 | uint8_t *hex_string_to_bin(char *hex_string) |
39 | { | 39 | { |
40 | // byte is represented by exactly 2 hex digits, so lenth of binary string | 40 | // byte is represented by exactly 2 hex digits, so lenth of binary string |
41 | // is half of that of the hex one. only hex string with even length | 41 | // is half of that of the hex one. only hex string with even length |
42 | // valid. the more proper implementation would be to check if strlen(hex_string) | 42 | // valid. the more proper implementation would be to check if strlen(hex_string) |
43 | // is odd and return error code if it is. we assume strlen is even. if it's not | 43 | // is odd and return error code if it is. we assume strlen is even. if it's not |
44 | // then the last byte just won't be written in 'ret'. | 44 | // then the last byte just won't be written in 'ret'. |
45 | size_t i, len = strlen(hex_string)/2; | 45 | size_t i, len = strlen(hex_string) / 2; |
46 | uint8_t *ret = malloc(len); | 46 | uint8_t *ret = malloc(len); |
47 | char *pos = hex_string; | 47 | char *pos = hex_string; |
48 | 48 | ||
diff --git a/testing/tox_sync.c b/testing/tox_sync.c index 5d38d2e5..2799e7fe 100644 --- a/testing/tox_sync.c +++ b/testing/tox_sync.c | |||
@@ -243,7 +243,7 @@ int main(int argc, char *argv[]) | |||
243 | return 1; | 243 | return 1; |
244 | } | 244 | } |
245 | 245 | ||
246 | uint8_t *bin_id = hex_string_to_bin(temp_id); | 246 | uint8_t *bin_id = hex_string_to_bin(temp_id); |
247 | int num = tox_add_friend(tox, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); | 247 | int num = tox_add_friend(tox, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); |
248 | free(bin_id); | 248 | free(bin_id); |
249 | 249 | ||