From 7a2ed25d3622ea92be0a7e00dc0415d9f0e953a4 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sun, 9 Feb 2014 09:43:16 -0500 Subject: [PATCH] Astyled and removed some useless files. --- .../tox_bootstrap_daemon.c | 6 +- testing/DHT_test.c | 2 +- testing/Messenger_test.c | 2 +- testing/experiment/group_chats_test.c | 105 ----------------- testing/experiment/group_chats_test1.c | 107 ------------------ testing/misc_tools.c | 12 +- testing/tox_sync.c | 2 +- 7 files changed, 13 insertions(+), 223 deletions(-) delete mode 100644 testing/experiment/group_chats_test.c delete mode 100644 testing/experiment/group_chats_test1.c diff --git a/other/bootstrap_serverdaemon/tox_bootstrap_daemon.c b/other/bootstrap_serverdaemon/tox_bootstrap_daemon.c index 7f1f652c..b7684115 100644 --- a/other/bootstrap_serverdaemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_serverdaemon/tox_bootstrap_daemon.c @@ -256,7 +256,8 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) // Process settings if (strlen(bs_public_key) != 64) { - syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_PUBLIC_KEY, bs_public_key); + syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_PUBLIC_KEY, + bs_public_key); goto next; } @@ -267,7 +268,8 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) } uint8_t *bs_public_key_bin = hex_string_to_bin((char *)bs_public_key); - const int address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), bs_public_key_bin); + const int address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), + bs_public_key_bin); free(bs_public_key_bin); if (!address_resolved) { 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[]) if (scanf("%s", temp_id) != 1) exit(0); - + uint8_t *bin_id = hex_string_to_bin(temp_id); DHT_addfriend(dht, bin_id); 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[]) if (scanf("%s", temp_hex_id) != 1) { return 1; } - + uint8_t *bin_id = hex_string_to_bin(temp_hex_id); int num = m_addfriend(m, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); 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 @@ -#include "../../toxcore/group_chats.h" -#define NUM_CHATS 8 - -#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) -#define c_sleep(x) Sleep(1*x) -#else -#define c_sleep(x) usleep(1000*x) -#endif -Group_Chat *chats[NUM_CHATS]; - -void print_close(Group_Close *close) -{ - uint32_t i, j; - IP_Port p_ip; - printf("___________________CLOSE________________________________\n"); - - for (i = 0; i < GROUP_CLOSE_CONNECTIONS; i++) { - printf("ClientID: "); - - for (j = 0; j < CLIENT_ID_SIZE; j++) { - printf("%02hhX", close[i].client_id[j]); - } - - p_ip = close[i].ip_port; - 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], - ntohs(p_ip.port)); - printf("\nTimestamp: %llu", (long long unsigned int) close[i].last_recv); - printf("\n"); - } -} - -void print_group(Group_Chat *chat) -{ - uint32_t i, j; - printf("-----------------\nClientID: "); - - for (j = 0; j < CLIENT_ID_SIZE; j++) { - printf("%02hhX", chat->self_public_key[j]); - } - - printf("\n___________________GROUP________________________________\n"); - - for (i = 0; i < chat->numpeers; i++) { - printf("ClientID: "); - - for (j = 0; j < CLIENT_ID_SIZE; j++) { - printf("%02hhX", chat->group[i].client_id[j]); - } - - printf("\nTimestamp: %llu", (long long unsigned int) chat->group[i].last_recv); - printf("\nlast_pinged: %llu", (long long unsigned int) chat->group[i].last_pinged); - printf("\npingid: %llu", (long long unsigned int) chat->group[i].pingid); - printf("\n"); - } -} - -void print_message(Group_Chat *chat, int peer_number, uint8_t *message, uint16_t length, void *userdata) -{ - printf("%u: %s | %u\n", peer_number, message, length); -} - -int main() -{ - IP ip; - ip.uint32 = 0; - uint32_t i; - - - for (i = 0; i < NUM_CHATS; ++i) { - chats[i] = new_groupchat(new_networking(ip, 12745)); - - if (chats[i] == 0) - exit(1); - - networking_registerhandler(chats[i]->net, 48, &handle_groupchatpacket, chats[i]); - callback_groupmessage(chats[i], &print_message, 0); - } - - printf("ok\n"); - IP_Port ip_port; - ip_port.ip.uint32 = 0; - ip_port.ip.uint8[0] = 127; - ip_port.ip.uint8[3] = 1; - ip_port.port = htons(12745); - - for (i = 0; i < NUM_CHATS; ++i) { - group_newpeer(chats[0], chats[i]->self_public_key); - chat_bootstrap(chats[i], ip_port, chats[0]->self_public_key); - printf("%u\n", i); - } - - while (1) { - for (i = 0; i < NUM_CHATS; ++i) { - networking_poll(chats[i]->net); - do_groupchat(chats[i]); - printf("%u\n", chats[i]->numpeers); - print_close(chats[i]->close); - print_group(chats[i]); - } - - c_sleep(100); - } - - return 0; -} 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 @@ -#include "../../toxcore/group_chats.h" -#include "../misc_tools.c" // hex_string_to_bin - -#define NUM_CHATS 8 - -#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) -#define c_sleep(x) Sleep(1*x) -#else -#define c_sleep(x) usleep(1000*x) -#endif -Group_Chat *chat; - -void print_close(Group_Close *close) -{ - uint32_t i, j; - IP_Port p_ip; - printf("___________________CLOSE________________________________\n"); - - for (i = 0; i < GROUP_CLOSE_CONNECTIONS; i++) { - printf("ClientID: "); - - for (j = 0; j < CLIENT_ID_SIZE; j++) { - printf("%02hhX", close[i].client_id[j]); - } - - p_ip = close[i].ip_port; - 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], - ntohs(p_ip.port)); - printf("\nTimestamp: %llu", (long long unsigned int) close[i].last_recv); - printf("\n"); - } -} - -void print_group(Group_Chat *chat) -{ - uint32_t i, j; - printf("-----------------\nClientID: "); - - for (j = 0; j < CLIENT_ID_SIZE; j++) { - printf("%02hhX", chat->self_public_key[j]); - } - - printf("\n___________________GROUP________________________________\n"); - - for (i = 0; i < chat->numpeers; i++) { - printf("ClientID: "); - - for (j = 0; j < CLIENT_ID_SIZE; j++) { - printf("%02hhX", chat->group[i].client_id[j]); - } - - printf("\nTimestamp: %llu", (long long unsigned int) chat->group[i].last_recv); - printf("\nlast_pinged: %llu", (long long unsigned int) chat->group[i].last_pinged); - printf("\npingid: %llu", (long long unsigned int) chat->group[i].pingid); - printf("\n"); - } -} - -void print_message(Group_Chat *chat, int peer_number, uint8_t *message, uint16_t length, void *userdata) -{ - printf("%u: %s | %u\n", peer_number, message, length); -} - -int main(int argc, char *argv[]) -{ - IP ip; - ip.uint32 = 0; - uint32_t i; - - chat = new_groupchat(new_networking(ip, 12745)); - - if (chat == 0) - exit(1); - - networking_registerhandler(chat->net, 48, &handle_groupchatpacket, chat); - - callback_groupmessage(chat, &print_message, 0); - - printf("ok\n"); - IP_Port bootstrap_ip_port; - bootstrap_ip_port.port = htons(atoi(argv[2])); - /* bootstrap_ip_port.ip.c[0] = 127; - * bootstrap_ip_port.ip.c[1] = 0; - * bootstrap_ip_port.ip.c[2] = 0; - * bootstrap_ip_port.ip.c[3] = 1; */ - bootstrap_ip_port.ip.uint32 = inet_addr(argv[1]); - - uint8_t *bootstrap_id = hex_string_to_bin(argv[3]); - - chat_bootstrap(chat, bootstrap_ip_port, bootstrap_id); - - free(bootstrap_id); - - while (1) { - - networking_poll(chat->net); - do_groupchat(chat); - printf("%u ", chat->numpeers); - printf("%u\n", group_sendmessage(chat, "Install Gentoo", sizeof("Install Gentoo"))); - //print_close(chat->close); - // print_group(chat); - - c_sleep(100); - } - - return 0; -} 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 @@ // You are responsible for freeing the return value! uint8_t *hex_string_to_bin(char *hex_string) { - // byte is represented by exactly 2 hex digits, so lenth of binary string - // is half of that of the hex one. only hex string with even length - // valid. the more proper implementation would be to check if strlen(hex_string) - // is odd and return error code if it is. we assume strlen is even. if it's not - // then the last byte just won't be written in 'ret'. - size_t i, len = strlen(hex_string)/2; + // byte is represented by exactly 2 hex digits, so lenth of binary string + // is half of that of the hex one. only hex string with even length + // valid. the more proper implementation would be to check if strlen(hex_string) + // is odd and return error code if it is. we assume strlen is even. if it's not + // then the last byte just won't be written in 'ret'. + size_t i, len = strlen(hex_string) / 2; uint8_t *ret = malloc(len); char *pos = hex_string; 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[]) return 1; } - uint8_t *bin_id = hex_string_to_bin(temp_id); + uint8_t *bin_id = hex_string_to_bin(temp_id); int num = tox_add_friend(tox, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); free(bin_id);