diff options
-rw-r--r-- | toxcore/TCP_connection.c | 15 | ||||
-rw-r--r-- | toxcore/TCP_connection.h | 5 | ||||
-rw-r--r-- | toxcore/net_crypto.c | 2 |
3 files changed, 13 insertions, 9 deletions
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c index b0b26d20..d26a60de 100644 --- a/toxcore/TCP_connection.c +++ b/toxcore/TCP_connection.c | |||
@@ -691,7 +691,7 @@ static int reconnect_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connec | |||
691 | uint8_t relay_pk[crypto_box_PUBLICKEYBYTES]; | 691 | uint8_t relay_pk[crypto_box_PUBLICKEYBYTES]; |
692 | memcpy(relay_pk, tcp_con->connection->public_key, crypto_box_PUBLICKEYBYTES); | 692 | memcpy(relay_pk, tcp_con->connection->public_key, crypto_box_PUBLICKEYBYTES); |
693 | kill_TCP_connection(tcp_con->connection); | 693 | kill_TCP_connection(tcp_con->connection); |
694 | tcp_con->connection = new_TCP_connection(ip_port, relay_pk, tcp_c->dht->self_public_key, tcp_c->dht->self_secret_key, | 694 | tcp_con->connection = new_TCP_connection(ip_port, relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, |
695 | &tcp_c->proxy_info); | 695 | &tcp_c->proxy_info); |
696 | 696 | ||
697 | if (!tcp_con->connection) { | 697 | if (!tcp_con->connection) { |
@@ -776,8 +776,8 @@ static int unsleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connecti | |||
776 | if (tcp_con->status != TCP_CONN_SLEEPING) | 776 | if (tcp_con->status != TCP_CONN_SLEEPING) |
777 | return -1; | 777 | return -1; |
778 | 778 | ||
779 | tcp_con->connection = new_TCP_connection(tcp_con->ip_port, tcp_con->relay_pk, tcp_c->dht->self_public_key, | 779 | tcp_con->connection = new_TCP_connection(tcp_con->ip_port, tcp_con->relay_pk, tcp_c->self_public_key, |
780 | tcp_c->dht->self_secret_key, &tcp_c->proxy_info); | 780 | tcp_c->self_secret_key, &tcp_c->proxy_info); |
781 | 781 | ||
782 | if (!tcp_con->connection) { | 782 | if (!tcp_con->connection) { |
783 | kill_tcp_relay_connection(tcp_c, tcp_connections_number); | 783 | kill_tcp_relay_connection(tcp_c, tcp_connections_number); |
@@ -1025,7 +1025,7 @@ static int add_tcp_relay(TCP_Connections *tcp_c, IP_Port ip_port, const uint8_t | |||
1025 | TCP_con *tcp_con = &tcp_c->tcp_connections[tcp_connections_number]; | 1025 | TCP_con *tcp_con = &tcp_c->tcp_connections[tcp_connections_number]; |
1026 | 1026 | ||
1027 | 1027 | ||
1028 | tcp_con->connection = new_TCP_connection(ip_port, relay_pk, tcp_c->dht->self_public_key, tcp_c->dht->self_secret_key, | 1028 | tcp_con->connection = new_TCP_connection(ip_port, relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, |
1029 | &tcp_c->proxy_info); | 1029 | &tcp_c->proxy_info); |
1030 | 1030 | ||
1031 | if (!tcp_con->connection) | 1031 | if (!tcp_con->connection) |
@@ -1237,9 +1237,9 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, _Bool status) | |||
1237 | return 0; | 1237 | return 0; |
1238 | } | 1238 | } |
1239 | 1239 | ||
1240 | TCP_Connections *new_tcp_connections(DHT *dht, TCP_Proxy_Info *proxy_info) | 1240 | TCP_Connections *new_tcp_connections(const uint8_t *secret_key, TCP_Proxy_Info *proxy_info) |
1241 | { | 1241 | { |
1242 | if (dht == NULL) | 1242 | if (secret_key == NULL) |
1243 | return NULL; | 1243 | return NULL; |
1244 | 1244 | ||
1245 | TCP_Connections *temp = calloc(1, sizeof(TCP_Connections)); | 1245 | TCP_Connections *temp = calloc(1, sizeof(TCP_Connections)); |
@@ -1247,7 +1247,8 @@ TCP_Connections *new_tcp_connections(DHT *dht, TCP_Proxy_Info *proxy_info) | |||
1247 | if (temp == NULL) | 1247 | if (temp == NULL) |
1248 | return NULL; | 1248 | return NULL; |
1249 | 1249 | ||
1250 | temp->dht = dht; | 1250 | memcpy(temp->self_secret_key, secret_key, crypto_box_SECRETKEYBYTES); |
1251 | crypto_scalarmult_curve25519_base(temp->self_public_key, temp->self_secret_key); | ||
1251 | temp->proxy_info = *proxy_info; | 1252 | temp->proxy_info = *proxy_info; |
1252 | 1253 | ||
1253 | return temp; | 1254 | return temp; |
diff --git a/toxcore/TCP_connection.h b/toxcore/TCP_connection.h index 29fbdee0..140d6de3 100644 --- a/toxcore/TCP_connection.h +++ b/toxcore/TCP_connection.h | |||
@@ -81,6 +81,9 @@ typedef struct { | |||
81 | typedef struct { | 81 | typedef struct { |
82 | DHT *dht; | 82 | DHT *dht; |
83 | 83 | ||
84 | uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; | ||
85 | uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; | ||
86 | |||
84 | TCP_Connection_to *connections; | 87 | TCP_Connection_to *connections; |
85 | uint32_t connections_length; /* Length of connections array. */ | 88 | uint32_t connections_length; /* Length of connections array. */ |
86 | 89 | ||
@@ -223,7 +226,7 @@ int add_tcp_relay_global(TCP_Connections *tcp_c, IP_Port ip_port, const uint8_t | |||
223 | */ | 226 | */ |
224 | unsigned int tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num); | 227 | unsigned int tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num); |
225 | 228 | ||
226 | TCP_Connections *new_tcp_connections(DHT *dht, TCP_Proxy_Info *proxy_info); | 229 | TCP_Connections *new_tcp_connections(const uint8_t *secret_key, TCP_Proxy_Info *proxy_info); |
227 | void do_tcp_connections(TCP_Connections *tcp_c); | 230 | void do_tcp_connections(TCP_Connections *tcp_c); |
228 | void kill_tcp_connections(TCP_Connections *tcp_c); | 231 | void kill_tcp_connections(TCP_Connections *tcp_c); |
229 | 232 | ||
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 96be059d..5aed104a 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -2392,7 +2392,7 @@ Net_Crypto *new_net_crypto(DHT *dht, TCP_Proxy_Info *proxy_info) | |||
2392 | if (temp == NULL) | 2392 | if (temp == NULL) |
2393 | return NULL; | 2393 | return NULL; |
2394 | 2394 | ||
2395 | temp->tcp_c = new_tcp_connections(dht, proxy_info); | 2395 | temp->tcp_c = new_tcp_connections(dht->self_secret_key, proxy_info); |
2396 | 2396 | ||
2397 | if (temp->tcp_c == NULL) { | 2397 | if (temp->tcp_c == NULL) { |
2398 | free(temp); | 2398 | free(temp); |