comment updates

This commit is contained in:
JamoBox 2013-09-02 17:12:02 +01:00
parent 433cc9c8b2
commit 7b944e9c65
5 changed files with 156 additions and 127 deletions

View File

@ -28,13 +28,15 @@
static void set_friend_status(Messenger *m, int friendnumber, uint8_t status);
static int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length);
/* return 1 if we are online.
* return 0 if we are offline.
* static uint8_t online;
/* static uint8_t online;
*
* return 1 if we are online.
* return 0 if we are offline.
*/
/* Set the size of the friend list to numfriends.
* return -1 if realloc fails.
*
* return -1 if realloc fails.
*/
int realloc_friendlist(Messenger *m, uint32_t num)
{
@ -53,8 +55,8 @@ int realloc_friendlist(Messenger *m, uint32_t num)
return 0;
}
/* return the friend id associated to that public key.
* return -1 if no such friend.
/* return the friend id associated to that public key.
* return -1 if no such friend.
*/
int getfriend_id(Messenger *m, uint8_t *client_id)
{
@ -71,8 +73,9 @@ int getfriend_id(Messenger *m, uint8_t *client_id)
/* Copies the public key associated to that friend id into client_id buffer.
* Make sure that client_id is of size CLIENT_ID_SIZE.
* return 0 if success.
* return -1 if failure.
*
* return 0 if success.
* return -1 if failure.
*/
int getclient_id(Messenger *m, int friend_id, uint8_t *client_id)
{
@ -86,10 +89,9 @@ int getclient_id(Messenger *m, int friend_id, uint8_t *client_id)
return -1;
}
/*
* return a uint16_t that represents the checksum of address of length len.
/* TODO: Another checksum algorithm might be better.
*
* TODO: Another checksum algorithm might be better.
* return a uint16_t that represents the checksum of address of length len.
*/
static uint16_t address_checksum(uint8_t *address, uint32_t len)
{
@ -104,10 +106,9 @@ static uint16_t address_checksum(uint8_t *address, uint32_t len)
return check;
}
/*
* return FRIEND_ADDRESS_SIZE byte address to give to others.
* Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]
/* Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]
*
* return FRIEND_ADDRESS_SIZE byte address to give to others.
*/
void getaddress(Messenger *m, uint8_t *address)
{
@ -124,16 +125,17 @@ void getaddress(Messenger *m, uint8_t *address)
* Address is the address of the friend (returned by getaddress of the friend you wish to add) it must be FRIEND_ADDRESS_SIZE bytes.
* TODO: add checksum.
* data is the data and length is the length.
* return the friend number if success.
* return FA_TOOLONG if message length is too long.
* return FAERR_NOMESSAGE if no message (message length must be >= 1 byte).
* return FAERR_OWNKEY if user's own key.
* return FAERR_ALREADYSENT if friend request already sent or already a friend.
* return FAERR_UNKNOWN for unknown error.
* return FAERR_BADCHECKSUM if bad checksum in address.
* return FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different.
* (the nospam for that friend was set to the new one).
* return FAERR_NOMEM if increasing the friend list size fails.
*
* return the friend number if success.
* return FA_TOOLONG if message length is too long.
* return FAERR_NOMESSAGE if no message (message length must be >= 1 byte).
* return FAERR_OWNKEY if user's own key.
* return FAERR_ALREADYSENT if friend request already sent or already a friend.
* return FAERR_UNKNOWN for unknown error.
* return FAERR_BADCHECKSUM if bad checksum in address.
* return FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different.
* (the nospam for that friend was set to the new one).
* return FAERR_NOMEM if increasing the friend list size fails.
*/
int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length)
{
@ -241,6 +243,7 @@ int m_addfriend_norequest(Messenger *m, uint8_t *client_id)
}
/* Remove a friend.
*
* return 0 if success.
* return -1 if failure.
*/
@ -268,11 +271,11 @@ int m_delfriend(Messenger *m, int friendnumber)
return 0;
}
/* return FRIEND_ONLINE if friend is online.
* return FRIEND_CONFIRMED if friend is confirmed.
* return FRIEND_REQUESTED if the friend request was sent.
* return FRIEND_ADDED if the friend was added.
* return NOFRIEND if there is no friend with that number.
/* return FRIEND_ONLINE if friend is online.
* return FRIEND_CONFIRMED if friend is confirmed.
* return FRIEND_REQUESTED if the friend request was sent.
* return FRIEND_ADDED if the friend was added.
* return NOFRIEND if there is no friend with that number.
*/
int m_friendstatus(Messenger *m, int friendnumber)
{
@ -283,8 +286,9 @@ int m_friendstatus(Messenger *m, int friendnumber)
}
/* Send a text chat message to an online friend.
* return the message id if packet was successfully put into the send queue.
* return 0 if it was not.
*
* return the message id if packet was successfully put into the send queue.
* return 0 if it was not.
*/
uint32_t m_sendmessage(Messenger *m, int friendnumber, uint8_t *message, uint32_t length)
{
@ -316,8 +320,9 @@ uint32_t m_sendmessage_withid(Messenger *m, int friendnumber, uint32_t theid, ui
}
/* Send an action to an online friend.
* return 1 if packet was successfully put into the send queue.
* return 0 if it was not.
*
* return 1 if packet was successfully put into the send queue.
* return 0 if it was not.
*/
int m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t length)
{
@ -336,8 +341,9 @@ static int m_sendname(Messenger *m, int friendnumber, uint8_t *name, uint16_t le
}
/* Set the name of a friend.
* return 0 if success.
* return -1 if failure.
*
* return 0 if success.
* return -1 if failure.
*/
static int setfriendname(Messenger *m, int friendnumber, uint8_t *name)
{
@ -352,8 +358,9 @@ static int setfriendname(Messenger *m, int friendnumber, uint8_t *name)
* name must be a string of maximum MAX_NAME_LENGTH length.
* length must be at least 1 byte.
* length is the length of name with the NULL terminator.
* return 0 if success.
* return -1 if failure.
*
* return 0 if success.
* return -1 if failure.
*/
int setname(Messenger *m, uint8_t *name, uint16_t length)
{
@ -371,8 +378,9 @@ int setname(Messenger *m, uint8_t *name, uint16_t length)
}
/* Get our nickname and put it in name.
* Name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes.
* return the length of the name.
* name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes.
*
* return the length of the name.
*/
uint16_t getself_name(Messenger *m, uint8_t *name, uint16_t nlen)
{
@ -389,9 +397,10 @@ uint16_t getself_name(Messenger *m, uint8_t *name, uint16_t nlen)
}
/* Get name of friendnumber and put it in name.
* Name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes.
* return 0 if success.
* return -1 if failure.
* name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes.
*
* return 0 if success.
* return -1 if failure.
*/
int getname(Messenger *m, int friendnumber, uint8_t *name)
{
@ -918,7 +927,7 @@ void doMessenger(Messenger *m)
LANdiscovery(m);
}
/* return the size of the messenger data (for saving) */
/* return size of the messenger data (for saving) */
uint32_t Messenger_size(Messenger *m)
{
return crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES

View File

@ -154,28 +154,27 @@ typedef struct Messenger {
} Messenger;
/*
* return FRIEND_ADDRESS_SIZE byte address to give to others.
* Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]
/* Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]
*
* return FRIEND_ADDRESS_SIZE byte address to give to others.
*/
void getaddress(Messenger *m, uint8_t *address);
/*
* Add a friend.
/* Add a friend.
* Set the data that will be sent along with friend request.
* address is the address of the friend (returned by getaddress of the friend you wish to add) it must be FRIEND_ADDRESS_SIZE bytes. TODO: add checksum.
* data is the data and length is the length.
* returns the friend number if success.
* return -1 if message length is too long.
* return -2 if no message (message length must be >= 1 byte).
* return -3 if user's own key.
* return -4 if friend request already sent or already a friend.
* return -5 for unknown error.
* return -6 if bad checksum in address.
* return -7 if the friend was already there but the nospam was different.
* (the nospam for that friend was set to the new one).
* return -8 if increasing the friend list size fails.
*
* return the friend number if success.
* return -1 if message length is too long.
* return -2 if no message (message length must be >= 1 byte).
* return -3 if user's own key.
* return -4 if friend request already sent or already a friend.
* return -5 for unknown error.
* return -6 if bad checksum in address.
* return -7 if the friend was already there but the nospam was different.
* (the nospam for that friend was set to the new one).
* return -8 if increasing the friend list size fails.
*/
int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length);
@ -186,13 +185,14 @@ int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length);
*/
int m_addfriend_norequest(Messenger *m, uint8_t *client_id);
/* return the friend id associated to that client id.
* return -1 if no such friend.
/* return the friend id associated to that client id.
* return -1 if no such friend.
*/
int getfriend_id(Messenger *m, uint8_t *client_id);
/* Copies the public key associated to that friend id into client_id buffer.
* Make sure that client_id is of size CLIENT_ID_SIZE.
*
* return 0 if success
* return -1 if failure
*/
@ -201,15 +201,16 @@ int getclient_id(Messenger *m, int friend_id, uint8_t *client_id);
/* Remove a friend. */
int m_delfriend(Messenger *m, int friendnumber);
/* return 4 if friend is online.
* return 3 if friend is confirmed.
* return 2 if the friend request was sent.
* return 1 if the friend was added.
* return 0 if there is no friend with that number.
/* return 4 if friend is online.
* return 3 if friend is confirmed.
* return 2 if the friend request was sent.
* return 1 if the friend was added.
* return 0 if there is no friend with that number.
*/
int m_friendstatus(Messenger *m, int friendnumber);
/* Send a text chat message to an online friend.
*
* return the message id if packet was successfully put into the send queue.
* return 0 if it was not.
*
@ -222,6 +223,7 @@ uint32_t m_sendmessage(Messenger *m, int friendnumber, uint8_t *message, uint32_
uint32_t m_sendmessage_withid(Messenger *m, int friendnumber, uint32_t theid, uint8_t *message, uint32_t length);
/* Send an action to an online friend.
*
* return 1 if packet was successfully put into the send queue.
* return 0 if it was not.
*/
@ -231,8 +233,9 @@ int m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t lengt
* name must be a string of maximum MAX_NAME_LENGTH length.
* length must be at least 1 byte.
* length is the length of name with the NULL terminator.
* return 0 if success.
* return -1 if failure.
*
* return 0 if success.
* return -1 if failure.
*/
int setname(Messenger *m, uint8_t *name, uint16_t length);
@ -241,28 +244,30 @@ int setname(Messenger *m, uint8_t *name, uint16_t length);
* m - The messanger context to use.
* name - Pointer to a string for the name.
* nlen - The length of the string buffer.
* return length of the name.
* return 0 on error.
*
* return length of the name.
* return 0 on error.
*/
uint16_t getself_name(Messenger *m, uint8_t *name, uint16_t nlen);
/* Get name of friendnumber and put it in name.
* name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes.
* name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes.
*
* return 0 if success.
* return -1 if failure.
*/
int getname(Messenger *m, int friendnumber, uint8_t *name);
/* Set our user status.
* You are responsible for freeing status after.
* You are responsible for freeing status after.
*
* returns 0 on success.
* returns -1 on failure.
*/
int m_set_statusmessage(Messenger *m, uint8_t *status, uint16_t length);
int m_set_userstatus(Messenger *m, USERSTATUS status);
/* return the length of friendnumber's status message,
* including null.
/* return the length of friendnumber's status message, including null.
* Pass it into malloc.
*/
int m_get_statusmessage_size(Messenger *m, int friendnumber);
@ -274,10 +279,10 @@ int m_get_statusmessage_size(Messenger *m, int friendnumber);
int m_copy_statusmessage(Messenger *m, int friendnumber, uint8_t *buf, uint32_t maxlen);
int m_copy_self_statusmessage(Messenger *m, uint8_t *buf, uint32_t maxlen);
/* return one of USERSTATUS values.
* Values unknown to your application should be represented as USERSTATUS_NONE.
* As above, the self variant will return our own USERSTATUS.
* If friendnumber is invalid, this shall return USERSTATUS_INVALID.
/* return one of USERSTATUS values.
* Values unknown to your application should be represented as USERSTATUS_NONE.
* As above, the self variant will return our own USERSTATUS.
* If friendnumber is invalid, this shall return USERSTATUS_INVALID.
*/
USERSTATUS m_get_userstatus(Messenger *m, int friendnumber);
USERSTATUS m_get_self_userstatus(Messenger *m);
@ -299,7 +304,7 @@ void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int,
void *userdata);
/* Set the function that will be executed when an action from a friend is received.
* function format is: function(int friendnumber, uint8_t * action, uint32_t length)
* Function format is: function(int friendnumber, uint8_t * action, uint32_t length)
*/
void m_callback_action(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), void *userdata);
@ -311,7 +316,7 @@ void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int, uin
void *userdata);
/* Set the callback for status message changes.
* function(int friendnumber, uint8_t *newstatus, uint16_t length)
* Function(int friendnumber, uint8_t *newstatus, uint16_t length)
*
* You are not responsible for freeing newstatus
*/
@ -319,12 +324,12 @@ void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int,
void *userdata);
/* Set the callback for status type changes.
* function(int friendnumber, USERSTATUS kind)
* Function(int friendnumber, USERSTATUS kind)
*/
void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int, USERSTATUS, void *), void *userdata);
/* Set the callback for read receipts.
* function(int friendnumber, uint32_t receipt)
* Function(int friendnumber, uint32_t receipt)
*
* If you are keeping a record of returns from m_sendmessage,
* receipt might be one of those values, meaning the message
@ -348,8 +353,8 @@ void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, u
void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int, uint8_t, void *), void *userdata);
/* Run this at startup.
* returns allocated instance of Messenger on success.
* returns 0 if there are problems.
* return allocated instance of Messenger on success.
* return 0 if there are problems.
*/
Messenger *initMessenger(void);

