X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fcore%2Fgnunet-service-core_sessions.c;h=973ef9c2faaa7d5592efa9c6df1e4ce478aed866;hb=4b766fd267ca83a8faa4e22353d5942074d6f2b7;hp=036fd1425ff0c2bfd6b5fdc78117cb8c87cf9aa1;hpb=5663ca18885242fca4dd209898ffda9cbe675c58;p=oweals%2Fgnunet.git diff --git a/src/core/gnunet-service-core_sessions.c b/src/core/gnunet-service-core_sessions.c index 036fd1425..973ef9c2f 100644 --- a/src/core/gnunet-service-core_sessions.c +++ b/src/core/gnunet-service-core_sessions.c @@ -56,6 +56,21 @@ struct SessionMessageEntry */ struct SessionMessageEntry *prev; + /** + * How important is this message. + */ + enum GNUNET_CORE_Priority priority; + + /** + * Flag set to #GNUNET_YES if this is a typemap message. + */ + int is_typemap; + + /** + * Flag set to #GNUNET_YES if this is a typemap confirmation message. + */ + int is_typemap_confirm; + /** * Deadline for transmission, 1s after we received it (if we * are not corking), otherwise "now". Note that this message @@ -70,11 +85,6 @@ struct SessionMessageEntry */ size_t size; - /** - * How important is this message. - */ - enum GNUNET_CORE_Priority priority; - }; @@ -90,9 +100,9 @@ struct Session /** * Key exchange state for this peer. - */ + */ struct GSC_KeyExchangeInfo *kx; - + /** * Head of list of requests from clients for transmission to * this peer. @@ -136,12 +146,6 @@ struct Session */ struct GNUNET_TIME_Relative typemap_delay; - /** - * Is the neighbour queue empty and thus ready for us - * to transmit an encrypted message? - */ - int ready_to_transmit; - /** * Is this the first time we're sending the typemap? If so, * we want to send it a bit faster the second time. 0 if @@ -275,14 +279,19 @@ transmit_typemap_task (void *cls) struct GNUNET_MessageHeader *hdr; struct GNUNET_TIME_Relative delay; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending TYPEMAP to %s\n", + GNUNET_i2s (session->peer)); session->typemap_delay = GNUNET_TIME_STD_BACKOFF (session->typemap_delay); delay = session->typemap_delay; /* randomize a bit to avoid spont. sync */ delay.rel_value_us += - GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000 * 1000); + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + 1000 * 1000); session->typemap_task = GNUNET_SCHEDULER_add_delayed (delay, - &transmit_typemap_task, session); + &transmit_typemap_task, + session); GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# type map refreshes sent"), 1, @@ -326,7 +335,7 @@ GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer, struct Session *session; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Creating session for peer `%4s'\n", + "Creating session for peer `%s'\n", GNUNET_i2s (peer)); session = GNUNET_new (struct Session); session->tmap = GSC_TYPEMAP_create (); @@ -406,8 +415,14 @@ GSC_SESSIONS_confirm_typemap (const struct GNUNET_PeerIdentity *peer, gettext_noop ("# outdated typemap confirmations received"), 1, GNUNET_NO); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Got outdated typemap confirmated from peer `%s'\n", + GNUNET_i2s (session->peer)); return; } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Got typemap confirmation from peer `%s'\n", + GNUNET_i2s (session->peer)); if (NULL != session->typemap_task) { GNUNET_SCHEDULER_cancel (session->typemap_task); @@ -502,9 +517,9 @@ GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car) } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received client transmission request. queueing\n"); - GNUNET_CONTAINER_DLL_insert (session->active_client_request_head, - session->active_client_request_tail, - car); + GNUNET_CONTAINER_DLL_insert_tail (session->active_client_request_head, + session->active_client_request_tail, + car); try_transmission (session); } @@ -620,13 +635,7 @@ try_transmission (struct Session *session) enum GNUNET_CORE_Priority maxpc; struct GSC_ClientActiveRequest *car; int excess; - - if (GNUNET_YES != session->ready_to_transmit) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Not yet ready to transmit, not evaluating queue\n"); - return; - } + msize = 0; min_deadline = GNUNET_TIME_UNIT_FOREVER_ABS; /* if the peer has excess bandwidth, background traffic is allowed, @@ -725,10 +734,10 @@ try_transmission (struct Session *session) GNUNET_YES)); if (NULL != session->cork_task) GNUNET_SCHEDULER_cancel (session->cork_task); - session->cork_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (min_deadline), - &pop_cork_task, - session); + session->cork_task + = GNUNET_SCHEDULER_add_at (min_deadline, + &pop_cork_task, + session); } else { @@ -751,7 +760,15 @@ try_transmission (struct Session *session) while ( (NULL != (pos = session->sme_head)) && (used + pos->size <= msize) ) { - GNUNET_memcpy (&pbuf[used], &pos[1], pos->size); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Adding message of type %d (%d/%d) to payload for %s\n", + ntohs (((const struct GNUNET_MessageHeader *)&pos[1])->type), + pos->is_typemap, + pos->is_typemap_confirm, + GNUNET_i2s (session->peer)); + GNUNET_memcpy (&pbuf[used], + &pos[1], + pos->size); used += pos->size; GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, @@ -799,8 +816,23 @@ do_restart_typemap_message (void *cls, struct SessionMessageEntry *sme; uint16_t size; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Restarting sending TYPEMAP to %s\n", + GNUNET_i2s (session->peer)); size = ntohs (hdr->size); + for (sme = session->sme_head; NULL != sme; sme = sme->next) + { + if (GNUNET_YES == sme->is_typemap) + { + GNUNET_CONTAINER_DLL_remove (session->sme_head, + session->sme_tail, + sme); + GNUNET_free (sme); + break; + } + } sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + size); + sme->is_typemap = GNUNET_YES; GNUNET_memcpy (&sme[1], hdr, size); @@ -844,10 +876,12 @@ GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid) { struct Session *session; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Transport solicits for %s\n", + GNUNET_i2s (pid)); session = find_session (pid); if (NULL == session) return; - session->ready_to_transmit = GNUNET_YES; try_transmission (session); } @@ -924,18 +958,37 @@ GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer, nmap = GSC_TYPEMAP_get_from_message (msg); if (NULL == nmap) + { + GNUNET_break_op (0); return; /* malformed */ + } session = find_session (peer); if (NULL == session) { + GSC_TYPEMAP_destroy (nmap); GNUNET_break (0); return; } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received TYPEMAP from %s\n", + GNUNET_i2s (session->peer)); + for (sme = session->sme_head; NULL != sme; sme = sme->next) + { + if (GNUNET_YES == sme->is_typemap_confirm) + { + GNUNET_CONTAINER_DLL_remove (session->sme_head, + session->sme_tail, + sme); + GNUNET_free (sme); + break; + } + } sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + sizeof (struct TypeMapConfirmationMessage)); sme->deadline = GNUNET_TIME_absolute_get (); sme->size = sizeof (struct TypeMapConfirmationMessage); sme->priority = GNUNET_CORE_PRIO_CRITICAL_CONTROL; + sme->is_typemap_confirm = GNUNET_YES; tmc = (struct TypeMapConfirmationMessage *) &sme[1]; tmc->header.size = htons (sizeof (struct TypeMapConfirmationMessage)); tmc->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP); @@ -975,11 +1028,15 @@ GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer, return; session = find_session (peer); GNUNET_assert (NULL != session); - if (GNUNET_YES == GSC_TYPEMAP_test_match (session->tmap, &type, 1)) + if (GNUNET_YES == GSC_TYPEMAP_test_match (session->tmap, + &type, 1)) return; /* already in it */ - nmap = GSC_TYPEMAP_extend (session->tmap, &type, 1); + nmap = GSC_TYPEMAP_extend (session->tmap, + &type, + 1); GSC_CLIENTS_notify_clients_about_neighbour (peer, - session->tmap, nmap); + session->tmap, + nmap); GSC_TYPEMAP_destroy (session->tmap); session->tmap = nmap; }