Added some functions to friend_connection.

This commit is contained in:
irungentoo 2014-09-30 21:00:56 -04:00
parent 45090ab2e5
commit 9dd62023f5
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
2 changed files with 83 additions and 0 deletions

View File

@ -370,6 +370,60 @@ static int send_ping(const Friend_Connections *fr_c, int friendcon_id)
return -1;
}
/* Increases lock_count for the connection with friendcon_id by 1.
*
* return 0 on success.
* return -1 on failure.
*/
int friend_connection_lock(Friend_Connections *fr_c, int friendcon_id)
{
Friend_Conn *friend_con = get_conn(fr_c, friendcon_id);
if (!friend_con)
return -1;
++friend_con->lock_count;
return 0;
}
/* return FRIENDCONN_STATUS_CONNECTED if the friend is connected.
* return FRIENDCONN_STATUS_CONNECTING if the friend isn't connected.
* return FRIENDCONN_STATUS_NONE on failure.
*/
unsigned int friend_con_connected(Friend_Connections *fr_c, int friendcon_id)
{
Friend_Conn *friend_con = get_conn(fr_c, friendcon_id);
if (!friend_con)
return 0;
return friend_con->status;
}
/* Copy public keys associated to friendcon_id.
*
* return 0 on success.
* return -1 on failure.
*/
int get_friendcon_public_keys(uint8_t *real_pk, uint8_t *dht_temp_pk, Friend_Connections *fr_c, int friendcon_id)
{
Friend_Conn *friend_con = get_conn(fr_c, friendcon_id);
if (!friend_con)
return -1;
memcpy(real_pk, friend_con->real_public_key, crypto_box_PUBLICKEYBYTES);
memcpy(dht_temp_pk, friend_con->dht_temp_pk, crypto_box_PUBLICKEYBYTES);
return 0;
}
/* Set temp dht key for connection.
*/
void set_dht_temp_pk(Friend_Connections *fr_c, int friendcon_id, uint8_t *dht_temp_pk)
{
dht_pk_callback(fr_c, friendcon_id, dht_temp_pk);
}
/* Set the callbacks for the friend connection.
* index is the index (0 to (MAX_FRIEND_CONNECTION_CALLBACKS - 1)) we want the callback to set in the array.
*

View File

@ -95,6 +95,35 @@ typedef struct {
} Friend_Connections;
/* return friendcon_id corresponding to the real public key on success.
* return -1 on failure.
*/
int getfriend_conn_id_pk(Friend_Connections *fr_c, const uint8_t *real_pk);
/* Increases lock_count for the connection with friendcon_id by 1.
*
* return 0 on success.
* return -1 on failure.
*/
int friend_connection_lock(Friend_Connections *fr_c, int friendcon_id);
/* return FRIENDCONN_STATUS_CONNECTED if the friend is connected.
* return FRIENDCONN_STATUS_CONNECTING if the friend isn't connected.
* return FRIENDCONN_STATUS_NONE on failure.
*/
unsigned int friend_con_connected(Friend_Connections *fr_c, int friendcon_id);
/* Copy public keys associated to friendcon_id.
*
* return 0 on success.
* return -1 on failure.
*/
int get_friendcon_public_keys(uint8_t *real_pk, uint8_t *dht_temp_pk, Friend_Connections *fr_c, int friendcon_id);
/* Set temp dht key for connection.
*/
void set_dht_temp_pk(Friend_Connections *fr_c, int friendcon_id, uint8_t *dht_temp_pk);
/* Set the callbacks for the friend connection.
* index is the index (0 to (MAX_FRIEND_CONNECTION_CALLBACKS - 1)) we want the callback to set in the array.
*