mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Code cleanups.
This commit is contained in:
parent
a67b4f8c6d
commit
2e75648f51
|
@ -1357,7 +1357,7 @@ static void LANdiscovery(Messenger *m)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Run this at startup. */
|
/* Run this at startup. */
|
||||||
Messenger *initMessenger(uint8_t ipv6enabled)
|
Messenger *new_messenger(uint8_t ipv6enabled)
|
||||||
{
|
{
|
||||||
Messenger *m = calloc(1, sizeof(Messenger));
|
Messenger *m = calloc(1, sizeof(Messenger));
|
||||||
|
|
||||||
|
@ -1402,7 +1402,7 @@ Messenger *initMessenger(uint8_t ipv6enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Run this before closing shop. */
|
/* Run this before closing shop. */
|
||||||
void cleanupMessenger(Messenger *m)
|
void kill_messenger(Messenger *m)
|
||||||
{
|
{
|
||||||
/* FIXME TODO: ideally cleanupMessenger will mirror initMessenger.
|
/* FIXME TODO: ideally cleanupMessenger will mirror initMessenger.
|
||||||
* This requires the other modules to expose cleanup functions.
|
* This requires the other modules to expose cleanup functions.
|
||||||
|
@ -1415,7 +1415,7 @@ void cleanupMessenger(Messenger *m)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Make this function not suck. */
|
/* TODO: Make this function not suck. */
|
||||||
void doFriends(Messenger *m)
|
void do_friends(Messenger *m)
|
||||||
{
|
{
|
||||||
/* TODO: Add incoming connections and some other stuff. */
|
/* TODO: Add incoming connections and some other stuff. */
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
@ -1725,7 +1725,7 @@ void doFriends(Messenger *m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void doInbound(Messenger *m)
|
void do_inbound(Messenger *m)
|
||||||
{
|
{
|
||||||
uint8_t secret_nonce[crypto_box_NONCEBYTES];
|
uint8_t secret_nonce[crypto_box_NONCEBYTES];
|
||||||
uint8_t public_key[crypto_box_PUBLICKEYBYTES];
|
uint8_t public_key[crypto_box_PUBLICKEYBYTES];
|
||||||
|
@ -1767,14 +1767,14 @@ static char *ID2String(uint8_t *client_id)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The main loop that needs to be run at least 20 times per second. */
|
/* The main loop that needs to be run at least 20 times per second. */
|
||||||
void doMessenger(Messenger *m)
|
void do_messenger(Messenger *m)
|
||||||
{
|
{
|
||||||
networking_poll(m->net);
|
networking_poll(m->net);
|
||||||
|
|
||||||
do_DHT(m->dht);
|
do_DHT(m->dht);
|
||||||
do_net_crypto(m->net_crypto);
|
do_net_crypto(m->net_crypto);
|
||||||
doFriends(m);
|
do_friends(m);
|
||||||
doInbound(m);
|
do_inbound(m);
|
||||||
do_allgroupchats(m);
|
do_allgroupchats(m);
|
||||||
LANdiscovery(m);
|
LANdiscovery(m);
|
||||||
|
|
||||||
|
@ -1873,17 +1873,17 @@ void doMessenger(Messenger *m)
|
||||||
/*
|
/*
|
||||||
* functions to avoid excessive polling
|
* functions to avoid excessive polling
|
||||||
*/
|
*/
|
||||||
int waitprepareMessenger(Messenger *m, uint8_t *data, uint16_t *lenptr)
|
int wait_prepare_messenger(Messenger *m, uint8_t *data, uint16_t *lenptr)
|
||||||
{
|
{
|
||||||
return networking_wait_prepare(m->net, sendqueue_total(m->net_crypto->lossless_udp), data, lenptr);
|
return networking_wait_prepare(m->net, sendqueue_total(m->net_crypto->lossless_udp), data, lenptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int waitexecuteMessenger(Messenger *m, uint8_t *data, uint16_t len, uint16_t milliseconds)
|
int wait_execute_messenger(Messenger *m, uint8_t *data, uint16_t len, uint16_t milliseconds)
|
||||||
{
|
{
|
||||||
return networking_wait_execute(data, len, milliseconds);
|
return networking_wait_execute(data, len, milliseconds);
|
||||||
};
|
};
|
||||||
|
|
||||||
void waitcleanupMessenger(Messenger *m, uint8_t *data, uint16_t len)
|
void wait_cleanup_messenger(Messenger *m, uint8_t *data, uint16_t len)
|
||||||
{
|
{
|
||||||
networking_wait_cleanup(m->net, data, len);
|
networking_wait_cleanup(m->net, data, len);
|
||||||
}
|
}
|
||||||
|
@ -2037,7 +2037,7 @@ static int Messenger_load_old(Messenger *m, uint8_t *data, uint32_t length)
|
||||||
#define MESSENGER_STATE_TYPE_NAME 4
|
#define MESSENGER_STATE_TYPE_NAME 4
|
||||||
|
|
||||||
/* return size of the messenger data (for saving) */
|
/* return size of the messenger data (for saving) */
|
||||||
uint32_t Messenger_size(Messenger *m)
|
uint32_t messenger_size(Messenger *m)
|
||||||
{
|
{
|
||||||
uint32_t size32 = sizeof(uint32_t), sizesubhead = size32 * 2;
|
uint32_t size32 = sizeof(uint32_t), sizesubhead = size32 * 2;
|
||||||
return size32 * 2 // global cookie
|
return size32 * 2 // global cookie
|
||||||
|
@ -2058,7 +2058,7 @@ static uint8_t *z_state_save_subheader(uint8_t *data, uint32_t len, uint16_t typ
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save the messenger in data of size Messenger_size(). */
|
/* Save the messenger in data of size Messenger_size(). */
|
||||||
void Messenger_save(Messenger *m, uint8_t *data)
|
void messenger_save(Messenger *m, uint8_t *data)
|
||||||
{
|
{
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
uint16_t type;
|
uint16_t type;
|
||||||
|
@ -2161,7 +2161,7 @@ static int messenger_load_state_callback(void *outer, uint8_t *data, uint32_t le
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load the messenger from data of size length. */
|
/* Load the messenger from data of size length. */
|
||||||
int Messenger_load(Messenger *m, uint8_t *data, uint32_t length)
|
int messenger_load(Messenger *m, uint8_t *data, uint32_t length)
|
||||||
{
|
{
|
||||||
uint32_t cookie_len = 2 * sizeof(uint32_t);
|
uint32_t cookie_len = 2 * sizeof(uint32_t);
|
||||||
|
|
||||||
|
|
|
@ -580,33 +580,33 @@ int m_msi_packet(Messenger *m, int friendnumber, uint8_t *data, uint16_t length)
|
||||||
* return allocated instance of Messenger on success.
|
* return allocated instance of Messenger on success.
|
||||||
* return 0 if there are problems.
|
* return 0 if there are problems.
|
||||||
*/
|
*/
|
||||||
Messenger *initMessenger(uint8_t ipv6enabled);
|
Messenger *new_messenger(uint8_t ipv6enabled);
|
||||||
|
|
||||||
/* Run this before closing shop
|
/* Run this before closing shop
|
||||||
* Free all datastructures.
|
* Free all datastructures.
|
||||||
*/
|
*/
|
||||||
void cleanupMessenger(Messenger *M);
|
void kill_messenger(Messenger *M);
|
||||||
|
|
||||||
/* The main loop that needs to be run at least 20 times per second. */
|
/* The main loop that needs to be run at least 20 times per second. */
|
||||||
void doMessenger(Messenger *m);
|
void do_messenger(Messenger *m);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* functions to avoid excessive polling
|
* functions to avoid excessive polling
|
||||||
*/
|
*/
|
||||||
int waitprepareMessenger(Messenger *m, uint8_t *data, uint16_t *lenptr);
|
int wait_prepare_messenger(Messenger *m, uint8_t *data, uint16_t *lenptr);
|
||||||
int waitexecuteMessenger(Messenger *m, uint8_t *data, uint16_t len, uint16_t milliseconds);
|
int wait_execute_messenger(Messenger *m, uint8_t *data, uint16_t len, uint16_t milliseconds);
|
||||||
void waitcleanupMessenger(Messenger *m, uint8_t *data, uint16_t len);
|
void wait_cleanup_messenger(Messenger *m, uint8_t *data, uint16_t len);
|
||||||
|
|
||||||
/* SAVING AND LOADING FUNCTIONS: */
|
/* SAVING AND LOADING FUNCTIONS: */
|
||||||
|
|
||||||
/* return size of the messenger data (for saving). */
|
/* return size of the messenger data (for saving). */
|
||||||
uint32_t Messenger_size(Messenger *m);
|
uint32_t messenger_size(Messenger *m);
|
||||||
|
|
||||||
/* Save the messenger in data (must be allocated memory of size Messenger_size()) */
|
/* Save the messenger in data (must be allocated memory of size Messenger_size()) */
|
||||||
void Messenger_save(Messenger *m, uint8_t *data);
|
void messenger_save(Messenger *m, uint8_t *data);
|
||||||
|
|
||||||
/* Load the messenger from data of size length. */
|
/* Load the messenger from data of size length. */
|
||||||
int Messenger_load(Messenger *m, uint8_t *data, uint32_t length);
|
int messenger_load(Messenger *m, uint8_t *data, uint32_t length);
|
||||||
|
|
||||||
/* Return the number of friends in the instance m.
|
/* Return the number of friends in the instance m.
|
||||||
* You should use this to determine how much memory to allocate
|
* You should use this to determine how much memory to allocate
|
||||||
|
|
|
@ -609,7 +609,7 @@ int tox_isconnected(Tox *tox)
|
||||||
*/
|
*/
|
||||||
Tox *tox_new(uint8_t ipv6enabled)
|
Tox *tox_new(uint8_t ipv6enabled)
|
||||||
{
|
{
|
||||||
return initMessenger(ipv6enabled);
|
return new_messenger(ipv6enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Run this before closing shop.
|
/* Run this before closing shop.
|
||||||
|
@ -618,14 +618,14 @@ Tox *tox_new(uint8_t ipv6enabled)
|
||||||
void tox_kill(Tox *tox)
|
void tox_kill(Tox *tox)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
cleanupMessenger(m);
|
kill_messenger(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The main loop that needs to be run at least 20 times per second. */
|
/* The main loop that needs to be run at least 20 times per second. */
|
||||||
void tox_do(Tox *tox)
|
void tox_do(Tox *tox)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
doMessenger(m);
|
do_messenger(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -634,19 +634,19 @@ void tox_do(Tox *tox)
|
||||||
int tox_wait_prepare(Tox *tox, uint8_t *data, uint16_t *lenptr)
|
int tox_wait_prepare(Tox *tox, uint8_t *data, uint16_t *lenptr)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return waitprepareMessenger(m, data, lenptr);
|
return wait_prepare_messenger(m, data, lenptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int tox_wait_execute(Tox *tox, uint8_t *data, uint16_t len, uint16_t milliseconds)
|
int tox_wait_execute(Tox *tox, uint8_t *data, uint16_t len, uint16_t milliseconds)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return waitexecuteMessenger(m, data, len, milliseconds);
|
return wait_execute_messenger(m, data, len, milliseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tox_wait_cleanup(Tox *tox, uint8_t *data, uint16_t len)
|
void tox_wait_cleanup(Tox *tox, uint8_t *data, uint16_t len)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
waitcleanupMessenger(m, data, len);
|
wait_cleanup_messenger(m, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SAVING AND LOADING FUNCTIONS: */
|
/* SAVING AND LOADING FUNCTIONS: */
|
||||||
|
@ -655,20 +655,20 @@ void tox_wait_cleanup(Tox *tox, uint8_t *data, uint16_t len)
|
||||||
uint32_t tox_size(Tox *tox)
|
uint32_t tox_size(Tox *tox)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return Messenger_size(m);
|
return messenger_size(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save the messenger in data (must be allocated memory of size Messenger_size()). */
|
/* Save the messenger in data (must be allocated memory of size Messenger_size()). */
|
||||||
void tox_save(Tox *tox, uint8_t *data)
|
void tox_save(Tox *tox, uint8_t *data)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
Messenger_save(m, data);
|
messenger_save(m, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load the messenger from data of size length. */
|
/* Load the messenger from data of size length. */
|
||||||
int tox_load(Tox *tox, uint8_t *data, uint32_t length)
|
int tox_load(Tox *tox, uint8_t *data, uint32_t length)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return Messenger_load(m, data, length);
|
return messenger_load(m, data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user