Fixed TOX_MAX_MESSAGE_LENGTH define.

Removed some useless code from toxcore.

Astyled core code with new version of astyle.
This commit is contained in:
irungentoo 2014-06-01 18:55:52 -04:00
parent 7c1b801bd0
commit 1bad0b5eea
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
10 changed files with 42 additions and 257 deletions

View File

@ -1257,8 +1257,6 @@ int main(int argc, char *argv[])
time_t timestamp0 = time(NULL); time_t timestamp0 = time(NULL);
uint8_t pollok = 0; uint8_t pollok = 0;
uint16_t len = tox_wait_data_size();
uint8_t data[len];
while (1) { while (1) {
if (on == 0) { if (on == 0) {

View File

@ -2427,31 +2427,6 @@ void do_messenger(Messenger *m)
#endif /* LOGGING */ #endif /* LOGGING */
} }
/*
* functions to avoid excessive polling
*/
size_t wait_data_size()
{
return networking_wait_data_size();
}
int wait_prepare_messenger(Messenger *m, uint8_t *data)
{
//TODO
//return networking_wait_prepare(m->net, sendqueue_total(m->net_crypto->lossless_udp), data);
return networking_wait_prepare(m->net, 1024, data);
}
int wait_execute_messenger(uint8_t *data, long seconds, long microseconds)
{
return networking_wait_execute(data, seconds, microseconds);
}
int wait_cleanup_messenger(Messenger *m, uint8_t *data)
{
return networking_wait_cleanup(m->net, data);
}
/* new messenger format for load/save, more robust and forward compatible */ /* new messenger format for load/save, more robust and forward compatible */
#define MESSENGER_STATE_COOKIE_GLOBAL_OLD 0x15ed1b1e #define MESSENGER_STATE_COOKIE_GLOBAL_OLD 0x15ed1b1e

View File

@ -727,14 +727,6 @@ void do_messenger(Messenger *m);
*/ */
uint32_t messenger_run_interval(Messenger *m); uint32_t messenger_run_interval(Messenger *m);
/*
* functions to avoid excessive polling
*/
size_t wait_data_size();
int wait_prepare_messenger(Messenger *m, uint8_t *data);
int wait_execute_messenger(uint8_t *data, long seconds, long microseconds);
int wait_cleanup_messenger(Messenger *m, uint8_t *data);
/* SAVING AND LOADING FUNCTIONS: */ /* SAVING AND LOADING FUNCTIONS: */
/* return size of the messenger data (for saving). */ /* return size of the messenger data (for saving). */

View File

@ -424,133 +424,6 @@ void networking_poll(Networking_Core *net)
} }
} }
/*
* function to avoid excessive polling
*/
typedef struct {
sock_t sock;
uint32_t sendqueue_length;
uint16_t send_fail_reset;
uint64_t send_fail_eagain;
} select_info;
size_t networking_wait_data_size()
{
return sizeof(select_info);
}
int networking_wait_prepare(Networking_Core *net, uint32_t sendqueue_length, uint8_t *data)
{
if (data == NULL) {
return 0;
}
select_info *s = (select_info *)data;
s->sock = net->sock;
s->sendqueue_length = sendqueue_length;
s->send_fail_reset = 0;
s->send_fail_eagain = net->send_fail_eagain;
return 1;
}
/* *** Function MUSTN'T poll. ***
* The function mustn't modify anything at all, so it can be called completely
* asynchronously without any worry.
*/
int networking_wait_execute(uint8_t *data, long seconds, long microseconds)
{
/* WIN32: supported since Win2K, but might need some adjustements */
/* UNIX: this should work for any remotely Unix'ish system */
if (data == NULL) {
return 0;
}
select_info *s = (select_info *)data;
/* add only if we had a failed write */
int writefds_add = 0;
/* if send_fail_eagain is set, that means that socket's buffer was full and couldn't fit data we tried to send,
* so this is the only case when we need to know when the socket becomes write-ready, i.e. socket's buffer gets
* some free space for us to put data to be sent in, but select will tell us that the socket is writable even
* if we can fit a small part of our data (say 1 byte), so we wait some time, in hope that large enough chunk
* of socket's buffer will be available (at least that's how I understand intentions of the previous author of
* that code)
*/
if (s->send_fail_eagain != 0) {
// current_time(): milliseconds
uint64_t now = current_time_monotonic();
/* s->sendqueue_length: might be used to guess how long we keep checking */
/* for now, threshold is hardcoded to 250ms, too long for a really really
* fast link, but too short for a sloooooow link... */
if (now - s->send_fail_eagain < 250) {
writefds_add = 1;
}
}
int nfds = 1 + s->sock;
/* the FD_ZERO calls might be superfluous */
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(s->sock, &readfds);
fd_set writefds;
FD_ZERO(&writefds);
if (writefds_add) {
FD_SET(s->sock, &writefds);
}
fd_set exceptfds;
FD_ZERO(&exceptfds);
FD_SET(s->sock, &exceptfds);
struct timeval timeout;
struct timeval *timeout_ptr = &timeout;
if (seconds < 0 || microseconds < 0) {
timeout_ptr = NULL;
} else {
timeout.tv_sec = seconds;
timeout.tv_usec = microseconds;
}
/* returns -1 on error, 0 on timeout, the socket on activity */
int res = select(nfds, &readfds, &writefds, &exceptfds, timeout_ptr);
LOGGER_SCOPE(
if (res) LOGGER_INFO("select(%d, %d): %d (%d, %s) - %d %d %d\n", microseconds, seconds, res, errno,
strerror(errno), FD_ISSET(s->sock, &readfds), FD_ISSET(s->sock, &writefds),
FD_ISSET(s->sock, &exceptfds));
);
if (FD_ISSET(s->sock, &writefds)) {
s->send_fail_reset = 1;
}
return res > 0 ? 2 : 1;
}
int networking_wait_cleanup(Networking_Core *net, uint8_t *data)
{
if (data == NULL) {
return 0;
}
select_info *s = (select_info *)data;
if (s->send_fail_reset) {
net->send_fail_eagain = 0;
}
return 1;
}
#ifndef VANILLA_NACL #ifndef VANILLA_NACL
/* Used for sodium_init() */ /* Used for sodium_init() */
#include <sodium.h> #include <sodium.h>

