diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-05-31 22:03:09 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-05-31 22:03:09 +0000 |
commit | e27921c7cfbc5b69aabf408d81d7fe85aab91e19 (patch) | |
tree | 0180709f8e1813adbeaeb3fa03d0ea9aa9322254 /src/core | |
parent | 4c6147e904989108966da156417f20599f1fe99c (diff) | |
download | gnunet-e27921c7cfbc5b69aabf408d81d7fe85aab91e19.tar.gz gnunet-e27921c7cfbc5b69aabf408d81d7fe85aab91e19.zip |
logging and proper limiting of message size
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/core_api.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/core/core_api.c b/src/core/core_api.c index 4af9aebfd..196191a32 100644 --- a/src/core/core_api.c +++ b/src/core/core_api.c | |||
@@ -25,6 +25,7 @@ | |||
25 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
26 | */ | 26 | */ |
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_constants.h" | ||
28 | #include "gnunet_core_service.h" | 29 | #include "gnunet_core_service.h" |
29 | #include "core.h" | 30 | #include "core.h" |
30 | 31 | ||
@@ -250,6 +251,10 @@ static size_t transmit_start (void *cls, size_t size, void *buf); | |||
250 | static void | 251 | static void |
251 | reconnect (struct GNUNET_CORE_Handle *h) | 252 | reconnect (struct GNUNET_CORE_Handle *h) |
252 | { | 253 | { |
254 | #if DEBUG_CORE | ||
255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
256 | "Reconnecting to CORE service\n"); | ||
257 | #endif | ||
253 | if (h->client_notifications != NULL) | 258 | if (h->client_notifications != NULL) |
254 | GNUNET_CLIENT_disconnect (h->client_notifications, GNUNET_NO); | 259 | GNUNET_CLIENT_disconnect (h->client_notifications, GNUNET_NO); |
255 | h->currently_down = GNUNET_YES; | 260 | h->currently_down = GNUNET_YES; |
@@ -277,11 +282,16 @@ reconnect (struct GNUNET_CORE_Handle *h) | |||
277 | * @param tc context, can be NULL (!) | 282 | * @param tc context, can be NULL (!) |
278 | */ | 283 | */ |
279 | static void | 284 | static void |
280 | timeout_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 285 | timeout_request (void *cls, |
286 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
281 | { | 287 | { |
282 | struct GNUNET_CORE_TransmitHandle *th = cls; | 288 | struct GNUNET_CORE_TransmitHandle *th = cls; |
283 | 289 | ||
284 | th->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 290 | th->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
291 | #if DEBUG_CORE | ||
292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
293 | "Signalling timeout of request for transmission to CORE service\n"); | ||
294 | #endif | ||
285 | GNUNET_assert (0 == th->get_message (th->get_message_cls, 0, NULL)); | 295 | GNUNET_assert (0 == th->get_message (th->get_message_cls, 0, NULL)); |
286 | } | 296 | } |
287 | 297 | ||
@@ -317,6 +327,11 @@ request_start (void *cls, size_t size, void *buf) | |||
317 | GNUNET_assert (size >= th->msize); | 327 | GNUNET_assert (size >= th->msize); |
318 | ret = th->get_message (th->get_message_cls, size, buf); | 328 | ret = th->get_message (th->get_message_cls, size, buf); |
319 | GNUNET_assert (ret <= size); | 329 | GNUNET_assert (ret <= size); |
330 | #if DEBUG_CORE | ||
331 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
332 | "Transmitting %u bytes to core\n", | ||
333 | ret); | ||
334 | #endif | ||
320 | return ret; | 335 | return ret; |
321 | } | 336 | } |
322 | 337 | ||
@@ -798,11 +813,6 @@ produce_send (void *cls, size_t size, void *buf) | |||
798 | trigger_next_request (h); | 813 | trigger_next_request (h); |
799 | return 0; | 814 | return 0; |
800 | } | 815 | } |
801 | #if DEBUG_CORE | ||
802 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
803 | "Preparing for P2P transmission to `%4s'.\n", | ||
804 | GNUNET_i2s(&th->peer)); | ||
805 | #endif | ||
806 | sm = (struct SendMessage *) buf; | 816 | sm = (struct SendMessage *) buf; |
807 | sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND); | 817 | sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND); |
808 | sm->priority = htonl (th->priority); | 818 | sm->priority = htonl (th->priority); |
@@ -812,6 +822,8 @@ produce_send (void *cls, size_t size, void *buf) | |||
812 | notify_cls = th->notify_cls; | 822 | notify_cls = th->notify_cls; |
813 | GNUNET_CORE_notify_transmit_ready_cancel (th); | 823 | GNUNET_CORE_notify_transmit_ready_cancel (th); |
814 | trigger_next_request (h); | 824 | trigger_next_request (h); |
825 | size = GNUNET_MIN (size, | ||
826 | GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); | ||
815 | GNUNET_assert (size >= sizeof (struct SendMessage)); | 827 | GNUNET_assert (size >= sizeof (struct SendMessage)); |
816 | dt = notify (notify_cls, size - sizeof (struct SendMessage), &sm[1]); | 828 | dt = notify (notify_cls, size - sizeof (struct SendMessage), &sm[1]); |
817 | if (0 == dt) | 829 | if (0 == dt) |
@@ -824,12 +836,23 @@ produce_send (void *cls, size_t size, void *buf) | |||
824 | /* client decided to send nothing! */ | 836 | /* client decided to send nothing! */ |
825 | return 0; | 837 | return 0; |
826 | } | 838 | } |
839 | #if DEBUG_CORE | ||
840 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
841 | "Produced SEND message to core with %u bytes payload\n", | ||
842 | dt); | ||
843 | #endif | ||
827 | GNUNET_assert (dt >= sizeof (struct GNUNET_MessageHeader)); | 844 | GNUNET_assert (dt >= sizeof (struct GNUNET_MessageHeader)); |
828 | if (dt + sizeof (struct SendMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 845 | if (dt + sizeof (struct SendMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
829 | { | 846 | { |
830 | GNUNET_break (0); | 847 | GNUNET_break (0); |
831 | return 0; | 848 | return 0; |
832 | } | 849 | } |
850 | #if DEBUG_CORE | ||
851 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
852 | "Preparing for P2P transmission of %u bytes to `%4s'.\n", | ||
853 | dt, | ||
854 | GNUNET_i2s(&th->peer)); | ||
855 | #endif | ||
833 | sm->header.size = htons (dt + sizeof (struct SendMessage)); | 856 | sm->header.size = htons (dt + sizeof (struct SendMessage)); |
834 | GNUNET_assert (dt + sizeof (struct SendMessage) <= size); | 857 | GNUNET_assert (dt + sizeof (struct SendMessage) <= size); |
835 | return dt + sizeof (struct SendMessage); | 858 | return dt + sizeof (struct SendMessage); |