[asterisk-commits] murf: branch murf/bug11210 r90405 - in /team/murf/bug11210: channels/ configs/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Nov 30 16:08:13 CST 2007


Author: murf
Date: Fri Nov 30 16:08:12 2007
New Revision: 90405

URL: http://svn.digium.com/view/asterisk?view=rev&rev=90405
Log:
a few fixes to prevent obvious crashes

Modified:
    team/murf/bug11210/channels/chan_sip.c
    team/murf/bug11210/configs/sip.conf.sample

Modified: team/murf/bug11210/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug11210/channels/chan_sip.c?view=diff&rev=90405&r1=90404&r2=90405
==============================================================================
--- team/murf/bug11210/channels/chan_sip.c (original)
+++ team/murf/bug11210/channels/chan_sip.c Fri Nov 30 16:08:12 2007
@@ -1407,14 +1407,14 @@
 /* --- Hash tables of various objects --------*/
 
 #ifdef LOW_MEMORY
-#define MAX_PEER_BUCKETS 17
-#define MAX_DIALOG_BUCKETS 17
+static int hash_peer_size = 17;
+static int hash_dialog_size = 17;
+static int hash_user_size = 17;
 #else
-#define MAX_PEER_BUCKETS 563
-#define MAX_DIALOG_BUCKETS 563
+static int hash_peer_size = 563;
+static int hash_dialog_size = 563;
+static int hash_user_size = 563;
 #endif
-
-#define MAX_USER_BUCKETS MAX_PEER_BUCKETS
 
 /*! \brief  The user list: Users and friends */
 struct ao2_container *users;
@@ -3350,17 +3350,31 @@
 	struct sip_peer tmp_peer;
 	
 	ast_copy_string(tmp_peer.name, peer, sizeof(tmp_peer.name));
-	tmp_peer.addr.sin_addr.s_addr = sin->sin_addr.s_addr;
-	tmp_peer.addr.sin_port = sin->sin_port;
+	if (sin) {
+		tmp_peer.addr.sin_addr.s_addr = sin->sin_addr.s_addr;
+		tmp_peer.addr.sin_port = sin->sin_port;
+	}
+	
 	
 	if (peer)
 		p = ao2_find(peers, &tmp_peer, OBJ_POINTER);
-	else /* search by addr? */
+	else if (sin) { /* search by addr? */
+		ast_log(LOG_NOTICE,"Searching for peer %s by IP addr/port = %d/%d\n", peer, sin->sin_addr.s_addr, sin->sin_port);
 		p = ao2_find(peers_by_ip, &tmp_peer, OBJ_POINTER); /* WAS:  p = ASTOBJ_CONTAINER_FIND_FULL(&peerl, sin, name, sip_addr_hashfunc, 1, sip_addrcmp); */
+	}
+	
 
 	if (!p && realtime)
 		p = realtime_peer(peer, sin);
 
+	if (!p && !sin)
+		ast_log(LOG_NOTICE,"Did not find peer %s\n", peer);
+	else if (!p)
+		ast_log(LOG_NOTICE,"Did not find peer %s / addr=%d port=%d\n", peer, sin->sin_addr.s_addr, sin->sin_port);
+
+	if (p)
+		ast_log(LOG_NOTICE,"FOUND peer %s\n", peer);
+		
 	return p;
 }
 
@@ -3869,6 +3883,7 @@
 	if (lockdialoglist)
 		dialoglist_lock();
 	cur = ao2_find(dialogs, p, OBJ_POINTER|OBJ_UNLINK);
+	ast_log(LOG_NOTICE,"Searched for dialog %s, to UNLINK. got %p\n", p->callid, cur);
 	if (lockdialoglist)
 		dialoglist_unlock();
 	if (!cur) {
@@ -5293,6 +5308,7 @@
 	/* Add to active dialog list */
 	
 	ao2_link(dialogs, p);
+	ast_log(LOG_NOTICE,"Linked in dialog %s\n", p->callid);
 	
 	ast_debug(1, "Allocating new SIP dialog for %s - %s (%s)\n", callid ? callid : "(No Call-ID)", sip_methods[intended_method].text, p->rtp ? "With RTP" : "No RTP");
 	return p;
@@ -5354,6 +5370,7 @@
 	
 		sip_pvt_ptr = ao2_find(dialogs, &tmp_dialog, OBJ_POINTER);
 		if (sip_pvt_ptr) {
+			ast_log(LOG_NOTICE,"Found dialog %s\n", tmp_dialog.callid);
 			if (!(!pedanticsipchecking || !tag || ast_strlen_zero(p->theirtag) || !strcmp(p->theirtag, tag)))
 			{
 				ao2_ref(sip_pvt_ptr,-1); /* basically, if the extra pedanticssipchecking constraints don't pan out,
@@ -9879,6 +9896,7 @@
 		sip_pvt_ptr = ao2_find(dialogs, &tmp_dialog, OBJ_POINTER);
 		if (sip_pvt_ptr) {
 			char *ourtag = sip_pvt_ptr->tag;
+			ast_log(LOG_NOTICE,"Found dialog %s\n", sip_pvt_ptr->callid);
 			/* Go ahead and lock it (and its owner) before returning */
 			sip_pvt_lock(sip_pvt_ptr);
 
@@ -9897,7 +9915,8 @@
 					ast_test_flag(&sip_pvt_ptr->flags[0], SIP_OUTGOING) ? "OUTGOING": "INCOMING",
 					sip_pvt_ptr->theirtag, sip_pvt_ptr->tag);
 		}
-		
+		else ast_log(LOG_NOTICE,"Did not Find dialog %s\n", tmp_dialog.callid);
+
 		ast_string_field_free_memory(&tmp_dialog);
 		return sip_pvt_ptr;
 	}
