mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Tox connection function and callback should now work as expected.
Changes in Messenger to call the callback every time the connection type changes from TCP to UDP.
This commit is contained in:
parent
53d0eb8937
commit
c87da9203e
|
@ -358,7 +358,19 @@ int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber)
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return m->friendlist[friendnumber].status == FRIEND_ONLINE;
|
if (m->friendlist[friendnumber].status == FRIEND_ONLINE) {
|
||||||
|
uint8_t direct_connected = 0;
|
||||||
|
crypto_connection_status(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
|
||||||
|
m->friendlist[friendnumber].friendcon_id), &direct_connected);
|
||||||
|
|
||||||
|
if (direct_connected) {
|
||||||
|
return CONNECTION_UDP;
|
||||||
|
} else {
|
||||||
|
return CONNECTION_TCP;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return CONNECTION_NONE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int m_friend_exists(const Messenger *m, int32_t friendnumber)
|
int m_friend_exists(const Messenger *m, int32_t friendnumber)
|
||||||
|
@ -969,6 +981,23 @@ void m_callback_avatar_data(Messenger *m, void (*function)(Messenger *m, uint32_
|
||||||
m->avatar_data_recv_userdata = userdata;
|
m->avatar_data_recv_userdata = userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber)
|
||||||
|
{
|
||||||
|
int last_connection_udp_tcp = m->friendlist[friendnumber].last_connection_udp_tcp;
|
||||||
|
|
||||||
|
int ret = m_get_friend_connectionstatus(m, friendnumber);
|
||||||
|
|
||||||
|
if (ret == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (last_connection_udp_tcp != ret) {
|
||||||
|
if (m->friend_connectionstatuschange)
|
||||||
|
m->friend_connectionstatuschange(m, friendnumber, ret, m->friend_connectionstatuschange_userdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
m->friendlist[friendnumber].last_connection_udp_tcp = ret;
|
||||||
|
}
|
||||||
|
|
||||||
static void break_files(const Messenger *m, int32_t friendnumber);
|
static void break_files(const Messenger *m, int32_t friendnumber);
|
||||||
static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, uint8_t status)
|
static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, uint8_t status)
|
||||||
{
|
{
|
||||||
|
@ -988,8 +1017,7 @@ static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, ui
|
||||||
|
|
||||||
m->friendlist[friendnumber].status = status;
|
m->friendlist[friendnumber].status = status;
|
||||||
|
|
||||||
if (m->friend_connectionstatuschange)
|
check_friend_tcp_udp(m, friendnumber);
|
||||||
m->friend_connectionstatuschange(m, friendnumber, is_online, m->friend_connectionstatuschange_userdata);
|
|
||||||
|
|
||||||
if (m->friend_connectionstatuschange_internal)
|
if (m->friend_connectionstatuschange_internal)
|
||||||
m->friend_connectionstatuschange_internal(m, friendnumber, is_online,
|
m->friend_connectionstatuschange_internal(m, friendnumber, is_online,
|
||||||
|
@ -2316,6 +2344,8 @@ void do_friends(Messenger *m)
|
||||||
if (m->friendlist[i].share_relays_lastsent + FRIEND_SHARE_RELAYS_INTERVAL < temp_time) {
|
if (m->friendlist[i].share_relays_lastsent + FRIEND_SHARE_RELAYS_INTERVAL < temp_time) {
|
||||||
send_relays(m, i);
|
send_relays(m, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_friend_tcp_udp(m, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,12 @@ enum {
|
||||||
#define AVATAR_DATA_TRANSFER_TIMEOUT (60) /* 164kB every 60 seconds is not a lot */
|
#define AVATAR_DATA_TRANSFER_TIMEOUT (60) /* 164kB every 60 seconds is not a lot */
|
||||||
|
|
||||||
|
|
||||||
|
enum {
|
||||||
|
CONNECTION_NONE,
|
||||||
|
CONNECTION_TCP,
|
||||||
|
CONNECTION_UDP
|
||||||
|
};
|
||||||
|
|
||||||
/* USERSTATUS -
|
/* USERSTATUS -
|
||||||
* Represents userstatuses someone can have.
|
* Represents userstatuses someone can have.
|
||||||
*/
|
*/
|
||||||
|
@ -215,6 +221,7 @@ typedef struct {
|
||||||
uint32_t friendrequest_nospam; // The nospam number used in the friend request.
|
uint32_t friendrequest_nospam; // The nospam number used in the friend request.
|
||||||
uint64_t ping_lastrecv;//TODO remove
|
uint64_t ping_lastrecv;//TODO remove
|
||||||
uint64_t share_relays_lastsent;
|
uint64_t share_relays_lastsent;
|
||||||
|
uint8_t last_connection_udp_tcp;
|
||||||
struct File_Transfers file_sending[MAX_CONCURRENT_FILE_PIPES];
|
struct File_Transfers file_sending[MAX_CONCURRENT_FILE_PIPES];
|
||||||
struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES];
|
struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES];
|
||||||
|
|
||||||
|
@ -372,8 +379,9 @@ int m_delfriend(Messenger *m, int32_t friendnumber);
|
||||||
|
|
||||||
/* Checks friend's connecting status.
|
/* Checks friend's connecting status.
|
||||||
*
|
*
|
||||||
* return 1 if friend is connected to us (Online).
|
* return CONNECTION_UDP (2) if friend is directly connected to us (Online UDP).
|
||||||
* return 0 if friend is not connected to us (Offline).
|
* return CONNECTION_TCP (1) if friend is connected to us (Online TCP).
|
||||||
|
* return CONNECTION_NONE (0) if friend is not connected to us (Offline).
|
||||||
* return -1 on failure.
|
* return -1 on failure.
|
||||||
*/
|
*/
|
||||||
int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber);
|
int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber);
|
||||||
|
|
|
@ -647,7 +647,7 @@ void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *
|
||||||
m_callback_statusmessage(m, function, user_data);
|
m_callback_statusmessage(m, function, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
TOX_STATUS tox_friend_get_status(Tox const *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
|
TOX_STATUS tox_friend_get_status(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
|
||||||
{
|
{
|
||||||
const Messenger *m = tox;
|
const Messenger *m = tox;
|
||||||
|
|
||||||
|
@ -668,10 +668,32 @@ void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *function, void *
|
||||||
m_callback_userstatus(m, function, user_data);
|
m_callback_userstatus(m, function, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tox_friend_get_typing(Tox const *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
|
TOX_CONNECTION tox_friend_get_connection_status(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
|
||||||
|
{
|
||||||
|
const Messenger *m = tox;
|
||||||
|
|
||||||
|
int ret = m_get_friend_connectionstatus(m, friend_number);
|
||||||
|
|
||||||
|
if (ret == -1) {
|
||||||
|
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND);
|
||||||
|
return TOX_CONNECTION_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_OK);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *function, void *user_data)
|
||||||
|
{
|
||||||
|
Messenger *m = tox;
|
||||||
|
m_callback_connectionstatus(m, function, user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
|
||||||
{
|
{
|
||||||
const Messenger *m = tox;
|
const Messenger *m = tox;
|
||||||
int ret = m_get_istyping(m, friend_number);
|
int ret = m_get_istyping(m, friend_number);
|
||||||
|
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND);
|
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user