diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Makefile.inc | 6 | ||||
-rw-r--r-- | toxcore/Messenger.c | 1 | ||||
-rw-r--r-- | toxcore/net_crypto.c | 11 | ||||
-rw-r--r-- | toxcore/net_crypto.h | 3 |
4 files changed, 17 insertions, 4 deletions
diff --git a/toxcore/Makefile.inc b/toxcore/Makefile.inc index 3cfdd73b..8e39f96e 100644 --- a/toxcore/Makefile.inc +++ b/toxcore/Makefile.inc | |||
@@ -50,7 +50,8 @@ libtoxcore_la_SOURCES = ../toxcore/DHT.h \ | |||
50 | libtoxcore_la_CFLAGS = -I$(top_srcdir) \ | 50 | libtoxcore_la_CFLAGS = -I$(top_srcdir) \ |
51 | -I$(top_srcdir)/toxcore \ | 51 | -I$(top_srcdir)/toxcore \ |
52 | $(LIBSODIUM_CFLAGS) \ | 52 | $(LIBSODIUM_CFLAGS) \ |
53 | $(NACL_CFLAGS) | 53 | $(NACL_CFLAGS) \ |
54 | $(PTHREAD_CFLAGS) | ||
54 | 55 | ||
55 | libtoxcore_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \ | 56 | libtoxcore_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \ |
56 | $(EXTRA_LT_LDFLAGS) \ | 57 | $(EXTRA_LT_LDFLAGS) \ |
@@ -62,4 +63,5 @@ libtoxcore_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \ | |||
62 | 63 | ||
63 | libtoxcore_la_LIBADD = $(LIBSODIUM_LIBS) \ | 64 | libtoxcore_la_LIBADD = $(LIBSODIUM_LIBS) \ |
64 | $(NACL_OBJECTS) \ | 65 | $(NACL_OBJECTS) \ |
65 | $(NAC_LIBS) | 66 | $(NAC_LIBS) \ |
67 | $(PTHREAD_LIBS) | ||
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 653a2ee1..05065e62 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -2184,6 +2184,7 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len) | |||
2184 | for (i = 0; i < n; i++) { | 2184 | for (i = 0; i < n; i++) { |
2185 | add_tcp_relay(m->net_crypto, nodes[i].ip_port, nodes[i].client_id); | 2185 | add_tcp_relay(m->net_crypto, nodes[i].ip_port, nodes[i].client_id); |
2186 | } | 2186 | } |
2187 | |||
2187 | break; | 2188 | break; |
2188 | } | 2189 | } |
2189 | 2190 | ||
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index bb38af26..78a6121c 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -728,16 +728,21 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *dat | |||
728 | if (conn == 0) | 728 | if (conn == 0) |
729 | return -1; | 729 | return -1; |
730 | 730 | ||
731 | pthread_mutex_lock(&conn->mutex); | ||
731 | uint8_t packet[1 + sizeof(uint16_t) + length + crypto_box_MACBYTES]; | 732 | uint8_t packet[1 + sizeof(uint16_t) + length + crypto_box_MACBYTES]; |
732 | packet[0] = NET_PACKET_CRYPTO_DATA; | 733 | packet[0] = NET_PACKET_CRYPTO_DATA; |
733 | memcpy(packet + 1, conn->sent_nonce + (crypto_box_NONCEBYTES - sizeof(uint16_t)), sizeof(uint16_t)); | 734 | memcpy(packet + 1, conn->sent_nonce + (crypto_box_NONCEBYTES - sizeof(uint16_t)), sizeof(uint16_t)); |
734 | int len = encrypt_data_symmetric(conn->shared_key, conn->sent_nonce, data, length, packet + 1 + sizeof(uint16_t)); | 735 | int len = encrypt_data_symmetric(conn->shared_key, conn->sent_nonce, data, length, packet + 1 + sizeof(uint16_t)); |
735 | 736 | ||
736 | if (len + 1 + sizeof(uint16_t) != sizeof(packet)) | 737 | if (len + 1 + sizeof(uint16_t) != sizeof(packet)) { |
738 | pthread_mutex_unlock(&conn->mutex); | ||
737 | return -1; | 739 | return -1; |
740 | } | ||
738 | 741 | ||
739 | increment_nonce(conn->sent_nonce); | 742 | increment_nonce(conn->sent_nonce); |
740 | return send_packet_to(c, crypt_connection_id, packet, sizeof(packet)); | 743 | int ret = send_packet_to(c, crypt_connection_id, packet, sizeof(packet)); |
744 | pthread_mutex_unlock(&conn->mutex); | ||
745 | return ret; | ||
741 | } | 746 | } |
742 | 747 | ||
743 | /* Creates and sends a data packet with buffer_start and num to the peer using the fastest route. | 748 | /* 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) | |||
1246 | 1251 | ||
1247 | memset(&(c->crypto_connections[c->crypto_connections_length]), 0, sizeof(Crypto_Connection)); | 1252 | memset(&(c->crypto_connections[c->crypto_connections_length]), 0, sizeof(Crypto_Connection)); |
1248 | int id = c->crypto_connections_length; | 1253 | int id = c->crypto_connections_length; |
1254 | pthread_mutex_init(&c->crypto_connections[id].mutex, NULL); | ||
1249 | ++c->crypto_connections_length; | 1255 | ++c->crypto_connections_length; |
1250 | return id; | 1256 | return id; |
1251 | } | 1257 | } |
@@ -1261,6 +1267,7 @@ static int wipe_crypto_connection(Net_Crypto *c, int crypt_connection_id) | |||
1261 | return -1; | 1267 | return -1; |
1262 | 1268 | ||
1263 | uint32_t i; | 1269 | uint32_t i; |
1270 | pthread_mutex_destroy(&c->crypto_connections[crypt_connection_id].mutex); | ||
1264 | memset(&(c->crypto_connections[crypt_connection_id]), 0 , sizeof(Crypto_Connection)); | 1271 | memset(&(c->crypto_connections[crypt_connection_id]), 0 , sizeof(Crypto_Connection)); |
1265 | 1272 | ||
1266 | for (i = c->crypto_connections_length; i != 0; --i) { | 1273 | for (i = c->crypto_connections_length; i != 0; --i) { |
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index b1108ae1..ee790f24 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h | |||
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include "DHT.h" | 27 | #include "DHT.h" |
28 | #include "TCP_client.h" | 28 | #include "TCP_client.h" |
29 | #include <pthread.h> | ||
29 | 30 | ||
30 | #define CRYPTO_CONN_NO_CONNECTION 0 | 31 | #define CRYPTO_CONN_NO_CONNECTION 0 |
31 | #define CRYPTO_CONN_COOKIE_REQUESTING 1 //send cookie request packets | 32 | #define CRYPTO_CONN_COOKIE_REQUESTING 1 //send cookie request packets |
@@ -155,6 +156,8 @@ typedef struct { | |||
155 | 156 | ||
156 | Node_format tcp_relays[MAX_TCP_RELAYS_PEER]; | 157 | Node_format tcp_relays[MAX_TCP_RELAYS_PEER]; |
157 | uint16_t num_tcp_relays; | 158 | uint16_t num_tcp_relays; |
159 | |||
160 | pthread_mutex_t mutex; | ||
158 | } Crypto_Connection; | 161 | } Crypto_Connection; |
159 | 162 | ||
160 | typedef struct { | 163 | typedef struct { |