diff options
Diffstat (limited to 'core/net_crypto.c')
-rw-r--r-- | core/net_crypto.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/core/net_crypto.c b/core/net_crypto.c index d4a3ba7b..62df614e 100644 --- a/core/net_crypto.c +++ b/core/net_crypto.c | |||
@@ -423,9 +423,14 @@ int getcryptconnection_id(uint8_t * public_key) | |||
423 | int crypto_connect(uint8_t * public_key, IP_Port ip_port) | 423 | int crypto_connect(uint8_t * public_key, IP_Port ip_port) |
424 | { | 424 | { |
425 | uint32_t i; | 425 | uint32_t i; |
426 | if(getcryptconnection_id(public_key) != -1) | 426 | int id = getcryptconnection_id(public_key); |
427 | if(id != -1) | ||
427 | { | 428 | { |
428 | return -1; | 429 | IP_Port c_ip = connection_ip(crypto_connections[id].number); |
430 | if(c_ip.ip.i == ip_port.ip.i && c_ip.port == ip_port.port) | ||
431 | { | ||
432 | return -1; | ||
433 | } | ||
429 | } | 434 | } |
430 | for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++) | 435 | for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++) |
431 | { | 436 | { |
@@ -503,6 +508,7 @@ int crypto_kill(int crypt_connection_id) | |||
503 | { | 508 | { |
504 | crypto_connections[crypt_connection_id].status = 0; | 509 | crypto_connections[crypt_connection_id].status = 0; |
505 | kill_connection(crypto_connections[crypt_connection_id].number); | 510 | kill_connection(crypto_connections[crypt_connection_id].number); |
511 | crypto_connections[crypt_connection_id].number = ~0; | ||
506 | return 0; | 512 | return 0; |
507 | } | 513 | } |
508 | return 1; | 514 | return 1; |
@@ -519,10 +525,11 @@ int accept_crypto_inbound(int connection_id, uint8_t * public_key, uint8_t * sec | |||
519 | { | 525 | { |
520 | return -1; | 526 | return -1; |
521 | } | 527 | } |
528 | /* | ||
522 | if(getcryptconnection_id(public_key) != -1) | 529 | if(getcryptconnection_id(public_key) != -1) |
523 | { | 530 | { |
524 | return -1; | 531 | return -1; |
525 | } | 532 | }*/ |
526 | for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++) | 533 | for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++) |
527 | { | 534 | { |
528 | if(crypto_connections[i].status == 0) | 535 | if(crypto_connections[i].status == 0) |
@@ -709,6 +716,11 @@ void initNetCrypto() | |||
709 | memset(crypto_connections, 0 ,sizeof(crypto_connections)); | 716 | memset(crypto_connections, 0 ,sizeof(crypto_connections)); |
710 | memset(outbound_friendrequests, -1 ,sizeof(outbound_friendrequests)); | 717 | memset(outbound_friendrequests, -1 ,sizeof(outbound_friendrequests)); |
711 | memset(incoming_connections, -1 ,sizeof(incoming_connections)); | 718 | memset(incoming_connections, -1 ,sizeof(incoming_connections)); |
719 | uint32_t i; | ||
720 | for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++) | ||
721 | { | ||
722 | crypto_connections[i].number = ~0; | ||
723 | } | ||
712 | } | 724 | } |
713 | 725 | ||
714 | static void killTimedout() | 726 | static void killTimedout() |
@@ -720,6 +732,11 @@ static void killTimedout() | |||
720 | { | 732 | { |
721 | crypto_connections[i].status = 4; | 733 | crypto_connections[i].status = 4; |
722 | } | 734 | } |
735 | else if(is_connected(crypto_connections[i].number) == 4) | ||
736 | { | ||
737 | kill_connection(crypto_connections[i].number); | ||
738 | crypto_connections[i].number = ~0; | ||
739 | } | ||
723 | } | 740 | } |
724 | } | 741 | } |
725 | 742 | ||