Astyled and removed some useless files.

pull/724/head
irungentoo 2014-02-09 09:43:16 -05:00
parent c498c206ed
commit 7a2ed25d36
7 changed files with 13 additions and 223 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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);