Merge branch 'master' of https://github.com/nurupo/InsertProjectNameHere into nurupo-master

Conflicts:
	core/Messenger.c
This commit is contained in:
irungentoo 2013-08-08 14:39:27 -04:00
commit 9634a23437
2 changed files with 28 additions and 7 deletions

View File

@ -55,6 +55,8 @@ static Friend *friendlist;
static uint32_t numfriends; static uint32_t numfriends;
static void set_friend_status(int friendnumber, uint8_t status);
/* 1 if we are online /* 1 if we are online
0 if we are offline 0 if we are offline
static uint8_t online; */ static uint8_t online; */
@ -134,7 +136,7 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length)
for (i = 0; i <= numfriends; ++i) { for (i = 0; i <= numfriends; ++i) {
if (friendlist[i].status == NOFRIEND) { if (friendlist[i].status == NOFRIEND) {
DHT_addfriend(client_id); DHT_addfriend(client_id);
friendlist[i].status = FRIEND_ADDED; set_friend_status(i, FRIEND_ADDED);
friendlist[i].crypt_connection_id = -1; friendlist[i].crypt_connection_id = -1;
friendlist[i].friend_request_id = -1; friendlist[i].friend_request_id = -1;
memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
@ -165,7 +167,7 @@ int m_addfriend_norequest(uint8_t * client_id)
for (i = 0; i <= numfriends; ++i) { for (i = 0; i <= numfriends; ++i) {
if(friendlist[i].status == NOFRIEND) { if(friendlist[i].status == NOFRIEND) {
DHT_addfriend(client_id); DHT_addfriend(client_id);
friendlist[i].status = FRIEND_REQUESTED; set_friend_status(i, FRIEND_REQUESTED);
friendlist[i].crypt_connection_id = -1; friendlist[i].crypt_connection_id = -1;
friendlist[i].friend_request_id = -1; friendlist[i].friend_request_id = -1;
memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
@ -477,6 +479,21 @@ void m_callback_read_receipt(void (*function)(int, uint32_t))
read_receipt_isset = 1; read_receipt_isset = 1;
} }
static void (*friend_statuschange)(int, uint8_t);
static uint8_t friend_statuschange_isset = 0;
void m_callback_friend_status(void (*function)(int, uint8_t))
{
friend_statuschange = function;
friend_statuschange_isset = 1;
}
static void set_friend_status(int friendnumber, uint8_t status)
{
if (friendlist[friendnumber].status != status && friend_statuschange_isset)
friend_statuschange(friendnumber, status);
friendlist[friendnumber].status = status;
}
#define PORT 33445 #define PORT 33445
/* run this at startup */ /* run this at startup */
int initMessenger(void) int initMessenger(void)
@ -504,9 +521,9 @@ static void doFriends(void)
if (friendlist[i].status == FRIEND_ADDED) { if (friendlist[i].status == FRIEND_ADDED) {
int fr = send_friendrequest(friendlist[i].client_id, friendlist[i].info, friendlist[i].info_size); int fr = send_friendrequest(friendlist[i].client_id, friendlist[i].info, 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 */ 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 */
friendlist[i].status = FRIEND_REQUESTED; set_friend_status(i, FRIEND_REQUESTED);
else if (fr > 0) else if (fr > 0)
friendlist[i].status = FRIEND_REQUESTED; set_friend_status(i, FRIEND_REQUESTED);
} }
if (friendlist[i].status == FRIEND_REQUESTED || friendlist[i].status == FRIEND_CONFIRMED) { /* friend is not online */ if (friendlist[i].status == FRIEND_REQUESTED || friendlist[i].status == FRIEND_CONFIRMED) { /* friend is not online */
if (friendlist[i].status == FRIEND_REQUESTED) { if (friendlist[i].status == FRIEND_REQUESTED) {
@ -522,7 +539,7 @@ static void doFriends(void)
friendlist[i].crypt_connection_id = crypto_connect(friendlist[i].client_id, friendip); friendlist[i].crypt_connection_id = crypto_connect(friendlist[i].client_id, friendip);
break; break;
case 3: /* Connection is established */ case 3: /* Connection is established */
friendlist[i].status = FRIEND_ONLINE; set_friend_status(i, FRIEND_ONLINE);
break; break;
case 4: case 4:
crypto_kill(friendlist[i].crypt_connection_id); crypto_kill(friendlist[i].crypt_connection_id);
@ -604,7 +621,7 @@ static void doFriends(void)
if (is_cryptoconnected(friendlist[i].crypt_connection_id) == 4) { /* if the connection timed out, kill it */ if (is_cryptoconnected(friendlist[i].crypt_connection_id) == 4) { /* if the connection timed out, kill it */
crypto_kill(friendlist[i].crypt_connection_id); crypto_kill(friendlist[i].crypt_connection_id);
friendlist[i].crypt_connection_id = -1; friendlist[i].crypt_connection_id = -1;
friendlist[i].status = FRIEND_CONFIRMED; set_friend_status(i, FRIEND_CONFIRMED);
} }
break; break;
} }
@ -625,7 +642,7 @@ static void doInbound(void)
friendlist[friend_id].crypt_connection_id = friendlist[friend_id].crypt_connection_id =
accept_crypto_inbound(inconnection, public_key, secret_nonce, session_key); accept_crypto_inbound(inconnection, public_key, secret_nonce, session_key);
friendlist[friend_id].status = FRIEND_CONFIRMED; set_friend_status(friend_id, FRIEND_CONFIRMED);
} }
} }
} }

View File

@ -201,6 +201,10 @@ void m_callback_userstatus(void (*function)(int, USERSTATUS));
in that case, you should discard it. */ in that case, you should discard it. */
void m_callback_read_receipt(void (*function)(int, uint32_t)); void m_callback_read_receipt(void (*function)(int, uint32_t));
/* set the callback for friend status changes
function(int friendnumber, uint8_t status) */
void m_callback_friendstatus(void (*function)(int, uint8_t));
/* run this at startup /* run this at startup
returns 0 if no connection problems returns 0 if no connection problems
returns -1 if there are problems */ returns -1 if there are problems */