mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Delete friends function now works and some other changes.
This commit is contained in:
parent
116f7b20ef
commit
e680d885d7
102
core/Messenger.c
102
core/Messenger.c
|
@ -29,39 +29,96 @@ Friend friendlist[MAX_NUM_FRIENDS];
|
|||
|
||||
uint32_t numfriends;
|
||||
|
||||
|
||||
//return the friend id associated to that public key.
|
||||
//return -1 if no such friend
|
||||
int getfriend_id(uint8_t * client_id)
|
||||
{
|
||||
uint32_t i;
|
||||
for(i = 0; i < numfriends; i++)
|
||||
{
|
||||
if(friendlist[i].status > 0)
|
||||
{
|
||||
if(memcmp(client_id, friendlist[i].client_id, crypto_box_PUBLICKEYBYTES) == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//add a friend
|
||||
//client_id is the client i of the friend
|
||||
//returns the friend number if success
|
||||
//return -1 if failure.
|
||||
int m_addfriend(uint8_t * client_id)
|
||||
{
|
||||
|
||||
if(getfriend_id(client_id) != -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
uint32_t i;
|
||||
for(i = 0; i < (numfriends + 1); i++)
|
||||
{
|
||||
if(friendlist[i].status == 0)
|
||||
{
|
||||
DHT_addfriend(client_id);
|
||||
friendlist[numfriends].status = 1;
|
||||
friendlist[numfriends].friend_request_id = -1;
|
||||
memcpy(friendlist[numfriends].client_id, client_id, CLIENT_ID_SIZE);
|
||||
friendlist[i].status = 1;
|
||||
friendlist[i].friend_request_id = -1;
|
||||
memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
|
||||
numfriends++;
|
||||
|
||||
return numfriends - 1;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int m_addfriend_norequest(uint8_t * client_id)
|
||||
{
|
||||
if(getfriend_id(client_id) != -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
uint32_t i;
|
||||
for(i = 0; i < (numfriends + 1); i++)
|
||||
{
|
||||
if(friendlist[i].status == 0)
|
||||
{
|
||||
DHT_addfriend(client_id);
|
||||
friendlist[numfriends].status = 2;
|
||||
friendlist[numfriends].friend_request_id = -1;
|
||||
memcpy(friendlist[numfriends].client_id, client_id, CLIENT_ID_SIZE);
|
||||
friendlist[i].status = 2;
|
||||
friendlist[i].friend_request_id = -1;
|
||||
memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
|
||||
numfriends++;
|
||||
|
||||
return numfriends - 1;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//remove a friend
|
||||
//returns 0 if success
|
||||
//return -1 if failure.
|
||||
int m_delfriend(int friendnumber)
|
||||
{/*
|
||||
TODO
|
||||
{
|
||||
if(friendnumber >= numfriends || friendnumber < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
DHT_delfriend(friendlist[friendnumber].client_id);
|
||||
*/
|
||||
memset(&friendlist[friendnumber], 0, sizeof(Friend));
|
||||
uint32_t i;
|
||||
for(i = numfriends; i != 0; i--)
|
||||
{
|
||||
if(friendlist[i].status != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
numfriends = i;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -220,23 +277,6 @@ void doFriendRequest()
|
|||
}
|
||||
|
||||
|
||||
//return the friend id associated to that public key.
|
||||
//return -1 if no such friend
|
||||
int getfriend_id(uint8_t * public_key)
|
||||
{
|
||||
uint32_t i;
|
||||
for(i = 0; i < numfriends; i++)
|
||||
{
|
||||
if(friendlist[i].status > 0)
|
||||
{
|
||||
if(memcmp(public_key, friendlist[i].client_id, crypto_box_PUBLICKEYBYTES) == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void doInbound()
|
||||
{
|
||||
|
|
|
@ -23,6 +23,9 @@ int m_addfriend(uint8_t * client_id);
|
|||
//return -1 if failure.
|
||||
int m_addfriend_norequest(uint8_t * client_id);
|
||||
|
||||
//return the friend id associated to that client id.
|
||||
//return -1 if no such friend
|
||||
int getfriend_id(uint8_t * client_id);
|
||||
|
||||
//remove a friend
|
||||
int m_delfriend(int friendnumber);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
* NOTE: this program simulates 33% packet loss.
|
||||
*
|
||||
* This is how I compile it: gcc -O2 -Wall -o test ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/DHT.c ../nacl/build/Linux/lib/amd64/* DHT_cryptosendfiletest.c
|
||||
* This is how I compile it: gcc -O2 -Wall -o test ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/DHT.c ../nacl/build/$HOSTNAME/lib/amd64/* DHT_cryptosendfiletest.c
|
||||
*
|
||||
*
|
||||
* Command line arguments are the ip and port of a node (for bootstrapping).
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* If it recieves a message from a friend it replies back.
|
||||
*
|
||||
*
|
||||
* This is how I compile it: gcc -O2 -Wall -o test ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/DHT.c ../core/Messenger.c ../nacl/build/Linux/lib/amd64/* Messenger_test.c
|
||||
* This is how I compile it: gcc -O2 -Wall -o test ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/DHT.c ../core/Messenger.c ../nacl/build/$HOSTNAME/lib/amd64/* Messenger_test.c
|
||||
*
|
||||
*
|
||||
* Command line arguments are the ip and port of a node (for bootstrapping).
|
||||
|
|
Loading…
Reference in New Issue
Block a user