gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r4303 - in GNUnet: . src/applications/transport src/include


From: grothoff
Subject: [GNUnet-SVN] r4303 - in GNUnet: . src/applications/transport src/include src/server src/transports src/util/network
Date: Tue, 16 Jan 2007 21:07:51 -0800 (PST)

Author: grothoff
Date: 2007-01-16 21:07:42 -0800 (Tue, 16 Jan 2007)
New Revision: 4303

Modified:
   GNUnet/ChangeLog
   GNUnet/src/applications/transport/transport.c
   GNUnet/src/include/gnunet_transport.h
   GNUnet/src/include/gnunet_transport_service.h
   GNUnet/src/include/gnunet_util_network.h
   GNUnet/src/server/connection.c
   GNUnet/src/transports/nat.c
   GNUnet/src/transports/tcp.c
   GNUnet/src/transports/tcp6.c
   GNUnet/src/transports/tcp_helper.c
   GNUnet/src/transports/tcp_old.c
   GNUnet/src/transports/udp.c
   GNUnet/src/transports/udp6.c
   GNUnet/src/transports/udp_helper.c
   GNUnet/src/util/network/select.c
Log:
reducing cpu utilization by avoiding encryption and message assembly if 
tcp-transports would discard the message anyway

Modified: GNUnet/ChangeLog
===================================================================
--- GNUnet/ChangeLog    2007-01-14 19:11:41 UTC (rev 4302)
+++ GNUnet/ChangeLog    2007-01-17 05:07:42 UTC (rev 4303)
@@ -1,3 +1,8 @@
+Tue Jan 16 21:43:26 MST 2007
+       Expanded transport APIs to avoid building messages for
+       transmission just to have them rejected by blocking TCPs
+       with full transmission queues (happened quite a bit).
+
 Mon Jan  8 22:21:15 MST 2007
        Making computation of send buffer permuations more
        efficient (in terms of calling weak_randomi) by only

Modified: GNUnet/src/applications/transport/transport.c
===================================================================
--- GNUnet/src/applications/transport/transport.c       2007-01-14 19:11:41 UTC 
(rev 4302)
+++ GNUnet/src/applications/transport/transport.c       2007-01-17 05:07:42 UTC 
(rev 4303)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2001, 2002, 2004, 2005, 2006 Christian Grothoff (and other 
contributing authors)
+     (C) 2001, 2002, 2004, 2005, 2006, 2007 Christian Grothoff (and other 
contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -542,6 +542,32 @@
 }
 
 /**
+ * Test if the transport would even try to send
+ * a message of the given size and importance
+ * for the given session.<br>
+ * This function is used to check if the core should
+ * even bother to construct (and encrypt) this kind
+ * of message.
+ *
+ * @return YES if the transport would try (i.e. queue
+ *         the message or call the OS to send),
+ *         NO if the transport would just drop the message,
+ *         SYSERR if the size/session is invalid
+ */
+static int testWouldTry(TSession * tsession,
+                       unsigned int size,
+                       int important) {
+  if (tsession == NULL) 
+    return SYSERR; 
+  if ( (tsession->ttype >= tapis_count) ||
+       (tapis[tsession->ttype] == NULL) ) 
+    return SYSERR;  
+  return tapis[tsession->ttype]->testWouldTry(tsession,
+                                             size,
+                                             important);
+}
+
+/**
  * Initialize the transport layer.
  */
 Transport_ServiceAPI *
@@ -691,6 +717,7 @@
   ret.getMTU = &transportGetMTU;
   ret.createhello = &transportCreatehello;
   ret.getAdvertisedhellos = &getAdvertisedhellos;
+  ret.testWouldTry = &testWouldTry;
 
   return &ret;
 }

