Merge branch 'notsecure-work3'

This commit is contained in:
irungentoo 2014-05-19 19:47:05 -04:00
commit 0fa5feb8b7
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
2 changed files with 46 additions and 0 deletions

View File

@ -714,6 +714,25 @@ static int send_ping(Messenger *m, int32_t friendnumber)
return ret; return ret;
} }
static int send_relays(Messenger *m, int32_t friendnumber)
{
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);
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) static int set_friend_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *status, uint16_t length)
{ {
if (friend_not_valid(m, friendnumber)) if (friend_not_valid(m, friendnumber))
@ -2160,6 +2179,20 @@ 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); (*m->msi_packet)(m, i, data, data_length, m->msi_packet_userdata);
} }
case PACKET_ID_SHARE_RELAYS: {
Node_format nodes[MAX_SHARED_RELAYS];
int n;
if ((n = unpack_nodes(nodes, MAX_SHARED_RELAYS, 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: { default: {
break; break;
} }
@ -2274,6 +2307,10 @@ void do_friends(Messenger *m)
m->friendlist[i].crypt_connection_id = -1; m->friendlist[i].crypt_connection_id = -1;
set_friend_status(m, i, FRIEND_CONFIRMED); set_friend_status(m, i, FRIEND_CONFIRMED);
} }
if (m->friendlist[i].share_relays_lastsent + FRIEND_SHARE_RELAYS_INTERVAL < temp_time) {
send_relays(m, i);
}
} }
} }
} }

View File

@ -41,6 +41,7 @@
/* NOTE: Packet ids below 16 must never be used. */ /* NOTE: Packet ids below 16 must never be used. */
#define PACKET_ID_ALIVE 16 #define PACKET_ID_ALIVE 16
#define PACKET_ID_SHARE_RELAYS 17
#define PACKET_ID_NICKNAME 48 #define PACKET_ID_NICKNAME 48
#define PACKET_ID_STATUSMESSAGE 49 #define PACKET_ID_STATUSMESSAGE 49
#define PACKET_ID_USERSTATUS 50 #define PACKET_ID_USERSTATUS 50
@ -59,6 +60,9 @@
/* Max number of groups we can invite someone at the same time to. */ /* Max number of groups we can invite someone at the same time to. */
#define MAX_INVITED_GROUPS 64 #define MAX_INVITED_GROUPS 64
/* Max number of tcp relays sent to friends */
#define MAX_SHARED_RELAYS 16
/* Status definitions. */ /* Status definitions. */
enum { enum {
NOFRIEND, NOFRIEND,
@ -88,9 +92,13 @@ enum {
/* Interval between the sending of ping packets. */ /* Interval between the sending of ping packets. */
#define FRIEND_PING_INTERVAL 5 #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. */ /* If no packets are received from friend in this time interval, kill the connection. */
#define FRIEND_CONNECTION_TIMEOUT (FRIEND_PING_INTERVAL * 2) #define FRIEND_CONNECTION_TIMEOUT (FRIEND_PING_INTERVAL * 2)
/* USERSTATUS - /* USERSTATUS -
* Represents userstatuses someone can have. * Represents userstatuses someone can have.
*/ */
@ -153,6 +161,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; uint64_t ping_lastrecv;
uint64_t ping_lastsent; uint64_t ping_lastsent;
uint64_t share_relays_lastsent;
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];
int invited_groups[MAX_INVITED_GROUPS]; int invited_groups[MAX_INVITED_GROUPS];