From 63538ec8e6a7d584daa8db2e17cfc6eaa6cbe002 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 26 Sep 2023 09:07:48 -0400 Subject: [PATCH] MT#57977 fix save/restore of "foreign" call flag With the "foreign" flag now stored in call_flags, restoring a call from Redis restores this flag as well, overwriting the desired flag as we had set it through call_get_or_create(). Reverse the flag setting by taking it out of call_get_or_create() (where it's always false anyway, except when coming from Redis) and setting it explicitly with call_make_own_foreign() after restorting call and its flags. Change-Id: Ib68be2aeedfa988b7555e426fa337657e1062245 (cherry picked from commit dbae76c3b6f2e3c6e84bbd5ad408dc2092fb428a) --- daemon/call.c | 8 ++------ daemon/call_interfaces.c | 4 ++-- daemon/janus.c | 2 +- daemon/redis.c | 7 ++++++- include/call.h | 2 +- t/test-stats.c | 4 ++-- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index 253a41043..74b96bc29 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -3804,7 +3804,7 @@ static struct call *call_create(const str *callid) { } /* returns call with master_lock held in W */ -struct call *call_get_or_create(const str *callid, bool foreign, bool exclusive) { +struct call *call_get_or_create(const str *callid, bool exclusive) { struct call *c; restart: @@ -3824,10 +3824,6 @@ restart: g_hash_table_insert(rtpe_callhash, &c->callid, obj_get(c)); RTPE_GAUGE_INC(total_sessions); - bf_set_clear(&c->call_flags, CALL_FLAG_FOREIGN, foreign); - - statistics_update_foreignown_inc(c); - rwlock_lock_w(&c->master_lock); rwlock_unlock_w(&rtpe_callhash_lock); @@ -3906,7 +3902,7 @@ struct call *call_get(const str *callid) { /* returns call with master_lock held in W, or possibly NULL iff opmode == OP_ANSWER */ struct call *call_get_opmode(const str *callid, enum call_opmode opmode) { if (opmode == OP_OFFER) - return call_get_or_create(callid, false, false); + return call_get_or_create(callid, false); return call_get(callid); } diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 7d1488cf7..e2485deb2 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -2019,7 +2019,7 @@ static const char *call_offer_answer_ng(struct ng_buffer *ngbuf, bencode_item_t goto out; } - call = call_get_or_create(&flags.call_id, false, false); + call = call_get_or_create(&flags.call_id, false); } errstr = "Unknown call-id"; @@ -3331,7 +3331,7 @@ const char *call_publish_ng(struct ng_buffer *ngbuf, bencode_item_t *input, benc if (sdp_streams(&parsed, &streams, &flags)) return "Incomplete SDP specification"; - call = call_get_or_create(&flags.call_id, false, false); + call = call_get_or_create(&flags.call_id, false); if (trickle_ice_update(ngbuf, call, &flags, &streams)) return NULL; diff --git a/daemon/janus.c b/daemon/janus.c index ca6f02a81..95323a8a6 100644 --- a/daemon/janus.c +++ b/daemon/janus.c @@ -208,7 +208,7 @@ static const char *janus_videoroom_create(struct janus_session *session, struct continue; room->call_id.s = janus_call_id(room_id); room->call_id.len = strlen(room->call_id.s); - struct call *call = call_get_or_create(&room->call_id, false, true); + struct call *call = call_get_or_create(&room->call_id, true); if (!call) { ilog(LOG_WARN, "Call with reserved Janus ID '" STR_FORMAT "' already exists", STR_FMT(&room->call_id)); diff --git a/daemon/redis.c b/daemon/redis.c index d95423ada..4c295ed07 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -1982,7 +1982,7 @@ static void json_restore_call(struct redis *r, const str *callid, bool foreign) goto err1; - c = call_get_or_create(callid, foreign, false); + c = call_get_or_create(callid, false); err = "failed to create call struct"; if (!c) goto err1; @@ -2086,6 +2086,11 @@ static void json_restore_call(struct redis *r, const str *callid, bool foreign) recording_start(c, s.s, NULL); } + // force-clear foreign flag (could have been set through call_flags), then + // set it to what we want, updating the statistics if needed + CALL_CLEAR(c, FOREIGN); + call_make_own_foreign(c, foreign); + err = NULL; err8: diff --git a/include/call.h b/include/call.h index 315975f07..575ed4a4d 100644 --- a/include/call.h +++ b/include/call.h @@ -730,7 +730,7 @@ void call_subscription_free(void *); void call_subscriptions_clear(GQueue *q); -struct call *call_get_or_create(const str *callid, bool foreign, bool exclusive); +struct call *call_get_or_create(const str *callid, bool exclusive); struct call *call_get_opmode(const str *callid, enum call_opmode opmode); void call_make_own_foreign(struct call *c, bool foreign); int call_get_mono_dialogue(struct call_subscription *dialogue[2], struct call *call, const str *fromtag, diff --git a/t/test-stats.c b/t/test-stats.c index 7dc80cac8..4f19c538b 100644 --- a/t/test-stats.c +++ b/t/test-stats.c @@ -4304,9 +4304,9 @@ int main(void) { const str callid1 = STR_CONST_INIT("test1"); const str callid2 = STR_CONST_INIT("test2"); - struct call *call1 = call_get_or_create(&callid1, false, true); + struct call *call1 = call_get_or_create(&callid1, true); struct call_monologue *ml1 = call_get_or_create_monologue(call1, &callid1); - struct call *call2 = call_get_or_create(&callid2, false, true); + struct call *call2 = call_get_or_create(&callid2, true); struct call_monologue *ml2 = call_get_or_create_monologue(call2, &callid2); call1->created = ml1->started = (struct timeval) {157,0}; call2->created = ml2->started = (struct timeval) {57,0};