From: Christian Grothoff Date: Fri, 13 Dec 2013 17:06:48 +0000 (+0000) Subject: -move tcp session check into extra checks condition X-Git-Tag: initial-import-from-subversion-38251~5484 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=007c852f2e43e658cb2581a62c03cd0ccbfd08f4;p=oweals%2Fgnunet.git -move tcp session check into extra checks condition --- diff --git a/src/include/platform.h b/src/include/platform.h index 385a0ffb5..57c6bdd6c 100644 --- a/src/include/platform.h +++ b/src/include/platform.h @@ -48,7 +48,10 @@ #include #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). diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index e0572d5d0..5193551de 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -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 @@ tcp_disconnect_session (void *cls, } +#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 @@ session_it (void *cls, } +/** + * 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 @@ find_session (struct Plugin *plugin, struct Session *session) */ 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]; diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index feed6959d..6bd96b365 100644 --- a/src/util/crypto_ecc.c +++ b/src/util/crypto_ecc.c @@ -27,7 +27,7 @@ #include #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