View File

@ -84,7 +84,7 @@ typedef struct tox_list {
struct tox_list *prev, *next;
} tox_list;
/* Returns a new tox_list_t. */
/* return new tox_list_t. */
static inline void tox_list_new(tox_list *lst)
{
lst->prev = lst->next = lst;

View File

@ -144,9 +144,9 @@ void random_nonce(uint8_t *nonce)
}
}
/* return 0 if there is no received data in the buffer.
* return -1 if the packet was discarded.
* return length of received data if successful.
/* return 0 if there is no received data in the buffer.
* return -1 if the packet was discarded.
* return length of received data if successful.
*/
int read_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data)
{
@ -177,8 +177,8 @@ int read_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data)
return -1;
}
/* return 0 if data could not be put in packet queue.
* return 1 if data was put into the queue.
/* return 0 if data could not be put in packet queue.
* return 1 if data was put into the queue.
*/
int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length)
{
@ -215,8 +215,8 @@ int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uin
* Data represents the data we send with the request with length being the length of the data.
* request_id is the id of the request (32 = friend request, 254 = ping request).
*
* returns -1 on failure.
* returns the length of the created packet on success.
* return -1 on failure.
* return the length of the created packet on success.
*/
int create_request(uint8_t *send_public_key, uint8_t *send_secret_key, uint8_t *packet, uint8_t *recv_public_key,
uint8_t *data, uint32_t length, uint8_t request_id)
@ -246,7 +246,8 @@ int create_request(uint8_t *send_public_key, uint8_t *send_secret_key, uint8_t *
/* Puts the senders public key in the request in public_key, the data from the request
* in data if a friend or ping request was sent to us and returns the length of the data.
* packet is the request packet and length is its length.
* return -1 if not valid request.
*
* return -1 if not valid request.
*/
static int handle_request(Net_Crypto *c, uint8_t *public_key, uint8_t *data, uint8_t *request_id, uint8_t *packet,
uint16_t length)
@ -341,8 +342,9 @@ static int send_cryptohandshake(Net_Crypto *c, int connection_id, uint8_t *publi
}
/* Extract secret nonce, session public key and public_key from a packet(data) with length length.
* return 1 if successful.
* return 0 if failure.
*
* return 1 if successful.
* return 0 if failure.
*/
static int handle_cryptohandshake(Net_Crypto *c, uint8_t *public_key, uint8_t *secret_nonce,
uint8_t *session_key, uint8_t *data, uint16_t length)
@ -374,8 +376,9 @@ static int handle_cryptohandshake(Net_Crypto *c, uint8_t *public_key, uint8_t *s
}
/* Get crypto connection id from public key of peer.
* return -1 if there are no connections like we are looking for.
* return id if it found it.
*
* return -1 if there are no connections like we are looking for.
* return id if it found it.
*/
static int getcryptconnection_id(Net_Crypto *c, uint8_t *public_key)
{
@ -391,7 +394,8 @@ static int getcryptconnection_id(Net_Crypto *c, uint8_t *public_key)
}
/* Set the size of the friend list to numfriends.
* return -1 if realloc fails.
*
* return -1 if realloc fails.
*/
int realloc_cryptoconnection(Net_Crypto *c, uint32_t num)
{
@ -411,8 +415,9 @@ int realloc_cryptoconnection(Net_Crypto *c, uint32_t num)
}
/* Start a secure connection with other peer who has public_key and ip_port.
* returns -1 if failure.
* returns crypt_connection_id of the initialized connection if everything went well.
*
* return -1 if failure.
* return crypt_connection_id of the initialized connection if everything went well.
*/
int crypto_connect(Net_Crypto *c, uint8_t *public_key, IP_Port ip_port)
{
@ -462,8 +467,9 @@ int crypto_connect(Net_Crypto *c, uint8_t *public_key, IP_Port ip_port)
}
/* Handle an incoming connection.
* return -1 if no crypto inbound connection.
* return incoming connection id (Lossless_UDP one) if there is an incoming crypto connection.
*
* return -1 if no crypto inbound connection.
* return incoming connection id (Lossless_UDP one) if there is an incoming crypto connection.
*
* Put the public key of the peer in public_key, the secret_nonce from the handshake into secret_nonce
* and the session public key for the connection in session_key.
@ -500,8 +506,9 @@ int crypto_inbound(Net_Crypto *c, uint8_t *public_key, uint8_t *secret_nonce, ui
}
/* Kill a crypto connection.
* return 0 if killed successfully.
* return 1 if there was a problem.
*
* return 0 if killed successfully.
* return 1 if there was a problem.
*/
int crypto_kill(Net_Crypto *c, int crypt_connection_id)
{
@ -529,8 +536,9 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id)
}
/* Accept an incoming connection using the parameters provided by crypto_inbound.
* return -1 if not successful.
* returns the crypt_connection_id if successful.
*
* return -1 if not successful.
* return the crypt_connection_id if successful.
*/
int accept_crypto_inbound(Net_Crypto *c, int connection_id, uint8_t *public_key, uint8_t *secret_nonce,
uint8_t *session_key)
@ -588,11 +596,11 @@ int accept_crypto_inbound(Net_Crypto *c, int connection_id, uint8_t *public_key,
return -1;
}
/* return 0 if no connection.
* return 1 we have sent a handshake.
* return 2 if connection is not confirmed yet (we have received a handshake but no empty data packet).
* return 3 if the connection is established.
* return 4 if the connection is timed out and waiting to be killed.
/* return 0 if no connection.
* return 1 we have sent a handshake.
* return 2 if connection is not confirmed yet (we have received a handshake but no empty data packet).
* return 3 if the connection is established.
* return 4 if the connection is timed out and waiting to be killed.
*/
int is_cryptoconnected(Net_Crypto *c, int crypt_connection_id)
{
@ -626,9 +634,10 @@ void load_keys(Net_Crypto *c, uint8_t *keys)
}
/* Adds an incoming connection to the incoming_connection list.
* returns 0 if successful
* returns 1 if failure.
* TODO: Optimize this.
*
* returns 0 if successful
* returns 1 if failure.
*/
static int new_incoming(Net_Crypto *c, int id)
{

View File

@ -80,7 +80,8 @@ typedef struct {
uint8_t crypto_iszero(uint8_t *buffer, uint32_t blen);
/* Encrypts plain of length length to encrypted of length + 16 using the
* public key(32 bytes) of the receiver and the secret key of the sender and a 24 byte nonce.
* public key(32 bytes) of the receiver and the secret key of the sender and a 24 byte nonce.
*
* return -1 if there was a problem.
* return length of encrypted data if everything was fine.
*/
@ -89,7 +90,8 @@ int encrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce,
/* Decrypts encrypted of length length to plain of length length - 16 using the
* public key(32 bytes) of the sender, the secret key of the receiver and a 24 byte nonce.
* public key(32 bytes) of the sender, the secret key of the receiver and a 24 byte nonce.
*
* return -1 if there was a problem (decryption failed).
* return length of plain data if everything was fine.
*/
@ -113,14 +115,14 @@ int decrypt_data_fast(uint8_t *enc_key, uint8_t *nonce,
/* Fill the given nonce with random bytes. */
void random_nonce(uint8_t *nonce);
/* return 0 if there is no received data in the buffer.
/* return 0 if there is no received data in the buffer.
* return -1 if the packet was discarded.
* return length of received data if successful.
*/
int read_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data);
/* return 0 if data could not be put in packet queue
* return 1 if data was put into the queue
/* return 0 if data could not be put in packet queue.
* return 1 if data was put into the queue.
*/
int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length);
@ -131,8 +133,8 @@ int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uin
* Data represents the data we send with the request with length being the length of the data.
* request_id is the id of the request (32 = friend request, 254 = ping request).
*
* returns -1 on failure.
* returns the length of the created packet on success.
* return -1 on failure.
* return the length of the created packet on success.
*/
int create_request(uint8_t *send_public_key, uint8_t *send_secret_key, uint8_t *packet, uint8_t *recv_public_key,
uint8_t *data, uint32_t length, uint8_t request_id);
@ -142,18 +144,21 @@ int create_request(uint8_t *send_public_key, uint8_t *send_secret_key, uint8_t *
void cryptopacket_registerhandler(Net_Crypto *c, uint8_t byte, cryptopacket_handler_callback cb, void *object);
/* Start a secure connection with other peer who has public_key and ip_port.
* returns -1 if failure.
* returns crypt_connection_id of the initialized connection if everything went well.
*
* return -1 if failure.
* return crypt_connection_id of the initialized connection if everything went well.
*/
int crypto_connect(Net_Crypto *c, uint8_t *public_key, IP_Port ip_port);
/* Kill a crypto connection.
*
* return 0 if killed successfully.
* return 1 if there was a problem.
*/
int crypto_kill(Net_Crypto *c, int crypt_connection_id);
/* Handle an incoming connection.
*
* return -1 if no crypto inbound connection.
* return incoming connection id (Lossless_UDP one) if there is an incoming crypto connection.
*
@ -165,17 +170,18 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id);
int crypto_inbound(Net_Crypto *c, uint8_t *public_key, uint8_t *secret_nonce, uint8_t *session_key);
/* Accept an incoming connection using the parameters provided by crypto_inbound.
*
* return -1 if not successful.
* returns the crypt_connection_id if successful.
* return crypt_connection_id if successful.
*/
int accept_crypto_inbound(Net_Crypto *c, int connection_id, uint8_t *public_key, uint8_t *secret_nonce,
uint8_t *session_key);
/* return 0 if no connection.
* return 1 we have sent a handshake
* return 2 if connexion is not confirmed yet (we have received a handshake but no empty data packet).
* return 3 if the connection is established.
* return 4 if the connection is timed out and waiting to be killed.
/* return 0 if no connection.
* return 1 we have sent a handshake
* return 2 if connexion is not confirmed yet (we have received a handshake but no empty data packet).
* return 3 if the connection is established.
* return 4 if the connection is timed out and waiting to be killed.
*/
int is_cryptoconnected(Net_Crypto *c, int crypt_connection_id);