[asterisk-commits] trunk r35264 - /trunk/channels/chan_iax2.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Jun 21 09:50:25 MST 2006


Author: file
Date: Wed Jun 21 11:50:24 2006
New Revision: 35264

URL: http://svn.digium.com/view/asterisk?rev=35264&view=rev
Log:
Fix timing issue (race) with poke/pong for very close peers that can cause a peer to be declared unreachable (issue #7396 reported by stevedavies)

Modified:
    trunk/channels/chan_iax2.c

Modified: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?rev=35264&r1=35263&r2=35264&view=diff
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Wed Jun 21 11:50:24 2006
@@ -336,7 +336,7 @@
 
 	/* Qualification */
 	int callno;					/*!< Call number of POKE request */
-	int pokeexpire;					/*!< When to expire poke */
+	int pokeexpire;					/*!< Scheduled qualification-related task (ie iax2_poke_peer_s or iax2_poke_noanswer) */
 	int lastms;					/*!< How long last response took (in ms), or -1 for no response */
 	int maxms;					/*!< Max ms we will accept for the host to be up, 0 to not monitor */
 
@@ -7143,18 +7143,21 @@
 					else					
 						peer->historicms = iaxs[fr->callno]->pingtime;
 
+					/* Remove scheduled iax2_poke_noanswer */
 					if (peer->pokeexpire > -1)
 						ast_sched_del(sched, peer->pokeexpire);
-					send_command_immediate(iaxs[fr->callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr->ts, NULL, 0,fr->iseqno);
-					iax2_destroy_nolock(fr->callno);
-					peer->callno = 0;
-					/* Try again eventually */
-					if (option_debug)
-						ast_log(LOG_DEBUG, "Peer lastms %d, historicms %d, maxms %d\n", peer->lastms, peer->historicms, peer->maxms);
+					/* Schedule the next cycle */
 					if ((peer->lastms < 0)  || (peer->historicms > peer->maxms)) 
 						peer->pokeexpire = ast_sched_add(sched, peer->pokefreqnotok, iax2_poke_peer_s, peer);
 					else
 						peer->pokeexpire = ast_sched_add(sched, peer->pokefreqok, iax2_poke_peer_s, peer);
+					/* and finally send the ack */
+					send_command_immediate(iaxs[fr->callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr->ts, NULL, 0,fr->iseqno);
+					/* And wrap up the qualify call */
+					iax2_destroy_nolock(fr->callno);
+					peer->callno = 0;
+					if (option_debug)
+						ast_log(LOG_DEBUG, "Peer %s: got pong, lastms %d, historicms %d, maxms %d\n", peer->name, peer->lastms, peer->historicms, peer->maxms);
 				}
 				break;
 			case IAX_COMMAND_LAGRQ:
@@ -7955,7 +7958,7 @@
 {
 	if (!peer->maxms || !peer->addr.sin_addr.s_addr) {
 		/* IF we have no IP, or this isn't to be monitored, return
-		  imeediately after clearing things out */
+		  immediately after clearing things out */
 		peer->lastms = 0;
 		peer->historicms = 0;
 		peer->pokeexpire = -1;
@@ -7975,18 +7978,24 @@
 		ast_log(LOG_WARNING, "Unable to allocate call for poking peer '%s'\n", peer->name);
 		return -1;
 	}
+
+	/* Speed up retransmission times for this qualify call */
+	iaxs[peer->callno]->pingtime = peer->maxms / 4 + 1;
+	iaxs[peer->callno]->peerpoke = peer;
+	
+	/* Remove any pending pokeexpire task */
 	if (peer->pokeexpire > -1)
 		ast_sched_del(sched, peer->pokeexpire);
-	/* Speed up retransmission times */
-	iaxs[peer->callno]->pingtime = peer->maxms / 4 + 1;
-	iaxs[peer->callno]->peerpoke = peer;
-	send_command(iaxs[peer->callno], AST_FRAME_IAX, IAX_COMMAND_POKE, 0, NULL, 0, -1);
-	
+
+	/* Queue up a new task to handle no reply */
 	/* If the host is already unreachable then use the unreachable interval instead */
 	if (peer->lastms < 0) {
 		peer->pokeexpire = ast_sched_add(sched, peer->pokefreqnotok, iax2_poke_noanswer, peer);
 	} else
 		peer->pokeexpire = ast_sched_add(sched, DEFAULT_MAXMS * 2, iax2_poke_noanswer, peer);
+
+	/* And send the poke */
+	send_command(iaxs[peer->callno], AST_FRAME_IAX, IAX_COMMAND_POKE, 0, NULL, 0, -1);
 
 	return 0;
 }



More information about the asterisk-commits mailing list