From 6be711e2b4a29d57e24c82f300338843f78ad604 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 18 Dec 2013 21:05:57 +0000 Subject: [PATCH] -misc fixes --- src/dv/dv_api.c | 24 ++++++++++++++-- src/dv/gnunet-service-dv.c | 4 +-- src/dv/plugin_transport_dv.c | 56 +++++++++++++++++++++++++++++------- 3 files changed, 69 insertions(+), 15 deletions(-) diff --git a/src/dv/dv_api.c b/src/dv/dv_api.c index 5932c7459..faf61df5e 100644 --- a/src/dv/dv_api.c +++ b/src/dv/dv_api.c @@ -426,6 +426,14 @@ handle_message_receipt (void *cls, reconnect (sh); return; } + if (NULL == + GNUNET_CONTAINER_multipeermap_get (sh->peers, + &rm->sender)) + { + GNUNET_break (0); + reconnect (sh); + return; + } sh->message_cb (sh->cls, &rm->sender, ntohl (rm->distance), @@ -443,7 +451,7 @@ handle_message_receipt (void *cls, peer = GNUNET_CONTAINER_multipeermap_get (sh->peers, &ack->target); if (NULL == peer) - return; /* this happens, just ignore */ + break; /* this happens, just ignore */ for (th = peer->head; NULL != th; th = th->next) { if (th->uid != ntohl (ack->uid)) @@ -466,6 +474,9 @@ handle_message_receipt (void *cls, reconnect (sh); break; } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received message, continuing receive loop for %p\n", + sh->client); GNUNET_CLIENT_receive (sh->client, &handle_message_receipt, sh, GNUNET_TIME_UNIT_FOREVER_REL); @@ -499,6 +510,9 @@ transmit_start (void *cls, start_message.size = htons (sizeof (struct GNUNET_MessageHeader)); start_message.type = htons (GNUNET_MESSAGE_TYPE_DV_START); memcpy (buf, &start_message, sizeof (start_message)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmitting START request, starting receive loop for %p\n", + sh->client); GNUNET_CLIENT_receive (sh->client, &handle_message_receipt, sh, GNUNET_TIME_UNIT_FOREVER_REL); @@ -520,6 +534,9 @@ reconnect (struct GNUNET_DV_ServiceHandle *sh) GNUNET_CLIENT_notify_transmit_ready_cancel (sh->th); sh->th = NULL; } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Disconnecting from DV service at %p\n", + sh->client); if (NULL != sh->client) { GNUNET_CLIENT_disconnect (sh->client); @@ -643,10 +660,11 @@ GNUNET_DV_send (struct GNUNET_DV_ServiceHandle *sh, return NULL; } LOG (GNUNET_ERROR_TYPE_DEBUG, - "Asked to send %u bytes of type %u to %s\n", + "Asked to send %u bytes of type %u to %s via %p\n", (unsigned int) ntohs (msg->size), (unsigned int) ntohs (msg->type), - GNUNET_i2s (target)); + GNUNET_i2s (target), + sh->client); peer = GNUNET_CONTAINER_multipeermap_get (sh->peers, target); if (NULL == peer) diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index 7cfbadbd5..43292e3aa 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c @@ -341,7 +341,7 @@ static struct GNUNET_CONTAINER_MultiPeerMap *direct_neighbors; /** * Hashmap with all routes that we currently support; contains * routing information for all peers from distance 2 - * up to distance DEFAULT_FISHEYE_DEPTH. + * up to distance #DEFAULT_FISHEYE_DEPTH. */ static struct GNUNET_CONTAINER_MultiPeerMap *all_routes; @@ -1974,7 +1974,7 @@ handle_dv_send_message (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_i2s (&msg->target)); forward_payload (route->next_hop, - ntohl (route->target.distance), + 0 /* first hop, distance is zero */, htonl (msg->uid), &my_identity, &msg->target, diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c index 646603655..4baabe12e 100644 --- a/src/dv/plugin_transport_dv.c +++ b/src/dv/plugin_transport_dv.c @@ -70,7 +70,7 @@ struct PendingRequest GNUNET_TRANSPORT_TransmitContinuation transmit_cont; /** - * Closure for transmit_cont. + * Closure for @e transmit_cont. */ void *transmit_cont_cls; @@ -84,6 +84,10 @@ struct PendingRequest */ struct Session *session; + /** + * Number of bytes to transmit. + */ + size_t size; }; @@ -214,6 +218,12 @@ unbox_cb (void *cls, ats.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); ats.value = htonl (session->distance); session->active = GNUNET_YES; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Delivering message of type %u with %u bytes from peer `%s'\n", + ntohs (message->type), + ntohs (message->size), + GNUNET_i2s (&session->sender)); + plugin->env->receive (plugin->env->cls, &session->sender, message, @@ -245,8 +255,7 @@ handle_dv_message_received (void *cls, struct Session *session; LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received `%s' message for peer `%s': new distance %u\n", - "DV_MESSAGE_RECEIVED", + "Received DV_MESSAGE_RECEIVED message for peer `%s': new distance %u\n", GNUNET_i2s (sender), distance); session = GNUNET_CONTAINER_multipeermap_get (plugin->sessions, sender); @@ -258,6 +267,8 @@ handle_dv_message_received (void *cls, if (GNUNET_MESSAGE_TYPE_DV_BOX == ntohs (msg->type)) { /* need to unbox using MST */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Unboxing DV message using MST\n"); GNUNET_SERVER_mst_receive (plugin->mst, session, (const char *) &msg[1], @@ -269,6 +280,11 @@ handle_dv_message_received (void *cls, ats.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); ats.value = htonl (distance); session->active = GNUNET_YES; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Delivering message of type %u with %u bytes from peer `%s'\n", + ntohs (msg->type), + ntohs (msg->size), + GNUNET_i2s (sender)); plugin->env->receive (plugin->env->cls, sender, msg, session, "", 0); @@ -420,7 +436,8 @@ free_session (struct Session *session) if (NULL != pr->transmit_cont) pr->transmit_cont (pr->transmit_cont_cls, &session->sender, - GNUNET_SYSERR, 0, 0); + GNUNET_SYSERR, + pr->size, 0); GNUNET_free (pr); } GNUNET_free (session); @@ -473,7 +490,8 @@ send_finished (void *cls, if (NULL != pr->transmit_cont) pr->transmit_cont (pr->transmit_cont_cls, &session->sender, - ok, 0, 0); + ok, + pr->size, 0); GNUNET_free (pr); } @@ -516,6 +534,8 @@ dv_plugin_send (void *cls, if (ntohs (msg->size) != msgbuf_size) { /* need to box */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Boxing DV message\n"); box = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader) + msgbuf_size); box->type = htons (GNUNET_MESSAGE_TYPE_DV_BOX); box->size = htons (sizeof (struct GNUNET_MessageHeader) + msgbuf_size); @@ -526,13 +546,14 @@ dv_plugin_send (void *cls, pr->transmit_cont = cont; pr->transmit_cont_cls = cont_cls; pr->session = session; + pr->size = msgbuf_size; GNUNET_CONTAINER_DLL_insert_tail (session->pr_head, session->pr_tail, pr); pr->th = GNUNET_DV_send (plugin->dvh, &session->sender, - msg , + msg, &send_finished, pr); GNUNET_free_non_null (box); @@ -570,7 +591,8 @@ dv_plugin_disconnect_peer (void *cls, if (NULL != pr->transmit_cont) pr->transmit_cont (pr->transmit_cont_cls, &session->sender, - GNUNET_SYSERR, 0, 0); + GNUNET_SYSERR, + pr->size, 0); GNUNET_free (pr); } session->active = GNUNET_NO; @@ -602,7 +624,8 @@ dv_plugin_disconnect_session (void *cls, if (NULL != pr->transmit_cont) pr->transmit_cont (pr->transmit_cont_cls, &session->sender, - GNUNET_SYSERR, 0, 0); + GNUNET_SYSERR, + pr->size, 0); GNUNET_free (pr); } session->active = GNUNET_NO; @@ -672,7 +695,7 @@ dv_plugin_address_to_string (void *cls, * * @param cls closure * @param addr pointer to the address - * @param addrlen length of addr + * @param addrlen length of @a addr * @return #GNUNET_OK if this is a plausible address for this peer * and transport, #GNUNET_SYSERR if not * @@ -743,14 +766,27 @@ dv_plugin_string_to_address (void *cls, return GNUNET_SYSERR; } + +/** + * Function that will be called whenever the transport service wants to + * notify the plugin that a session is still active and in use and + * therefore the session timeout for this session has to be updated + * + * @param cls closure (`struct Plugin *`) + * @param peer which peer was the session for + * @param session which session is being updated + */ static void dv_plugin_update_session_timeout (void *cls, const struct GNUNET_PeerIdentity *peer, struct Session *session) { - + /* DV currently doesn't time out like "normal" plugins, + so it should be safe to do nothing, right? + (or should we add an internal timeout?) */ } + /** * Function to obtain the network type for a session * FIXME: we should probably look at the network type -- 2.25.1