From: Christian Grothoff Date: Sun, 14 Aug 2011 16:40:38 +0000 (+0000) Subject: demultiplexing X-Git-Tag: initial-import-from-subversion-38251~17346 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b4b8ee35e09ef1828a342355cd0e6ca58fc6441e;p=oweals%2Fgnunet.git demultiplexing --- diff --git a/src/transport/gnunet-service-transport-new.c b/src/transport/gnunet-service-transport-new.c index 4536d2573..6bc3c2541 100644 --- a/src/transport/gnunet-service-transport-new.c +++ b/src/transport/gnunet-service-transport-new.c @@ -116,6 +116,25 @@ process_hello_update (void *cls, } +/** + * Try to initiate a connection to the given peer if the blacklist + * allowed it. + * + * @param cls closure (unused, NULL) + * @param peer identity of peer that was tested + * @param result GNUNET_OK if the connection is allowed, + * GNUNET_NO if not + */ +static void +try_connect_if_allowed (void *cls, + const struct GNUNET_PeerIdentity *peer, + int result) +{ + if (GNUNET_OK != result) + return; /* not allowed */ + GST_neighbours_try_connect (peer); +} + /** * Function called by the transport for each received message. @@ -152,17 +171,74 @@ plugin_env_receive_callback (void *cls, const char *plugin_name = cls; int do_forward; struct GNUNET_TIME_Relative ret; + uint16_t type; + - do_forward = GNUNET_SYSERR; - ret = GST_neighbours_calculate_receive_delay (peer, - (message == NULL) - ? 0 - : ntohs (message->size), - &do_forward); - /* FIXME: look at the type of the message (PING, PONG, CONNECT, payload...) */ - if ( (NULL != message) && - (do_forward == GNUNET_YES) ) - GST_clients_broadcast (message, GNUNET_YES); + ret = GNUNET_TIME_UNIT_ZERO; + if (NULL != message) + { + type = ntohs (message->type); + switch (type) + { + case GNUNET_MESSAGE_TYPE_HELLO: + GST_validation_handle_hello (message); + break; + case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, + "Processing `%s' from `%s'\n", + "PING", + (sender_address != NULL) + ? GST_plugins_a2s (plugin_name, + sender_address, + sender_address_len) + : ""); +#endif + GST_validation_handle_ping (peer, + message, + plugin_name, + session, + sender_address, sender_address_len); + break; + case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, + "Processing `%s' from `%s'\n", + "PONG", + (sender_address != NULL) + ? GST_plugins_a2s (plugin_name, + sender_address, + sender_address_len) + : ""); +#endif + GST_validation_handle_pong (peer, + message); + break; + case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: + (void) GST_blacklist_test_allowed (peer, + NULL, + &try_connect_if_allowed, NULL); + /* TODO: if 'session != NULL', maybe notify ATS that this is now the preferred + way to communicate with this peer (other peer switched transport) */ + break; + case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: + /* TODO: do some validation to prevent an attacker from sending + a fake disconnect message... */ + GST_neighbours_force_disconnect (peer); + break; + default: + /* should be payload */ + do_forward = GNUNET_SYSERR; + ret = GST_neighbours_calculate_receive_delay (peer, + (message == NULL) + ? 0 + : ntohs (message->size), + &do_forward); + if (do_forward == GNUNET_YES) + GST_clients_broadcast (message, GNUNET_YES); + break; + } + } GNUNET_ATS_address_update (GST_ats, peer, GNUNET_TIME_absolute_get (), /* valid at least until right now... */ @@ -171,6 +247,7 @@ plugin_env_receive_callback (void *cls, sender_address, sender_address_len, ats, ats_count); + return ret; } diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index 0e701ea02..ca686057d 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c @@ -532,7 +532,6 @@ clients_handle_send (void *cls, &handle_send_transmit_continuation, stcc); } - /** diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index aabb28068..cbfd16b7e 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c @@ -618,7 +618,6 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, const void *sender_address, size_t sender_address_len) { - const struct TransportPingMessage *ping; struct TransportPongMessage *pong; struct GNUNET_TRANSPORT_PluginFunctions *papi; @@ -979,17 +978,10 @@ add_valid_peer_address (void *cls, * * @param sender peer sending the PONG * @param hdr the PONG - * @param plugin_name name of plugin that received the PONG - * @param sender_address address of the sender as known to the plugin, NULL - * if we did not initiate the connection - * @param sender_address_len number of bytes in sender_address */ void GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_MessageHeader *hdr, - const char *plugin_name, - const void *sender_address, - size_t sender_address_len) + const struct GNUNET_MessageHeader *hdr) { const struct TransportPongMessage *pong; struct ValidationEntry *ve; @@ -1018,16 +1010,6 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, GNUNET_break_op (0); return; } -#if DEBUG_TRANSPORT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, - "Processing `%s' from `%s'\n", - "PONG", - (sender_address != NULL) - ? GST_plugin_a2s (plugin_name, - sender_address, - sender_address_len) - : ""); -#endif addr = (const char*) &pong[1]; alen = ntohs (hdr->size) - sizeof (struct TransportPongMessage); addrend = memchr (addr, '\0', alen); diff --git a/src/transport/gnunet-service-transport_validation.h b/src/transport/gnunet-service-transport_validation.h index 5ab2e9163..73d346678 100644 --- a/src/transport/gnunet-service-transport_validation.h +++ b/src/transport/gnunet-service-transport_validation.h @@ -71,17 +71,10 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, * * @param sender peer sending the PONG * @param hdr the PONG - * @param plugin_name name of plugin that received the PONG - * @param sender_address address of the sender as known to the plugin, NULL - * if we did not initiate the connection - * @param sender_address_len number of bytes in sender_address */ void GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_MessageHeader *hdr, - const char *plugin_name, - const void *sender_address, - size_t sender_address_len); + const struct GNUNET_MessageHeader *hdr); /**