[asterisk-commits] bbryant: branch bbryant/iax2_rotation r115550 - in /team/bbryant/iax2_rotatio...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 8 10:14:21 CDT 2008


Author: bbryant
Date: Thu May  8 10:14:21 2008
New Revision: 115550

URL: http://svn.digium.com/view/asterisk?view=rev&rev=115550
Log:
Update the development branch for iax2 rotation.

Modified:
    team/bbryant/iax2_rotation/channels/chan_iax2.c
    team/bbryant/iax2_rotation/main/sched.c

Modified: team/bbryant/iax2_rotation/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/bbryant/iax2_rotation/channels/chan_iax2.c?view=diff&rev=115550&r1=115549&r2=115550
==============================================================================
--- team/bbryant/iax2_rotation/channels/chan_iax2.c (original)
+++ team/bbryant/iax2_rotation/channels/chan_iax2.c Thu May  8 10:14:21 2008
@@ -3723,9 +3723,14 @@
 static int iax2_start_transfer(unsigned short callno0, unsigned short callno1, int mediaonly)
 {
 	int res;
+	int call0enc; /*!< Is callno0 encrypted? */
+	int call1enc; /*!< Is callno1 encrypted? */
 	struct iax_ie_data ied0;
 	struct iax_ie_data ied1;
 	unsigned int transferid = (unsigned int)ast_random();
+
+	call0enc = (ast_test_flag(iaxs[callno0], IAX_ENCRYPTED) && ast_test_flag(iaxs[callno0], IAX_KEYPOPULATED));
+	call1enc = (ast_test_flag(iaxs[callno1], IAX_ENCRYPTED) && ast_test_flag(iaxs[callno1], IAX_KEYPOPULATED));
 
 	memset(&ied0, 0, sizeof(ied0));
 	iax_ie_append_addr(&ied0, IAX_IE_APPARENT_ADDR, &iaxs[callno1]->addr);
@@ -3737,9 +3742,13 @@
 	iax_ie_append_short(&ied1, IAX_IE_CALLNO, iaxs[callno0]->peercallno);
 	iax_ie_append_int(&ied1, IAX_IE_TRANSFERID, transferid);
 	
-	if ((ast_test_flag(iaxs[callno0], IAX_ENCRYPTED) && ast_test_flag(iaxs[callno0], IAX_KEYPOPULATED)) &&
-		(ast_test_flag(iaxs[callno1], IAX_ENCRYPTED) && ast_test_flag(iaxs[callno1], IAX_KEYPOPULATED))) {
+	if (call0enc && call1enc) {
 		iax2_send_rotate_transfer(iaxs[callno0], iaxs[callno1]);
+	} else if (call0enc || call1enc) {
+		ast_set_flag(iaxs[callno0], IAX_NOTRANSFER);
+		ast_set_flag(iaxs[callno1], IAX_NOTRANSFER);
+		return 0; /* If only one end is encrypted, don't attempt a transfer */
+		/* return 0 so that no errors show up from this */
 	}
 
 	res = send_command(iaxs[callno0], AST_FRAME_IAX, IAX_COMMAND_TXREQ, 0, ied0.buf, ied0.pos, -1);
@@ -4574,26 +4583,24 @@
 {
 	struct MD5Context md5;
 	unsigned char digest[16];
-	char dgststr[33] = "", *tmp;
+	char dgststr[33] = ""; //, *tmp;
 	int i;
 
 	MD5Init(&md5);
 	MD5Update(&md5, (unsigned char *)ies->challenge, strlen(ies->challenge));
 	MD5Final(digest, &md5);
 
+#if 0
 	for (tmp = dgststr, i = 0; i < 16; i++, tmp += 2)
 		snprintf(tmp, 3, "%02x", digest[i]);
-
-//	ast_log(LOG_NOTICE, "iax2_rotate: challenge (%d) == '%s'\n", (int)strlen(ies->challenge), ies->challenge);
-
-	ast_log(LOG_NOTICE, "iax2_rotate [%d]: rotating %s to new key '%s'\n", pvt->callno, (subclass == IAX_COMMAND_RTENC) ? "dcx" : "ecx", dgststr);
+#endif
 
 	if (subclass == IAX_COMMAND_RTENC) {
 		ast_aes_decrypt_key(digest, &pvt->dcx);
 	} else if (subclass == IAX_COMMAND_RTDEC) {
 		ast_aes_encrypt_key(digest, &pvt->ecx);
 	} else {
-		ast_log(LOG_ERROR, "iax2_rotate: invalid IAX_COMMAND = %d\n", subclass);
+		ast_log(LOG_WARNING, "iax2_rotate: invalid IAX_COMMAND = %d\n", subclass);
 		return -1;
 	}
 
@@ -4615,13 +4622,6 @@
 
 	iax_ie_append_str(&ied, IAX_IE_CHALLENGE, challenge);
 
-	if (send_command(pvt0, AST_FRAME_IAX, IAX_COMMAND_RTENC, 0, ied.buf, ied.pos, -1) ||
-		send_command(pvt0, AST_FRAME_IAX, IAX_COMMAND_RTDEC, 0, ied.buf, ied.pos, -1) ||
-		send_command(pvt1, AST_FRAME_IAX, IAX_COMMAND_RTENC, 0, ied.buf, ied.pos, -1) ||
-		send_command(pvt1, AST_FRAME_IAX, IAX_COMMAND_RTDEC, 0, ied.buf, ied.pos, -1))
-		return -1;
-
-	
 	MD5Init(&md5);
 	MD5Update(&md5, (unsigned char *)challenge, strlen(challenge));
 	MD5Final(digest, &md5);
@@ -4631,9 +4631,24 @@
 
 	ast_log(LOG_NOTICE, "iax2_send_rotate_transfer: challenge (%d) == '%s'\n", (int)strlen(challenge), challenge);
 
+	if (send_command(pvt0, AST_FRAME_IAX, IAX_COMMAND_RTENC, 0, ied.buf, ied.pos, -1))
+		return -1;
+
 	ast_aes_encrypt_key(digest, &pvt0->ecx);
+
+	if (send_command(pvt0, AST_FRAME_IAX, IAX_COMMAND_RTDEC, 0, ied.buf, ied.pos, -1))
+		return -1;
+
 	ast_aes_decrypt_key(digest, &pvt0->dcx);
+
+	if (send_command(pvt1, AST_FRAME_IAX, IAX_COMMAND_RTENC, 0, ied.buf, ied.pos, -1))
+		return -1;
+
 	ast_aes_encrypt_key(digest, &pvt1->ecx);
+
+	if (send_command(pvt1, AST_FRAME_IAX, IAX_COMMAND_RTDEC, 0, ied.buf, ied.pos, -1))
+		return -1;
+
 	ast_aes_decrypt_key(digest, &pvt1->dcx);
 
 	return 0;
@@ -4646,14 +4661,10 @@
 	struct MD5Context md5;
 	char challenge[11] = "";
 	unsigned char digest[16];
-	char dgststr[33] = "", *tmp;
+	char dgststr[33] = ""; //, *tmp;
 	int res = 0, i;
 
-	//ast_sched_del(sched, p->rotateid);
-	ast_log(LOG_ERROR, " -- iax2_send_rotate: START SCHEDULER! %d\n",
-		(pvt->rotateid = iax2_sched_add(sched, 200, iax2_send_rotate, pvt))
-	);
-//	pvt->rotateid = iax2_sched_add(sched, ((ast_random() % 4) + 2) * 3600000, iax2_send_rotate, pvt);
+	pvt->rotateid = iax2_sched_add(sched, (ast_random() % 180001) + 120000, iax2_send_rotate, pvt);
 
 	memset(&ied, 0, sizeof(ied));
 
@@ -4666,10 +4677,10 @@
 	MD5Update(&md5, (unsigned char *)challenge, strlen(challenge));
 	MD5Final(digest, &md5);
 
-	for (tmp = dgststr, i = 0; i < 16; i++, tmp += 2)
-		snprintf(tmp, 3, "%02x", digest[i]);
-
-	ast_log(LOG_NOTICE, "iax2_send_rotate: challenge (%d) == '%s'\n", (int)strlen(challenge), challenge);
+//	for (tmp = dgststr, i = 0; i < 16; i++, tmp += 2)
+//		snprintf(tmp, 3, "%02x", digest[i]);
+
+//	ast_log(LOG_NOTICE, "iax2_send_rotate: challenge (%d) == '%s'\n", (int)strlen(challenge), challenge);
 
 //	ast_log(LOG_NOTICE, "iax2_send_rotate: sending new ecx key '%s'\n", dgststr);
 
@@ -10021,7 +10032,8 @@
 		pthread_testcancel();
 
 		count = ast_sched_runq(sched);
-//		if (count >= 20)
+
+		if (count >= 20)
 			ast_debug(1, "chan_iax2: ast_sched_runq ran %d scheduled tasks all at once\n", count);
 	}
 

Modified: team/bbryant/iax2_rotation/main/sched.c
URL: http://svn.digium.com/view/asterisk/team/bbryant/iax2_rotation/main/sched.c?view=diff&rev=115550&r1=115549&r2=115550
==============================================================================
--- team/bbryant/iax2_rotation/main/sched.c (original)
+++ team/bbryant/iax2_rotation/main/sched.c Thu May  8 10:14:21 2008
@@ -27,7 +27,7 @@
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
-#if defined(DEBUG_SCHEDULER) || !defined(DEBUG_SCHEDULER)
+#ifdef DEBUG_SCHEDULER
 #define DEBUG(a) do { \
 	if (option_debug) \
 		DEBUG_M(a) \
@@ -280,8 +280,6 @@
 	if (!when) {
 		ast_log(LOG_NOTICE, "Scheduled event in 0 ms?\n");
 		return -1;
-	} else {
-		ast_log(LOG_NOTICE, "Scheduled event in %d ms\n", when);
 	}
 	ast_mutex_lock(&con->lock);
 	if ((tmp = sched_alloc(con))) {




More information about the asterisk-commits mailing list