[asterisk-commits] bbryant: branch bbryant/iax2_rotation r127837 - in /team/bbryant/iax2_rotatio...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jul 3 15:20:31 CDT 2008
Author: bbryant
Date: Thu Jul 3 15:20:30 2008
New Revision: 127837
URL: http://svn.digium.com/view/asterisk?view=rev&rev=127837
Log:
Update iax2_rotation branch to try and fix automerge problem.
Modified:
team/bbryant/iax2_rotation/ (props changed)
team/bbryant/iax2_rotation/channels/chan_iax2.c
team/bbryant/iax2_rotation/channels/iax2-parser.c
team/bbryant/iax2_rotation/channels/iax2.h
Propchange: team/bbryant/iax2_rotation/
------------------------------------------------------------------------------
automerge = yes
Propchange: team/bbryant/iax2_rotation/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Thu Jul 3 15:20:30 2008
@@ -1,1 +1,1 @@
-/trunk:1-115613
+/trunk:1-116978
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=127837&r1=127836&r2=127837
==============================================================================
--- team/bbryant/iax2_rotation/channels/chan_iax2.c (original)
+++ team/bbryant/iax2_rotation/channels/chan_iax2.c Thu Jul 3 15:20:30 2008
@@ -432,6 +432,11 @@
struct sockaddr_in us; /*!< Who the server thinks we are */
struct ast_dnsmgr_entry *dnsmgr; /*!< DNS refresh manager */
AST_LIST_ENTRY(iax2_registry) entry;
+};
+
+struct iax2_transfer_wait {
+ int callnos[2], mediaonly;
+ unsigned int responses:2;
};
static AST_LIST_HEAD_STATIC(registrations, iax2_registry);
@@ -540,6 +545,11 @@
unsigned char aseqno;
/*! TODO explain */
int rotateid;
+ /*! TODO explain ... ... */
+ int pauserotate:1;
+ /*! TODO explain ... */
+ struct iax2_transfer_wait *transferwait;
+
AST_DECLARE_STRING_FIELDS(
/*! Peer name */
@@ -3733,7 +3743,7 @@
return &ast_null_frame;
}
-static char *iax2_send_rotate_transfer(struct chan_iax2_pvt *, struct chan_iax2_pvt *);
+static int iax2_send_rotate_transfer(struct chan_iax2_pvt *, struct chan_iax2_pvt *);
static void lock_both(unsigned short callno0, unsigned short callno1);
static void unlock_both(unsigned short callno0, unsigned short callno1);
@@ -3745,7 +3755,6 @@
struct iax_ie_data ied0;
struct iax_ie_data ied1;
unsigned int transferid = (unsigned int)ast_random();
- char *challenge = NULL;
#if 0
call0enc = ast_test_flag(iaxs[callno0], IAX_ENCRYPTED | IAX_KEYPOPULATED);
@@ -3755,6 +3764,41 @@
call1enc = iaxs[callno1]->encmethods;
lock_both(callno0, callno1);
+
+ if (call0enc & call1enc) {
+ if (!iaxs[callno0]->transferwait) {
+ if (!(iaxs[callno0]->transferwait = iaxs[callno1]->transferwait
+ = ast_calloc(1, sizeof(*iaxs[callno0]->transferwait)))) {
+ unlock_both(callno0, callno1);
+ return -1;
+ }
+
+ iaxs[callno0]->transferwait->callnos[0] = callno0;
+ iaxs[callno1]->transferwait->callnos[1] = callno1;
+ iaxs[callno0]->transferwait->mediaonly = mediaonly;
+ iaxs[callno0]->pauserotate =
+ iaxs[callno1]->pauserotate = 1;
+
+ if (send_command(iaxs[callno0], AST_FRAME_IAX, IAX_COMMAND_RTPAUSE, 0, NULL, 0, -1) ||
+ send_command(iaxs[callno1], AST_FRAME_IAX, IAX_COMMAND_RTPAUSE, 0, NULL, 0, -1)) {
+ unlock_both(callno0, callno1);
+ return -1;
+ }
+
+ unlock_both(callno0, callno1);
+ return 0;
+ }
+
+ if (iaxs[callno0]->transferwait->responses < 2) {
+ unlock_both(callno0, callno1);
+ return 0;
+ }
+
+ ast_free(iaxs[callno0]->transferwait);
+
+ iaxs[callno0]->transferwait =
+ iaxs[callno1]->transferwait = NULL;
+ }
ast_log(LOG_NOTICE, "iax2_start_transfer begin %d (%s) %d (%s)\n", call0enc, iaxs[callno0]->username, call1enc, iaxs[callno1]->username);
@@ -3771,14 +3815,12 @@
iax_ie_append_int(&ied1, IAX_IE_TRANSFERID, transferid);
if (call0enc & call1enc) {
- if (!(challenge = iax2_send_rotate_transfer(iaxs[callno0], iaxs[callno1])))
- return -1;
-
- iax_ie_append_str(&ied0, IAX_IE_CHALLENGE, challenge);
- iax_ie_append_str(&ied1, IAX_IE_CHALLENGE, challenge);
- ast_free(challenge);
-
- ast_log(LOG_NOTICE, "iax2_start_transfer: rotate_transfer returned with, %s\n", challenge);
+ if ((res = iax2_send_rotate_transfer(iaxs[callno0], iaxs[callno1]))) {
+ ast_log(LOG_ERROR, "!!! send_rotate_transfer returned with %d ... !!!", res);
+ return res;
+ }
+
+ ast_log(LOG_NOTICE, "send_rotate_transfer returned SUCCESSFULLY\n");
} else if (call0enc || call1enc) {
ast_set_flag(iaxs[callno0], IAX_NOTRANSFER);
ast_set_flag(iaxs[callno1], IAX_NOTRANSFER);
@@ -4653,30 +4695,38 @@
return res;
}
-//<<<<<<< .working
static int iax2_rotate(struct chan_iax2_pvt *pvt, int subclass, struct iax_ies *ies)
{
struct MD5Context md5;
unsigned char digest[16];
- //char dgststr[33] = ""; //, *tmp;
- //int i;
+ char dgststr[33] = ""; //, *tmp;
+ int i;
ast_log(LOG_NOTICE, " ...\n");
+
+// if (pvt->transferring) {
+// ast_log(LOG_WARNING, "..] Oops, we're transferring... iax2_rotate returning -1!!\n");
+// return -1;
+// }
MD5Init(&md5);
MD5Update(&md5, (unsigned char *)ies->challenge, strlen(ies->challenge));
MD5Final(digest, &md5);
-#if 0
+#if 1
for (tmp = dgststr, i = 0; i < 16; i++, tmp += 2)
snprintf(tmp, 3, "%02x", digest[i]);
#endif
switch (subclass) {
case IAX_COMMAND_RTENC:
+ ast_log(LOG_NOTICE, "..] (_RTENC) rotating decrypt key... challenge: '%s' digest: '%s'\n",
+ ies->challenge, dgststr);
ast_aes_decrypt_key(digest, &pvt->dcx);
break;
case IAX_COMMAND_RTDEC:
+ ast_log(LOG_NOTICE, "..] (_RTDEC) rotating encrypt key... challenge: '%s' digest: '%s'\n",
+ ies->challenge, dgststr);
ast_aes_encrypt_key(digest, &pvt->ecx);
break;
default:
@@ -4689,61 +4739,75 @@
#define TICK(s) ast_log(LOG_NOTICE, "%s\n", (s))
-static char *iax2_send_rotate_transfer(struct chan_iax2_pvt *pvt0, struct chan_iax2_pvt *pvt1)
+static int iax2_send_rotate_transfer(struct chan_iax2_pvt *pvt0, struct chan_iax2_pvt *pvt1)
{
struct iax_ie_data ied;
+ struct iax_ies ies;
struct MD5Context md5;
- char *challenge = NULL;
+ char challenge[11] = "";
unsigned char digest[16];
char dgststr[33] = "", *tmp;
- int i;
+ int ret, i;
TICK("start");
- if (!(challenge = ast_calloc(sizeof(char), 11)))
- goto error;
-
memset(&ied, 0, sizeof(ied));
- sprintf(challenge, "%010x", (int)ast_random());
+ sprintf(challenge, "%.*x", 10, (int)ast_random());
+
+ ast_log(LOG_NOTICE, "challenge (%d) '%s'", (int)strlen(challenge), challenge);
iax_ie_append_str(&ied, IAX_IE_CHALLENGE, challenge);
+ ies.challenge = challenge;
+
MD5Init(&md5);
- MD5Update(&md5, (unsigned char *)challenge, strlen(challenge));
+ MD5Update(&md5, (unsigned char *)ies.challenge, strlen(ies.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_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))
+ ast_log(LOG_NOTICE, "iax2_send_rotate_transfer: challenge (%d) == '%s' ... digest: '%s'\n",
+ (int)strlen(challenge), challenge, dgststr);
+
+ if (send_command(pvt0, AST_FRAME_IAX, IAX_COMMAND_RTENC, 0, ied.buf, ied.pos, -1)) {
+ ret = 1;
goto error;
-
- ast_aes_encrypt_key(digest, &pvt0->ecx);
-
- if (send_command(pvt0, AST_FRAME_IAX, IAX_COMMAND_RTDEC, 0, ied.buf, ied.pos, -1))
+ }
+
+ iax2_rotate(pvt0, IAX_COMMAND_RTDEC, &ies);
+// ast_aes_encrypt_key(digest, &pvt0->ecx);
+
+ if (send_command(pvt0, AST_FRAME_IAX, IAX_COMMAND_RTDEC, 0, ied.buf, ied.pos, -1)) {
+ ret = 2;
goto error;
-
- ast_aes_decrypt_key(digest, &pvt0->dcx);
-
- if (send_command(pvt1, AST_FRAME_IAX, IAX_COMMAND_RTENC, 0, ied.buf, ied.pos, -1))
+ }
+
+ iax2_rotate(pvt0, IAX_COMMAND_RTENC, &ies);
+// ast_aes_decrypt_key(digest, &pvt0->dcx);
+
+ if (send_command(pvt1, AST_FRAME_IAX, IAX_COMMAND_RTENC, 0, ied.buf, ied.pos, -1)) {
+ ret = 3;
goto error;
-
- ast_aes_encrypt_key(digest, &pvt1->ecx);
-
- if (send_command(pvt1, AST_FRAME_IAX, IAX_COMMAND_RTDEC, 0, ied.buf, ied.pos, -1))
+ }
+
+ iax2_rotate(pvt1, IAX_COMMAND_RTDEC, &ies);
+// ast_aes_encrypt_key(digest, &pvt1->ecx);
+
+ if (send_command(pvt1, AST_FRAME_IAX, IAX_COMMAND_RTDEC, 0, ied.buf, ied.pos, -1)) {
+ ret = 4;
goto error;
-
- ast_aes_decrypt_key(digest, &pvt1->dcx);
-
- return challenge;
+ }
+
+ iax2_rotate(pvt1, IAX_COMMAND_RTENC, &ies);
+// ast_aes_decrypt_key(digest, &pvt1->dcx);
+
+ return 0;
error:
- if (challenge)
- ast_free(challenge);
- return NULL;
+ ast_log(LOG_NOTICE, "Returning from here with error code '%d'\n", ret);
+ return ret;
}
static int iax2_send_rotate(const void *p)
@@ -4758,7 +4822,7 @@
pvt->rotateid = iax2_sched_add(sched, (ast_random() % 180001) + 120000, iax2_send_rotate, pvt);
- if (pvt->transferring)
+ if (pvt->pauserotate || pvt->transferring)
return 0;
memset(&ied, 0, sizeof(ied));
@@ -6636,6 +6700,7 @@
bcopy(ies->apparent_addr, &new, sizeof(new));
if (ies->callno)
newcall = ies->callno;
+#if 0
if (ies->challenge) {
struct MD5Context md5;
unsigned char digest[16];
@@ -6646,6 +6711,7 @@
build_enc_keys(digest, &pvt->ecx, &pvt->dcx);
}
+#endif
if (!newcall || !new.sin_addr.s_addr || !new.sin_port) {
ast_log(LOG_WARNING, "Invalid transfer request\n");
@@ -9597,11 +9663,29 @@
break;
case IAX_COMMAND_RTENC:
case IAX_COMMAND_RTDEC:
+ ast_log(LOG_NOTICE, "..] receiving '%s'...\n", ((f.subclass == IAX_COMMAND_RTENC) ? "IAX_COMMAND_RTENC" : "IAX_COMMAND_RTDEC"));
+
if (!ast_test_flag(iaxs[fr->callno], IAX_ENCRYPTED) || !ast_test_flag(iaxs[fr->callno], IAX_KEYPOPULATED)) {
+ ast_log(LOG_WARNING, "**] breaking out of rotate sequence!!!\n");
break;
}
+ ast_log(LOG_NOTICE, "..] calling iax2_rotate\n");
iax2_rotate(iaxs[fr->callno], f.subclass, &ies);
+ break;
+ case IAX_COMMAND_RTPAUSE:
+ iaxs[fr->callno]->pauserotate = 1;
+ send_command(iaxs[fr->callno], AST_FRAME_IAX, IAX_COMMAND_RTRESP, 0, NULL, 0, -1);
+ break;
+ case IAX_COMMAND_RTRESP:
+ if (!iaxs[fr->callno]->transferwait) {
+ ast_log(LOG_NOTICE, "Received RTRESP without awaiting one for a transfer to begin! (could potentially lockup call).\n");
+ break;
+ }
+
+ if (iaxs[fr->callno]->transferwait->responses++ > 1)
+ iax2_start_transfer(iaxs[fr->callno]->transferwait->callnos[0], iaxs[fr->callno]->transferwait->callnos[1], iaxs[fr->callno]->transferwait->mediaonly);
+
break;
default:
ast_debug(1, "Unknown IAX command %d on %d/%d\n", f.subclass, fr->callno, iaxs[fr->callno]->peercallno);
Modified: team/bbryant/iax2_rotation/channels/iax2-parser.c
URL: http://svn.digium.com/view/asterisk/team/bbryant/iax2_rotation/channels/iax2-parser.c?view=diff&rev=127837&r1=127836&r2=127837
==============================================================================
--- team/bbryant/iax2_rotation/channels/iax2-parser.c (original)
+++ team/bbryant/iax2_rotation/channels/iax2-parser.c Thu Jul 3 15:20:30 2008
@@ -447,7 +447,11 @@
"PROVISN",
"FWDWNLD",
"FWDATA ",
- "TXMEDIA"
+ "TXMEDIA",
+ "RTENC ",
+ "RTDEC ",
+ "RTPAUSE",
+ "RTRESP "
};
const char *cmds[] = {
"(0?)",
Modified: team/bbryant/iax2_rotation/channels/iax2.h
URL: http://svn.digium.com/view/asterisk/team/bbryant/iax2_rotation/channels/iax2.h?view=diff&rev=127837&r1=127836&r2=127837
==============================================================================
--- team/bbryant/iax2_rotation/channels/iax2.h (original)
+++ team/bbryant/iax2_rotation/channels/iax2.h Thu Jul 3 15:20:30 2008
@@ -113,6 +113,10 @@
IAX_COMMAND_RTENC = 39,
/*! Command to send new key used for decryption */
IAX_COMMAND_RTDEC = 40,
+ /*! ... */
+ IAX_COMMAND_RTPAUSE = 41,
+ /*! ... ... */
+ IAX_COMMAND_RTRESP = 42,
};
/*! By default require re-registration once per minute */
More information about the asterisk-commits
mailing list