Skip to content

Commit

Permalink
rtpengine: Fix deletion for branching scenarios
Browse files Browse the repository at this point in the history
- hash table entry contains callid, viabranch
- hash table lookup based on callid, viabranch (useful for branching scenarios);
keep doing the hash table remove right away
- remove op param when select_rtpp_node(); not needed
  • Loading branch information
Stefan Mititelu committed Nov 16, 2015
1 parent 7ad4dad commit 5f936a3
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 76 deletions.
69 changes: 38 additions & 31 deletions modules/rtpengine/rtpengine.c
Expand Up @@ -193,9 +193,9 @@ static int rtpengine_offer_answer(struct sip_msg *msg, const char *flags, int op
static int fixup_set_id(void ** param, int param_no);
static int set_rtpengine_set_f(struct sip_msg * msg, char * str1, char * str2);
static struct rtpp_set * select_rtpp_set(int id_set);
static struct rtpp_node *select_rtpp_node_new(str, int, int);
static struct rtpp_node *select_rtpp_node_old(str, int, int);
static struct rtpp_node *select_rtpp_node(str, int, int);
static struct rtpp_node *select_rtpp_node_new(str, str, int);
static struct rtpp_node *select_rtpp_node_old(str, str, int);
static struct rtpp_node *select_rtpp_node(str, str, int);
static char *send_rtpp_command(struct rtpp_node *, bencode_item_t *, int *);
static int get_extra_id(struct sip_msg* msg, str *id_str);

Expand Down Expand Up @@ -1859,7 +1859,8 @@ static bencode_item_t *rtpp_function_call(bencode_buffer_t *bencbuf, struct sip_
{
struct ng_flags_parse ng_flags;
bencode_item_t *item, *resp;
str callid, from_tag, to_tag, body, viabranch, error;
str callid = STR_NULL, from_tag = STR_NULL, to_tag = STR_NULL, viabranch = STR_NULL;
str body = STR_NULL, error = STR_NULL;
int ret, queried_nodes;
struct rtpp_node *node;
char *cp;
Expand Down Expand Up @@ -1992,7 +1993,7 @@ static bencode_item_t *rtpp_function_call(bencode_buffer_t *bencbuf, struct sip_
LM_ERR("queried nodes limit reached\n");
goto error;
}
node = select_rtpp_node(callid, 1, op);
node = select_rtpp_node(callid, viabranch, 1);
if (!node) {
LM_ERR("no available proxies\n");
goto error;
Expand Down Expand Up @@ -2036,12 +2037,12 @@ static bencode_item_t *rtpp_function_call(bencode_buffer_t *bencbuf, struct sip_

if (op == OP_DELETE) {
/* Delete the key<->value from the hashtable */
if (!rtpengine_hash_table_remove(&callid)) {
LM_ERR("rtpengine hash table failed to remove entry for callen=%d callid=%.*s\n",
callid.len, callid.len, callid.s);
if (!rtpengine_hash_table_remove(callid, viabranch)) {
LM_ERR("rtpengine hash table failed to remove entry for callen=%d callid=%.*s viabranch=%.*s\n",
callid.len, callid.len, callid.s, viabranch.len, viabranch.s);
} else {
LM_DBG("rtpengine hash table remove entry for callen=%d callid=%.*s\n",
callid.len, callid.len, callid.s);
LM_DBG("rtpengine hash table remove entry for callen=%d callid=%.*s viabranch=%.*s\n",
callid.len, callid.len, callid.s, viabranch.len, viabranch.s);
}
}

Expand Down Expand Up @@ -2278,7 +2279,7 @@ static struct rtpp_set * select_rtpp_set(int id_set ){
* run the selection algorithm and return the new selected node
*/
static struct rtpp_node *
select_rtpp_node_new(str callid, int do_test, int op)
select_rtpp_node_new(str callid, str viabranch, int do_test)
{
struct rtpp_node* node;
unsigned i, sum, sumcut, weight_sum;
Expand Down Expand Up @@ -2350,34 +2351,40 @@ select_rtpp_node_new(str callid, int do_test, int op)
}

/* build the entry */
struct rtpengine_hash_entry *entry = shm_malloc(sizeof(struct rtpp_node));
struct rtpengine_hash_entry *entry = shm_malloc(sizeof(struct rtpengine_hash_entry));
if (!entry) {
LM_ERR("rtpengine hash table fail to create entry for calllen=%d callid=%.*s\n",
callid.len, callid.len, callid.s);
LM_ERR("rtpengine hash table fail to create entry for calllen=%d callid=%.*s viabranch=%.*s\n",
callid.len, callid.len, callid.s, viabranch.len, viabranch.s);
return node;
}
memset(entry, 0, sizeof(struct rtpengine_hash_entry));

/* fill the entry */
if (shm_str_dup(&entry->callid, &callid) < 0) {
LM_ERR("rtpengine hash table fail to duplicate calllen=%d callid=%.*s\n",
callid.len, callid.len, callid.s);
shm_free(entry);
rtpengine_hash_table_free_entry(entry);
return node;
}
if (shm_str_dup(&entry->viabranch, &viabranch) < 0) {
LM_ERR("rtpengine hash table fail to duplicate calllen=%d viabranch=%.*s\n",
callid.len, viabranch.len, viabranch.s);
rtpengine_hash_table_free_entry(entry);
return node;
}
entry->node = node;
entry->next = NULL;
entry->tout = get_ticks() + hash_table_tout;

/* insert the key<->entry from the hashtable */
if (!rtpengine_hash_table_insert(&callid, entry)) {
LM_ERR("rtpengine hash table fail to insert node=%.*s for calllen=%d callid=%.*s\n",
node->rn_url.len, node->rn_url.s, callid.len, callid.len, callid.s);
shm_free(entry->callid.s);
shm_free(entry);
if (!rtpengine_hash_table_insert(callid, viabranch, entry)) {
LM_ERR("rtpengine hash table fail to insert node=%.*s for calllen=%d callid=%.*s viabranch=%.*s\n",
node->rn_url.len, node->rn_url.s, callid.len, callid.len, callid.s, viabranch.len, viabranch.s);
rtpengine_hash_table_free_entry(entry);
return node;
} else {
LM_DBG("rtpengine hash table insert node=%.*s for calllen=%d callid=%.*s\n",
node->rn_url.len, node->rn_url.s, callid.len, callid.len, callid.s);
LM_DBG("rtpengine hash table insert node=%.*s for calllen=%d callid=%.*s viabranch=%.*s\n",
node->rn_url.len, node->rn_url.s, callid.len, callid.len, callid.s, viabranch.len, viabranch.s);
}

/* return selected node */
Expand All @@ -2388,19 +2395,19 @@ select_rtpp_node_new(str callid, int do_test, int op)
* lookup the hastable (key=callid value=node) and get the old node (e.g. for answer/delete)
*/
static struct rtpp_node *
select_rtpp_node_old(str callid, int do_test, int op)
select_rtpp_node_old(str callid, str viabranch, int do_test)
{
struct rtpp_node *node = NULL;

node = rtpengine_hash_table_lookup(&callid);
node = rtpengine_hash_table_lookup(callid, viabranch);

if (!node) {
LM_NOTICE("rtpengine hash table lookup failed to find node for calllen=%d callid=%.*s\n",
callid.len, callid.len, callid.s);
LM_NOTICE("rtpengine hash table lookup failed to find node for calllen=%d callid=%.*s viabranch=%.*s\n",
callid.len, callid.len, callid.s, viabranch.len, viabranch.s);
return NULL;
} else {
LM_DBG("rtpengine hash table lookup find node=%.*s for calllen=%d callid=%.*s\n",
node->rn_url.len, node->rn_url.s, callid.len, callid.len, callid.s);
LM_DBG("rtpengine hash table lookup find node=%.*s for calllen=%d callid=%.*s viabranch=%.*s\n",
node->rn_url.len, node->rn_url.s, callid.len, callid.len, callid.s, viabranch.len, viabranch.s);
}

return node;
Expand All @@ -2411,7 +2418,7 @@ select_rtpp_node_old(str callid, int do_test, int op)
* the call if some proxies were disabled or enabled (e.g. kamctl command)
*/
static struct rtpp_node *
select_rtpp_node(str callid, int do_test, int op)
select_rtpp_node(str callid, str viabranch, int do_test)
{
struct rtpp_node *node = NULL;

Expand All @@ -2421,12 +2428,12 @@ select_rtpp_node(str callid, int do_test, int op)
}

// lookup node
node = select_rtpp_node_old(callid, do_test, op);
node = select_rtpp_node_old(callid, viabranch, do_test);

// check node
if (!node) {
// run the selection algorithm
node = select_rtpp_node_new(callid, do_test, op);
node = select_rtpp_node_new(callid, viabranch, do_test);

// check node
if (!node) {
Expand Down

0 comments on commit 5f936a3

Please sign in to comment.