[asterisk-commits] russell: trunk r56487 - /trunk/channels/chan_iax2.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Feb 23 15:26:00 MST 2007


Author: russell
Date: Fri Feb 23 16:26:00 2007
New Revision: 56487

URL: http://svn.digium.com/view/asterisk?view=rev&rev=56487
Log:
Make the hashing function calculate something that makes more sense.
(Thanks to bmd on #asterisk-dev for pointing out my pointless math).

Modified:
    trunk/channels/chan_iax2.c

Modified: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?view=diff&rev=56487&r1=56486&r2=56487
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Fri Feb 23 16:26:00 2007
@@ -633,7 +633,7 @@
 	int frames_received;
 
 	AST_LIST_ENTRY(chan_iax2_pvt) entry;
-	unsigned int hash;
+	unsigned short hash;
 };
 
 /* Somewhat arbitrary prime number */
@@ -1265,15 +1265,10 @@
 	return res;
 }
 
-static inline unsigned int peer_hash_val(const struct sockaddr_in *sin, unsigned short callno)
-{
-	return ( (sin->sin_addr.s_addr & 0xFF000000) ^ 
-	         (sin->sin_addr.s_addr & 0x00FF0000) ^
-	         (sin->sin_addr.s_addr & 0x0000FF00) ^ 
-	         (sin->sin_addr.s_addr & 0x000000FF) ^
-	         (sin->sin_port & 0xFF00) ^ (sin->sin_port ^ 0x00FF) ^
-	         (callno & 0xFF00) ^ (callno & 0x00FF) ) 
-	         % PVT_HASH_SIZE;
+static inline unsigned short peer_hash_val(const struct sockaddr_in *sin, unsigned short callno)
+{
+	return ( (sin->sin_addr.s_addr >> 16) ^ sin->sin_addr.s_addr ^
+	         sin->sin_port ^ callno ) % PVT_HASH_SIZE;
 }
 
 static inline void hash_on_peer(struct chan_iax2_pvt *pvt)
@@ -1298,7 +1293,7 @@
 	struct timeval now;
 	char host[80];
 	if (new <= NEW_ALLOW) {
-		unsigned int hash = peer_hash_val(sin, callno);
+		unsigned short hash = peer_hash_val(sin, callno);
 		const struct chan_iax2_pvt *pvt;
 		AST_RWLIST_RDLOCK(&pvt_hash_tbl[hash]);
 		AST_RWLIST_TRAVERSE(&pvt_hash_tbl[hash], pvt, entry) {



More information about the asterisk-commits mailing list