Merge pull request #630 from Bahkuh/master

Minor improvements
This commit is contained in:
irungentoo 2013-10-22 13:29:45 -07:00
commit b515eac0a3
5 changed files with 27 additions and 32 deletions

27
.gitignore vendored
View File

@ -3,31 +3,28 @@
.DS_Store? .DS_Store?
._* ._*
.Spotlight-V100 .Spotlight-V100
.Trashes .Trash*
Icon?
ethumbs.db ethumbs.db
Thumbs.db Thumbs.db
*.tmp
//nacl build # Make
nacl/build/
build/
!build/Makefile.am
sodium
CMakeCache.txt CMakeCache.txt
CMakeFiles CMakeFiles
Makefile Makefile
cmake_install.cmake cmake_install.cmake
install_manifest.txt install_manifest.txt
tags
Makefile.in
# Testing
testing/data testing/data
*~ *~
# Vim # Vim
*.swp *.swp
# Ctags
tags
# Object files # Object files
*.o *.o
*.lo *.lo
@ -37,14 +34,13 @@ tags
*.exe *.exe
*.out *.out
*.app *.app
*.swp
*.la *.la
# Misc (?)
m4/* m4/*
!m4/pkg.m4
configure configure
configure_aux configure_aux
Makefile.in !m4/pkg.m4
aclocal.m4 aclocal.m4
config.h* config.h*
config.log config.log
@ -53,13 +49,12 @@ stamp-h1
autom4te.cache autom4te.cache
libtoxcore.pc libtoxcore.pc
libtool libtool
.deps .deps
.libs .libs
.dirstamp .dirstamp
#netbeans # Netbeans
nbproject nbproject
#astyle # astyle
*.orig *.orig

View File

@ -198,8 +198,8 @@ int new_connection(Lossless_UDP *ludp, IP_Port ip_port)
memset(connection, 0, sizeof(Connection)); memset(connection, 0, sizeof(Connection));
uint32_t handshake_id1 = handshake_id(ludp, ip_port); uint32_t handshake_id1 = handshake_id(ludp, ip_port);
/* add randomness to timeout to prevent connections getting stuck in a loop. */ /* Add randomness to timeout to prevent connections getting stuck in a loop. */
uint8_t timeout = CONNEXION_TIMEOUT + rand() % CONNEXION_TIMEOUT; uint8_t timeout = CONNECTION_TIMEOUT + rand() % CONNECTION_TIMEOUT;
*connection = (Connection) { *connection = (Connection) {
.ip_port = ip_port, .ip_port = ip_port,
@ -260,7 +260,7 @@ static int new_inconnection(Lossless_UDP *ludp, IP_Port ip_port)
Connection *connection = &tox_array_get(&ludp->connections, connection_id, Connection); Connection *connection = &tox_array_get(&ludp->connections, connection_id, Connection);
memset(connection, 0, sizeof(Connection)); memset(connection, 0, sizeof(Connection));
/* Add randomness to timeout to prevent connections getting stuck in a loop. */ /* Add randomness to timeout to prevent connections getting stuck in a loop. */
uint8_t timeout = CONNEXION_TIMEOUT + rand() % CONNEXION_TIMEOUT; uint8_t timeout = CONNECTION_TIMEOUT + rand() % CONNECTION_TIMEOUT;
*connection = (Connection) { *connection = (Connection) {
.ip_port = ip_port, .ip_port = ip_port,
@ -403,7 +403,7 @@ int connection_confirmed(Lossless_UDP *ludp, int connection_id)
} }
/* Confirm an incoming connection. /* Confirm an incoming connection.
* Also disables the auto kill timeout on incomming connections. * Also disable the auto kill timeout on incomming connections.
* *
* return 0 on success * return 0 on success
* return -1 on failure. * return -1 on failure.
@ -777,7 +777,7 @@ static int handle_handshake(void *object, IP_Port source, uint8_t *packet, uint3
/* if handshake_id2 is what we sent previously as handshake_id1 */ /* if handshake_id2 is what we sent previously as handshake_id1 */
if (handshake_id2 == connection->handshake_id1) { if (handshake_id2 == connection->handshake_id1) {
connection->status = LUDP_NOT_CONFIRMED; connection->status = LUDP_NOT_CONFIRMED;
/* NOTE: is this necessary? /* NOTE: Is this necessary?
connection->handshake_id2 = handshake_id1; */ connection->handshake_id2 = handshake_id1; */
connection->orecv_packetnum = handshake_id2; connection->orecv_packetnum = handshake_id2;
connection->osent_packetnum = handshake_id1; connection->osent_packetnum = handshake_id1;
@ -847,7 +847,7 @@ static int handle_SYNC2(Lossless_UDP *ludp, int connection_id, uint8_t counter,
/* /*
* Automatically adjusts send rates of data packets for optimal transmission. * Automatically adjusts send rates of data packets for optimal transmission.
* *
* TODO: Impove this. * TODO: Improve this.
*/ */
static void adjust_datasendspeed(Connection *connection, uint32_t req_packets) static void adjust_datasendspeed(Connection *connection, uint32_t req_packets)
{ {
@ -1144,7 +1144,7 @@ static void adjust_rates(Lossless_UDP *ludp)
} }
} }
/* Call this function a couple times per second It's the main loop. */ /* Call this function a couple times per second. It is the main loop. */
void do_lossless_udp(Lossless_UDP *ludp) void do_lossless_udp(Lossless_UDP *ludp)
{ {
do_new(ludp); do_new(ludp);

View File

@ -38,10 +38,10 @@
/* Maximum number of data packets in the buffer. */ /* Maximum number of data packets in the buffer. */
#define MAX_REQUESTED_PACKETS 256 #define MAX_REQUESTED_PACKETS 256
/* Timeout per connection is randomly set between CONNEXION_TIMEOUT and 2*CONNEXION_TIMEOUT. */ /* Timeout per connection is randomly set between CONNECTION_TIMEOUT and 2*CONNECTION_TIMEOUT. */
#define CONNEXION_TIMEOUT 5 #define CONNECTION_TIMEOUT 5
/* Initial amount of sync/hanshake packets to send per second. */ /* Initial amount of sync/handshake packets to send per second. */
#define SYNC_RATE 2 #define SYNC_RATE 2
/* Initial send rate of data. */ /* Initial send rate of data. */
@ -124,7 +124,7 @@ typedef struct {
uint8_t send_counter; uint8_t send_counter;
uint8_t timeout; /* connection timeout in seconds. */ uint8_t timeout; /* connection timeout in seconds. */
/* is the connection confirmed or not 1 if yes, 0 if no */ /* Is the connection confirmed or not? 1 if yes, 0 if no */
uint8_t confirmed; uint8_t confirmed;
} Connection; } Connection;
@ -249,7 +249,7 @@ uint32_t recvqueue(Lossless_UDP *ludp, int connection_id);
*/ */
int is_connected(Lossless_UDP *ludp, int connection_id); int is_connected(Lossless_UDP *ludp, int connection_id);
/* Call this function a couple times per second It's the main loop. */ /* Call this function a couple times per second. It is the main loop. */
void do_lossless_udp(Lossless_UDP *ludp); void do_lossless_udp(Lossless_UDP *ludp);
/* This function sets up LosslessUDP packet handling. */ /* This function sets up LosslessUDP packet handling. */

View File

@ -152,7 +152,7 @@ void random_nonce(uint8_t *nonce)
static uint8_t base_nonce[crypto_box_NONCEBYTES]; static uint8_t base_nonce[crypto_box_NONCEBYTES];
static uint8_t nonce_set = 0; static uint8_t nonce_set = 0;
/*Gives a nonce guaranteed to be different from previous ones.*/ /* Gives a nonce guaranteed to be different from previous ones.*/
void new_nonce(uint8_t *nonce) void new_nonce(uint8_t *nonce)
{ {
if (nonce_set == 0) { if (nonce_set == 0) {
@ -240,7 +240,7 @@ int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uin
return 1; return 1;
} }
/* Ceate a request to peer. /* Create a request to peer.
* send_public_key and send_secret_key are the pub/secret keys of the sender. * send_public_key and send_secret_key are the pub/secret keys of the sender.
* recv_public_key is public key of reciever. * recv_public_key is public key of reciever.
* packet must be an array of MAX_DATA_SIZE big. * packet must be an array of MAX_DATA_SIZE big.

View File

@ -28,7 +28,7 @@
#define CRYPTO_PACKET_FRIEND_REQ 32 /* Friend request crypto packet ID. */ #define CRYPTO_PACKET_FRIEND_REQ 32 /* Friend request crypto packet ID. */
#define CRYPTO_PACKET_NAT_PING 254 /* NAT ping crypto packet ID. */ #define CRYPTO_PACKET_NAT_PING 254 /* NAT ping crypto packet ID. */
#define CRYPTO_HANDSHAKE_TIMEOUT (CONNEXION_TIMEOUT * 2) #define CRYPTO_HANDSHAKE_TIMEOUT (CONNECTION_TIMEOUT * 2)
typedef struct { typedef struct {
uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* The real public key of the peer. */ uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* The real public key of the peer. */
@ -38,7 +38,7 @@ typedef struct {
uint8_t sessionsecret_key[crypto_box_SECRETKEYBYTES]; /* Our private key for this session. */ uint8_t sessionsecret_key[crypto_box_SECRETKEYBYTES]; /* Our private key for this session. */
uint8_t peersessionpublic_key[crypto_box_PUBLICKEYBYTES]; /* The public key of the peer. */ uint8_t peersessionpublic_key[crypto_box_PUBLICKEYBYTES]; /* The public key of the peer. */
uint8_t shared_key[crypto_box_BEFORENMBYTES]; /* The precomputed shared key from encrypt_precompute. */ uint8_t shared_key[crypto_box_BEFORENMBYTES]; /* The precomputed shared key from encrypt_precompute. */
uint8_t status; /* 0 if no connection, 1 we have sent a handshake, 2 if connexion is not confirmed yet uint8_t status; /* 0 if no connection, 1 we have sent a handshake, 2 if connection is not confirmed yet
* (we have received a handshake but no empty data packet), 3 if the connection is established. * (we have received a handshake but no empty data packet), 3 if the connection is established.
* 4 if the connection is timed out. * 4 if the connection is timed out.
*/ */