Astyled the code.

This commit is contained in:
irungentoo 2013-12-16 20:49:24 -05:00
parent 24974ef816
commit 15d17b0a3c
6 changed files with 42 additions and 19 deletions

View File

@ -65,9 +65,11 @@ START_TEST(test_fillup)
//uint32_t a = current_time();
uint32_t a = 2710106197;
srand(a);
for(i = 0; i < CLIENT_ID_SIZE; ++i) {
for (i = 0; i < CLIENT_ID_SIZE; ++i) {
id[i] = rand();
}
Assoc *assoc = new_Assoc(6, 15, id);
ck_assert_msg(assoc != NULL, "failed to create default assoc");
struct entry {
@ -78,11 +80,13 @@ START_TEST(test_fillup)
unsigned int fail = 0;
struct entry entries[128];
struct entry closest[8];
for(j = 0; j < 128; ++j) {
for(i = 0; i < CLIENT_ID_SIZE; ++i) {
for (j = 0; j < 128; ++j) {
for (i = 0; i < CLIENT_ID_SIZE; ++i) {
entries[j].id[i] = rand();
}
IP_Port ipp;
ipp.ip.family = AF_INET;
ipp.ip.ip4.uint32 = rand();
@ -92,14 +96,17 @@ START_TEST(test_fillup)
ipp.ip.ip4.uint32 = rand();
ipp.port = rand();
entries[j].ipp_recv = ipp;
if (j % 16 == 0) {
memcpy(entries[j].id, id, CLIENT_ID_SIZE - 30);
memcpy(&closest[j/16], &entries[j], sizeof(struct entry));
memcpy(&closest[j / 16], &entries[j], sizeof(struct entry));
}
uint8_t res = Assoc_add_entry(assoc, entries[j].id, &entries[j].ippts_send, &entries[j].ipp_recv, 1);
ck_assert_msg(res == 1, "failed to store entry: expected %u, got %u, j = %u", 1, res, j);
}
int good = 0;
Assoc_close_entries close_entries;
memset(&close_entries, 0, sizeof(close_entries));
@ -112,12 +119,15 @@ START_TEST(test_fillup)
uint8_t found = Assoc_get_close_entries(assoc, &close_entries);
ck_assert_msg(found == 8, "get_close_entries(): expected %u, got %u", 1, found);
for (i = 0; i < 8; ++i) {
for (j = 0; j < 8; ++j) {
if (id_equal(entri[j]->client_id, closest[i].id))
++good;
}
}ck_assert_msg(good == 8, "Entries found were not the closest ones. Only %u/8 were.", good);
}
ck_assert_msg(good == 8, "Entries found were not the closest ones. Only %u/8 were.", good);
//printf("good: %u %u %u\n", good, a, ((uint32_t)current_time() - a));
}
END_TEST

View File

@ -54,9 +54,10 @@
uint8_t zeroes_cid[CLIENT_ID_SIZE];
void print_client_id(uint8_t * client_id)
void print_client_id(uint8_t *client_id)
{
uint32_t j;
for (j = 0; j < CLIENT_ID_SIZE; j++) {
printf("%02hhX", client_id[j]);
}
@ -67,13 +68,16 @@ void print_hardening(Hardening *h)
printf("Hardening:\n");
printf("routes_requests_ok: %hhu\n", h->routes_requests_ok);
printf("routes_requests_timestamp: %llu\n", (long long unsigned int)h->routes_requests_timestamp);
printf("routes_requests_pingedid: "); print_client_id(h->routes_requests_pingedid);
printf("routes_requests_pingedid: ");
print_client_id(h->routes_requests_pingedid);
printf("\nsend_nodes_ok: %hhu\n", h->send_nodes_ok);
printf("send_nodes_timestamp: %llu\n", (long long unsigned int)h->send_nodes_timestamp);
printf("send_nodes_pingedid: "); print_client_id(h->send_nodes_pingedid);
printf("send_nodes_pingedid: ");
print_client_id(h->send_nodes_pingedid);
printf("\ntesting_requests: %hhu\n", h->testing_requests);
printf("testing_timestamp: %llu\n", (long long unsigned int)h->testing_timestamp);
printf("testing_pingedid: "); print_client_id(h->testing_pingedid);
printf("testing_pingedid: ");
print_client_id(h->testing_pingedid);
printf("\n\n");
}
@ -85,23 +89,28 @@ void print_assoc(IPPTsPng *assoc, uint8_t ours)
printf("\nLast pinged: %llu\n", (long long unsigned int) assoc->last_pinged);
ipp = &assoc->ret_ip_port;
if (ours)
printf("OUR IP: %s Port: %u\n", ip_ntoa(&ipp->ip), ntohs(ipp->port));
else
printf("RET IP: %s Port: %u\n", ip_ntoa(&ipp->ip), ntohs(ipp->port));
printf("Timestamp: %llu\n", (long long unsigned int) assoc->ret_timestamp);
print_hardening(&assoc->hardening);
}
void print_clientlist(DHT *dht)
{
uint32_t i;
printf("___________________CLOSE________________________________\n");
for (i = 0; i < LCLIENT_LIST; i++) {
Client_data *client = &dht->close_clientlist[i];
if(memcmp(client->client_id, zeroes_cid, CLIENT_ID_SIZE) == 0)
if (memcmp(client->client_id, zeroes_cid, CLIENT_ID_SIZE) == 0)
continue;
printf("ClientID: ");
print_client_id(client->client_id);
@ -129,8 +138,10 @@ void print_friendlist(DHT *dht)
for (i = 0; i < MAX_FRIEND_CLIENTS; i++) {
Client_data *client = &dht->friends_list[k].client_list[i];
if(memcmp(client->client_id, zeroes_cid, CLIENT_ID_SIZE) == 0)
if (memcmp(client->client_id, zeroes_cid, CLIENT_ID_SIZE) == 0)
continue;
printf("ClientID: ");
print_client_id(client->client_id);

View File

@ -63,7 +63,7 @@ void send_filesenders(Tox *m)
while (1) {
if (!tox_file_send_data(m, file_senders[i].friendnum, file_senders[i].filenumber, file_senders[i].nextpiece,
file_senders[i].piecelength))
file_senders[i].piecelength))
break;
file_senders[i].piecelength = fread(file_senders[i].nextpiece, 1, tox_file_data_size(m, file_senders[i].friendnum),

View File

@ -393,7 +393,8 @@ static int get_close_nodes(DHT *dht, uint8_t *client_id, Node_format *nodes_list
}
#ifdef LOGGING
sprintf(logbuffer, "get_close_nodes(): Assoc_get_close_entries() returned %i 'direct' and %i 'indirect' nodes.\n", request.count_good, num_found - request.count_good);
sprintf(logbuffer, "get_close_nodes(): Assoc_get_close_entries() returned %i 'direct' and %i 'indirect' nodes.\n",
request.count_good, num_found - request.count_good);
loglog(logbuffer);
#endif

View File

@ -106,7 +106,7 @@ void callback_groupmessage(Group_Chat *chat, void (*function)(Group_Chat *chat,
* format of function is: function(Group_Chat *chat, peer number, action, action length, userdata)
*/
void callback_groupaction(Group_Chat *chat, void (*function)(Group_Chat *chat, int, uint8_t *, uint16_t, void *),
void *userdata);
void *userdata);
/*
* Set callback function for peer name list changes.

View File

@ -323,7 +323,8 @@ void tox_callback_friend_message(Tox *tox, void (*function)(Messenger *tox, int,
/* Set the function that will be executed when an action from a friend is received.
* function format is: function(int friendnumber, uint8_t * action, uint32_t length)
*/
void tox_callback_friend_action(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), void *userdata)
void tox_callback_friend_action(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *),
void *userdata)
{
Messenger *m = tox;
m_callback_action(m, function, userdata);
@ -422,7 +423,7 @@ void tox_callback_group_message(Tox *tox, void (*function)(Messenger *tox, int,
* Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * action, uint16_t length, void *userdata)
*/
void tox_callback_group_action(Tox *tox, void (*function)(Messenger *tox, int, int, uint8_t *, uint16_t, void *),
void *userdata)
void *userdata)
{
Messenger *m = tox;
m_callback_group_action(m, function, userdata);