aboutsummaryrefslogtreecommitdiff
path: root/src/core/gnunet-service-core_sessions.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-02-19 20:31:12 +0100
committerChristian Grothoff <christian@grothoff.org>2017-02-19 20:31:12 +0100
commit3902d240e408e85f08d9c444356eb18fc6ea44e7 (patch)
treea92c4b953d8a719ebb8a9f567d053352bff9933b /src/core/gnunet-service-core_sessions.c
parent8802f213c67692abebebdf9fe2d4a77afe2b1fcb (diff)
downloadgnunet-3902d240e408e85f08d9c444356eb18fc6ea44e7.tar.gz
gnunet-3902d240e408e85f08d9c444356eb18fc6ea44e7.zip
mostly logging, avoid having more than one typemap in transmission queue, accept port=0 as not an error, tolerate link-local addrs
Diffstat (limited to 'src/core/gnunet-service-core_sessions.c')
-rw-r--r--src/core/gnunet-service-core_sessions.c96
1 files changed, 81 insertions, 15 deletions
diff --git a/src/core/gnunet-service-core_sessions.c b/src/core/gnunet-service-core_sessions.c
index 6687b4819..034f2e883 100644
--- a/src/core/gnunet-service-core_sessions.c
+++ b/src/core/gnunet-service-core_sessions.c
@@ -57,6 +57,21 @@ struct SessionMessageEntry
57 struct SessionMessageEntry *prev; 57 struct SessionMessageEntry *prev;
58 58
59 /** 59 /**
60 * How important is this message.
61 */
62 enum GNUNET_CORE_Priority priority;
63
64 /**
65 * Flag set to #GNUNET_YES if this is a typemap message.
66 */
67 int is_typemap;
68
69 /**
70 * Flag set to #GNUNET_YES if this is a typemap confirmation message.
71 */
72 int is_typemap_confirm;
73
74 /**
60 * Deadline for transmission, 1s after we received it (if we 75 * Deadline for transmission, 1s after we received it (if we
61 * are not corking), otherwise "now". Note that this message 76 * are not corking), otherwise "now". Note that this message
62 * does NOT expire past its deadline. 77 * does NOT expire past its deadline.
@@ -70,11 +85,6 @@ struct SessionMessageEntry
70 */ 85 */
71 size_t size; 86 size_t size;
72 87
73 /**
74 * How important is this message.
75 */
76 enum GNUNET_CORE_Priority priority;
77
78}; 88};
79 89
80 90
@@ -275,14 +285,19 @@ transmit_typemap_task (void *cls)
275 struct GNUNET_MessageHeader *hdr; 285 struct GNUNET_MessageHeader *hdr;
276 struct GNUNET_TIME_Relative delay; 286 struct GNUNET_TIME_Relative delay;
277 287
288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
289 "Sending TYPEMAP to %s\n",
290 GNUNET_i2s (session->peer));
278 session->typemap_delay = GNUNET_TIME_STD_BACKOFF (session->typemap_delay); 291 session->typemap_delay = GNUNET_TIME_STD_BACKOFF (session->typemap_delay);
279 delay = session->typemap_delay; 292 delay = session->typemap_delay;
280 /* randomize a bit to avoid spont. sync */ 293 /* randomize a bit to avoid spont. sync */
281 delay.rel_value_us += 294 delay.rel_value_us +=
282 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000 * 1000); 295 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
296 1000 * 1000);
283 session->typemap_task = 297 session->typemap_task =
284 GNUNET_SCHEDULER_add_delayed (delay, 298 GNUNET_SCHEDULER_add_delayed (delay,
285 &transmit_typemap_task, session); 299 &transmit_typemap_task,
300 session);
286 GNUNET_STATISTICS_update (GSC_stats, 301 GNUNET_STATISTICS_update (GSC_stats,
287 gettext_noop ("# type map refreshes sent"), 302 gettext_noop ("# type map refreshes sent"),
288 1, 303 1,
@@ -326,7 +341,7 @@ GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer,
326 struct Session *session; 341 struct Session *session;
327 342
328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 343 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
329 "Creating session for peer `%4s'\n", 344 "Creating session for peer `%s'\n",
330 GNUNET_i2s (peer)); 345 GNUNET_i2s (peer));
331 session = GNUNET_new (struct Session); 346 session = GNUNET_new (struct Session);
332 session->tmap = GSC_TYPEMAP_create (); 347 session->tmap = GSC_TYPEMAP_create ();
@@ -406,8 +421,14 @@ GSC_SESSIONS_confirm_typemap (const struct GNUNET_PeerIdentity *peer,
406 gettext_noop 421 gettext_noop
407 ("# outdated typemap confirmations received"), 422 ("# outdated typemap confirmations received"),
408 1, GNUNET_NO); 423 1, GNUNET_NO);
424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
425 "Got outdated typemap confirmated from peer `%s'\n",
426 GNUNET_i2s (session->peer));
409 return; 427 return;
410 } 428 }
429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
430 "Got typemap confirmation from peer `%s'\n",
431 GNUNET_i2s (session->peer));
411 if (NULL != session->typemap_task) 432 if (NULL != session->typemap_task)
412 { 433 {
413 GNUNET_SCHEDULER_cancel (session->typemap_task); 434 GNUNET_SCHEDULER_cancel (session->typemap_task);
@@ -502,9 +523,9 @@ GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car)
502 } 523 }
503 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 524 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
504 "Received client transmission request. queueing\n"); 525 "Received client transmission request. queueing\n");
505 GNUNET_CONTAINER_DLL_insert (session->active_client_request_head, 526 GNUNET_CONTAINER_DLL_insert_tail (session->active_client_request_head,
506 session->active_client_request_tail, 527 session->active_client_request_tail,
507 car); 528 car);
508 try_transmission (session); 529 try_transmission (session);
509} 530}
510 531
@@ -751,7 +772,15 @@ try_transmission (struct Session *session)
751 while ( (NULL != (pos = session->sme_head)) && 772 while ( (NULL != (pos = session->sme_head)) &&
752 (used + pos->size <= msize) ) 773 (used + pos->size <= msize) )
753 { 774 {
754 GNUNET_memcpy (&pbuf[used], &pos[1], pos->size); 775 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
776 "Adding message of type %d (%d/%d) to payload for %s\n",
777 ntohs (((const struct GNUNET_MessageHeader *)&pos[1])->type),
778 pos->is_typemap,
779 pos->is_typemap_confirm,
780 GNUNET_i2s (session->peer));
781 GNUNET_memcpy (&pbuf[used],
782 &pos[1],
783 pos->size);
755 used += pos->size; 784 used += pos->size;
756 GNUNET_CONTAINER_DLL_remove (session->sme_head, 785 GNUNET_CONTAINER_DLL_remove (session->sme_head,
757 session->sme_tail, 786 session->sme_tail,
@@ -799,8 +828,23 @@ do_restart_typemap_message (void *cls,
799 struct SessionMessageEntry *sme; 828 struct SessionMessageEntry *sme;
800 uint16_t size; 829 uint16_t size;
801 830
831 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
832 "Restarting sending TYPEMAP to %s\n",
833 GNUNET_i2s (session->peer));
802 size = ntohs (hdr->size); 834 size = ntohs (hdr->size);
835 for (sme = session->sme_head; NULL != sme; sme = sme->next)
836 {
837 if (GNUNET_YES == sme->is_typemap)
838 {
839 GNUNET_CONTAINER_DLL_remove (session->sme_head,
840 session->sme_tail,
841 sme);
842 GNUNET_free (sme);
843 break;
844 }
845 }
803 sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + size); 846 sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + size);
847 sme->is_typemap = GNUNET_YES;
804 GNUNET_memcpy (&sme[1], 848 GNUNET_memcpy (&sme[1],
805 hdr, 849 hdr,
806 size); 850 size);
@@ -924,18 +968,36 @@ GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
924 968
925 nmap = GSC_TYPEMAP_get_from_message (msg); 969 nmap = GSC_TYPEMAP_get_from_message (msg);
926 if (NULL == nmap) 970 if (NULL == nmap)
971 {
972 GNUNET_break_op (0);
927 return; /* malformed */ 973 return; /* malformed */
974 }
928 session = find_session (peer); 975 session = find_session (peer);
929 if (NULL == session) 976 if (NULL == session)
930 { 977 {
931 GNUNET_break (0); 978 GNUNET_break (0);
932 return; 979 return;
933 } 980 }
981 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
982 "Received TYPEMAP from %s\n",
983 GNUNET_i2s (session->peer));
984 for (sme = session->sme_head; NULL != sme; sme = sme->next)
985 {
986 if (GNUNET_YES == sme->is_typemap_confirm)
987 {
988 GNUNET_CONTAINER_DLL_remove (session->sme_head,
989 session->sme_tail,
990 sme);
991 GNUNET_free (sme);
992 break;
993 }
994 }
934 sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + 995 sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) +
935 sizeof (struct TypeMapConfirmationMessage)); 996 sizeof (struct TypeMapConfirmationMessage));
936 sme->deadline = GNUNET_TIME_absolute_get (); 997 sme->deadline = GNUNET_TIME_absolute_get ();
937 sme->size = sizeof (struct TypeMapConfirmationMessage); 998 sme->size = sizeof (struct TypeMapConfirmationMessage);
938 sme->priority = GNUNET_CORE_PRIO_CRITICAL_CONTROL; 999 sme->priority = GNUNET_CORE_PRIO_CRITICAL_CONTROL;
1000 sme->is_typemap_confirm = GNUNET_YES;
939 tmc = (struct TypeMapConfirmationMessage *) &sme[1]; 1001 tmc = (struct TypeMapConfirmationMessage *) &sme[1];
940 tmc->header.size = htons (sizeof (struct TypeMapConfirmationMessage)); 1002 tmc->header.size = htons (sizeof (struct TypeMapConfirmationMessage));
941 tmc->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP); 1003 tmc->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP);
@@ -975,11 +1037,15 @@ GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
975 return; 1037 return;
976 session = find_session (peer); 1038 session = find_session (peer);
977 GNUNET_assert (NULL != session); 1039 GNUNET_assert (NULL != session);
978 if (GNUNET_YES == GSC_TYPEMAP_test_match (session->tmap, &type, 1)) 1040 if (GNUNET_YES == GSC_TYPEMAP_test_match (session->tmap,
1041 &type, 1))
979 return; /* already in it */ 1042 return; /* already in it */
980 nmap = GSC_TYPEMAP_extend (session->tmap, &type, 1); 1043 nmap = GSC_TYPEMAP_extend (session->tmap,
1044 &type,
1045 1);
981 GSC_CLIENTS_notify_clients_about_neighbour (peer, 1046 GSC_CLIENTS_notify_clients_about_neighbour (peer,
982 session->tmap, nmap); 1047 session->tmap,
1048 nmap);
983 GSC_TYPEMAP_destroy (session->tmap); 1049 GSC_TYPEMAP_destroy (session->tmap);
984 session->tmap = nmap; 1050 session->tmap = nmap;
985} 1051}