Modified: GNUnet/src/include/gnunet_transport.h
===================================================================
--- GNUnet/src/include/gnunet_transport.h       2007-01-14 19:11:41 UTC (rev 
4302)
+++ GNUnet/src/include/gnunet_transport.h       2007-01-17 05:07:42 UTC (rev 
4303)
@@ -253,7 +253,7 @@
    * @return OK on success, SYSERR if the operation failed
    */
   int (*connect)(const P2P_hello_MESSAGE * hello,
-                TSession ** tsession);
+                TSession ** tsession);  
 
   /**
    * Send a message to the specified remote node.
@@ -330,6 +330,23 @@
   char * (*addressToString)(const P2P_hello_MESSAGE * hello,
                            int resolve_ip);
 
+  /**
+   * Test if the transport would even try to send
+   * a message of the given size and importance
+   * for the given session.<br>
+   * This function is used to check if the core should
+   * even bother to construct (and encrypt) this kind
+   * of message.
+   *
+   * @return YES if the transport would try (i.e. queue
+   *         the message or call the OS to send),
+   *         NO if the transport would just drop the message,
+   *         SYSERR if the size/session is invalid
+   */
+  int (*testWouldTry)(TSession * tsession,
+                     unsigned int size,
+                     int important);
+  
 } TransportAPI;
 
 /**

Modified: GNUnet/src/include/gnunet_transport_service.h
===================================================================
--- GNUnet/src/include/gnunet_transport_service.h       2007-01-14 19:11:41 UTC 
(rev 4302)
+++ GNUnet/src/include/gnunet_transport_service.h       2007-01-17 05:07:42 UTC 
(rev 4303)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other 
contributing authors)
+     (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and 
other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -186,6 +186,24 @@
   int (*getAdvertisedhellos)(unsigned int maxLen,
                            char * buff);
 
+  /**
+   * Test if the transport would even try to send
+   * a message of the given size and importance
+   * for the given session.<br>
+   * This function is used to check if the core should
+   * even bother to construct (and encrypt) this kind
+   * of message.
+   *
+   * @return YES if the transport would try (i.e. queue
+   *         the message or call the OS to send),
+   *         NO if the transport would just drop the message,
+   *         SYSERR if the size/session is invalid
+   */
+  int (*testWouldTry)(TSession * tsession,
+                     unsigned int size,
+                     int important);
+  
+
 } Transport_ServiceAPI;
 
 #if 0 /* keep Emacsens' auto-indent happy */

Modified: GNUnet/src/include/gnunet_util_network.h
===================================================================
--- GNUnet/src/include/gnunet_util_network.h    2007-01-14 19:11:41 UTC (rev 
4302)
+++ GNUnet/src/include/gnunet_util_network.h    2007-01-17 05:07:42 UTC (rev 
4303)
@@ -464,7 +464,26 @@
                 int mayBlock,
                 int force);
 
+
 /**
+ * Would select queue or send the given message at this time?
+ *
+ * @param mayBlock if YES, blocks this thread until message
+ *        has been sent
+ * @param size size of the message
+ * @param force message is important, queue even if
+ *        there is not enough space
+ * @return OK if the message would be sent or queued,
+ *         NO if there was not enough memory to queue it,
+ *         SYSERR if the sock does not belong with this select
+ */
+int select_would_try(struct SelectHandle * sh,
+                    struct SocketHandle * sock,
+                    unsigned int size,
+                    int mayBlock,
+                    int force);
+
+/**
  * Add another (already connected) socket to the set of
  * sockets managed by the select.
  */

Modified: GNUnet/src/server/connection.c
===================================================================
--- GNUnet/src/server/connection.c      2007-01-14 19:11:41 UTC (rev 4302)
+++ GNUnet/src/server/connection.c      2007-01-17 05:07:42 UTC (rev 4303)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other 
contributing authors)
+     (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and 
other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -976,8 +976,9 @@
  * @return total number of bytes of messages selected
  *   including P2P message header.
  */
-static unsigned int selectMessagesToSend(BufferEntry * be,
-                                         unsigned int *priority) {
+static unsigned int 
+selectMessagesToSend(BufferEntry * be,
+                    unsigned int *priority) {
   unsigned int totalMessageSize;
   SendEntry *entry;
   int i;
@@ -1520,8 +1521,17 @@
 #endif
     return NO;  /* deferr further */
   }
-  GE_ASSERT(ectx, totalMessageSize > sizeof(P2P_PACKET_HEADER));
-
+  GE_ASSERT(ectx,
+           totalMessageSize > sizeof(P2P_PACKET_HEADER));
+  if (YES != transport->testWouldTry(be->session.tsession,                     
        
+                                    totalMessageSize,
+                                    (priority >= EXTREME_PRIORITY) ? YES : 
NO)) {
+    /* transport's buffer full -- no point in
+       creating the actual message! */
+    expireSendBufferEntries(be);
+    be->inSendBuffer = NO;
+    return NO;
+  }
   /* check if we (sender) have enough bandwidth available
      if so, trigger callbacks on selected entries; if either
      fails, return (but clean up garbage) */
@@ -1609,7 +1619,8 @@
 
   encryptedMsg = MALLOC(p);
   hash(&p2pHdr->sequenceNumber,
-       p - sizeof(HashCode512), (HashCode512 *) encryptedMsg);
+       p - sizeof(HashCode512), 
+       (HashCode512 *) encryptedMsg);
   ret = encryptBlock(&p2pHdr->sequenceNumber,
                     p - sizeof(HashCode512),
                     &be->skey_local,
@@ -1624,7 +1635,8 @@
                   ret));
 #endif
   if(stats != NULL)
