diff libfdcore/sctps.c @ 706:4ffbc9f1e922

Large UNTESTED commit with the following changes: * Improved DiameterIdentity handling (esp. interationalization issues), and improve efficiency of some string operations in peers, sessions, and dictionary modules (closes #7) * Cleanup in the session module to free only unreferenced sessions (#16) * Removed fd_cpu_flush_cache(), replaced by more robust alternatives. * Improved peer state machine algorithm to counter SCTP multistream race condition.
author Sebastien Decugis <sdecugis@nict.go.jp>
date Wed, 09 Feb 2011 15:26:58 +0900
parents 2e94ef0515d7
children 4a9f08d6b6ba
line wrap: on
line diff
--- a/libfdcore/sctps.c	Mon Jan 31 17:22:21 2011 +0900
+++ b/libfdcore/sctps.c	Wed Feb 09 15:26:58 2011 +0900
@@ -56,7 +56,7 @@
 This complexity is required because we cannot read a socket for a given stream only; we can only get the next message and find its stream.
 */
 
-
+/* TODO: change this whole wrapper to DTLS which should not require many different threads */
 
 /*************************************************************/
 /*                      threads                              */
@@ -82,12 +82,11 @@
 	}
 	
 	ASSERT( conn->cc_proto == IPPROTO_SCTP );
-	ASSERT( Target_Queue(conn) );
+	ASSERT( fd_cnx_target_queue(conn) );
 	ASSERT( conn->cc_sctps_data.array );
 	
 	do {
-		fd_cpu_flush_cache();
-		CHECK_FCT_DO( fd_sctp_recvmeta(conn->cc_socket, &strid, &buf, &bufsz, &event, &conn->cc_status), goto fatal );
+		CHECK_FCT_DO( fd_sctp_recvmeta(conn, &strid, &buf, &bufsz, &event), goto fatal );
 		switch (event) {
 			case FDEVP_CNX_MSG_RECV:
 				/* Demux this message to the appropriate fifo, another thread will pull, gnutls process, and send to target queue */
@@ -101,8 +100,7 @@
 				
 			case FDEVP_CNX_EP_CHANGE:
 				/* Send this event to the target queue */
-				fd_cpu_flush_cache();
-				CHECK_FCT_DO( fd_event_send( Target_Queue(conn), event, bufsz, buf), goto fatal );
+				CHECK_FCT_DO( fd_event_send( fd_cnx_target_queue(conn), event, bufsz, buf), goto fatal );
 				break;
 			
 			case FDEVP_CNX_ERROR:
@@ -143,7 +141,7 @@
 	TRACE_ENTRY("%p", arg);
 	CHECK_PARAMS_DO(ctx && ctx->raw_recv && ctx->parent, goto error);
 	cnx = ctx->parent;
-	ASSERT( Target_Queue(cnx) );
+	ASSERT( fd_cnx_target_queue(cnx) );
 	
 	/* Set the thread name */
 	{
@@ -172,8 +170,7 @@
 	TRACE_ENTRY("%p %p %zd", tr, data, len);
 	CHECK_PARAMS_DO( tr && data, { errno = EINVAL; return -1; } );
 	
-	fd_cpu_flush_cache();
-	CHECK_FCT_DO( fd_sctp_sendstr(ctx->parent->cc_socket, ctx->strid, (uint8_t *)data, len, &ctx->parent->cc_status), /* errno is already set */ return -1 );
+	CHECK_FCT_DO( fd_sctp_sendstr(ctx->parent, ctx->strid, (uint8_t *)data, len), /* errno is already set */ return -1 );
 	
 	return len;
 }
@@ -305,15 +302,7 @@
 		int cmp = 0;
 		struct sr_data * sr = (struct sr_data *)ret;
 		
-		if ( key.size < sr->key.size )
-			break;
-		
-		if ( key.size > sr->key.size )
-			continue;
-		
-		/* Key sizes are equal */
-		cmp = memcmp( key.data, sr->key.data, key.size );
-		
+		cmp = fd_os_cmp(key.data, key.size, sr->key.data, sr->key.size);
 		if (cmp > 0)
 			continue;
 		
@@ -626,8 +615,7 @@
 	
 	/* End all TLS sessions, in series (not as efficient as paralel, but simpler) */
 	for (i = 1; i < conn->cc_sctp_para.pairs; i++) {
-		fd_cpu_flush_cache();
-		if ( ! (conn->cc_status & CC_STATUS_ERROR)) {
+		if ( ! fd_cnx_teststate(conn, CC_STATUS_ERROR)) {
 			CHECK_GNUTLS_DO( gnutls_bye(conn->cc_sctps_data.array[i].session, GNUTLS_SHUT_WR), fd_cnx_markerror(conn) );
 		}
 	}
"Welcome to our mercurial repository"