summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-09-30 21:00:56 -0400
committerirungentoo <irungentoo@gmail.com>2014-09-30 21:00:56 -0400
commit9dd62023f50a2b5f91a52a4f7c8602b549a28ae0 (patch)
tree71c330b9fec67a66b14c55abf2ff3adf3a04aee5
parent45090ab2e51928ee1f1d96cc2a82dfc3d25c5cf0 (diff)
Added some functions to friend_connection.
-rw-r--r--toxcore/friend_connection.c54
-rw-r--r--toxcore/friend_connection.h29
2 files changed, 83 insertions, 0 deletions
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c
index 09dea4c3..1838c62d 100644
--- a/toxcore/friend_connection.c
+++ b/toxcore/friend_connection.c
@@ -370,6 +370,60 @@ static int send_ping(const Friend_Connections *fr_c, int friendcon_id)
370 return -1; 370 return -1;
371} 371}
372 372
373/* Increases lock_count for the connection with friendcon_id by 1.
374 *
375 * return 0 on success.
376 * return -1 on failure.
377 */
378int friend_connection_lock(Friend_Connections *fr_c, int friendcon_id)
379{
380 Friend_Conn *friend_con = get_conn(fr_c, friendcon_id);
381
382 if (!friend_con)
383 return -1;
384
385 ++friend_con->lock_count;
386 return 0;
387}
388
389/* return FRIENDCONN_STATUS_CONNECTED if the friend is connected.
390 * return FRIENDCONN_STATUS_CONNECTING if the friend isn't connected.
391 * return FRIENDCONN_STATUS_NONE on failure.
392 */
393unsigned int friend_con_connected(Friend_Connections *fr_c, int friendcon_id)
394{
395 Friend_Conn *friend_con = get_conn(fr_c, friendcon_id);
396
397 if (!friend_con)
398 return 0;
399
400 return friend_con->status;
401}
402
403/* Copy public keys associated to friendcon_id.
404 *
405 * return 0 on success.
406 * return -1 on failure.
407 */
408int get_friendcon_public_keys(uint8_t *real_pk, uint8_t *dht_temp_pk, Friend_Connections *fr_c, int friendcon_id)
409{
410 Friend_Conn *friend_con = get_conn(fr_c, friendcon_id);
411
412 if (!friend_con)
413 return -1;
414
415 memcpy(real_pk, friend_con->real_public_key, crypto_box_PUBLICKEYBYTES);
416 memcpy(dht_temp_pk, friend_con->dht_temp_pk, crypto_box_PUBLICKEYBYTES);
417 return 0;
418}
419
420/* Set temp dht key for connection.
421 */
422void set_dht_temp_pk(Friend_Connections *fr_c, int friendcon_id, uint8_t *dht_temp_pk)
423{
424 dht_pk_callback(fr_c, friendcon_id, dht_temp_pk);
425}
426
373/* Set the callbacks for the friend connection. 427/* Set the callbacks for the friend connection.
374 * index is the index (0 to (MAX_FRIEND_CONNECTION_CALLBACKS - 1)) we want the callback to set in the array. 428 * index is the index (0 to (MAX_FRIEND_CONNECTION_CALLBACKS - 1)) we want the callback to set in the array.
375 * 429 *
diff --git a/toxcore/friend_connection.h b/toxcore/friend_connection.h
index 62b82dc2..56401547 100644
--- a/toxcore/friend_connection.h
+++ b/toxcore/friend_connection.h
@@ -95,6 +95,35 @@ typedef struct {
95 95
96} Friend_Connections; 96} Friend_Connections;
97 97
98/* return friendcon_id corresponding to the real public key on success.
99 * return -1 on failure.
100 */
101int getfriend_conn_id_pk(Friend_Connections *fr_c, const uint8_t *real_pk);
102
103/* Increases lock_count for the connection with friendcon_id by 1.
104 *
105 * return 0 on success.
106 * return -1 on failure.
107 */
108int friend_connection_lock(Friend_Connections *fr_c, int friendcon_id);
109
110/* return FRIENDCONN_STATUS_CONNECTED if the friend is connected.
111 * return FRIENDCONN_STATUS_CONNECTING if the friend isn't connected.
112 * return FRIENDCONN_STATUS_NONE on failure.
113 */
114unsigned int friend_con_connected(Friend_Connections *fr_c, int friendcon_id);
115
116/* Copy public keys associated to friendcon_id.
117 *
118 * return 0 on success.
119 * return -1 on failure.
120 */
121int get_friendcon_public_keys(uint8_t *real_pk, uint8_t *dht_temp_pk, Friend_Connections *fr_c, int friendcon_id);
122
123/* Set temp dht key for connection.
124 */
125void set_dht_temp_pk(Friend_Connections *fr_c, int friendcon_id, uint8_t *dht_temp_pk);
126
98/* Set the callbacks for the friend connection. 127/* Set the callbacks for the friend connection.
99 * index is the index (0 to (MAX_FRIEND_CONNECTION_CALLBACKS - 1)) we want the callback to set in the array. 128 * index is the index (0 to (MAX_FRIEND_CONNECTION_CALLBACKS - 1)) we want the callback to set in the array.
100 * 129 *