mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
A/V integration in progress.
Added functions to send/receive msi packets via secure messenger connections. Made function to get the ip/port of a friend in Messenger.c public
This commit is contained in:
parent
dc1c019a2d
commit
a81b708eb5
|
@ -682,7 +682,7 @@ int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint
|
|||
/* returns valid ip port of connected friend on success
|
||||
* returns zeroed out IP_Port on failure
|
||||
*/
|
||||
static IP_Port get_friend_ipport(Messenger *m, int friendnumber)
|
||||
IP_Port get_friend_ipport(Messenger *m, int friendnumber)
|
||||
{
|
||||
IP_Port zero;
|
||||
memset(&zero, 0, sizeof(zero));
|
||||
|
@ -1266,6 +1266,26 @@ static int handle_filecontrol(Messenger *m, int friendnumber, uint8_t send_recei
|
|||
|
||||
/**************************************/
|
||||
|
||||
/* Set the callback for msi packets.
|
||||
*
|
||||
* Function(Messenger *m, int friendnumber, uint8_t *data, uint16_t length, void *userdata)
|
||||
*/
|
||||
void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *),
|
||||
void *userdata)
|
||||
{
|
||||
m->msi_packet = function;
|
||||
m->msi_packet_userdata = userdata;
|
||||
}
|
||||
|
||||
/* Send an msi packet.
|
||||
*
|
||||
* return 1 on success
|
||||
* return 0 on failure
|
||||
*/
|
||||
int m_msi_packet(Messenger *m, int friendnumber, uint8_t *data, uint16_t length)
|
||||
{
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length);
|
||||
}
|
||||
|
||||
/* Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds. */
|
||||
static void LANdiscovery(Messenger *m)
|
||||
|
@ -1419,11 +1439,12 @@ void doFriends(Messenger *m)
|
|||
}
|
||||
|
||||
len = read_cryptpacket(m->net_crypto, m->friendlist[i].crypt_connection_id, temp);
|
||||
|
||||
if (len > 0) {
|
||||
uint8_t packet_id = temp[0];
|
||||
uint8_t *data = temp + 1;
|
||||
uint32_t data_length = len - 1;
|
||||
|
||||
if (len > 0) {
|
||||
switch (packet_id) {
|
||||
case PACKET_ID_PING: {
|
||||
m->friendlist[i].ping_lastrecv = temp_time;
|
||||
|
@ -1508,6 +1529,7 @@ void doFriends(Messenger *m)
|
|||
if (m->friendlist[i].receives_read_receipts) {
|
||||
write_cryptpacket_id(m, i, PACKET_ID_RECEIPT, message_id, message_id_length);
|
||||
}
|
||||
|
||||
if (m->friend_action)
|
||||
(*m->friend_action)(m, i, action, action_length, m->friend_action_userdata);
|
||||
|
||||
|
@ -1611,6 +1633,14 @@ void doFriends(Messenger *m)
|
|||
break;
|
||||
}
|
||||
|
||||
case PACKET_ID_MSI: {
|
||||
if (data_length == 0)
|
||||
break;
|
||||
|
||||
if (m->msi_packet)
|
||||
(*m->msi_packet)(m, i, data, data_length, m->msi_packet_userdata);
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#define PACKET_ID_RECEIPT 65
|
||||
#define PACKET_ID_MESSAGE 64
|
||||
#define PACKET_ID_ACTION 63
|
||||
#define PACKET_ID_MSI 69
|
||||
#define PACKET_ID_FILE_SENDREQUEST 80
|
||||
#define PACKET_ID_FILE_CONTROL 81
|
||||
#define PACKET_ID_FILE_DATA 82
|
||||
|
@ -198,6 +199,9 @@ typedef struct Messenger {
|
|||
void (*file_filedata)(struct Messenger *m, int, uint8_t, uint8_t *, uint16_t length, void *);
|
||||
void *file_filedata_userdata;
|
||||
|
||||
void (*msi_packet)(struct Messenger *m, int, uint8_t *, uint16_t, void *);
|
||||
void *msi_packet_userdata;
|
||||
|
||||
} Messenger;
|
||||
|
||||
/* Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]
|
||||
|
@ -327,6 +331,11 @@ uint16_t getself_name(Messenger *m, uint8_t *name, uint16_t nlen);
|
|||
*/
|
||||
int getname(Messenger *m, int friendnumber, uint8_t *name);
|
||||
|
||||
/* returns valid ip port of connected friend on success
|
||||
* returns zeroed out IP_Port on failure
|
||||
*/
|
||||
IP_Port get_friend_ipport(Messenger *m, int friendnumber);
|
||||
|
||||
/* Set our user status.
|
||||
* You are responsible for freeing status after.
|
||||
*
|
||||
|
@ -547,7 +556,23 @@ int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data,
|
|||
*/
|
||||
uint64_t file_dataremaining(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t send_receive);
|
||||
|
||||
/*********************************/
|
||||
/*************** A/V related ******************/
|
||||
|
||||
/* Set the callback for msi packets.
|
||||
*
|
||||
* Function(Messenger *m, int friendnumber, uint8_t *data, uint16_t length, void *userdata)
|
||||
*/
|
||||
void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *),
|
||||
void *userdata);
|
||||
|
||||
/* Send an msi packet.
|
||||
*
|
||||
* return 1 on success
|
||||
* return 0 on failure
|
||||
*/
|
||||
int m_msi_packet(Messenger *m, int friendnumber, uint8_t *data, uint16_t length);
|
||||
|
||||
/**********************************************/
|
||||
|
||||
/* Run this at startup.
|
||||
* return allocated instance of Messenger on success.
|
||||
|
|
Loading…
Reference in New Issue
Block a user