sip: improve retransmission detection performance

This commit is contained in:
Kaian 2016-08-03 13:24:29 +02:00
parent 35a51311df
commit 93d7215e9d
6 changed files with 23 additions and 12 deletions

View File

@ -544,13 +544,13 @@ call_flow_draw_message(ui_t *ui, call_flow_arrow_t *arrow, int cline)
// Write the arrow at the end of the message (two arros if this is a retrans)
if (arrow_dir == CF_ARROW_RIGHT) {
mvwaddch(flow_win, cline, endpos - 2, '>');
if (call_msg_is_retrans(msg)) {
if (msg->retrans) {
mvwaddch(flow_win, cline, endpos - 3, '>');
mvwaddch(flow_win, cline, endpos - 4, '>');
}
} else {
mvwaddch(flow_win, cline, startpos + 2, '<');
if (call_msg_is_retrans(msg)) {
if (msg->retrans) {
mvwaddch(flow_win, cline, startpos + 3, '<');
mvwaddch(flow_win, cline, startpos + 4, '<');
}

View File

@ -370,6 +370,9 @@ sip_check_packet(packet_t *packet)
// Add the message to the call
call_add_message(call, msg);
// check if message is a retransmission
call_msg_retrans_check(msg);
if (call_is_invite(call)) {
// Parse media data
sip_parse_msg_media(msg, payload);
@ -591,7 +594,10 @@ sip_parse_msg_media(sip_msg_t *msg, const u_char *payload)
char *payload2, *tofree, *line;
sip_call_t *call = msg_get_call(msg);
if (call_msg_is_retrans(msg)) {
// If message is retrans, there's no need to parse the payload again
if (msg->retrans) {
// Use the media vector from the original message
msg->medias = msg->retrans->medias;
return;
}

View File

@ -149,8 +149,8 @@ call_is_invite(sip_call_t *call)
return 0;
}
int
call_msg_is_retrans(sip_msg_t *msg)
void
call_msg_retrans_check(sip_msg_t *msg)
{
sip_msg_t *prev = NULL;
vector_iter_t it;
@ -164,7 +164,10 @@ call_msg_is_retrans(sip_msg_t *msg)
break;
}
return (prev && !strcasecmp(msg_get_payload(msg), msg_get_payload(prev)));
// Store the flag that determines if message is retrans
if (prev && !strcasecmp(msg_get_payload(msg), msg_get_payload(prev))) {
msg->retrans = prev;
}
}
sip_msg_t *
@ -175,7 +178,6 @@ call_msg_with_media(sip_call_t *call, address_t dst)
vector_iter_t itmsg;
vector_iter_t itmedia;
// Get message with media address configured in given dst
itmsg = vector_iterator(call->msgs);
while ((msg = vector_iterator_next(&itmsg))) {

View File

@ -197,10 +197,9 @@ call_is_invite(sip_call_t *call);
* in the dialog, to check if it has the same content.
*
* @param msg SIP message that will be checked
* @return 1 if the previous message is equal to msg, 0 otherwise
*/
int
call_msg_is_retrans(sip_msg_t *msg);
void
call_msg_retrans_check(sip_msg_t *msg);
/**
* @brief Find a message in the call with SDP with the given address

View File

@ -45,7 +45,9 @@ void
msg_destroy(sip_msg_t *msg)
{
// Free message SDP media
if (!msg->retrans)
vector_destroy(msg->medias);
// Free message packets
packet_destroy(msg->packet);
// Free all memory

View File

@ -68,6 +68,8 @@ struct sip_msg {
uint32_t index;
//! Message owner
struct sip_call *call;
//! Message is a retransmission from other message
sip_msg_t *retrans;
};