@@ -12222,7 +12241,7 @@
 		ast_cli(arg.fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type", "Mailbox");
 
 	/* iterate on the container and invoke the callback on each item */
-	ao2_callback(dialogs, 0, show_channels_cb, 0);
+	ao2_callback(dialogs, 0, show_channels_cb, &arg);
 	
 	/* print summary information */
 	ast_cli(arg.fd, "%d active SIP %s%s\n", arg.numchans,
@@ -18674,6 +18693,27 @@
 			} else {
 				ast_log(LOG_WARNING, "Invalid port number '%s' at line %d of %s\n", v->value, v->lineno, config);
 			}
+		} else if (!strcasecmp(v->name, "hash_user")) {
+			int i;
+			if (sscanf(v->value, "%d", &i) > 2) {
+				hash_user_size = i;
+			} else {
+				ast_log(LOG_WARNING, "Invalid hash_user size '%s' at line %d of %s -- should be much larger than 2\n", v->value, v->lineno, config);
+			}
+		} else if (!strcasecmp(v->name, "hash_peer")) {
+			int i;
+			if (sscanf(v->value, "%d", &i) > 2) {
+				hash_peer_size = i;
+			} else {
+				ast_log(LOG_WARNING, "Invalid hash_peer size '%s' at line %d of %s -- should be much larger than 2\n", v->value, v->lineno, config);
+			}
+		} else if (!strcasecmp(v->name, "hash_dialog")) {
+			int i;
+			if (sscanf(v->value, "%d", &i) > 2) {
+				hash_dialog_size = i;
+			} else {
+				ast_log(LOG_WARNING, "Invalid hash_dialog size '%s' at line %d of %s -- should be much larger than 2\n", v->value, v->lineno, config);
+			}
 		} else if (!strcasecmp(v->name, "qualify")) {
 			if (!strcasecmp(v->value, "no")) {
 				default_qualify = 0;
@@ -19473,10 +19513,10 @@
 	ast_verbose("SIP channel loading...\n");
 	/* the fact that ao2_containers can't resize automatically is a major worry! */
     /* if the number of objects gets above MAX_XXX_BUCKETS, things will slow down */
-	users = ao2_container_alloc(MAX_USER_BUCKETS, user_hash_cb, user_cmp_cb);
-	peers = ao2_container_alloc(MAX_PEER_BUCKETS, peer_hash_cb, peer_cmp_cb);
-	peers_by_ip = ao2_container_alloc(MAX_PEER_BUCKETS, peer_iphash_cb, peer_ipcmp_cb);
-	dialogs = ao2_container_alloc(MAX_DIALOG_BUCKETS, dialog_hash_cb, dialog_cmp_cb);
+	users = ao2_container_alloc(hash_user_size, user_hash_cb, user_cmp_cb);
+	peers = ao2_container_alloc(hash_peer_size, peer_hash_cb, peer_cmp_cb);
+	peers_by_ip = ao2_container_alloc(hash_peer_size, peer_iphash_cb, peer_ipcmp_cb);
+	dialogs = ao2_container_alloc(hash_dialog_size, dialog_hash_cb, dialog_cmp_cb);
 	
 	ASTOBJ_CONTAINER_INIT(&regl); /* Registry object list -- not searched for anything */
 

Modified: team/murf/bug11210/configs/sip.conf.sample
URL: http://svn.digium.com/view/asterisk/team/murf/bug11210/configs/sip.conf.sample?view=diff&rev=90405&r1=90404&r2=90405
==============================================================================
--- team/murf/bug11210/configs/sip.conf.sample (original)
+++ team/murf/bug11210/configs/sip.conf.sample Fri Nov 30 16:08:12 2007
@@ -38,7 +38,16 @@
 ;match_auth_username=yes	; if available, match user entry using the
 				; 'username' field from the authentication line
 				; instead of the From: field.
-				
+;; hash table sizes. For maximum efficiency, adjust the following
+;; values to be slightly larger than the maximum number of users/peers.
+;; Too large, and space is wasted. Too small, and things will run slower.
+;; 563 is probably way too big for small (home) applications, but it
+;; should cover most small/medium sites.
+;; This was internally set to 17 for small-memory applications...
+hash_users=563
+hash_peers=563
+hash_dialogs=563
+
 allowoverlap=no			; Disable overlap dialing support. (Default is yes)
 ;allowtransfer=no		; Disable all transfers (unless enabled in peers or users)
 				; Default is enabled
@@ -56,7 +65,7 @@
 				; Disabling DNS SRV lookups disables the 
 				; ability to place SIP calls based on domain 
 				; names to some other SIP users on the Internet
-				
+
 ;domain=mydomain.tld		; Set default domain for this host
 				; If configured, Asterisk will only allow
 				; INVITE and REFER to non-local domains




More information about the asterisk-commits mailing list