diff --git a/apps/sbc/RegisterCache.cpp b/apps/sbc/RegisterCache.cpp index c4a52eb3..61ec2c05 100644 --- a/apps/sbc/RegisterCache.cpp +++ b/apps/sbc/RegisterCache.cpp @@ -49,14 +49,14 @@ void AorHash::gbc(long int now, auto& binding = reg_it->second; - if (binding.reg_expire <= now) { + if (binding.get_expire() <= now) { alias_list.push_back(binding.alias); AorEntry::iterator del_it = reg_it++; DBG("delete binding: '%s' -> '%s' (%li <= %li)", del_it->first.c_str(), binding.alias.c_str(), - binding.reg_expire, now); + binding.get_expire(), now); it->second.erase(del_it); continue; @@ -341,7 +341,7 @@ void _RegisterCache::update(const string& alias, long int reg_expires, } } // and update binding - binding_it->second.reg_expire = reg_expires; + reg_cache_ht.set_expire(aor_e_it, binding_it, reg_expires); auto alias_e_it = id_idx.find(alias); // if no alias map entry, insert a new one @@ -445,7 +445,7 @@ void _RegisterCache::update(long int reg_expires, const AliasEntry& alias_update uri.c_str(), binding_it->second.alias.c_str()); } // and update binding - binding_it->second.reg_expire = reg_expires; + reg_cache_ht.set_expire(aor_e_it, binding_it, reg_expires); lock_guard _id_l(id_idx); @@ -793,7 +793,7 @@ bool _RegisterCache::throttleRegister(RegisterCacheCtx& ctx, const string& uri = contact_it->uri_str(); if(!getAlias(ctx.from_aor,uri,req.remote_ip,reg_binding) || - !reg_binding.reg_expire) { + !reg_binding.get_expire()) { DBG("!getAlias(%s,%s,...) || !reg_binding.reg_expire", ctx.from_aor.c_str(),uri.c_str()); return false; // fwd @@ -804,8 +804,8 @@ bool _RegisterCache::throttleRegister(RegisterCacheCtx& ctx, contact_expires += now.tv_sec; if(contact_expires + 4 /* 4 seconds buffer */ - >= reg_binding.reg_expire) { - DBG("%li + 4 >= %li",contact_expires,reg_binding.reg_expire); + >= reg_binding.get_expire()) { + DBG("%li + 4 >= %li",contact_expires,reg_binding.get_expire()); return false; // fwd } diff --git a/apps/sbc/RegisterCache.h b/apps/sbc/RegisterCache.h index d9fe4fe6..b937f64f 100644 --- a/apps/sbc/RegisterCache.h +++ b/apps/sbc/RegisterCache.h @@ -33,22 +33,35 @@ using std::unique_ptr; struct RegBinding { +private: // Absolute timestamp representing // the expiration timer at the // registrar side long int reg_expire; +public: // unique-id used as contact user toward the registrar string alias; RegBinding() : reg_expire(0) {} + + long int get_expire() const { + return reg_expire; + } + + friend class AorEntry; }; // Contact-URI/Public-IP -> RegBinding class AorEntry : public unordered_map { + void set_expire(const iterator& it, long int expire) { + it->second.reg_expire = expire; + } + + friend class AorHash; }; struct AliasEntry @@ -141,6 +154,10 @@ class AorHash : public unordered_hash_map { public: + void set_expire(const iterator& aor_it, const AorEntry::iterator& binding_it, long int expire) { + aor_it->second.set_expire(binding_it, expire); + } + /* Maintenance stuff */ void gbc(long int now, list& alias_list); diff --git a/apps/sbc/RegisterDialog.cpp b/apps/sbc/RegisterDialog.cpp index ab82a374..aee04971 100644 --- a/apps/sbc/RegisterDialog.cpp +++ b/apps/sbc/RegisterDialog.cpp @@ -204,7 +204,7 @@ int RegisterDialog::fixUacContacts(const AmSipRequest& req) if(!reg_cache_reply) continue; - if(is_a_dereg || !reg_binding.reg_expire) { // no contact with expires=0 + if(is_a_dereg || !reg_binding.get_expire()) { // no contact with expires=0 reg_cache_reply = false; } @@ -220,12 +220,12 @@ int RegisterDialog::fixUacContacts(const AmSipRequest& req) DBG("min_reg_expire = %u", min_reg_expire); DBG("max_ua_expire = %u", max_ua_expire); DBG("contact_expires = %lu", contact_expires); - DBG("reg_expires = %li", reg_binding.reg_expire - now.tv_sec); + DBG("reg_expires = %li", reg_binding.get_expire() - now.tv_sec); contact_expires += now.tv_sec; if(contact_expires + 4 /* 4 seconds buffer */ - >= reg_binding.reg_expire) { + >= reg_binding.get_expire()) { reg_cache_reply = false; continue; }