8000 fix: some friend connection issues by JFreegman · Pull Request #1699 · TokTok/c-toxcore · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: some friend connection issues #1699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions toxcore/Messenger.c
Origi 8000 nal file line number Diff line number Diff line change
Expand Up @@ -444,26 +444,31 @@ int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber)
return -1;
}

if (m->friendlist[friendnumber].status == FRIEND_ONLINE) {
bool direct_connected = 0;
unsigned int num_online_relays = 0;
int crypt_conn_id = friend_connection_crypt_connection_id(m->fr_c, m->friendlist[friendnumber].friendcon_id);
if (m->friendlist[friendnumber].status != FRIEND_ONLINE) {
return CONNECTION_NONE;
}

// FIXME(sudden6): handle return value
crypto_connection_status(m->net_crypto, crypt_conn_id, &direct_connected, &num_online_relays);
bool direct_connected = 0;
unsigned int num_online_relays = 0;
int crypt_conn_id = friend_connection_crypt_connection_id(m->fr_c, m->friendlist[friendnumber].friendcon_id);

if (direct_connected) {
return CONNECTION_UDP;
}
if (!crypto_connection_status(m->net_crypto, crypt_conn_id, &direct_connected, &num_online_relays)) {
return CONNECTION_NONE;
}

if (num_online_relays) {
return CONNECTION_TCP;
}
if (direct_connected) {
return CONNECTION_UDP;
}

return CONNECTION_UNKNOWN;
if (num_online_relays) {
return CONNECTION_TCP;
}

return CONNECTION_NONE;
/* if we have a valid friend connection but do not have an established connection
* we leave the connection status unchanged until the friend connection is either
* established or dropped.
*/
return m->friendlist[friendnumber].last_connection_udp_tcp;
}

int m_friend_exists(const Messenger *m, int32_t friendnumber)
Expand Down Expand Up @@ -899,14 +904,6 @@ static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber, void *userd
return;
}

if (ret == CONNECTION_UNKNOWN) {
if (last_connection_udp_tcp == CONNECTION_UDP) {
return;
}

ret = CONNECTION_TCP;
}

if (last_connection_udp_tcp != ret) {
if (m->friend_connectionstatuschange) {
m->friend_connectionstatuschange(m, friendnumber, ret, userdata);
Expand Down
5 changes: 2 additions & 3 deletions toxcore/Messenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ typedef enum Connection_Status {
CONNECTION_NONE,
CONNECTION_TCP,
CONNECTION_UDP,
CONNECTION_UNKNOWN,
} Connection_Status;

/* USERSTATUS -
Expand Down Expand Up @@ -225,7 +224,7 @@ typedef struct Friend {
uint32_t message_id; // a semi-unique id used in read receipts.
uint32_t friendrequest_nospam; // The nospam number used in the friend request.
uint64_t last_seen_time;
uint8_t last_connection_udp_tcp;
Connection_Status last_connection_udp_tcp;
struct File_Transfers file_sending[MAX_CONCURRENT_FILE_PIPES];
uint32_t num_sending_files;
struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES];
Expand Down Expand Up @@ -360,7 +359,7 @@ int getfriendcon_id(const Messenger *m, int32_t friendnumber);
*/
int m_delfriend(Messenger *m, int32_t friendnumber);

/* Checks friend's connecting status.
/* Checks friend's connection status.
*
* return CONNECTION_UDP (2) if friend is directly connected to us (Online UDP).
* return CONNECTION_TCP (1) if friend is connected to us (Online TCP).
Expand Down
4 changes: 1 addition & 3 deletions toxcore/net_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -2921,9 +2921,7 @@ bool crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, bool

if ((UDP_DIRECT_TIMEOUT + conn->direct_lastrecv_timev4) > current_time) {
*direct_connected = 1;
}

if ((UDP_DIRECT_TIMEOUT + conn->direct_lastrecv_timev6) > current_time) {
} else if ((UDP_DIRECT_TIMEOUT + conn->direct_lastrecv_timev6) > current_time) {
*direct_connected = 1;
}
}
Expand Down
0