Module: kamailio
Branch: master
Commit: 596dd912af90a31909b43a675f51c4f163b6b2f0
URL: 
https://github.com/kamailio/kamailio/commit/596dd912af90a31909b43a675f51c4f163b6b2f0

Author: Stefan Mititelu <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2026-05-11T21:32:09+02:00

dmq_usrloc: add Last Write Win logic

---

Modified: src/modules/dmq_usrloc/usrloc_sync.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/596dd912af90a31909b43a675f51c4f163b6b2f0.diff
Patch: 
https://github.com/kamailio/kamailio/commit/596dd912af90a31909b43a675f51c4f163b6b2f0.patch

---

diff --git a/src/modules/dmq_usrloc/usrloc_sync.c 
b/src/modules/dmq_usrloc/usrloc_sync.c
index d17b5836275..9bcaf2cdf48 100644
--- a/src/modules/dmq_usrloc/usrloc_sync.c
+++ b/src/modules/dmq_usrloc/usrloc_sync.c
@@ -90,6 +90,18 @@ static int add_contact(str aor, ucontact_info_t *ci)
                res = dmq_ul.get_urecord_by_ruid(
                                _d, dmq_ul.get_aorhash(&aor), &ci->ruid, &r, 
&c);
                if(res == 0) {
+                       /* LWW: skip update if local contact is newer */
+                       if(ci->last_modified > 0 && c->last_modified > 
ci->last_modified) {
+                               LM_DBG("LWW: skipping stale update for 
contact=[%.*s] "
+                                          "ruid=[%.*s] "
+                                          "local=%u incoming=%u\n",
+                                               c->c.len, c->c.s, c->ruid.len, 
c->ruid.s,
+                                               (unsigned int)c->last_modified,
+                                               (unsigned 
int)ci->last_modified);
+                               dmq_ul.release_urecord(r);
+                               dmq_ul.unlock_udomain(_d, &aor);
+                               return 0;
+                       }
                        LM_DBG("Found contact\n");
                        dmq_ul.update_ucontact(r, c, ci);
                        LM_DBG("Release record\n");
@@ -115,8 +127,18 @@ static int add_contact(str aor, ucontact_info_t *ci)
                        contact.len = ci->c->len;
                        dmq_ul.insert_ucontact(r, &contact, ci, &c);
                } else if(res == 0) {
-                       LM_DBG("Found contact\n");
-                       dmq_ul.update_ucontact(r, c, ci);
+                       /* LWW: skip update if local contact is newer */
+                       if(ci->last_modified > 0 && c->last_modified > 
ci->last_modified) {
+                               LM_DBG("LWW: skipping stale update for 
contact=[%.*s] "
+                                          "ruid=[%.*s] "
+                                          "local=%u incoming=%u\n",
+                                               c->c.len, c->c.s, c->ruid.len, 
c->ruid.s,
+                                               (unsigned int)c->last_modified,
+                                               (unsigned 
int)ci->last_modified);
+                       } else {
+                               LM_DBG("Found contact\n");
+                               dmq_ul.update_ucontact(r, c, ci);
+                       }
                }
        } else {
                LM_DBG("'%.*s' Not found in usrloc\n", aor.len, ZSW(aor.s));
@@ -162,6 +184,17 @@ static int delete_contact(str aor, ucontact_info_t *ci)
                LM_DBG("AOR/Contact [%.*s] not found\n", aor.len, aor.s);
                return -1;
        }
+       /* LWW: skip delete if local contact is newer */
+       if(ci->last_modified > 0 && c->last_modified > ci->last_modified) {
+               LM_DBG("LWW: skipping stale delete for contact=[%.*s] 
ruid=[%.*s] "
+                          "local=%u incoming=%u\n",
+                               c->c.len, c->c.s, c->ruid.len, c->ruid.s,
+                               (unsigned int)c->last_modified,
+                               (unsigned int)ci->last_modified);
+               dmq_ul.release_urecord(r);
+               dmq_ul.unlock_udomain(_d, &aor);
+               return 0;
+       }
        if(dmq_ul.delete_ucontact(r, c) != 0) {
                dmq_ul.unlock_udomain(_d, &aor);
                LM_WARN("could not delete contact\n");

_______________________________________________
Kamailio - Development Mailing List -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to