Skip to content

Commit

Permalink
Fixed connection issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
irungentoo committed May 18, 2014
1 parent e87929e commit d573271
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions toxcore/net_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, uint8_t *data,
if (conn == 0)
return -1;

int direct_send_attempt = 0;

//TODO: on bad networks, direct connections might not last indefinitely.
if (conn->ip_port.ip.family != 0) {
uint8_t direct_connected = 0;
Expand All @@ -415,8 +417,10 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, uint8_t *data,
return 0;

//TODO: a better way of sending packets directly to confirm the others ip.
if (length < 96 || data[0] == NET_PACKET_COOKIE_REQUEST || data[0] == NET_PACKET_CRYPTO_HS)
sendpacket(c->dht->net, conn->ip_port, data, length);
if (length < 96 || data[0] == NET_PACKET_COOKIE_REQUEST || data[0] == NET_PACKET_CRYPTO_HS) {
if ((uint32_t)sendpacket(c->dht->net, conn->ip_port, data, length) == length)
direct_send_attempt = 1;
}

}

Expand All @@ -436,6 +440,11 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, uint8_t *data,
return 0;
}
}

if (direct_send_attempt) {
return 0;
}

return -1;
}

Expand Down

0 comments on commit d573271

Please sign in to comment.