-    stats->change(stat_encrypted, p - sizeof(HashCode512));
+    stats->change(stat_encrypted, 
+                 p - sizeof(HashCode512));
   GE_ASSERT(ectx, be->session.tsession != NULL);
 #if DEBUG_CONNECTION
   GE_LOG(ectx,
@@ -1646,8 +1658,8 @@
   if (ret == YES) {
     if(stats != NULL)
       stats->change(stat_transmitted, p);
-    if (be->available_send_window > totalMessageSize)
-      be->available_send_window -= totalMessageSize;
+    if (be->available_send_window > p)
+      be->available_send_window -= p;
     else
       be->available_send_window = 0;  /* if we overrode limits,
                                          reset to 0 at least... */

Modified: GNUnet/src/transports/nat.c
===================================================================
--- GNUnet/src/transports/nat.c 2007-01-14 19:11:41 UTC (rev 4302)
+++ GNUnet/src/transports/nat.c 2007-01-17 05:07:42 UTC (rev 4303)
@@ -178,6 +178,11 @@
   return STRDUP("NAT");
 }
 
+static int testWouldTry(TSession * tsession,
+                       unsigned int size,
+                       int important) {
+  return SYSERR;
+}
 
 /**
  * The exported method. Makes the core api available via a global and
@@ -197,6 +202,7 @@
   natAPI.startTransportServer = &startTransportServer;
   natAPI.stopTransportServer  = &stopTransportServer;
   natAPI.addressToString      = &addressToString;
+  natAPI.testWouldTry         = &testWouldTry;
 
   return &natAPI;
 }

Modified: GNUnet/src/transports/tcp.c
===================================================================
--- GNUnet/src/transports/tcp.c 2007-01-14 19:11:41 UTC (rev 4302)
+++ GNUnet/src/transports/tcp.c 2007-01-17 05:07:42 UTC (rev 4303)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other 
contributing authors)
+     (C) 2002, 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and other 
contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -583,6 +583,7 @@
   tcpAPI.startTransportServer = &startTransportServer;
   tcpAPI.stopTransportServer  = &stopTransportServer;
   tcpAPI.addressToString      = &addressToString;
+  tcpAPI.testWouldTry         = &tcpTestWouldTry;
 
   return &tcpAPI;
 }

Modified: GNUnet/src/transports/tcp6.c
===================================================================
--- GNUnet/src/transports/tcp6.c        2007-01-14 19:11:41 UTC (rev 4302)
+++ GNUnet/src/transports/tcp6.c        2007-01-17 05:07:42 UTC (rev 4303)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2003, 2004, 2005, 2006 Christian Grothoff (and other contributing 
authors)
+     (C) 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and other 
contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -534,6 +534,7 @@
   tcp6API.startTransportServer = &startTransportServer;
   tcp6API.stopTransportServer  = &stopTransportServer;
   tcp6API.addressToString      = &addressToString;
+  tcp6API.testWouldTry         = &tcpTestWouldTry;
 
   return &tcp6API;
 }

Modified: GNUnet/src/transports/tcp_helper.c
===================================================================
--- GNUnet/src/transports/tcp_helper.c  2007-01-14 19:11:41 UTC (rev 4302)
+++ GNUnet/src/transports/tcp_helper.c  2007-01-17 05:07:42 UTC (rev 4303)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other 
contributing authors)
+     (C) 2002, 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and other 
contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -354,6 +354,44 @@
 }
 
 /**
+ * Test if the transport would even try to send
+ * a message of the given size and importance
+ * for the given session.<br>
+ * This function is used to check if the core should
+ * even bother to construct (and encrypt) this kind
+ * of message.
+ *
+ * @return YES if the transport would try (i.e. queue
+ *         the message or call the OS to send),
+ *         NO if the transport would just drop the message,
+ *         SYSERR if the size/session is invalid
+ */
+static int tcpTestWouldTry(TSession * tsession,
+                          const unsigned int size,
+                          int important) {
+  TCPSession * tcpSession = tsession->internal;
+
+  if (size >= MAX_BUFFER_SIZE - sizeof(MESSAGE_HEADER)) {
+    GE_BREAK(ectx, 0);
+    return SYSERR;
+  }
+  if (selector == NULL) 
+    return SYSERR;
+  if (size == 0) {
+    GE_BREAK(ectx, 0);
+    return SYSERR;
+  }
+  if (tcpSession->sock == NULL) 
+    return SYSERR; /* other side closed connection */  
+  return select_would_try(selector,
+                         tcpSession->sock,
+                         size,
+                         NO,
+                         important);
+}
+
+
+/**
  * Establish a connection to a remote node.
  *
  * @param helo the hello-Message for the target node

Modified: GNUnet/src/transports/tcp_old.c
===================================================================
--- GNUnet/src/transports/tcp_old.c     2007-01-14 19:11:41 UTC (rev 4302)
+++ GNUnet/src/transports/tcp_old.c     2007-01-17 05:07:42 UTC (rev 4303)
@@ -834,15 +834,12 @@
   size_t ret;
   int success;
 
-  if (tcp_shutdown == YES) {
-    return SYSERR;
-  }
-  if (tcpSession->sock == -1) {
-    return SYSERR;
-  }
-  if (ssize == 0) {
-    return SYSERR;
-  }
+  if (tcp_shutdown == YES) 
+    return SYSERR;  
+  if (tcpSession->sock == -1) 
+    return SYSERR;  
+  if (ssize == 0) 
+    return SYSERR;  
   MUTEX_LOCK(tcplock);
   if (tcpSession->wpos > 0) {
     /* select already pending... */
@@ -898,15 +895,12 @@
                                 unsigned int ssize) {
   int ok;
 
-  if (tcp_shutdown == YES) {
+  if (tcp_shutdown == YES) 
+    return SYSERR;  
+  if (tcpSession->sock == -1) 
+    return SYSERR;  
+  if (ssize == 0)
     return SYSERR;
-  }
-  if (tcpSession->sock == -1) {
-    return SYSERR;
-  }
-  if (ssize == 0) {
-    return SYSERR;
-  }
   MUTEX_LOCK(tcplock);
   if (tcpSession->wpos > 0) {
     unsigned int old = tcpSession->wpos;
@@ -1096,19 +1090,16 @@
   TCPP2P_PACKET * mp;
   int ok;
 
-  if (size >= MAX_BUFFER_SIZE) {
-    return SYSERR;
-  }
-
+  if (size >= MAX_BUFFER_SIZE) 
+    return SYSERR; 
   if (tcp_shutdown == YES) {
     if (stats != NULL)
       stats->change(stat_bytesDropped,
                    size);
     return SYSERR;
   }
-  if (size == 0) {
-    return SYSERR;
-  }
+  if (size == 0) 
+    return SYSERR;  
   if (((TCPSession*)tsession->internal)->sock == -1) {
     if (stats != NULL)
       stats->change(stat_bytesDropped,
@@ -1267,6 +1258,20 @@
   return ret;
 }
 
+static int testWouldTry(TSession * tsession,
+                       unsigned int size,
+                       int important) {
+  if (size >= MAX_BUFFER_SIZE) 
+    return SYSERR;
+  if (tcp_shutdown == YES) 
+    return SYSERR;  
+  if (size == 0) 
+    return SYSERR;
+  if ( (((TCPSession*)tsession->internal)->wpos + size < TARGET_BUFFER_SIZE) ||
+       (((TCPSession*)tsession->internal)->wpos == 0) )
+    return YES;
+  return NO;
+}
 
 /* ******************** public API ******************** */
 
@@ -1303,6 +1308,7 @@
   tcpAPI.startTransportServer = &startTransportServer;
   tcpAPI.stopTransportServer  = &stopTransportServer;
   tcpAPI.addressToString      = &addressToString;
+  tcpAPI.testWouldTry         = &testWouldTry;
 
   return &tcpAPI;
 }

Modified: GNUnet/src/transports/udp.c
===================================================================
--- GNUnet/src/transports/udp.c 2007-01-14 19:11:41 UTC (rev 4302)
+++ GNUnet/src/transports/udp.c 2007-01-17 05:07:42 UTC (rev 4303)
@@ -569,6 +569,7 @@
   udpAPI.startTransportServer = &startTransportServer;
   udpAPI.stopTransportServer  = &stopTransportServer;
   udpAPI.addressToString      = &addressToString;
+  udpAPI.testWouldTry         = &testWouldTry;
 
   return &udpAPI;
 }

Modified: GNUnet/src/transports/udp6.c
===================================================================
--- GNUnet/src/transports/udp6.c        2007-01-14 19:11:41 UTC (rev 4302)
+++ GNUnet/src/transports/udp6.c        2007-01-17 05:07:42 UTC (rev 4303)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2003, 2004, 2005 Christian Grothoff (and other contributing authors)
+     (C) 2003, 2004, 2005, 2007 Christian Grothoff (and other contributing 
authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -534,6 +534,7 @@
   udpAPI.startTransportServer = &startTransportServer;
   udpAPI.stopTransportServer  = &stopTransportServer;
   udpAPI.addressToString      = &addressToString;
+  udpAPI.testWouldTry         = &testWouldTry;
 
   return &udpAPI;
 }

Modified: GNUnet/src/transports/udp_helper.c
===================================================================
--- GNUnet/src/transports/udp_helper.c  2007-01-14 19:11:41 UTC (rev 4302)
+++ GNUnet/src/transports/udp_helper.c  2007-01-17 05:07:42 UTC (rev 4303)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other 
contributing authors)
+     (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and 
other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -196,4 +196,39 @@
   return OK;
 }
 
