mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Added different error codes for custom packet functions in Messenger.
This commit is contained in:
parent
e61e2919a9
commit
e5791ed9ef
|
@ -428,13 +428,14 @@ int rtp_send_msg ( RTPSession *session, Messenger *messenger, const uint8_t *dat
|
||||||
|
|
||||||
if ( !msg ) return -1;
|
if ( !msg ) return -1;
|
||||||
|
|
||||||
if ( -1 == send_custom_lossy_packet(messenger, session->dest, msg->data, msg->length) ) {
|
int ret = send_custom_lossy_packet(messenger, session->dest, msg->data, msg->length);
|
||||||
LOGGER_WARNING("Failed to send full packet (len: %d)! std error: %s", length, strerror(errno));
|
|
||||||
|
if ( 0 != ret) {
|
||||||
|
LOGGER_WARNING("Failed to send full packet (len: %d)! error: %i", length, ret);
|
||||||
rtp_free_msg ( session, msg );
|
rtp_free_msg ( session, msg );
|
||||||
return rtp_ErrorSending;
|
return rtp_ErrorSending;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Set sequ number */
|
/* Set sequ number */
|
||||||
session->sequnum = session->sequnum >= MAX_SEQU_NUM ? 0 : session->sequnum + 1;
|
session->sequnum = session->sequnum >= MAX_SEQU_NUM ? 0 : session->sequnum + 1;
|
||||||
rtp_free_msg ( session, msg );
|
rtp_free_msg ( session, msg );
|
||||||
|
|
|
@ -1379,11 +1379,24 @@ int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uin
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (m->friendlist[friendnumber].status != FRIEND_ONLINE)
|
if (length == 0 || length > MAX_CRYPTO_DATA_SIZE)
|
||||||
return -1;
|
return -2;
|
||||||
|
|
||||||
return send_lossy_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
|
if (data[0] < PACKET_ID_LOSSY_RANGE_START)
|
||||||
m->friendlist[friendnumber].friendcon_id), data, length);
|
return -3;
|
||||||
|
|
||||||
|
if (data[0] >= (PACKET_ID_LOSSY_RANGE_START + PACKET_ID_LOSSY_RANGE_SIZE))
|
||||||
|
return -3;
|
||||||
|
|
||||||
|
if (m->friendlist[friendnumber].status != FRIEND_ONLINE)
|
||||||
|
return -4;
|
||||||
|
|
||||||
|
if (send_lossy_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
|
||||||
|
m->friendlist[friendnumber].friendcon_id), data, length) == -1) {
|
||||||
|
return -5;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length)
|
static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length)
|
||||||
|
@ -1417,21 +1430,21 @@ int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (length == 0)
|
if (length == 0 || length > MAX_CRYPTO_DATA_SIZE)
|
||||||
return -1;
|
return -2;
|
||||||
|
|
||||||
if (data[0] < PACKET_ID_LOSSLESS_RANGE_START)
|
if (data[0] < PACKET_ID_LOSSLESS_RANGE_START)
|
||||||
return -1;
|
return -3;
|
||||||
|
|
||||||
if (data[0] >= (PACKET_ID_LOSSLESS_RANGE_START + PACKET_ID_LOSSLESS_RANGE_SIZE))
|
if (data[0] >= (PACKET_ID_LOSSLESS_RANGE_START + PACKET_ID_LOSSLESS_RANGE_SIZE))
|
||||||
return -1;
|
return -3;
|
||||||
|
|
||||||
if (m->friendlist[friendnumber].status != FRIEND_ONLINE)
|
if (m->friendlist[friendnumber].status != FRIEND_ONLINE)
|
||||||
return -1;
|
return -4;
|
||||||
|
|
||||||
if (write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
|
if (write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
|
||||||
m->friendlist[friendnumber].friendcon_id), data, length, 1) == -1) {
|
m->friendlist[friendnumber].friendcon_id), data, length, 1) == -1) {
|
||||||
return -1;
|
return -5;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -650,7 +650,11 @@ void custom_lossy_packet_registerhandler(Messenger *m, void (*packet_handler_cal
|
||||||
|
|
||||||
/* High level function to send custom lossy packets.
|
/* High level function to send custom lossy packets.
|
||||||
*
|
*
|
||||||
* return -1 on failure.
|
* return -1 if friend invalid.
|
||||||
|
* return -2 if length wrong.
|
||||||
|
* return -3 if first byte invalid.
|
||||||
|
* return -4 if friend offline.
|
||||||
|
* return -5 if packet failed to send because of other error.
|
||||||
* return 0 on success.
|
* return 0 on success.
|
||||||
*/
|
*/
|
||||||
int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
|
int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
|
||||||
|
@ -664,7 +668,11 @@ void custom_lossless_packet_registerhandler(Messenger *m, void (*packet_handler_
|
||||||
|
|
||||||
/* High level function to send custom lossless packets.
|
/* High level function to send custom lossless packets.
|
||||||
*
|
*
|
||||||
* return -1 on failure.
|
* return -1 if friend invalid.
|
||||||
|
* return -2 if length wrong.
|
||||||
|
* return -3 if first byte invalid.
|
||||||
|
* return -4 if friend offline.
|
||||||
|
* return -5 if packet failed to send because of other error.
|
||||||
* return 0 on success.
|
* return 0 on success.
|
||||||
*/
|
*/
|
||||||
int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
|
int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user