mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
tcp relay sharing (PACKET_ID_SHARE_RELAYS)
This commit is contained in:
parent
d27a83820c
commit
987a8d9850
|
@ -714,6 +714,25 @@ static int send_ping(Messenger *m, int32_t friendnumber)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int send_relays(Messenger *m, int32_t friendnumber)
|
||||
{
|
||||
Node_format nodes[MAX_TCP_CONNECTIONS];
|
||||
uint8_t data[1024];
|
||||
int n, length;
|
||||
|
||||
n = copy_connected_tcp_relays(m->net_crypto, nodes, MAX_TCP_CONNECTIONS);
|
||||
length = pack_nodes(data, sizeof(data), nodes, n);
|
||||
|
||||
int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_SHARE_RELAYS, data, length);
|
||||
|
||||
if (ret == 1)
|
||||
m->friendlist[friendnumber].share_relays_lastsent = unix_time();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int set_friend_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *status, uint16_t length)
|
||||
{
|
||||
if (friend_not_valid(m, friendnumber))
|
||||
|
@ -2160,6 +2179,19 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
|
|||
(*m->msi_packet)(m, i, data, data_length, m->msi_packet_userdata);
|
||||
}
|
||||
|
||||
case PACKET_ID_SHARE_RELAYS: {
|
||||
Node_format nodes[MAX_TCP_CONNECTIONS];
|
||||
int n;
|
||||
|
||||
if ((n = unpack_nodes(nodes, MAX_TCP_CONNECTIONS, NULL, data, data_length, 1) == -1))
|
||||
break;
|
||||
|
||||
int i;
|
||||
for(i = 0; i < n; i++) {
|
||||
add_tcp_relay(m->net_crypto, nodes[i].ip_port, nodes[i].client_id);
|
||||
}
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
|
@ -2274,6 +2306,10 @@ void do_friends(Messenger *m)
|
|||
m->friendlist[i].crypt_connection_id = -1;
|
||||
set_friend_status(m, i, FRIEND_CONFIRMED);
|
||||
}
|
||||
|
||||
if (m->friendlist[i].share_relays_lastsent + FRIEND_SHARE_RELAYS_INTERVAL < temp_time) {
|
||||
send_relays(m, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
|
||||
/* NOTE: Packet ids below 16 must never be used. */
|
||||
#define PACKET_ID_ALIVE 16
|
||||
#define PACKET_ID_SHARE_RELAYS 17
|
||||
#define PACKET_ID_NICKNAME 48
|
||||
#define PACKET_ID_STATUSMESSAGE 49
|
||||
#define PACKET_ID_USERSTATUS 50
|
||||
|
@ -88,9 +89,13 @@ enum {
|
|||
/* Interval between the sending of ping packets. */
|
||||
#define FRIEND_PING_INTERVAL 5
|
||||
|
||||
/* Interval between the sending of tcp relay information */
|
||||
#define FRIEND_SHARE_RELAYS_INTERVAL (5 * 60)
|
||||
|
||||
/* If no packets are received from friend in this time interval, kill the connection. */
|
||||
#define FRIEND_CONNECTION_TIMEOUT (FRIEND_PING_INTERVAL * 2)
|
||||
|
||||
|
||||
/* USERSTATUS -
|
||||
* Represents userstatuses someone can have.
|
||||
*/
|
||||
|
@ -153,6 +158,7 @@ typedef struct {
|
|||
uint32_t friendrequest_nospam; // The nospam number used in the friend request.
|
||||
uint64_t ping_lastrecv;
|
||||
uint64_t ping_lastsent;
|
||||
uint64_t share_relays_lastsent;
|
||||
struct File_Transfers file_sending[MAX_CONCURRENT_FILE_PIPES];
|
||||
struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES];
|
||||
int invited_groups[MAX_INVITED_GROUPS];
|
||||
|
|
Loading…
Reference in New Issue
Block a user