Made new_tcp_connections() not depend on dht.

This commit is contained in:
irungentoo 2015-06-16 23:00:24 -04:00
parent 48ef0f3241
commit 67df1ab7ce
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
3 changed files with 13 additions and 9 deletions

View File

@ -691,7 +691,7 @@ static int reconnect_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connec
uint8_t relay_pk[crypto_box_PUBLICKEYBYTES];
memcpy(relay_pk, tcp_con->connection->public_key, crypto_box_PUBLICKEYBYTES);
kill_TCP_connection(tcp_con->connection);
tcp_con->connection = new_TCP_connection(ip_port, relay_pk, tcp_c->dht->self_public_key, tcp_c->dht->self_secret_key,
tcp_con->connection = new_TCP_connection(ip_port, relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key,
&tcp_c->proxy_info);
if (!tcp_con->connection) {
@ -776,8 +776,8 @@ static int unsleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connecti
if (tcp_con->status != TCP_CONN_SLEEPING)
return -1;
tcp_con->connection = new_TCP_connection(tcp_con->ip_port, tcp_con->relay_pk, tcp_c->dht->self_public_key,
tcp_c->dht->self_secret_key, &tcp_c->proxy_info);
tcp_con->connection = new_TCP_connection(tcp_con->ip_port, tcp_con->relay_pk, tcp_c->self_public_key,
tcp_c->self_secret_key, &tcp_c->proxy_info);
if (!tcp_con->connection) {
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
TCP_con *tcp_con = &tcp_c->tcp_connections[tcp_connections_number];
tcp_con->connection = new_TCP_connection(ip_port, relay_pk, tcp_c->dht->self_public_key, tcp_c->dht->self_secret_key,
tcp_con->connection = new_TCP_connection(ip_port, relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key,
&tcp_c->proxy_info);
if (!tcp_con->connection)
@ -1237,9 +1237,9 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, _Bool status)
return 0;
}
TCP_Connections *new_tcp_connections(DHT *dht, TCP_Proxy_Info *proxy_info)
TCP_Connections *new_tcp_connections(const uint8_t *secret_key, TCP_Proxy_Info *proxy_info)
{
if (dht == NULL)
if (secret_key == NULL)
return NULL;
TCP_Connections *temp = calloc(1, sizeof(TCP_Connections));
@ -1247,7 +1247,8 @@ TCP_Connections *new_tcp_connections(DHT *dht, TCP_Proxy_Info *proxy_info)
if (temp == NULL)
return NULL;
temp->dht = dht;
memcpy(temp->self_secret_key, secret_key, crypto_box_SECRETKEYBYTES);
crypto_scalarmult_curve25519_base(temp->self_public_key, temp->self_secret_key);
temp->proxy_info = *proxy_info;
return temp;

View File

@ -81,6 +81,9 @@ typedef struct {
typedef struct {
DHT *dht;
uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
TCP_Connection_to *connections;
uint32_t connections_length; /* Length of connections array. */
@ -223,7 +226,7 @@ int add_tcp_relay_global(TCP_Connections *tcp_c, IP_Port ip_port, const uint8_t
*/
unsigned int tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num);
TCP_Connections *new_tcp_connections(DHT *dht, TCP_Proxy_Info *proxy_info);
TCP_Connections *new_tcp_connections(const uint8_t *secret_key, TCP_Proxy_Info *proxy_info);
void do_tcp_connections(TCP_Connections *tcp_c);
void kill_tcp_connections(TCP_Connections *tcp_c);

View File

@ -2392,7 +2392,7 @@ Net_Crypto *new_net_crypto(DHT *dht, TCP_Proxy_Info *proxy_info)
if (temp == NULL)
return NULL;
temp->tcp_c = new_tcp_connections(dht, proxy_info);
temp->tcp_c = new_tcp_connections(dht->self_secret_key, proxy_info);
if (temp->tcp_c == NULL) {
free(temp);