[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r31370 - in gnunet/src: include transport util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r31370 - in gnunet/src: include transport util |
Date: |
Fri, 13 Dec 2013 18:06:48 +0100 |
Author: grothoff
Date: 2013-12-13 18:06:48 +0100 (Fri, 13 Dec 2013)
New Revision: 31370
Modified:
gnunet/src/include/platform.h
gnunet/src/transport/plugin_transport_tcp.c
gnunet/src/util/crypto_ecc.c
Log:
-move tcp session check into extra checks condition
Modified: gnunet/src/include/platform.h
===================================================================
--- gnunet/src/include/platform.h 2013-12-13 16:59:28 UTC (rev 31369)
+++ gnunet/src/include/platform.h 2013-12-13 17:06:48 UTC (rev 31370)
@@ -48,7 +48,10 @@
#include <sys/types.h>
#endif
-#define ALLOW_EXTRA_CHECKS GNUNET_NO
+/**
+ * These may be expensive, but good for debugging...
+ */
+#define ALLOW_EXTRA_CHECKS GNUNET_YES
/**
* For strptime (glibc2 needs this).
Modified: gnunet/src/transport/plugin_transport_tcp.c
===================================================================
--- gnunet/src/transport/plugin_transport_tcp.c 2013-12-13 16:59:28 UTC (rev
31369)
+++ gnunet/src/transport/plugin_transport_tcp.c 2013-12-13 17:06:48 UTC (rev
31370)
@@ -43,6 +43,8 @@
#define PLUGIN_NAME "tcp"
+#define EXTRA_CHECKS ALLOW_EXTRA_CHECKS
+
/**
* How long until we give up on establishing an NAT connection?
* Must be > 4 RTT
@@ -1108,21 +1110,41 @@
}
+#if EXTRA_CHECKS
+/**
+ * Closure for #session_it().
+ */
struct FindSessionContext
{
+ /**
+ * Session we are looking for.
+ */
struct Session *s;
+
+ /**
+ * Set to #GNUNET_OK if we found the session.
+ */
int res;
};
+/**
+ * Function called to check if a session is in our maps.
+ *
+ * @param cls the `struct FindSessionContext`
+ * @param key peer identity
+ * @param value session in the map
+ * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session
+ */
static int
session_it (void *cls,
- const struct GNUNET_PeerIdentity * key,
+ const struct GNUNET_PeerIdentity *key,
void *value)
{
struct FindSessionContext *res = cls;
+ struct Session *session = value;
- if (res->s == value)
+ if (res->s == session)
{
res->res = GNUNET_OK;
return GNUNET_NO;
@@ -1131,27 +1153,37 @@
}
+/**
+ * Check that the given session is known to the plugin and
+ * is in one of our maps.
+ *
+ * @param plugin the plugin to check against
+ * @param session the session to check
+ * @return #GNUNET_OK if all is well, #GNUNET_SYSERR if the session is invalid
+ */
static int
-find_session (struct Plugin *plugin, struct Session *session)
+find_session (struct Plugin *plugin,
+ struct Session *session)
{
struct FindSessionContext session_map_res;
struct FindSessionContext nat_map_res;
session_map_res.s = session;
session_map_res.res = GNUNET_SYSERR;
- GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, &session_it,
&session_map_res);
-
+ GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap,
+ &session_it, &session_map_res);
+ if (GNUNET_SYSERR != session_map_res.res)
+ return GNUNET_OK;
nat_map_res.s = session;
nat_map_res.res = GNUNET_SYSERR;
- GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns, &session_it,
&nat_map_res);
-
- if ((session_map_res.res == GNUNET_SYSERR) && (nat_map_res.res ==
GNUNET_SYSERR))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
+ GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns,
+ &session_it, &nat_map_res);
+ if (GNUNET_SYSERR != nat_map_res.res)
+ return GNUNET_OK;
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
}
+#endif
/**
@@ -1183,25 +1215,23 @@
*/
static ssize_t
tcp_plugin_send (void *cls,
- struct Session *session,
- const char *msgbuf, size_t msgbuf_size,
- unsigned int priority,
- struct GNUNET_TIME_Relative to,
- GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
+ struct Session *session,
+ const char *msgbuf, size_t msgbuf_size,
+ unsigned int priority,
+ struct GNUNET_TIME_Relative to,
+ GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
{
struct Plugin * plugin = cls;
struct PendingMessage *pm;
- GNUNET_assert (NULL != plugin);
- GNUNET_assert (NULL != session);
-
- if (GNUNET_SYSERR == find_session(plugin, session))
+#if EXTRA_CHECKS
+ if (GNUNET_SYSERR == find_session (plugin, session))
{
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Trying to send with invalid session %p\n"));
- return GNUNET_SYSERR;
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Trying to send with invalid session %p\n"));
+ return GNUNET_SYSERR;
}
-
+#endif
/* create new message entry */
pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size);
pm->msg = (const char *) &pm[1];
Modified: gnunet/src/util/crypto_ecc.c
===================================================================
--- gnunet/src/util/crypto_ecc.c 2013-12-13 16:59:28 UTC (rev 31369)
+++ gnunet/src/util/crypto_ecc.c 2013-12-13 17:06:48 UTC (rev 31370)
@@ -27,7 +27,7 @@
#include <gcrypt.h>
#include "gnunet_util_lib.h"
-#define EXTRA_CHECKS ALLOW_EXTRA_CHECKS
+#define EXTRA_CHECKS 0
/**
* Name of the curve we are using. Note that we have hard-coded
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r31370 - in gnunet/src: include transport util,
gnunet <=