+/**
+ * Test if the transport would even try to send
+ * a message of the given size and importance
+ * for the given session.<br>
+ * This function is used to check if the core should
+ * even bother to construct (and encrypt) this kind
+ * of message.
+ *
+ * @return YES if the transport would try (i.e. queue
+ *         the message or call the OS to send),
+ *         NO if the transport would just drop the message,
+ *         SYSERR if the size/session is invalid
+ */
+static int testWouldTry(TSession * tsession,
+                       unsigned int size,
+                       int important) {
+  const P2P_hello_MESSAGE * hello;
+
+  if (udp_sock == NULL)
+    return SYSERR;
+  if (size == 0) {
+    GE_BREAK(ectx, 0);
+    return SYSERR;
+  }
+  if (size > udpAPI.mtu) {
+    GE_BREAK(ectx, 0);
+    return SYSERR;
+  }
+  hello = (const P2P_hello_MESSAGE*)tsession->internal;
+  if (hello == NULL)
+    return SYSERR;
+  return YES;
+}
+
+
 /* end of udp_helper.c */

Modified: GNUnet/src/util/network/select.c
===================================================================
--- GNUnet/src/util/network/select.c    2007-01-14 19:11:41 UTC (rev 4302)
+++ GNUnet/src/util/network/select.c    2007-01-17 05:07:42 UTC (rev 4303)
@@ -1006,6 +1006,48 @@
 }
 
 /**
+ * Would select queue or send the given message at this time?
+ *
+ * @param mayBlock if YES, blocks this thread until message
+ *        has been sent
+ * @param size size of the message
+ * @param force message is important, queue even if
+ *        there is not enough space
+ * @return OK if the message would be sent or queued,
+ *         NO if there was not enough memory to queue it,
+ *         SYSERR if the sock does not belong with this select
+ */
+int select_would_try(struct SelectHandle * sh,
+                    struct SocketHandle * sock,
+                    unsigned int size,
+                    int mayBlock,
+                    int force) {
+  Session * session;
+  int i;
+
+  session = NULL;
+  MUTEX_LOCK(sh->lock);
+  for (i=0;i<sh->sessionCount;i++)
+    if (sh->sessions[i]->sock == sock) {
+      session = sh->sessions[i];
+      break;
+    }
+  if (session == NULL) {
+    MUTEX_UNLOCK(sh->lock);
+    return SYSERR;
+  }
+  GE_ASSERT(NULL, session->wapos >= session->wspos);
+  if ( (sh->memory_quota > 0) &&
+       (session->wapos - session->wspos + size > sh->memory_quota) ) {
+    /* not enough free space, not allowed to grow that much */
+    MUTEX_UNLOCK(sh->lock);
+    return NO;
+  }
+  MUTEX_UNLOCK(sh->lock);
+  return YES;
+}
+
+/**
  * Add another (already connected) socket to the set of
  * sockets managed by the select.
  */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]