mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
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:
parent
4f2674eb0f
commit
2740099da0
16
configure.ac
16
configure.ac
@ -459,15 +459,13 @@ if (test "x$WIN32" != "xyes") && (test "x$MACH" != "xyes") && (test "x$DISABLE_R
|
|||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test "x$BUILD_AV" = "xyes"; then
|
|
||||||
AX_PTHREAD(
|
AX_PTHREAD(
|
||||||
[],
|
[],
|
||||||
[
|
[
|
||||||
AC_MSG_WARN([disabling AV support: required pthread library not found])
|
AC_MSG_ERROR([required library pthread was not found on your system])
|
||||||
BUILD_AV="no"
|
]
|
||||||
]
|
)
|
||||||
)
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test "x$BUILD_AV" = "xyes"; then
|
if test "x$BUILD_AV" = "xyes"; then
|
||||||
PKG_CHECK_MODULES([OPUS], [opus],
|
PKG_CHECK_MODULES([OPUS], [opus],
|
||||||
|
@ -50,7 +50,8 @@ libtoxcore_la_SOURCES = ../toxcore/DHT.h \
|
|||||||
libtoxcore_la_CFLAGS = -I$(top_srcdir) \
|
libtoxcore_la_CFLAGS = -I$(top_srcdir) \
|
||||||
-I$(top_srcdir)/toxcore \
|
-I$(top_srcdir)/toxcore \
|
||||||
$(LIBSODIUM_CFLAGS) \
|
$(LIBSODIUM_CFLAGS) \
|
||||||
$(NACL_CFLAGS)
|
$(NACL_CFLAGS) \
|
||||||
|
$(PTHREAD_CFLAGS)
|
||||||
|
|
||||||
libtoxcore_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \
|
libtoxcore_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \
|
||||||
$(EXTRA_LT_LDFLAGS) \
|
$(EXTRA_LT_LDFLAGS) \
|
||||||
@ -62,4 +63,5 @@ libtoxcore_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \
|
|||||||
|
|
||||||
libtoxcore_la_LIBADD = $(LIBSODIUM_LIBS) \
|
libtoxcore_la_LIBADD = $(LIBSODIUM_LIBS) \
|
||||||
$(NACL_OBJECTS) \
|
$(NACL_OBJECTS) \
|
||||||
$(NAC_LIBS)
|
$(NAC_LIBS) \
|
||||||
|
$(PTHREAD_LIBS)
|
||||||
|
@ -2184,6 +2184,7 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
|
|||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
add_tcp_relay(m->net_crypto, nodes[i].ip_port, nodes[i].client_id);
|
add_tcp_relay(m->net_crypto, nodes[i].ip_port, nodes[i].client_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -728,16 +728,21 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *dat
|
|||||||
if (conn == 0)
|
if (conn == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&conn->mutex);
|
||||||
uint8_t packet[1 + sizeof(uint16_t) + length + crypto_box_MACBYTES];
|
uint8_t packet[1 + sizeof(uint16_t) + length + crypto_box_MACBYTES];
|
||||||
packet[0] = NET_PACKET_CRYPTO_DATA;
|
packet[0] = NET_PACKET_CRYPTO_DATA;
|
||||||
memcpy(packet + 1, conn->sent_nonce + (crypto_box_NONCEBYTES - sizeof(uint16_t)), sizeof(uint16_t));
|
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));
|
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;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
increment_nonce(conn->sent_nonce);
|
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.
|
/* 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));
|
memset(&(c->crypto_connections[c->crypto_connections_length]), 0, sizeof(Crypto_Connection));
|
||||||
int id = c->crypto_connections_length;
|
int id = c->crypto_connections_length;
|
||||||
|
pthread_mutex_init(&c->crypto_connections[id].mutex, NULL);
|
||||||
++c->crypto_connections_length;
|
++c->crypto_connections_length;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -1261,6 +1267,7 @@ static int wipe_crypto_connection(Net_Crypto *c, int crypt_connection_id)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
pthread_mutex_destroy(&c->crypto_connections[crypt_connection_id].mutex);
|
||||||
memset(&(c->crypto_connections[crypt_connection_id]), 0 , sizeof(Crypto_Connection));
|
memset(&(c->crypto_connections[crypt_connection_id]), 0 , sizeof(Crypto_Connection));
|
||||||
|
|
||||||
for (i = c->crypto_connections_length; i != 0; --i) {
|
for (i = c->crypto_connections_length; i != 0; --i) {
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include "DHT.h"
|
#include "DHT.h"
|
||||||
#include "TCP_client.h"
|
#include "TCP_client.h"
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
#define CRYPTO_CONN_NO_CONNECTION 0
|
#define CRYPTO_CONN_NO_CONNECTION 0
|
||||||
#define CRYPTO_CONN_COOKIE_REQUESTING 1 //send cookie request packets
|
#define CRYPTO_CONN_COOKIE_REQUESTING 1 //send cookie request packets
|
||||||
@ -155,6 +156,8 @@ typedef struct {
|
|||||||
|
|
||||||
Node_format tcp_relays[MAX_TCP_RELAYS_PEER];
|
Node_format tcp_relays[MAX_TCP_RELAYS_PEER];
|
||||||
uint16_t num_tcp_relays;
|
uint16_t num_tcp_relays;
|
||||||
|
|
||||||
|
pthread_mutex_t mutex;
|
||||||
} Crypto_Connection;
|
} Crypto_Connection;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user