don't retry failed de-register. delete_failed_deregistrations option

sayer/1.4-spce2.6
Stefan Sayer 15 years ago committed by Stefan Sayer
parent 526678f013
commit d56e0fec7f

@ -48,6 +48,7 @@ unsigned int DBRegAgent::ratelimit_per = 0;
bool DBRegAgent::ratelimit_slowstart = false;
bool DBRegAgent::delete_removed_registrations = true;
bool DBRegAgent::delete_failed_deregistrations = false;
bool DBRegAgent::save_contacts = true;
bool DBRegAgent::db_read_contact = false;
string DBRegAgent::contact_hostport;
@ -136,6 +137,9 @@ int DBRegAgent::onLoad()
delete_removed_registrations =
cfg.getParameter("delete_removed_registrations", "yes") == "yes";
delete_failed_deregistrations =
cfg.getParameter("delete_failed_deregistrations", "no") == "yes";
save_contacts =
cfg.getParameter("save_contacts", "yes") == "yes";
@ -449,8 +453,9 @@ void DBRegAgent::updateRegistration(long subscriber_id,
return;
}
bool need_reregister = it->second->getInfo().domain != realm ||
it->second->getInfo().user != user;
bool need_reregister = it->second->getInfo().domain != realm
|| it->second->getInfo().user != user;
string old_realm = it->second->getInfo().domain;
string old_user = it->second->getInfo().user;
it->second->setRegistrationInfo(SIPRegistrationInfo(realm, user,
@ -568,7 +573,7 @@ void DBRegAgent::onRegistrationActionEvent(RegistrationActionEvent* reg_action_e
if (!it->second->doRegistration()) {
updateDBRegistration(ProcessorDBConnection,
reg_action_ev->subscriber_id,
480, "unable to send request",
480, ERR_REASON_UNABLE_TO_SEND_REQUEST,
true, REG_STATUS_FAILED);
if (error_retry_interval) {
// schedule register-refresh after error_retry_interval
@ -590,14 +595,24 @@ void DBRegAgent::onRegistrationActionEvent(RegistrationActionEvent* reg_action_e
reg_action_ev->subscriber_id);
} else {
if (!it->second->doUnregister()) {
updateDBRegistration(ProcessorDBConnection,
reg_action_ev->subscriber_id,
480, "unable to send request",
true, REG_STATUS_TO_BE_REMOVED);
if (error_retry_interval) {
// schedule register-refresh after error_retry_interval
setRegistrationTimer(reg_action_ev->subscriber_id, error_retry_interval,
RegistrationActionEvent::Deregister);
if (delete_removed_registrations && delete_failed_deregistrations) {
DBG("sending de-Register failed - deleting registration %i "
"(delete_failed_deregistrations=yes)\n", reg_action_ev->subscriber_id);
deleteDBRegistration(reg_action_ev->subscriber_id, ProcessorDBConnection);
} else {
DBG("failed sending de-register, updating DB with REG_STATUS_TO_BE_REMOVED "
ERR_REASON_UNABLE_TO_SEND_REQUEST "for subscriber %i\n",
reg_action_ev->subscriber_id);
updateDBRegistration(ProcessorDBConnection,
reg_action_ev->subscriber_id,
480, ERR_REASON_UNABLE_TO_SEND_REQUEST,
true, REG_STATUS_TO_BE_REMOVED);
// don't re-try de-registrations if sending failed
// if (error_retry_interval) {
// // schedule register-refresh after error_retry_interval
// setRegistrationTimer(reg_action_ev->subscriber_id, error_retry_interval,
// RegistrationActionEvent::Deregister);
// }
}
}
}
@ -753,27 +768,34 @@ void DBRegAgent::onSipReplyEvent(AmSipReplyEvent* ev) {
bool auth_pending = false;
if (ev->reply.code >= 300) {
// auth response codes
// REGISTER or de-REGISTER failed
if ((ev->reply.code == 401 || ev->reply.code == 407) &&
// auth response codes
// processing reply triggered sending request: resent by auth
(cseq_before != registration->getDlg()->cseq)) {
DBG("received negative reply, but still in pending state (auth).\n");
auth_pending = true;
} else {
// registration failed - mark in DB
DBG("registration failed - mark in DB\n");
update_status = true;
status = REG_STATUS_FAILED;
if (error_retry_interval) {
if (registration->getUnregistering()) {
// schedule deregister after error_retry_interval
setRegistrationTimer(subscriber_id, error_retry_interval,
RegistrationActionEvent::Deregister);
} else {
if (!registration->getUnregistering()) {
// REGISTER failed - mark in DB
DBG("registration failed - mark in DB\n");
update_status = true;
status = REG_STATUS_FAILED;
if (error_retry_interval) {
// schedule register-refresh after error_retry_interval
setRegistrationTimer(subscriber_id, error_retry_interval,
RegistrationActionEvent::Register);
}
} else {
// de-REGISTER failed
if (delete_removed_registrations && delete_failed_deregistrations) {
DBG("de-Register failed - deleting registration %ld "
"(delete_failed_deregistrations=yes)\n", subscriber_id);
delete_status = true;
} else {
update_status = true;
status = REG_STATUS_TO_BE_REMOVED;
}
}
}
} else if (ev->reply.code >= 200) {
@ -1042,6 +1064,7 @@ void DBRegAgent::DIupdateRegistration(int subscriber_id, const string& user,
DBG("DI method: updateRegistration(%i, %s, %s, %s)\n",
subscriber_id, user.c_str(),
pass.c_str(), realm.c_str());
updateRegistration(subscriber_id, user, pass, realm, contact);
ret.push(200);
ret.push("OK");

@ -68,6 +68,8 @@ using std::queue;
#define RegistrationActionEventID 117
#define ERR_REASON_UNABLE_TO_SEND_REQUEST "unable to send request"
struct RegistrationActionEvent : public AmEvent {
enum RegAction { Register=0, Deregister };
@ -129,6 +131,7 @@ class DBRegAgent
static bool ratelimit_slowstart;
static bool delete_removed_registrations;
static bool delete_failed_deregistrations;
static bool save_contacts;
static bool db_read_contact;

@ -90,3 +90,10 @@ joined_query="select subscribers.subscriber_id as subscriber_id, subscribers.use
# default: yes
#
#delete_removed_registrations=no
# delete_failed_deregistrations=yes : delete failed de-registrations from registrations
# table in DB? (otherwise they will stay with STATUS_TO_BE_REMOVED)
# only applicable if delete_removed_registrations=yes
# default: no
#
#delete_failed_deregistrations=no

@ -105,6 +105,15 @@ CREATE TABLE IF NOT EXISTS `subscribers` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
Error handling
--------------
If a REGISTER or de-REGISTER could not be sent, the status in the database
is set to 480 "unable to send request".
Failed REGISTERs are re-tried after retry_interval. Failed de-REGISTERs are
not retried.
Todo
----
o (optionally) create DB entries on DI functions

Loading…
Cancel
Save