mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Metadata collection prevention part 2 of ???
Improved friend request sending. As a side effect friend requests should now be routed less than before. See added comments for details.
This commit is contained in:
parent
88ff81d9de
commit
1207304f0b
20
core/DHT.c
20
core/DHT.c
@ -741,8 +741,8 @@ IP_Port DHT_getfriendip(uint8_t *client_id)
|
||||
return empty;
|
||||
}
|
||||
|
||||
/* Ping each client in the "friends" list every 60 seconds. Send a get nodes request
|
||||
* every 20 seconds to a random good node for each "friend" in our "friends" list.
|
||||
/* Ping each client in the "friends" list every PING_INTERVAL seconds. Send a get nodes request
|
||||
* every GET_NODE_INTERVAL seconds to a random good node for each "friend" in our "friends" list.
|
||||
*/
|
||||
static void doDHTFriends(void)
|
||||
{
|
||||
@ -783,8 +783,8 @@ static void doDHTFriends(void)
|
||||
|
||||
static uint64_t close_lastgetnodes;
|
||||
|
||||
/* Ping each client in the close nodes list every 60 seconds.
|
||||
* Send a get nodes request every 20 seconds to a random good node in the list.
|
||||
/* Ping each client in the close nodes list every PING_INTERVAL seconds.
|
||||
* Send a get nodes request every GET_NODE_INTERVAL seconds to a random good node in the list.
|
||||
*/
|
||||
static void doClose(void)
|
||||
{
|
||||
@ -823,6 +823,7 @@ static void doClose(void)
|
||||
void DHT_bootstrap(IP_Port ip_port, uint8_t *public_key)
|
||||
{
|
||||
getnodes(ip_port, public_key, self_public_key);
|
||||
send_ping_request(ip_port, (clientid_t *) public_key);
|
||||
}
|
||||
|
||||
/* send the given packet to node with client_id
|
||||
@ -875,8 +876,11 @@ static int friend_iplist(IP_Port *ip_portlist, uint16_t friend_num)
|
||||
return num_ips;
|
||||
}
|
||||
|
||||
|
||||
/* Send the following packet to everyone who tells us they are connected to friend_id
|
||||
* returns the number of nodes it sent the packet to
|
||||
*
|
||||
* Only works if more than (MAX_FRIEND_CLIENTS / 2) return an ip for friend.
|
||||
*/
|
||||
int route_tofriend(uint8_t *friend_id, uint8_t *packet, uint32_t length)
|
||||
{
|
||||
@ -886,6 +890,13 @@ int route_tofriend(uint8_t *friend_id, uint8_t *packet, uint32_t length)
|
||||
return 0;
|
||||
|
||||
uint32_t i, sent = 0;
|
||||
|
||||
IP_Port ip_list[MAX_FRIEND_CLIENTS];
|
||||
int ip_num = friend_iplist(ip_list, num);
|
||||
|
||||
if (ip_num < (MAX_FRIEND_CLIENTS / 2))
|
||||
return 0;
|
||||
|
||||
uint64_t temp_time = unix_time();
|
||||
Friend *friend = &friends_list[num];
|
||||
Client_data *client;
|
||||
@ -895,7 +906,6 @@ int route_tofriend(uint8_t *friend_id, uint8_t *packet, uint32_t length)
|
||||
|
||||
/*If ip is not zero and node is good */
|
||||
if (client->ret_ip_port.ip.i != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
|
||||
|
||||
if (sendpacket(client->ip_port, packet, length) == length)
|
||||
++sent;
|
||||
}
|
||||
|
@ -172,7 +172,8 @@ int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length)
|
||||
DHT_addfriend(client_id);
|
||||
m->friendlist[i].status = FRIEND_ADDED;
|
||||
m->friendlist[i].crypt_connection_id = -1;
|
||||
m->friendlist[i].friend_request_id = -1;
|
||||
m->friendlist[i].friendrequest_lastsent = 0;
|
||||
m->friendlist[i].friendrequest_timeout = FRIENDREQUEST_TIMEOUT;
|
||||
memcpy(m->friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
|
||||
m->friendlist[i].statusmessage = calloc(1, 1);
|
||||
m->friendlist[i].statusmessage_length = 1;
|
||||
@ -205,9 +206,9 @@ int m_addfriend_norequest(Messenger *m, uint8_t *client_id)
|
||||
for (i = 0; i <= m->numfriends; ++i) {
|
||||
if (m->friendlist[i].status == NOFRIEND) {
|
||||
DHT_addfriend(client_id);
|
||||
m->friendlist[i].status = FRIEND_REQUESTED;
|
||||
m->friendlist[i].status = FRIEND_CONFIRMED;
|
||||
m->friendlist[i].crypt_connection_id = -1;
|
||||
m->friendlist[i].friend_request_id = -1;
|
||||
m->friendlist[i].friendrequest_lastsent = 0;
|
||||
memcpy(m->friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
|
||||
m->friendlist[i].statusmessage = calloc(1, 1);
|
||||
m->friendlist[i].statusmessage_length = 1;
|
||||
@ -622,6 +623,7 @@ Messenger *initMessenger(void)
|
||||
LANdiscovery_init();
|
||||
set_nospam(random_int());
|
||||
|
||||
send_LANdiscovery(htons(PORT));
|
||||
timer_single(&LANdiscovery, 0, LAN_DISCOVERY_INTERVAL);
|
||||
|
||||
return m;
|
||||
@ -650,19 +652,22 @@ void doFriends(Messenger *m)
|
||||
int fr = send_friendrequest(m->friendlist[i].client_id, m->friendlist[i].friendrequest_nospam, m->friendlist[i].info,
|
||||
m->friendlist[i].info_size);
|
||||
|
||||
if (fr == 0) /* TODO: This needs to be fixed so that it sends the friend requests a couple of times in case of packet loss */
|
||||
set_friend_status(m, i, FRIEND_REQUESTED);
|
||||
else if (fr > 0)
|
||||
if (fr >= 0) {
|
||||
set_friend_status(m, i, FRIEND_REQUESTED);
|
||||
m->friendlist[i].friendrequest_lastsent = unix_time();
|
||||
}
|
||||
}
|
||||
|
||||
if (m->friendlist[i].status == FRIEND_REQUESTED
|
||||
|| m->friendlist[i].status == FRIEND_CONFIRMED) { /* friend is not online */
|
||||
if (m->friendlist[i].status == FRIEND_REQUESTED) {
|
||||
if (m->friendlist[i].friend_request_id + 10 < unix_time()) { /*I know this is hackish but it should work.*/
|
||||
send_friendrequest(m->friendlist[i].client_id, m->friendlist[i].friendrequest_nospam, m->friendlist[i].info,
|
||||
m->friendlist[i].info_size);
|
||||
m->friendlist[i].friend_request_id = unix_time();
|
||||
/* If we didn't connect to friend after successfully sending him a friend request the request is deemed
|
||||
unsuccessful so we set the status back to FRIEND_ADDED and try again.*/
|
||||
if (m->friendlist[i].friendrequest_lastsent + m->friendlist[i].friendrequest_timeout < unix_time()) {
|
||||
set_friend_status(m, i, FRIEND_ADDED);
|
||||
/* Double the default timeout everytime if friendrequest is assumed to have been
|
||||
sent unsuccessfully. */
|
||||
m->friendlist[i].friendrequest_timeout *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,6 +68,9 @@ extern "C" {
|
||||
/* don't assume MAX_STATUSMESSAGE_LENGTH will stay at 128, it may be increased
|
||||
to an absurdly large number later */
|
||||
|
||||
/* Default start timeout in seconds between friend requests */
|
||||
#define FRIENDREQUEST_TIMEOUT 5;
|
||||
|
||||
/* USERSTATUS
|
||||
* Represents userstatuses someone can have. */
|
||||
|
||||
@ -82,7 +85,8 @@ USERSTATUS;
|
||||
typedef struct {
|
||||
uint8_t client_id[CLIENT_ID_SIZE];
|
||||
int crypt_connection_id;
|
||||
uint64_t friend_request_id; /* id of the friend request corresponding to the current friend request to the current friend. */
|
||||
uint64_t friendrequest_lastsent; /* time at which the last friend request was sent. */
|
||||
uint32_t friendrequest_timeout; /* The timeout between successful friendrequest sending attempts */
|
||||
uint8_t status; /* 0 if no friend, 1 if added, 2 if friend request sent, 3 if confirmed friend, 4 if online. */
|
||||
uint8_t info[MAX_DATA_SIZE]; /* the data that is sent during the friend requests we do */
|
||||
uint8_t name[MAX_NAME_LENGTH];
|
||||
|
Loading…
x
Reference in New Issue
Block a user