View File

@ -350,14 +350,6 @@ void networking_registerhandler(Networking_Core *net, uint8_t byte, packet_handl
/* Call this several times a second. */ /* Call this several times a second. */
void networking_poll(Networking_Core *net); void networking_poll(Networking_Core *net);
/*
* functions to avoid excessive polling
*/
size_t networking_wait_data_size();
int networking_wait_prepare(Networking_Core *net, uint32_t sendqueue_length, uint8_t *data);
int networking_wait_execute(uint8_t *data, long seconds, long microseconds);
int networking_wait_cleanup(Networking_Core *net, uint8_t *data);
/* Initialize networking. /* Initialize networking.
* bind to ip and port. * bind to ip and port.
* ip must be in network order EX: 127.0.0.1 = (7F000001). * ip must be in network order EX: 127.0.0.1 = (7F000001).

View File

@ -52,7 +52,8 @@
int send_announce_request(Networking_Core *net, Onion_Path *path, Node_format dest, uint8_t *public_key, int send_announce_request(Networking_Core *net, Onion_Path *path, Node_format dest, uint8_t *public_key,
uint8_t *secret_key, uint8_t *ping_id, uint8_t *client_id, uint8_t *data_public_key, uint64_t sendback_data) uint8_t *secret_key, uint8_t *ping_id, uint8_t *client_id, uint8_t *data_public_key, uint64_t sendback_data)
{ {
uint8_t plain[ONION_PING_ID_SIZE + crypto_box_PUBLICKEYBYTES + crypto_box_PUBLICKEYBYTES + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH]; uint8_t plain[ONION_PING_ID_SIZE + crypto_box_PUBLICKEYBYTES + crypto_box_PUBLICKEYBYTES +
ONION_ANNOUNCE_SENDBACK_DATA_LENGTH];
memcpy(plain, ping_id, ONION_PING_ID_SIZE); memcpy(plain, ping_id, ONION_PING_ID_SIZE);
memcpy(plain + ONION_PING_ID_SIZE, client_id, crypto_box_PUBLICKEYBYTES); memcpy(plain + ONION_PING_ID_SIZE, client_id, crypto_box_PUBLICKEYBYTES);
memcpy(plain + ONION_PING_ID_SIZE + crypto_box_PUBLICKEYBYTES, data_public_key, crypto_box_PUBLICKEYBYTES); memcpy(plain + ONION_PING_ID_SIZE + crypto_box_PUBLICKEYBYTES, data_public_key, crypto_box_PUBLICKEYBYTES);
@ -223,7 +224,8 @@ static int handle_announce_request(void *object, IP_Port source, uint8_t *packet
uint8_t shared_key[crypto_box_BEFORENMBYTES]; uint8_t shared_key[crypto_box_BEFORENMBYTES];
get_shared_key(&onion_a->shared_keys_recv, shared_key, onion_a->dht->self_secret_key, packet_public_key); get_shared_key(&onion_a->shared_keys_recv, shared_key, onion_a->dht->self_secret_key, packet_public_key);
uint8_t plain[ONION_PING_ID_SIZE + crypto_box_PUBLICKEYBYTES + crypto_box_PUBLICKEYBYTES + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH]; uint8_t plain[ONION_PING_ID_SIZE + crypto_box_PUBLICKEYBYTES + crypto_box_PUBLICKEYBYTES +
ONION_ANNOUNCE_SENDBACK_DATA_LENGTH];
int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES, int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES,
ONION_PING_ID_SIZE + crypto_box_PUBLICKEYBYTES + crypto_box_PUBLICKEYBYTES + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + ONION_PING_ID_SIZE + crypto_box_PUBLICKEYBYTES + crypto_box_PUBLICKEYBYTES + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH +
crypto_box_MACBYTES, plain); crypto_box_MACBYTES, plain);

View File

@ -820,32 +820,6 @@ void tox_do(Tox *tox)
do_messenger(m); do_messenger(m);
} }
/*
* functions to avoid excessive polling
*/
size_t tox_wait_data_size()
{
return wait_data_size();
}
int tox_wait_prepare(Tox *tox, uint8_t *data)
{
Messenger *m = tox;
return wait_prepare_messenger(m, data);
}
int tox_wait_execute(uint8_t *data, long seconds, long microseconds)
{
return wait_execute_messenger(data, seconds, microseconds);
}
int tox_wait_cleanup(Tox *tox, uint8_t *data)
{
Messenger *m = tox;
return wait_cleanup_messenger(m, data);
}
/* SAVING AND LOADING FUNCTIONS: */ /* SAVING AND LOADING FUNCTIONS: */
/* return size of the messenger data (for saving). */ /* return size of the messenger data (for saving). */

View File

@ -26,50 +26,20 @@
#include <stdint.h> #include <stdint.h>
#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
#ifndef WINVER
//Windows XP
#define WINVER 0x0501
#endif
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif
#else
#include <sys/types.h>
#ifdef __OpenBSD__
#include <netinet/in_systm.h>
#endif
#include <netinet/in.h>
#include <netinet/ip.h>
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define TOX_MAX_NAME_LENGTH 128 #define TOX_MAX_NAME_LENGTH 128
/* Maximum message and action length that can be sent. */
#define TOX_MAX_MESSAGE_LENGTH 1003 /* Maximum length of single messages after which they should be split. */
#define TOX_MAX_MESSAGE_LENGTH 1368
#define TOX_MAX_STATUSMESSAGE_LENGTH 1007 #define TOX_MAX_STATUSMESSAGE_LENGTH 1007
#define TOX_CLIENT_ID_SIZE 32 #define TOX_CLIENT_ID_SIZE 32
#define TOX_FRIEND_ADDRESS_SIZE (TOX_CLIENT_ID_SIZE + sizeof(uint32_t) + sizeof(uint16_t)) #define TOX_FRIEND_ADDRESS_SIZE (TOX_CLIENT_ID_SIZE + sizeof(uint32_t) + sizeof(uint16_t))
#define TOX_PORTRANGE_FROM 33445
#define TOX_PORTRANGE_TO 33545
#define TOX_PORT_DEFAULT TOX_PORTRANGE_FROM
#define TOX_ENABLE_IPV6_DEFAULT 1 #define TOX_ENABLE_IPV6_DEFAULT 1
/* Errors for m_addfriend /* Errors for m_addfriend
@ -177,6 +147,10 @@ int tox_friend_exists(Tox *tox, int32_t friendnumber);
* return the message id if packet was successfully put into the send queue. * return the message id if packet was successfully put into the send queue.
* return 0 if it was not. * return 0 if it was not.
* *
* maximum length of messages is TOX_MAX_MESSAGE_LENGTH, your client must split larger messages
* or else sending them will not work. No the core will not split messages for you because that
* requires me to parse UTF-8.
*
* You will want to retain the return value, it will be passed to your read_receipt callback * You will want to retain the return value, it will be passed to your read_receipt callback
* if one is received. * if one is received.
* m_sendmessage_withid will send a message with the id of your choosing, * m_sendmessage_withid will send a message with the id of your choosing,
@ -190,6 +164,10 @@ uint32_t tox_send_message_withid(Tox *tox, int32_t friendnumber, uint32_t theid,
* return the message id if packet was successfully put into the send queue. * return the message id if packet was successfully put into the send queue.
* return 0 if it was not. * return 0 if it was not.
* *
* maximum length of actions is TOX_MAX_MESSAGE_LENGTH, your client must split larger actions
* or else sending them will not work. No the core will not split actions for you because that
* requires me to parse UTF-8.
*
* You will want to retain the return value, it will be passed to your read_receipt callback * You will want to retain the return value, it will be passed to your read_receipt callback
* if one is received. * if one is received.
* m_sendaction_withid will send an action message with the id of your choosing, * m_sendaction_withid will send an action message with the id of your choosing,
@ -235,6 +213,7 @@ int tox_get_self_name_size(Tox *tox);
/* Set our user status. /* Set our user status.
* *
* userstatus must be one of TOX_USERSTATUS values. * userstatus must be one of TOX_USERSTATUS values.
* max length of the status is TOX_MAX_STATUSMESSAGE_LENGTH.
* *
* returns 0 on success. * returns 0 on success.
* returns -1 on failure. * returns -1 on failure.