Skip to content

Commit 7ea4f1f

Browse files
committed
b2b_entities: add more randomness to callid generation to handle client_htable collisions
1 parent cdb5d49 commit 7ea4f1f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

modules/b2b_entities/b2be_load.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#define B2B_NOTIFY_FL_TERM_BYE (1<<2)
5656

5757
#define B2B_MAX_PREFIX_LEN 5
58-
#define B2B_MAX_KEY_SIZE (B2B_MAX_PREFIX_LEN+4+10+10+INT2STR_MAX_LEN)
58+
#define B2B_MAX_KEY_SIZE (B2B_MAX_PREFIX_LEN+5+10+10+INT2STR_MAX_LEN+10)
5959

6060
enum b2b_entity_type {B2B_SERVER=0, B2B_CLIENT, B2B_NONE};
6161

modules/b2b_entities/dlg.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ str* b2b_htable_insert(b2b_table table, b2b_dlg_t* dlg, int hash_index,
290290
return b2b_key;
291291
}
292292

293-
/* key format : B2B.hash_index.local_index.timestamp *
293+
/* key format : B2B.hash_index.local_index.timestamp.random *
294294
*/
295295

296296
int b2b_parse_key(str* key, unsigned int* hash_index, unsigned int* local_index,
@@ -341,8 +341,14 @@ int b2b_parse_key(str* key, unsigned int* hash_index, unsigned int* local_index,
341341
}
342342

343343
if (timestamp) {
344-
s.s = p+1;
345-
s.len = key->len - (s.s - key->s);
344+
s.s = p+1;
345+
// There might be a random number after timestamp, we want to ignore it.
346+
p= strchr(s.s, '.');
347+
if (p != NULL) {
348+
s.len= p - s.s;
349+
} else {
350+
s.len = key->len - (s.s - key->s);
351+
}
346352
if(str2int64(&s, timestamp) < 0)
347353
{
348354
LM_DBG("Could not extract timestamp [%.*s] from key [%.*s]\n", s.len, s.s, key->len, key->s);
@@ -366,8 +372,8 @@ str* b2b_generate_key(unsigned int hash_index, unsigned int local_index,
366372
str* b2b_key;
367373
int len;
368374

369-
len = sprintf(buf, "%s.%d.%d.%ld", b2b_key_prefix.s, hash_index, local_index,
370-
timestamp ? timestamp : startup_time+get_ticks());
375+
len = sprintf(buf, "%s.%d.%d.%ld.%d", b2b_key_prefix.s, hash_index, local_index,
376+
timestamp ? timestamp : startup_time+get_ticks(), rand());
371377

372378
b2b_key = (str*)pkg_malloc(sizeof(str)+ len);
373379
if(b2b_key== NULL)

0 commit comments

Comments
 (0)