From 2e0b0c8b13496bde84f42a45c8dc72ed78a86971 Mon Sep 17 00:00:00 2001 From: "Nathan S. Evans" Date: Fri, 3 Sep 2010 15:28:43 +0000 Subject: [PATCH] making core request connect work --- src/include/gnunet_protocols.h | 6 ++ src/transport/gnunet-service-transport.c | 69 +++++++++++++++++++---- src/transport/transport.h | 18 ++++++ src/transport/transport_api.c | 72 +++++++++++++++++++++--- 4 files changed, 147 insertions(+), 18 deletions(-) diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 841c8d663..8b1d630a5 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -184,6 +184,12 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_TRANSPORT_PONG 33 +/** + * Message for TRANSPORT asking that a connection + * be initiated with a peer. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT 34 + /** * Request update and listing of a peer. */ diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 9c873291f..8423d9cf5 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -43,7 +43,7 @@ #define DEBUG_PING_PONG GNUNET_NO -#define DEBUG_TRANSPORT_HELLO GNUNET_NO +#define DEBUG_TRANSPORT_HELLO GNUNET_YES /** * Should we do some additional checks (to validate behavior @@ -2625,7 +2625,7 @@ add_to_foreign_address_list (void *cls, fal = find_peer_address (n, tname, NULL, addr, addrlen); if (fal == NULL) { -#if DEBUG_TRANSPORT +#if DEBUG_TRANSPORT_HELLO GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding address `%s' (%s) for peer `%4s' due to PEERINFO data for %llums.\n", a2s (tname, addr, addrlen), @@ -2656,7 +2656,7 @@ add_to_foreign_address_list (void *cls, } if (fal == NULL) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to add new address for `%4s'\n", GNUNET_i2s (&n->id)); return GNUNET_OK; @@ -3028,13 +3028,16 @@ setup_peer_check_blacklist (const struct GNUNET_PeerIdentity *peer, n = find_neighbour(peer); if (n != NULL) { - cont (cont_cls, n); + if (cont != NULL) + cont (cont_cls, n); return; } if (bl_head == NULL) { - cont (cont_cls, - setup_new_neighbour (peer, do_hello)); + if (cont != NULL) + cont (cont_cls, setup_new_neighbour (peer, do_hello)); + else + setup_new_neighbour(peer, do_hello); return; } bc = GNUNET_malloc (sizeof (struct BlacklistCheck)); @@ -3414,7 +3417,7 @@ handle_payload_message (const struct GNUNET_MessageHeader *message, } #if DEBUG_TRANSPORT - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %u and size %u from `%4s', sending to all clients.\n", ntohs (message->type), ntohs (message->size), @@ -4026,7 +4029,7 @@ check_hello_validated (void *cls, NULL); GNUNET_PEERINFO_add_peer (peerinfo, plain_hello); GNUNET_free (plain_hello); -#if DEBUG_TRANSPORT +#if DEBUG_TRANSPORT_HELLO GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PEERINFO had no `%s' message for peer `%4s', full validation needed.\n", "HELLO", @@ -4060,7 +4063,7 @@ check_hello_validated (void *cls, } if (h == NULL) return; -#if DEBUG_TRANSPORT +#if DEBUG_TRANSPORT_HELLO GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PEERINFO had `%s' message for peer `%4s', validating only new addresses.\n", "HELLO", @@ -4070,6 +4073,11 @@ check_hello_validated (void *cls, n = find_neighbour (peer); if (n != NULL) { +#if DEBUG_TRANSPORT_HELLO + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Calling hello_iterate_addresses for %s!\n", + GNUNET_i2s (peer)); +#endif GNUNET_HELLO_iterate_addresses (h, GNUNET_NO, &add_to_foreign_address_list, @@ -4078,6 +4086,11 @@ check_hello_validated (void *cls, } else { +#if DEBUG_TRANSPORT_HELLO + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "No existing neighbor record for %s!\n", + GNUNET_i2s (peer)); +#endif GNUNET_STATISTICS_update (stats, gettext_noop ("# no existing neighbour record (validating HELLO)"), 1, @@ -4159,6 +4172,13 @@ process_hello (struct TransportPlugin *plugin, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &target.hashPubKey); +#if DEBUG_TRANSPORT_HELLO + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received `%s' message for `%4s'\n", + "HELLO", + GNUNET_i2s (&target)); +#endif + if (0 == memcmp (&my_identity, &target, sizeof (struct GNUNET_PeerIdentity))) @@ -4952,13 +4972,13 @@ handle_send (void *cls, obm = (const struct OutboundMessage *) message; obmm = (const struct GNUNET_MessageHeader *) &obm[1]; msize = size - sizeof (struct OutboundMessage); -#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' request from client with target `%4s' and message of type %u and size %u\n", "SEND", GNUNET_i2s (&obm->peer), ntohs (obmm->type), msize); -#endif + tcmc = GNUNET_malloc (sizeof (struct TransmitClientMessageContext) + msize); tcmc->client = client; tcmc->priority = ntohl (obm->priority); @@ -4973,6 +4993,31 @@ handle_send (void *cls, } +/** + * Handle request connect message + * + * @param cls closure (always NULL) + * @param client identification of the client + * @param message the actual message + */ +static void +handle_request_connect (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + const struct TransportRequestConnectMessage *trcm = + (const struct TransportRequestConnectMessage *) message; + + GNUNET_STATISTICS_update (stats, + gettext_noop ("# REQUEST CONNECT messages received"), + 1, + GNUNET_NO); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received a request connect message for peer %s\n", GNUNET_i2s(&trcm->peer)); + setup_peer_check_blacklist (&trcm->peer, GNUNET_YES, + NULL, NULL); + GNUNET_SERVER_receive_done (client, GNUNET_OK); +} + /** * Handle SET_QUOTA-message. * @@ -5373,6 +5418,8 @@ run (void *cls, GNUNET_MESSAGE_TYPE_HELLO, 0}, {&handle_send, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0}, + {&handle_request_connect, NULL, + GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT, sizeof(struct TransportRequestConnectMessage)}, {&handle_set_quota, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct QuotaSetMessage)}, {&handle_address_lookup, NULL, diff --git a/src/transport/transport.h b/src/transport/transport.h index aa934c944..237f31581 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h @@ -127,6 +127,24 @@ struct DisconnectInfoMessage }; +/** + * Message type for sending a request connect message + * to the transport service. Must be done before transport + * api will allow messages to be queued/sent to transport + * service for transmission to a peer. + */ +struct TransportRequestConnectMessage +{ + /** + * Message header + */ + struct GNUNET_MessageHeader header; + + /** + * Identity of the peer we would like to connect to. + */ + struct GNUNET_PeerIdentity peer; +}; /** * Message used to set a particular bandwidth quota. Send TO the diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index fa06f7fdb..4809981f5 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c @@ -456,6 +456,9 @@ schedule_peer_transmission (struct GNUNET_TRANSPORT_Handle *h) next = n->next; if (n->transmit_stage != TS_QUEUED) continue; /* not eligible */ + if (n->is_connected != GNUNET_YES) + continue; + th = &n->transmit_handle; GNUNET_break (n == th->neighbour); /* check outgoing quota */ @@ -500,6 +503,7 @@ schedule_peer_transmission (struct GNUNET_TRANSPORT_Handle *h) th->notify_size - sizeof (struct OutboundMessage), GNUNET_i2s (&n->id)); #endif + if ( (ret == NULL) || (ret->priority < th->priority) ) ret = th; @@ -664,7 +668,7 @@ schedule_transmission (struct GNUNET_TRANSPORT_Handle *h) return; if (h->client == NULL) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Could not yet schedule transmission: we are not yet connected to the transport service!\n")); return; /* not yet connected */ } @@ -688,6 +692,10 @@ schedule_transmission (struct GNUNET_TRANSPORT_Handle *h) size = th->notify_size; timeout = GNUNET_TIME_absolute_get_remaining (th->timeout); } +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Calling notify_transmit_ready\n"); +#endif h->network_handle = GNUNET_CLIENT_notify_transmit_ready (h->client, size, @@ -979,7 +987,7 @@ send_hello (void *cls, size_t size, void *buf) if (buf == NULL) { #if DEBUG_TRANSPORT_TIMEOUT - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout while trying to transmit `%s' request.\n", "HELLO"); #endif @@ -1246,6 +1254,40 @@ schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h) } +/** + * Send request connect message to the service. + * + * @param cls the TransportRequestConnectMessage + * @param size number of bytes available in buf + * @param buf where to copy the message + * @return number of bytes copied to buf + */ +static size_t +send_transport_request_connect (void *cls, size_t size, void *buf) +{ + struct TransportRequestConnectMessage *trcm = cls; + + if (buf == NULL) + { +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Buffer null for %s\n", + "REQUEST_CONNECT"); +#endif + GNUNET_free (trcm); + return 0; + } +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Transmitting `%s' request for `%4s'.\n", + "REQUEST_CONNECT", + GNUNET_i2s (&trcm->peer)); +#endif + GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage)); + memcpy(buf, trcm, sizeof(struct TransportRequestConnectMessage)); + return sizeof(struct TransportRequestConnectMessage); +} + /** * Add neighbour to our list * @@ -1256,6 +1298,7 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h, const struct GNUNET_PeerIdentity *pid) { struct NeighbourList *n; + struct TransportRequestConnectMessage *trcm; if (GNUNET_YES == h->in_disconnect) return NULL; @@ -1278,6 +1321,15 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h, n->next = h->neighbours; n->h = h; h->neighbours = n; + + trcm = GNUNET_malloc(sizeof(struct TransportRequestConnectMessage)); + trcm->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT); + trcm->header.size = htons(sizeof(struct TransportRequestConnectMessage)); + memcpy(&trcm->peer, pid, sizeof(struct GNUNET_PeerIdentity)); + schedule_control_transmit (h, + sizeof (struct TransportRequestConnectMessage), + GNUNET_NO, + GNUNET_TIME_UNIT_FOREVER_REL, &send_transport_request_connect, trcm); return n; } @@ -1655,7 +1707,7 @@ peer_transmit_timeout (void *cls, th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; n = th->neighbour; #if DEBUG_TRANSPORT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Triggering timeout for request to transmit to `%4s' (%d)\n", GNUNET_i2s (&n->id), n->transmit_stage); @@ -1729,18 +1781,24 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle GNUNET_break (0); return NULL; } -#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking transport service for transmission of %u bytes to peer `%4s' within %llu ms.\n", size, GNUNET_i2s (target), (unsigned long long) timeout.value); -#endif + n = neighbour_find (handle, target); if (n == NULL) - n = neighbour_add (handle, target); + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created neighbour entry for peer `%s'\n", + GNUNET_i2s (target)); + n = neighbour_add (handle, target); + + } if (n == NULL) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not create neighbour entry for peer `%s'\n", GNUNET_i2s (target)); return NULL; -- 2.25.1