pthread is now a core dependency instead of just a toxav dependency.

Fixed possible thread bug with sending A/V packets.

TODO: eventually make toxcore thread safe.
This commit is contained in:
irungentoo 2014-06-12 11:15:20 -04:00
parent 4f2674eb0f
commit 2740099da0
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
5 changed files with 24 additions and 13 deletions

View File

@ -459,15 +459,13 @@ if (test "x$WIN32" != "xyes") && (test "x$MACH" != "xyes") && (test "x$DISABLE_R
)
fi
if test "x$BUILD_AV" = "xyes"; then
AX_PTHREAD(
[],
[
AC_MSG_WARN([disabling AV support: required pthread library not found])
BUILD_AV="no"
]
)
fi
AX_PTHREAD(
[],
[
AC_MSG_ERROR([required library pthread was not found on your system])
]
)
if test "x$BUILD_AV" = "xyes"; then
PKG_CHECK_MODULES([OPUS], [opus],

View File

@ -50,7 +50,8 @@ libtoxcore_la_SOURCES = ../toxcore/DHT.h \
libtoxcore_la_CFLAGS = -I$(top_srcdir) \
-I$(top_srcdir)/toxcore \
$(LIBSODIUM_CFLAGS) \
$(NACL_CFLAGS)
$(NACL_CFLAGS) \
$(PTHREAD_CFLAGS)
libtoxcore_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \
$(EXTRA_LT_LDFLAGS) \
@ -62,4 +63,5 @@ libtoxcore_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \
libtoxcore_la_LIBADD = $(LIBSODIUM_LIBS) \
$(NACL_OBJECTS) \
$(NAC_LIBS)
$(NAC_LIBS) \
$(PTHREAD_LIBS)

View File

@ -2184,6 +2184,7 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
for (i = 0; i < n; i++) {
add_tcp_relay(m->net_crypto, nodes[i].ip_port, nodes[i].client_id);
}
break;
}

View File

@ -728,16 +728,21 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *dat
if (conn == 0)
return -1;
pthread_mutex_lock(&conn->mutex);
uint8_t packet[1 + sizeof(uint16_t) + length + crypto_box_MACBYTES];
packet[0] = NET_PACKET_CRYPTO_DATA;
memcpy(packet + 1, conn->sent_nonce + (crypto_box_NONCEBYTES - sizeof(uint16_t)), sizeof(uint16_t));
int len = encrypt_data_symmetric(conn->shared_key, conn->sent_nonce, data, length, packet + 1 + sizeof(uint16_t));
if (len + 1 + sizeof(uint16_t) != sizeof(packet))
if (len + 1 + sizeof(uint16_t) != sizeof(packet)) {
pthread_mutex_unlock(&conn->mutex);
return -1;
}
increment_nonce(conn->sent_nonce);
return send_packet_to(c, crypt_connection_id, packet, sizeof(packet));
int ret = send_packet_to(c, crypt_connection_id, packet, sizeof(packet));
pthread_mutex_unlock(&conn->mutex);
return ret;
}
/* Creates and sends a data packet with buffer_start and num to the peer using the fastest route.
@ -1246,6 +1251,7 @@ static int create_crypto_connection(Net_Crypto *c)
memset(&(c->crypto_connections[c->crypto_connections_length]), 0, sizeof(Crypto_Connection));
int id = c->crypto_connections_length;
pthread_mutex_init(&c->crypto_connections[id].mutex, NULL);
++c->crypto_connections_length;
return id;
}
@ -1261,6 +1267,7 @@ static int wipe_crypto_connection(Net_Crypto *c, int crypt_connection_id)
return -1;
uint32_t i;
pthread_mutex_destroy(&c->crypto_connections[crypt_connection_id].mutex);
memset(&(c->crypto_connections[crypt_connection_id]), 0 , sizeof(Crypto_Connection));
for (i = c->crypto_connections_length; i != 0; --i) {

View File

@ -26,6 +26,7 @@
#include "DHT.h"
#include "TCP_client.h"
#include <pthread.h>
#define CRYPTO_CONN_NO_CONNECTION 0
#define CRYPTO_CONN_COOKIE_REQUESTING 1 //send cookie request packets
@ -155,6 +156,8 @@ typedef struct {
Node_format tcp_relays[MAX_TCP_RELAYS_PEER];
uint16_t num_tcp_relays;
pthread_mutex_t mutex;
} Crypto_Connection;
typedef struct {