diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/DHT.c | 6 | ||||
-rw-r--r-- | core/DHT.h | 2 | ||||
-rw-r--r-- | core/Lossless_UDP.c | 16 | ||||
-rw-r--r-- | core/Lossless_UDP.h | 2 | ||||
-rw-r--r-- | core/net_crypto.c | 22 | ||||
-rw-r--r-- | core/net_crypto.h | 12 | ||||
-rw-r--r-- | core/network.c | 2 | ||||
-rw-r--r-- | core/network.h | 4 |
8 files changed, 33 insertions, 33 deletions
@@ -246,7 +246,7 @@ int get_close_nodes(uint8_t * client_id, Node_format * nodes_list) | |||
246 | 246 | ||
247 | 247 | ||
248 | //replace first bad (or empty) node with this one | 248 | //replace first bad (or empty) node with this one |
249 | //return 0 if successfull | 249 | //return 0 if successful |
250 | //return 1 if not (list contains no bad nodes) | 250 | //return 1 if not (list contains no bad nodes) |
251 | int replace_bad(Client_data * list, uint32_t length, uint8_t * client_id, IP_Port ip_port)//tested | 251 | int replace_bad(Client_data * list, uint32_t length, uint8_t * client_id, IP_Port ip_port)//tested |
252 | { | 252 | { |
@@ -291,7 +291,7 @@ void addto_lists(IP_Port ip_port, uint8_t * client_id) | |||
291 | { | 291 | { |
292 | uint32_t i; | 292 | uint32_t i; |
293 | 293 | ||
294 | //NOTE: current behaviour if there are two clients with the same id is to only keep one (the first one) | 294 | //NOTE: current behavior if there are two clients with the same id is to only keep one (the first one) |
295 | if(!client_in_list(close_clientlist, LCLIENT_LIST, client_id, ip_port)) | 295 | if(!client_in_list(close_clientlist, LCLIENT_LIST, client_id, ip_port)) |
296 | { | 296 | { |
297 | 297 | ||
@@ -548,7 +548,7 @@ int sendnodes(IP_Port ip_port, uint8_t * client_id, uint32_t ping_id) | |||
548 | 548 | ||
549 | 549 | ||
550 | //Packet handling functions | 550 | //Packet handling functions |
551 | //One to handle each types of packets we recieve | 551 | //One to handle each types of packets we receive |
552 | //return 0 if handled correctly, 1 if packet is bad. | 552 | //return 0 if handled correctly, 1 if packet is bad. |
553 | int handle_pingreq(uint8_t * packet, uint32_t length, IP_Port source)//tested | 553 | int handle_pingreq(uint8_t * packet, uint32_t length, IP_Port source)//tested |
554 | { | 554 | { |
@@ -62,7 +62,7 @@ IP_Port DHT_getfriendip(uint8_t * client_id); | |||
62 | //Run this function at least a couple times per second (It's the main loop) | 62 | //Run this function at least a couple times per second (It's the main loop) |
63 | void doDHT(); | 63 | void doDHT(); |
64 | 64 | ||
65 | //if we recieve a DHT packet we call this function so it can be handled. | 65 | //if we receive a DHT packet we call this function so it can be handled. |
66 | //Return 0 if packet is handled correctly. | 66 | //Return 0 if packet is handled correctly. |
67 | //return 1 if it didn't handle the packet or if the packet was shit. | 67 | //return 1 if it didn't handle the packet or if the packet was shit. |
68 | int DHT_handlepacket(uint8_t * packet, uint32_t length, IP_Port source); | 68 | int DHT_handlepacket(uint8_t * packet, uint32_t length, IP_Port source); |
diff --git a/core/Lossless_UDP.c b/core/Lossless_UDP.c index b249760a..080dc821 100644 --- a/core/Lossless_UDP.c +++ b/core/Lossless_UDP.c | |||
@@ -27,7 +27,7 @@ | |||
27 | 27 | ||
28 | 28 | ||
29 | 29 | ||
30 | //maximum data packets in sent and recieve queues. | 30 | //maximum data packets in sent and receive queues. |
31 | #define MAX_QUEUE_NUM 16 | 31 | #define MAX_QUEUE_NUM 16 |
32 | 32 | ||
33 | //maximum length of the data in the data packets | 33 | //maximum length of the data in the data packets |
@@ -66,14 +66,14 @@ typedef struct | |||
66 | uint16_t data_rate;//current data packet send rate packets per second. | 66 | uint16_t data_rate;//current data packet send rate packets per second. |
67 | uint64_t last_SYNC; //time at which our last SYNC packet was sent. | 67 | uint64_t last_SYNC; //time at which our last SYNC packet was sent. |
68 | uint64_t last_sent; //time at which our last data or handshake packet was sent. | 68 | uint64_t last_sent; //time at which our last data or handshake packet was sent. |
69 | uint64_t last_recv; //time at which we last recieved something from the other | 69 | uint64_t last_recv; //time at which we last received something from the other |
70 | uint64_t killat; //time at which to kill the connection | 70 | uint64_t killat; //time at which to kill the connection |
71 | Data sendbuffer[MAX_QUEUE_NUM];//packet send buffer. | 71 | Data sendbuffer[MAX_QUEUE_NUM];//packet send buffer. |
72 | Data recvbuffer[MAX_QUEUE_NUM];//packet recieve buffer. | 72 | Data recvbuffer[MAX_QUEUE_NUM];//packet receive buffer. |
73 | uint32_t handshake_id1; | 73 | uint32_t handshake_id1; |
74 | uint32_t handshake_id2; | 74 | uint32_t handshake_id2; |
75 | uint32_t recv_packetnum; //number of data packets recieved (also used as handshake_id1) | 75 | uint32_t recv_packetnum; //number of data packets received (also used as handshake_id1) |
76 | uint32_t orecv_packetnum; //number of packets recieved by the other peer | 76 | uint32_t orecv_packetnum; //number of packets received by the other peer |
77 | uint32_t sent_packetnum; //number of data packets sent | 77 | uint32_t sent_packetnum; //number of data packets sent |
78 | uint32_t osent_packetnum; //number of packets sent by the other peer. | 78 | uint32_t osent_packetnum; //number of packets sent by the other peer. |
79 | uint32_t sendbuff_packetnum; //number of latest packet written onto the sendbuffer | 79 | uint32_t sendbuff_packetnum; //number of latest packet written onto the sendbuffer |
@@ -250,7 +250,7 @@ int kill_connection_in(int connection_id, uint32_t seconds) | |||
250 | //return 1 if attempting handshake | 250 | //return 1 if attempting handshake |
251 | //return 2 if handshake is done | 251 | //return 2 if handshake is done |
252 | //return 3 if fully connected | 252 | //return 3 if fully connected |
253 | //return 4 if timed out and wating to be killed | 253 | //return 4 if timed out and waiting to be killed |
254 | int is_connected(int connection_id) | 254 | int is_connected(int connection_id) |
255 | { | 255 | { |
256 | if(connection_id >= 0 && connection_id < MAX_CONNECTIONS) | 256 | if(connection_id >= 0 && connection_id < MAX_CONNECTIONS) |
@@ -450,7 +450,7 @@ int send_DATA(uint32_t connection_id) | |||
450 | 450 | ||
451 | 451 | ||
452 | //Packet handling functions | 452 | //Packet handling functions |
453 | //One to handle each type of packets we recieve | 453 | //One to handle each type of packets we receive |
454 | //return 0 if handled correctly, 1 if packet is bad. | 454 | //return 0 if handled correctly, 1 if packet is bad. |
455 | int handle_handshake(uint8_t * packet, uint32_t length, IP_Port source) | 455 | int handle_handshake(uint8_t * packet, uint32_t length, IP_Port source) |
456 | { | 456 | { |
@@ -607,7 +607,7 @@ int handle_SYNC(uint8_t * packet, uint32_t length, IP_Port source) | |||
607 | return 0; | 607 | return 0; |
608 | } | 608 | } |
609 | 609 | ||
610 | //add a packet to the recieved buffer and set the recv_packetnum of the connection to its proper value. | 610 | //add a packet to the received buffer and set the recv_packetnum of the connection to its proper value. |
611 | //return 1 if data was too big, 0 if not. | 611 | //return 1 if data was too big, 0 if not. |
612 | int add_recv(int connection_id, uint32_t data_num, uint8_t * data, uint16_t size) | 612 | int add_recv(int connection_id, uint32_t data_num, uint8_t * data, uint16_t size) |
613 | { | 613 | { |
diff --git a/core/Lossless_UDP.h b/core/Lossless_UDP.h index 18224088..ad8c545c 100644 --- a/core/Lossless_UDP.h +++ b/core/Lossless_UDP.h | |||
@@ -69,7 +69,7 @@ IP_Port connection_ip(int connection_id); | |||
69 | char id_packet(int connection_id); | 69 | char id_packet(int connection_id); |
70 | 70 | ||
71 | //return 0 if there is no received data in the buffer. | 71 | //return 0 if there is no received data in the buffer. |
72 | //return length of recieved packet if successful | 72 | //return length of received packet if successful |
73 | int read_packet(int connection_id, uint8_t * data); | 73 | int read_packet(int connection_id, uint8_t * data); |
74 | 74 | ||
75 | 75 | ||
diff --git a/core/net_crypto.c b/core/net_crypto.c index 3a3785ff..980250d0 100644 --- a/core/net_crypto.c +++ b/core/net_crypto.c | |||
@@ -36,13 +36,13 @@ uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; | |||
36 | typedef struct | 36 | typedef struct |
37 | { | 37 | { |
38 | uint8_t public_key[crypto_box_PUBLICKEYBYTES];//the real public key of the peer. | 38 | uint8_t public_key[crypto_box_PUBLICKEYBYTES];//the real public key of the peer. |
39 | uint8_t recv_nonce[crypto_box_NONCEBYTES];//nonce of recieved packets | 39 | uint8_t recv_nonce[crypto_box_NONCEBYTES];//nonce of received packets |
40 | uint8_t sent_nonce[crypto_box_NONCEBYTES];//nonce of sent packets. | 40 | uint8_t sent_nonce[crypto_box_NONCEBYTES];//nonce of sent packets. |
41 | uint8_t sessionpublic_key[crypto_box_PUBLICKEYBYTES];//our public key for this session. | 41 | uint8_t sessionpublic_key[crypto_box_PUBLICKEYBYTES];//our public key for this session. |
42 | uint8_t sessionsecret_key[crypto_box_SECRETKEYBYTES];//our private key for this session. | 42 | uint8_t sessionsecret_key[crypto_box_SECRETKEYBYTES];//our private key for this session. |
43 | uint8_t peersessionpublic_key[crypto_box_PUBLICKEYBYTES];//The public key of the peer. | 43 | uint8_t peersessionpublic_key[crypto_box_PUBLICKEYBYTES];//The public key of the peer. |
44 | uint8_t status;//0 if no connection, 1 we have sent a handshake, 2 if connexion is not confirmed yet | 44 | uint8_t status;//0 if no connection, 1 we have sent a handshake, 2 if connexion is not confirmed yet |
45 | //(we have recieved a hanshake but no empty data packet), 3 if the connection is established. | 45 | //(we have received a handshake but no empty data packet), 3 if the connection is established. |
46 | //4 if the connection is timed out. | 46 | //4 if the connection is timed out. |
47 | uint16_t number; //Lossless_UDP connection number corresponding to this connection. | 47 | uint16_t number; //Lossless_UDP connection number corresponding to this connection. |
48 | 48 | ||
@@ -63,7 +63,7 @@ int outbound_friendrequests[MAX_FRIEND_REQUESTS]; | |||
63 | int incoming_connections[MAX_INCOMING]; | 63 | int incoming_connections[MAX_INCOMING]; |
64 | 64 | ||
65 | //encrypts plain of length length to encrypted of length + 16 using the | 65 | //encrypts plain of length length to encrypted of length + 16 using the |
66 | //public key(32 bytes) of the reciever and the secret key of the sender and a 24 byte nonce | 66 | //public key(32 bytes) of the receiver and the secret key of the sender and a 24 byte nonce |
67 | //return -1 if there was a problem. | 67 | //return -1 if there was a problem. |
68 | //return length of encrypted data if everything was fine. | 68 | //return length of encrypted data if everything was fine. |
69 | int encrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce, | 69 | int encrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce, |
@@ -93,7 +93,7 @@ int encrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce, | |||
93 | } | 93 | } |
94 | 94 | ||
95 | //decrypts encrypted of length length to plain of length length - 16 using the | 95 | //decrypts encrypted of length length to plain of length length - 16 using the |
96 | //public key(32 bytes) of the sender, the secret key of the reciever and a 24 byte nonce | 96 | //public key(32 bytes) of the sender, the secret key of the receiver and a 24 byte nonce |
97 | //return -1 if there was a problem(decryption failed) | 97 | //return -1 if there was a problem(decryption failed) |
98 | //return length of plain data if everything was fine. | 98 | //return length of plain data if everything was fine. |
99 | int decrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce, | 99 | int decrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce, |
@@ -151,7 +151,7 @@ void random_nonce(uint8_t * nonce) | |||
151 | 151 | ||
152 | //return 0 if there is no received data in the buffer | 152 | //return 0 if there is no received data in the buffer |
153 | //return -1 if the packet was discarded. | 153 | //return -1 if the packet was discarded. |
154 | //return length of recieved data if successful | 154 | //return length of received data if successful |
155 | int read_cryptpacket(int crypt_connection_id, uint8_t * data) | 155 | int read_cryptpacket(int crypt_connection_id, uint8_t * data) |
156 | { | 156 | { |
157 | if(crypt_connection_id < 0 || crypt_connection_id >= MAX_CRYPTO_CONNECTIONS) | 157 | if(crypt_connection_id < 0 || crypt_connection_id >= MAX_CRYPTO_CONNECTIONS) |
@@ -436,7 +436,7 @@ int crypto_connect(uint8_t * public_key, IP_Port ip_port) | |||
436 | 436 | ||
437 | //handle an incoming connection | 437 | //handle an incoming connection |
438 | //return -1 if no crypto inbound connection | 438 | //return -1 if no crypto inbound connection |
439 | //return incomming connection id (Lossless_UDP one) if there is an incomming crypto connection | 439 | //return incoming connection id (Lossless_UDP one) if there is an incoming crypto connection |
440 | //Put the public key of the peer in public_key, the secret_nonce from the handshake into secret_nonce | 440 | //Put the public key of the peer in public_key, the secret_nonce from the handshake into secret_nonce |
441 | //and the session public key for the connection in session_key | 441 | //and the session public key for the connection in session_key |
442 | //to accept it see: accept_crypto_inbound(...) | 442 | //to accept it see: accept_crypto_inbound(...) |
@@ -524,8 +524,8 @@ int accept_crypto_inbound(int connection_id, uint8_t * public_key, uint8_t * sec | |||
524 | } | 524 | } |
525 | 525 | ||
526 | //return 0 if no connection, 1 we have sent a handshake, 2 if connexion is not confirmed yet | 526 | //return 0 if no connection, 1 we have sent a handshake, 2 if connexion is not confirmed yet |
527 | //(we have recieved a hanshake but no empty data packet), 3 if the connection is established. | 527 | //(we have received a handshake but no empty data packet), 3 if the connection is established. |
528 | //4 if the connection is timed out and wating to be killed | 528 | //4 if the connection is timed out and waiting to be killed |
529 | int is_cryptoconnected(int crypt_connection_id) | 529 | int is_cryptoconnected(int crypt_connection_id) |
530 | { | 530 | { |
531 | if(crypt_connection_id >= 0 && crypt_connection_id < MAX_CRYPTO_CONNECTIONS) | 531 | if(crypt_connection_id >= 0 && crypt_connection_id < MAX_CRYPTO_CONNECTIONS) |
@@ -580,8 +580,8 @@ void handle_incomings() | |||
580 | } | 580 | } |
581 | } | 581 | } |
582 | 582 | ||
583 | //handle recieved packets for not yet established crypto connections. | 583 | //handle received packets for not yet established crypto connections. |
584 | void recieve_crypto() | 584 | void receive_crypto() |
585 | { | 585 | { |
586 | uint32_t i; | 586 | uint32_t i; |
587 | for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++) | 587 | for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++) |
@@ -678,6 +678,6 @@ void doNetCrypto() | |||
678 | //handle new incoming connections | 678 | //handle new incoming connections |
679 | //handle friend requests | 679 | //handle friend requests |
680 | handle_incomings(); | 680 | handle_incomings(); |
681 | recieve_crypto(); | 681 | receive_crypto(); |
682 | killTimedout(); | 682 | killTimedout(); |
683 | } | 683 | } |
diff --git a/core/net_crypto.h b/core/net_crypto.h index a9bf1351..c8837c03 100644 --- a/core/net_crypto.h +++ b/core/net_crypto.h | |||
@@ -36,7 +36,7 @@ extern uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; | |||
36 | 36 | ||
37 | 37 | ||
38 | //encrypts plain of length length to encrypted of length + 16 using the | 38 | //encrypts plain of length length to encrypted of length + 16 using the |
39 | //public key(32 bytes) of the reciever and the secret key of the sender and a 24 byte nonce | 39 | //public key(32 bytes) of the receiver and the secret key of the sender and a 24 byte nonce |
40 | //return -1 if there was a problem. | 40 | //return -1 if there was a problem. |
41 | //return length of encrypted data if everything was fine. | 41 | //return length of encrypted data if everything was fine. |
42 | int encrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce, | 42 | int encrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce, |
@@ -44,7 +44,7 @@ int encrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce, | |||
44 | 44 | ||
45 | 45 | ||
46 | //decrypts encrypted of length length to plain of length length - 16 using the | 46 | //decrypts encrypted of length length to plain of length length - 16 using the |
47 | //public key(32 bytes) of the sender, the secret key of the reciever and a 24 byte nonce | 47 | //public key(32 bytes) of the sender, the secret key of the receiver and a 24 byte nonce |
48 | //return -1 if there was a problem(decryption failed) | 48 | //return -1 if there was a problem(decryption failed) |
49 | //return length of plain data if everything was fine. | 49 | //return length of plain data if everything was fine. |
50 | int decrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce, | 50 | int decrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce, |
@@ -53,7 +53,7 @@ int decrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce, | |||
53 | 53 | ||
54 | //return 0 if there is no received data in the buffer | 54 | //return 0 if there is no received data in the buffer |
55 | //return -1 if the packet was discarded. | 55 | //return -1 if the packet was discarded. |
56 | //return length of recieved data if successful | 56 | //return length of received data if successful |
57 | int read_cryptpacket(int crypt_connection_id, uint8_t * data); | 57 | int read_cryptpacket(int crypt_connection_id, uint8_t * data); |
58 | 58 | ||
59 | 59 | ||
@@ -94,7 +94,7 @@ int crypto_kill(int crypt_connection_id); | |||
94 | 94 | ||
95 | //handle an incoming connection | 95 | //handle an incoming connection |
96 | //return -1 if no crypto inbound connection | 96 | //return -1 if no crypto inbound connection |
97 | //return incomming connection id (Lossless_UDP one) if there is an incomming crypto connection | 97 | //return incoming connection id (Lossless_UDP one) if there is an incoming crypto connection |
98 | //Put the public key of the peer in public_key, the secret_nonce from the handshake into secret_nonce | 98 | //Put the public key of the peer in public_key, the secret_nonce from the handshake into secret_nonce |
99 | //and the session public key for the connection in session_key | 99 | //and the session public key for the connection in session_key |
100 | //to accept it see: accept_crypto_inbound(...) | 100 | //to accept it see: accept_crypto_inbound(...) |
@@ -108,8 +108,8 @@ int crypto_inbound(uint8_t * public_key, uint8_t * secret_nonce, uint8_t * sessi | |||
108 | int accept_crypto_inbound(int connection_id, uint8_t * public_key, uint8_t * secret_nonce, uint8_t * session_key); | 108 | int accept_crypto_inbound(int connection_id, uint8_t * public_key, uint8_t * secret_nonce, uint8_t * session_key); |
109 | 109 | ||
110 | //return 0 if no connection, 1 we have sent a handshake, 2 if connexion is not confirmed yet | 110 | //return 0 if no connection, 1 we have sent a handshake, 2 if connexion is not confirmed yet |
111 | //(we have recieved a hanshake but no empty data packet), 3 if the connection is established. | 111 | //(we have received a handshake but no empty data packet), 3 if the connection is established. |
112 | //4 if the connection is timed out and wating to be killed | 112 | //4 if the connection is timed out and waiting to be killed |
113 | int is_cryptoconnected(int crypt_connection_id); | 113 | int is_cryptoconnected(int crypt_connection_id); |
114 | 114 | ||
115 | 115 | ||
diff --git a/core/network.c b/core/network.c index 6b5f9970..9693df1c 100644 --- a/core/network.c +++ b/core/network.c | |||
@@ -74,7 +74,7 @@ int sendpacket(IP_Port ip_port, uint8_t * data, uint32_t length) | |||
74 | //the packet data into data | 74 | //the packet data into data |
75 | //the packet length into length. | 75 | //the packet length into length. |
76 | //dump all empty packets. | 76 | //dump all empty packets. |
77 | int recievepacket(IP_Port * ip_port, uint8_t * data, uint32_t * length) | 77 | int receivepacket(IP_Port * ip_port, uint8_t * data, uint32_t * length) |
78 | { | 78 | { |
79 | ADDR addr; | 79 | ADDR addr; |
80 | #ifdef WIN32 | 80 | #ifdef WIN32 |
diff --git a/core/network.h b/core/network.h index 9606d237..894bedeb 100644 --- a/core/network.h +++ b/core/network.h | |||
@@ -97,10 +97,10 @@ uint32_t random_int(); | |||
97 | //Function to send packet(data) of length length to ip_port | 97 | //Function to send packet(data) of length length to ip_port |
98 | int sendpacket(IP_Port ip_port, uint8_t * data, uint32_t length); | 98 | int sendpacket(IP_Port ip_port, uint8_t * data, uint32_t length); |
99 | 99 | ||
100 | //Function to recieve data, ip and port of sender is put into ip_port | 100 | //Function to receive data, ip and port of sender is put into ip_port |
101 | //the packet data into data | 101 | //the packet data into data |
102 | //the packet length into length. | 102 | //the packet length into length. |
103 | int recievepacket(IP_Port * ip_port, uint8_t * data, uint32_t * length); | 103 | int receivepacket(IP_Port * ip_port, uint8_t * data, uint32_t * length); |
104 | 104 | ||
105 | //initialize networking | 105 | //initialize networking |
106 | //bind to ip and port | 106 | //bind to ip and port |