mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Astyled the code.
This commit is contained in:
parent
24974ef816
commit
15d17b0a3c
|
@ -65,9 +65,11 @@ START_TEST(test_fillup)
|
||||||
//uint32_t a = current_time();
|
//uint32_t a = current_time();
|
||||||
uint32_t a = 2710106197;
|
uint32_t a = 2710106197;
|
||||||
srand(a);
|
srand(a);
|
||||||
for(i = 0; i < CLIENT_ID_SIZE; ++i) {
|
|
||||||
|
for (i = 0; i < CLIENT_ID_SIZE; ++i) {
|
||||||
id[i] = rand();
|
id[i] = rand();
|
||||||
}
|
}
|
||||||
|
|
||||||
Assoc *assoc = new_Assoc(6, 15, id);
|
Assoc *assoc = new_Assoc(6, 15, id);
|
||||||
ck_assert_msg(assoc != NULL, "failed to create default assoc");
|
ck_assert_msg(assoc != NULL, "failed to create default assoc");
|
||||||
struct entry {
|
struct entry {
|
||||||
|
@ -78,11 +80,13 @@ START_TEST(test_fillup)
|
||||||
unsigned int fail = 0;
|
unsigned int fail = 0;
|
||||||
struct entry entries[128];
|
struct entry entries[128];
|
||||||
struct entry closest[8];
|
struct entry closest[8];
|
||||||
for(j = 0; j < 128; ++j) {
|
|
||||||
|
for (j = 0; j < 128; ++j) {
|
||||||
for(i = 0; i < CLIENT_ID_SIZE; ++i) {
|
|
||||||
|
for (i = 0; i < CLIENT_ID_SIZE; ++i) {
|
||||||
entries[j].id[i] = rand();
|
entries[j].id[i] = rand();
|
||||||
}
|
}
|
||||||
|
|
||||||
IP_Port ipp;
|
IP_Port ipp;
|
||||||
ipp.ip.family = AF_INET;
|
ipp.ip.family = AF_INET;
|
||||||
ipp.ip.ip4.uint32 = rand();
|
ipp.ip.ip4.uint32 = rand();
|
||||||
|
@ -92,14 +96,17 @@ START_TEST(test_fillup)
|
||||||
ipp.ip.ip4.uint32 = rand();
|
ipp.ip.ip4.uint32 = rand();
|
||||||
ipp.port = rand();
|
ipp.port = rand();
|
||||||
entries[j].ipp_recv = ipp;
|
entries[j].ipp_recv = ipp;
|
||||||
|
|
||||||
if (j % 16 == 0) {
|
if (j % 16 == 0) {
|
||||||
memcpy(entries[j].id, id, CLIENT_ID_SIZE - 30);
|
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);
|
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);
|
ck_assert_msg(res == 1, "failed to store entry: expected %u, got %u, j = %u", 1, res, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
int good = 0;
|
int good = 0;
|
||||||
Assoc_close_entries close_entries;
|
Assoc_close_entries close_entries;
|
||||||
memset(&close_entries, 0, sizeof(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);
|
uint8_t found = Assoc_get_close_entries(assoc, &close_entries);
|
||||||
ck_assert_msg(found == 8, "get_close_entries(): expected %u, got %u", 1, found);
|
ck_assert_msg(found == 8, "get_close_entries(): expected %u, got %u", 1, found);
|
||||||
|
|
||||||
for (i = 0; i < 8; ++i) {
|
for (i = 0; i < 8; ++i) {
|
||||||
for (j = 0; j < 8; ++j) {
|
for (j = 0; j < 8; ++j) {
|
||||||
if (id_equal(entri[j]->client_id, closest[i].id))
|
if (id_equal(entri[j]->client_id, closest[i].id))
|
||||||
++good;
|
++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));
|
//printf("good: %u %u %u\n", good, a, ((uint32_t)current_time() - a));
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
|
@ -54,9 +54,10 @@
|
||||||
|
|
||||||
uint8_t zeroes_cid[CLIENT_ID_SIZE];
|
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;
|
uint32_t j;
|
||||||
|
|
||||||
for (j = 0; j < CLIENT_ID_SIZE; j++) {
|
for (j = 0; j < CLIENT_ID_SIZE; j++) {
|
||||||
printf("%02hhX", client_id[j]);
|
printf("%02hhX", client_id[j]);
|
||||||
}
|
}
|
||||||
|
@ -67,13 +68,16 @@ void print_hardening(Hardening *h)
|
||||||
printf("Hardening:\n");
|
printf("Hardening:\n");
|
||||||
printf("routes_requests_ok: %hhu\n", h->routes_requests_ok);
|
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_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("\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_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("\ntesting_requests: %hhu\n", h->testing_requests);
|
||||||
printf("testing_timestamp: %llu\n", (long long unsigned int)h->testing_timestamp);
|
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");
|
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);
|
printf("\nLast pinged: %llu\n", (long long unsigned int) assoc->last_pinged);
|
||||||
|
|
||||||
ipp = &assoc->ret_ip_port;
|
ipp = &assoc->ret_ip_port;
|
||||||
|
|
||||||
if (ours)
|
if (ours)
|
||||||
printf("OUR IP: %s Port: %u\n", ip_ntoa(&ipp->ip), ntohs(ipp->port));
|
printf("OUR IP: %s Port: %u\n", ip_ntoa(&ipp->ip), ntohs(ipp->port));
|
||||||
else
|
else
|
||||||
printf("RET IP: %s Port: %u\n", ip_ntoa(&ipp->ip), ntohs(ipp->port));
|
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);
|
printf("Timestamp: %llu\n", (long long unsigned int) assoc->ret_timestamp);
|
||||||
print_hardening(&assoc->hardening);
|
print_hardening(&assoc->hardening);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_clientlist(DHT *dht)
|
void print_clientlist(DHT *dht)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
printf("___________________CLOSE________________________________\n");
|
printf("___________________CLOSE________________________________\n");
|
||||||
|
|
||||||
for (i = 0; i < LCLIENT_LIST; i++) {
|
for (i = 0; i < LCLIENT_LIST; i++) {
|
||||||
Client_data *client = &dht->close_clientlist[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;
|
continue;
|
||||||
|
|
||||||
printf("ClientID: ");
|
printf("ClientID: ");
|
||||||
print_client_id(client->client_id);
|
print_client_id(client->client_id);
|
||||||
|
|
||||||
|
@ -129,8 +138,10 @@ void print_friendlist(DHT *dht)
|
||||||
|
|
||||||
for (i = 0; i < MAX_FRIEND_CLIENTS; i++) {
|
for (i = 0; i < MAX_FRIEND_CLIENTS; i++) {
|
||||||
Client_data *client = &dht->friends_list[k].client_list[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;
|
continue;
|
||||||
|
|
||||||
printf("ClientID: ");
|
printf("ClientID: ");
|
||||||
print_client_id(client->client_id);
|
print_client_id(client->client_id);
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ void send_filesenders(Tox *m)
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (!tox_file_send_data(m, file_senders[i].friendnum, file_senders[i].filenumber, file_senders[i].nextpiece,
|
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;
|
break;
|
||||||
|
|
||||||
file_senders[i].piecelength = fread(file_senders[i].nextpiece, 1, tox_file_data_size(m, file_senders[i].friendnum),
|
file_senders[i].piecelength = fread(file_senders[i].nextpiece, 1, tox_file_data_size(m, file_senders[i].friendnum),
|
||||||
|
|
|
@ -393,7 +393,8 @@ static int get_close_nodes(DHT *dht, uint8_t *client_id, Node_format *nodes_list
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LOGGING
|
#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);
|
loglog(logbuffer);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -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)
|
* 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 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.
|
* Set callback function for peer name list changes.
|
||||||
|
|
|
@ -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.
|
/* 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)
|
* 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;
|
Messenger *m = tox;
|
||||||
m_callback_action(m, function, userdata);
|
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)
|
* 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 tox_callback_group_action(Tox *tox, void (*function)(Messenger *tox, int, int, uint8_t *, uint16_t, void *),
|
||||||
void *userdata)
|
void *userdata)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
m_callback_group_action(m, function, userdata);
|
m_callback_group_action(m, function, userdata);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user