[asterisk-commits] oej: branch oej/reinvite-racing r91542 - /team/oej/reinvite-racing/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Dec 6 14:35:47 CST 2007


Author: oej
Date: Thu Dec  6 14:35:47 2007
New Revision: 91542

URL: http://svn.digium.com/view/asterisk?view=rev&rev=91542
Log:
Trying to handle 491 on re-invites

Modified:
    team/oej/reinvite-racing/channels/chan_sip.c

Modified: team/oej/reinvite-racing/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/reinvite-racing/channels/chan_sip.c?view=diff&rev=91542&r1=91541&r2=91542
==============================================================================
--- team/oej/reinvite-racing/channels/chan_sip.c (original)
+++ team/oej/reinvite-racing/channels/chan_sip.c Thu Dec  6 14:35:47 2007
@@ -986,6 +986,7 @@
 	
 	int maxtime;				/*!< Max time for first response */
 	int initid;				/*!< Auto-congest ID if appropriate (scheduler) */
+	int waitid;				/*!< Wait ID for scheduler after 491 or other delays */
 	int autokillid;				/*!< Auto-kill ID (scheduler) */
 	enum transfermodes allowtransfer;	/*!< REFER: restriction scheme */
 	struct sip_refer *refer;		/*!< REFER: SIP transfer data structure */
@@ -1326,7 +1327,6 @@
 static void *do_monitor(void *data);
 static int restart_monitor(void);
 static int sip_send_mwi_to_peer(struct sip_peer *peer);
-static void sip_destroy(struct sip_pvt *p);
 static int sip_addrcmp(char *name, struct sockaddr_in *sin);	/* Support for peer matching */
 static int sip_refer_allocate(struct sip_pvt *p);
 static void ast_quiet_chan(struct ast_channel *chan);
@@ -3043,6 +3043,8 @@
 		ast_extension_state_del(p->stateid, NULL);
 	if (p->initid > -1)
 		ast_sched_del(sched, p->initid);
+	if (p->waitid > -1)
+		ast_sched_del(sched, p->waitid);
 	if (p->autokillid > -1)
 		ast_sched_del(sched, p->autokillid);
 
@@ -11905,6 +11907,18 @@
 	}
 }
 
+/*! \brief Reset the NEEDREINVITE flag after waiting when we get 491 on a Re-invite
+	to avoid race conditions between asterisk servers */
+static int sip_reinvite_retry(const void *data) 
+{
+	struct sip_pvt *p = (struct sip_pvt *) data;
+
+	ast_set_flag(&p->flags[0], SIP_NEEDREINVITE);	
+	p->waitid = -1;
+	return 0;
+}
+
+
 /*! \brief Handle SIP response to INVITE dialogue */
 static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno)
 {
@@ -12205,9 +12219,18 @@
 			/* We should support the retry-after at some point */
 		/* At this point, we treat this as a congestion */
 		xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE);
-		if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE))
-			ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
-		ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);	
+		if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE)) {
+			if (p->owner->_state != AST_STATE_UP) {
+				ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
+				ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);	
+			} else {
+				/* This is a re-invite that failed. */
+				/* Reset the flag after a while 
+				   The 5 should be random really, but let's test this now.
+				 */
+				p->waitid = ast_sched_add(sched, 5, sip_reinvite_retry, p); 
+			}
+		}
 		break;
 
 	case 501: /* Not implemented */




More information about the asterisk-commits mailing list