mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Properly share connected relays and connect to the friend correctly
with them.
This commit is contained in:
parent
de8956267c
commit
92a708578f
|
@ -755,11 +755,23 @@ static int send_user_istyping(const Messenger *m, int32_t friendnumber, uint8_t
|
|||
|
||||
static int send_relays(const Messenger *m, int32_t friendnumber)
|
||||
{
|
||||
if (friend_not_valid(m, friendnumber))
|
||||
return 0;
|
||||
|
||||
Node_format nodes[MAX_SHARED_RELAYS];
|
||||
uint8_t data[1024];
|
||||
int n, length;
|
||||
|
||||
n = copy_connected_tcp_relays(m->net_crypto, nodes, MAX_SHARED_RELAYS);
|
||||
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < n; ++i) {
|
||||
/* Associated the relays being sent with this connection.
|
||||
On receiving the peer will do the same which will establish the connection. */
|
||||
friend_add_tcp_relay(m->fr_c, m->friendlist[friendnumber].friendcon_id, nodes[i].ip_port, nodes[i].public_key);
|
||||
}
|
||||
|
||||
length = pack_nodes(data, sizeof(data), nodes, n);
|
||||
|
||||
int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_SHARE_RELAYS, data, length, 0);
|
||||
|
@ -1914,6 +1926,7 @@ static int handle_status(void *object, int i, uint8_t status)
|
|||
m->friendlist[i].userstatus_sent = 0;
|
||||
m->friendlist[i].statusmessage_sent = 0;
|
||||
m->friendlist[i].user_istyping_sent = 0;
|
||||
m->friendlist[i].share_relays_lastsent = 0;
|
||||
} else { /* Went offline. */
|
||||
if (m->friendlist[i].status == FRIEND_ONLINE) {
|
||||
set_friend_status(m, i, FRIEND_CONFIRMED);
|
||||
|
|
|
@ -63,7 +63,7 @@ enum {
|
|||
#define PACKET_ID_LOSSY_GROUPCHAT 199
|
||||
|
||||
/* Max number of tcp relays sent to friends */
|
||||
#define MAX_SHARED_RELAYS 16
|
||||
#define MAX_SHARED_RELAYS (RECOMMENDED_FRIEND_TCP_CONNECTIONS)
|
||||
|
||||
/* All packets starting with a byte in this range can be used for anything. */
|
||||
#define PACKET_ID_LOSSLESS_RANGE_START 160
|
||||
|
|
|
@ -901,10 +901,10 @@ int add_tcp_relay_connection(TCP_Connections *tcp_c, int connections_number, IP_
|
|||
*/
|
||||
unsigned int tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num)
|
||||
{
|
||||
unsigned int i, copied = 0;
|
||||
unsigned int i, copied = 0, r = rand();
|
||||
|
||||
for (i = 0; (i < tcp_c->tcp_connections_length) && (copied < max_num); ++i) {
|
||||
TCP_con *tcp_con = get_tcp_connection(tcp_c, i);
|
||||
TCP_con *tcp_con = get_tcp_connection(tcp_c, (i + r) % tcp_c->tcp_connections_length);
|
||||
|
||||
if (!tcp_con) {
|
||||
continue;
|
||||
|
|
|
@ -34,14 +34,14 @@
|
|||
#define TCP_CONNECTIONS_STATUS_REGISTERED 1
|
||||
#define TCP_CONNECTIONS_STATUS_ONLINE 2
|
||||
|
||||
#define MAX_FRIEND_TCP_CONNECTIONS 4
|
||||
#define MAX_FRIEND_TCP_CONNECTIONS 6
|
||||
|
||||
/* Time until connection to friend gets killed (if it doesn't get locked withing that time) */
|
||||
#define TCP_CONNECTION_ANNOUNCE_TIMEOUT (TCP_CONNECTION_TIMEOUT)
|
||||
|
||||
/* The amount of recommended connections for each friend
|
||||
NOTE: Must be equal or smaller than MAX_FRIEND_TCP_CONNECTIONS */
|
||||
#define RECOMMENDED_FRIEND_TCP_CONNECTIONS 3
|
||||
NOTE: Must be at most (MAX_FRIEND_TCP_CONNECTIONS / 2) */
|
||||
#define RECOMMENDED_FRIEND_TCP_CONNECTIONS (MAX_FRIEND_TCP_CONNECTIONS / 2)
|
||||
|
||||
typedef struct {
|
||||
uint8_t status;
|
||||
|
|
Loading…
Reference in New Issue
Block a user