diff options
Diffstat (limited to 'src/core')
25 files changed, 826 insertions, 661 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am index ad9bddc..e95cbcf 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -20,7 +20,8 @@ lib_LTLIBRARIES = \ libgnunetcore_la_SOURCES = \ core_api.c core.h \ - core_api_iterate_peers.c + core_api_iterate_peers.c \ + core_api_is_connected.c libgnunetcore_la_LIBADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(GN_LIBINTL) $(XLIB) @@ -31,7 +32,7 @@ libgnunetcore_la_LDFLAGS = \ bin_PROGRAMS = \ gnunet-service-core \ - gnunet-core-list-connections + gnunet-core gnunet_service_core_SOURCES = \ gnunet-service-core.c gnunet-service-core.h \ @@ -49,14 +50,12 @@ gnunet_service_core_LDADD = \ $(GN_LIBINTL) -lz -gnunet_core_list_connections_SOURCES = \ - gnunet-core-list-connections.c -gnunet_core_list_connections_LDADD = \ +gnunet_core_SOURCES = \ + gnunet-core.c +gnunet_core_LDADD = \ $(top_builddir)/src/core/libgnunetcore.la \ - $(top_builddir)/src/transport/libgnunettransport.la \ - $(top_builddir)/src/hello/libgnunethello.la \ $(top_builddir)/src/util/libgnunetutil.la -gnunet_core_list_connections_DEPENDENCIES = \ +gnunet_core_DEPENDENCIES = \ libgnunetcore.la check_PROGRAMS = \ diff --git a/src/core/Makefile.in b/src/core/Makefile.in index 42177b4..f181a54 100644 --- a/src/core/Makefile.in +++ b/src/core/Makefile.in @@ -37,8 +37,7 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ -bin_PROGRAMS = gnunet-service-core$(EXEEXT) \ - gnunet-core-list-connections$(EXEEXT) +bin_PROGRAMS = gnunet-service-core$(EXEEXT) gnunet-core$(EXEEXT) check_PROGRAMS = test_core_api_start_only$(EXEEXT) \ test_core_api$(EXEEXT) test_core_api_reliability$(EXEEXT) \ test_core_quota_compliance_symmetric$(EXEEXT) \ @@ -95,7 +94,8 @@ am__DEPENDENCIES_1 = libgnunetcore_la_DEPENDENCIES = \ $(top_builddir)/src/util/libgnunetutil.la \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) -am_libgnunetcore_la_OBJECTS = core_api.lo core_api_iterate_peers.lo +am_libgnunetcore_la_OBJECTS = core_api.lo core_api_iterate_peers.lo \ + core_api_is_connected.lo libgnunetcore_la_OBJECTS = $(am_libgnunetcore_la_OBJECTS) AM_V_lt = $(am__v_lt_$(V)) am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) @@ -105,10 +105,8 @@ libgnunetcore_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_CFLAGS) $(CFLAGS) $(libgnunetcore_la_LDFLAGS) $(LDFLAGS) \ -o $@ PROGRAMS = $(bin_PROGRAMS) -am_gnunet_core_list_connections_OBJECTS = \ - gnunet-core-list-connections.$(OBJEXT) -gnunet_core_list_connections_OBJECTS = \ - $(am_gnunet_core_list_connections_OBJECTS) +am_gnunet_core_OBJECTS = gnunet-core.$(OBJEXT) +gnunet_core_OBJECTS = $(am_gnunet_core_OBJECTS) am_gnunet_service_core_OBJECTS = gnunet-service-core.$(OBJEXT) \ gnunet-service-core_clients.$(OBJEXT) \ gnunet-service-core_neighbours.$(OBJEXT) \ @@ -203,8 +201,7 @@ am__v_CCLD_0 = @echo " CCLD " $@; AM_V_GEN = $(am__v_GEN_$(V)) am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) am__v_GEN_0 = @echo " GEN " $@; -SOURCES = $(libgnunetcore_la_SOURCES) \ - $(gnunet_core_list_connections_SOURCES) \ +SOURCES = $(libgnunetcore_la_SOURCES) $(gnunet_core_SOURCES) \ $(gnunet_service_core_SOURCES) $(test_core_api_SOURCES) \ $(test_core_api_reliability_SOURCES) \ $(test_core_api_send_to_self_SOURCES) \ @@ -212,8 +209,7 @@ SOURCES = $(libgnunetcore_la_SOURCES) \ $(test_core_quota_compliance_asymmetric_recv_limited_SOURCES) \ $(test_core_quota_compliance_asymmetric_send_limited_SOURCES) \ $(test_core_quota_compliance_symmetric_SOURCES) -DIST_SOURCES = $(libgnunetcore_la_SOURCES) \ - $(gnunet_core_list_connections_SOURCES) \ +DIST_SOURCES = $(libgnunetcore_la_SOURCES) $(gnunet_core_SOURCES) \ $(gnunet_service_core_SOURCES) $(test_core_api_SOURCES) \ $(test_core_api_reliability_SOURCES) \ $(test_core_api_send_to_self_SOURCES) \ @@ -282,6 +278,7 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ INTLLIBS = @INTLLIBS@ INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ +JAVAPORT = @JAVAPORT@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBADD_DL = @LIBADD_DL@ @@ -315,6 +312,7 @@ LT_DLLOADERS = @LT_DLLOADERS@ LT_DLPREOPEN = @LT_DLPREOPEN@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ +MONKEYPREFIX = @MONKEYPREFIX@ MSGFMT = @MSGFMT@ MSGFMT_015 = @MSGFMT_015@ MSGMERGE = @MSGMERGE@ @@ -444,7 +442,8 @@ lib_LTLIBRARIES = \ libgnunetcore_la_SOURCES = \ core_api.c core.h \ - core_api_iterate_peers.c + core_api_iterate_peers.c \ + core_api_is_connected.c libgnunetcore_la_LIBADD = \ $(top_builddir)/src/util/libgnunetutil.la \ @@ -470,16 +469,14 @@ gnunet_service_core_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(GN_LIBINTL) -lz -gnunet_core_list_connections_SOURCES = \ - gnunet-core-list-connections.c +gnunet_core_SOURCES = \ + gnunet-core.c -gnunet_core_list_connections_LDADD = \ +gnunet_core_LDADD = \ $(top_builddir)/src/core/libgnunetcore.la \ - $(top_builddir)/src/transport/libgnunettransport.la \ - $(top_builddir)/src/hello/libgnunethello.la \ $(top_builddir)/src/util/libgnunetutil.la -gnunet_core_list_connections_DEPENDENCIES = \ +gnunet_core_DEPENDENCIES = \ libgnunetcore.la @ENABLE_TEST_RUN_TRUE@TESTS = $(check_PROGRAMS) @@ -675,9 +672,9 @@ clean-checkPROGRAMS: list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ echo " rm -f" $$list; \ rm -f $$list -gnunet-core-list-connections$(EXEEXT): $(gnunet_core_list_connections_OBJECTS) $(gnunet_core_list_connections_DEPENDENCIES) - @rm -f gnunet-core-list-connections$(EXEEXT) - $(AM_V_CCLD)$(LINK) $(gnunet_core_list_connections_OBJECTS) $(gnunet_core_list_connections_LDADD) $(LIBS) +gnunet-core$(EXEEXT): $(gnunet_core_OBJECTS) $(gnunet_core_DEPENDENCIES) + @rm -f gnunet-core$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(gnunet_core_OBJECTS) $(gnunet_core_LDADD) $(LIBS) gnunet-service-core$(EXEEXT): $(gnunet_service_core_OBJECTS) $(gnunet_service_core_DEPENDENCIES) @rm -f gnunet-service-core$(EXEEXT) $(AM_V_CCLD)$(LINK) $(gnunet_service_core_OBJECTS) $(gnunet_service_core_LDADD) $(LIBS) @@ -710,8 +707,9 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/core_api.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/core_api_is_connected.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/core_api_iterate_peers.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnunet-core-list-connections.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnunet-core.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnunet-service-core.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnunet-service-core_clients.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnunet-service-core_kx.Po@am__quote@ diff --git a/src/core/core.conf.in b/src/core/core.conf.in index 84e2df9..61ac84e 100644 --- a/src/core/core.conf.in +++ b/src/core/core.conf.in @@ -1,6 +1,6 @@ [core] AUTOSTART = YES -@UNIXONLY@ PORT = 2092 +@JAVAPORT@PORT = 2092 HOSTNAME = localhost HOME = $SERVICEHOME CONFIG = $DEFAULTCONFIG diff --git a/src/core/core.h b/src/core/core.h index 4942ad0..03e328c 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -112,7 +112,6 @@ struct ConnectNotifyMessage /** * Number of ATS key-value pairs that follow this struct - * (excluding the 0-terminator). */ uint32_t ats_count GNUNET_PACKED; @@ -222,12 +221,11 @@ struct NotifyTrafficMessage */ struct GNUNET_PeerIdentity peer; - /** - * First of the ATS information blocks (we must have at least - * one due to the 0-termination requirement). + /* Followed by ATS information blocks: + * struct GNUNET_ATS_Information ats[ats_count] */ - struct GNUNET_ATS_Information ats; + /* Followed by payload (message or just header), variable size */ }; @@ -332,7 +330,7 @@ struct SendMessage struct GNUNET_TIME_AbsoluteNBO deadline; /** - * Identity of the receiver or sender. + * Identity of the intended receiver. */ struct GNUNET_PeerIdentity peer; @@ -349,32 +347,6 @@ struct SendMessage }; -/** - * Client asking core to connect to a particular target. There is no - * response from the core to this type of request (however, if an - * actual connection is created or destroyed, be it because of this - * type request or not, the core generally needs to notify the - * clients). - */ -struct ConnectMessage -{ - /** - * Header with type GNUNET_MESSAGE_TYPE_REQUEST_CONNECT or - * GNUNET_MESSAGE_TYPE_REQUEST_DISCONNECT. - */ - struct GNUNET_MessageHeader header; - - /** - * For alignment. - */ - uint32_t reserved GNUNET_PACKED; - - /** - * Identity of the other peer. - */ - struct GNUNET_PeerIdentity peer; - -}; GNUNET_NETWORK_STRUCT_END #endif /* end of core.h */ diff --git a/src/core/core_api.c b/src/core/core_api.c index 66df134..526dc9f 100644 --- a/src/core/core_api.c +++ b/src/core/core_api.c @@ -367,9 +367,7 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct GNUNET_CORE_Handle *h = cls; h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service after delay\n"); -#endif reconnect (h); } @@ -450,7 +448,7 @@ reconnect_later (struct GNUNET_CORE_Handle *h) } if (h->client != NULL) { - GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); + GNUNET_CLIENT_disconnect (h->client); h->client = NULL; } h->currently_down = GNUNET_YES; @@ -546,11 +544,9 @@ request_next_transmission (struct PeerRecord *pr) smr->smr_id = htons (th->smr_id = pr->smr_id_gen++); GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head, h->control_pending_tail, cm); -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding SEND REQUEST for peer `%s' to message queue\n", GNUNET_i2s (&pr->peer)); -#endif trigger_next_request (h, GNUNET_NO); } @@ -580,10 +576,15 @@ transmission_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * us from the 'ready' list */ GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr); } -#if DEBUG_CORE + if (NULL != th->cm) + { + /* we're currently in the control queue, remove */ + GNUNET_CONTAINER_DLL_remove (h->control_pending_head, + h->control_pending_tail, th->cm); + GNUNET_free (th->cm); + } LOG (GNUNET_ERROR_TYPE_DEBUG, "Signalling timeout of request for transmission to CORE service\n"); -#endif request_next_transmission (pr); GNUNET_assert (0 == th->get_message (th->get_message_cls, 0, NULL)); GNUNET_free (th); @@ -592,6 +593,11 @@ transmission_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) /** * Transmit the next message to the core service. + * + * @param cls closure with the 'struct GNUNET_CORE_Handle' + * @param size number of bytes available in buf + * @param buf where the callee should write the message + * @return number of bytes written to buf */ static size_t transmit_message (void *cls, size_t size, void *buf) @@ -609,10 +615,8 @@ transmit_message (void *cls, size_t size, void *buf) h->cth = NULL; if (buf == NULL) { -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmission failed, initiating reconnect\n"); -#endif reconnect_later (h); return 0; } @@ -626,11 +630,9 @@ transmit_message (void *cls, size_t size, void *buf) trigger_next_request (h, GNUNET_NO); return 0; } -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting control message with %u bytes of type %u to core.\n", (unsigned int) msize, (unsigned int) ntohs (hdr->type)); -#endif memcpy (buf, hdr, msize); GNUNET_CONTAINER_DLL_remove (h->control_pending_head, h->control_pending_tail, cm); @@ -660,11 +662,9 @@ transmit_message (void *cls, size_t size, void *buf) GNUNET_SCHEDULER_cancel (pr->timeout_task); pr->timeout_task = GNUNET_SCHEDULER_NO_TASK; } -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting SEND request to `%s' with %u bytes.\n", GNUNET_i2s (&pr->peer), (unsigned int) th->msize); -#endif sm = (struct SendMessage *) buf; sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND); sm->priority = htonl (th->priority); @@ -676,28 +676,22 @@ transmit_message (void *cls, size_t size, void *buf) th->get_message (th->get_message_cls, size - sizeof (struct SendMessage), &sm[1]); -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting SEND request to `%s' yielded %u bytes.\n", GNUNET_i2s (&pr->peer), ret); -#endif GNUNET_free (th); if (0 == ret) { -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Size of clients message to peer %s is 0!\n", GNUNET_i2s (&pr->peer)); -#endif /* client decided to send nothing! */ request_next_transmission (pr); return 0; } -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Produced SEND message to core with %u bytes payload\n", (unsigned int) ret); -#endif GNUNET_assert (ret >= sizeof (struct GNUNET_MessageHeader)); if (ret + sizeof (struct SendMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) { @@ -729,17 +723,13 @@ trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down) if ((GNUNET_YES == h->currently_down) && (ignore_currently_down == GNUNET_NO)) { -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Core connection down, not processing queue\n"); -#endif return; } if (NULL != h->cth) { -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Request pending, not processing queue\n"); -#endif return; } if (h->control_pending_head != NULL) @@ -751,10 +741,8 @@ trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down) h->ready_peer_head->pending_head->msize + sizeof (struct SendMessage); else { -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Request queue empty, not processing queue\n"); -#endif return; /* no pending message */ } h->cth = @@ -791,7 +779,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) uint16_t et; uint32_t ats_count; - if (msg == NULL) + if (NULL == msg) { LOG (GNUNET_ERROR_TYPE_INFO, _ @@ -800,11 +788,9 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) return; } msize = ntohs (msg->size); -#if DEBUG_CORE > 2 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing message of type %u and size %u from core service\n", ntohs (msg->type), msize); -#endif switch (ntohs (msg->type)) { case GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY: @@ -828,22 +814,18 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) { /* mark so we don't call init on reconnect */ h->init = NULL; -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to core service of peer `%s'.\n", GNUNET_i2s (&h->me)); -#endif init (h->cls, h, &h->me); } else { -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Successfully reconnected to core service.\n"); -#endif } /* fake 'connect to self' */ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &h->me.hashPubKey); - GNUNET_assert (pr == NULL); + GNUNET_assert (NULL == pr); pr = GNUNET_malloc (sizeof (struct PeerRecord)); pr->peer = h->me; pr->ch = h; @@ -871,11 +853,9 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) reconnect_later (h); return; } -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Received notification about connection from `%s'.\n", GNUNET_i2s (&cnm->peer)); -#endif if (0 == memcmp (&h->me, &cnm->peer, sizeof (struct GNUNET_PeerIdentity))) { /* connect to self!? */ @@ -883,7 +863,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) return; } pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &cnm->peer.hashPubKey); - if (pr != NULL) + if (NULL != pr) { GNUNET_break (0); reconnect_later (h); @@ -915,13 +895,11 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) return; } GNUNET_break (0 == ntohl (dnm->reserved)); -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Received notification about disconnect from `%s'.\n", GNUNET_i2s (&dnm->peer)); -#endif pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &dnm->peer.hashPubKey); - if (pr == NULL) + if (NULL == pr) { GNUNET_break (0); reconnect_later (h); @@ -941,31 +919,21 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) return; } ntm = (const struct NotifyTrafficMessage *) msg; - ats_count = ntohl (ntm->ats_count); if ((msize < sizeof (struct NotifyTrafficMessage) + ats_count * sizeof (struct GNUNET_ATS_Information) + - sizeof (struct GNUNET_MessageHeader)) || - (GNUNET_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type))) + sizeof (struct GNUNET_MessageHeader)) ) { GNUNET_break (0); reconnect_later (h); return; } - em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count + 1]; -#if DEBUG_CORE + ats = (const struct GNUNET_ATS_Information*) &ntm[1]; + em = (const struct GNUNET_MessageHeader *) &ats[ats_count]; LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %u and size %u from peer `%4s'\n", ntohs (em->type), ntohs (em->size), GNUNET_i2s (&ntm->peer)); -#endif - pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &ntm->peer.hashPubKey); - if (pr == NULL) - { - GNUNET_break (0); - reconnect_later (h); - return; - } if ((GNUNET_NO == h->inbound_hdr_only) && (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage) + @@ -989,8 +957,15 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) GNUNET_break_op (0); continue; } + pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &ntm->peer.hashPubKey); + if (NULL == pr) + { + GNUNET_break (0); + reconnect_later (h); + return; + } if (GNUNET_OK != - h->handlers[hpos].callback (h->cls, &ntm->peer, em, &ntm->ats, + h->handlers[hpos].callback (h->cls, &ntm->peer, em, ats, ats_count)) { /* error in processing, do not process other messages! */ @@ -998,7 +973,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) } } if (NULL != h->inbound_notify) - h->inbound_notify (h->cls, &ntm->peer, em, &ntm->ats, ats_count); + h->inbound_notify (h->cls, &ntm->peer, em, ats, ats_count); break; case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND: if (msize < sizeof (struct NotifyTrafficMessage)) @@ -1008,36 +983,21 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) return; } ntm = (const struct NotifyTrafficMessage *) msg; - if (0 == memcmp (&h->me, &ntm->peer, sizeof (struct GNUNET_PeerIdentity))) - { - /* self-change!? */ - GNUNET_break (0); - return; - } ats_count = ntohl (ntm->ats_count); if ((msize < sizeof (struct NotifyTrafficMessage) + ats_count * sizeof (struct GNUNET_ATS_Information) + - sizeof (struct GNUNET_MessageHeader)) || - (GNUNET_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type))) - { - GNUNET_break (0); - reconnect_later (h); - return; - } - em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count + 1]; - pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &ntm->peer.hashPubKey); - if (pr == NULL) + sizeof (struct GNUNET_MessageHeader)) ) { GNUNET_break (0); reconnect_later (h); return; } -#if DEBUG_CORE + ats = (const struct GNUNET_ATS_Information*) &ntm[1]; + em = (const struct GNUNET_MessageHeader *) &ats[ats_count]; LOG (GNUNET_ERROR_TYPE_DEBUG, "Received notification about transmission to `%s'.\n", GNUNET_i2s (&ntm->peer)); -#endif if ((GNUNET_NO == h->outbound_hdr_only) && (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage) + @@ -1052,7 +1012,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) GNUNET_break (0); break; } - h->outbound_notify (h->cls, &ntm->peer, em, &ntm->ats, ats_count); + h->outbound_notify (h->cls, &ntm->peer, em, ats, ats_count); break; case GNUNET_MESSAGE_TYPE_CORE_SEND_READY: if (msize != sizeof (struct SendMessageReady)) @@ -1063,18 +1023,16 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) } smr = (const struct SendMessageReady *) msg; pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &smr->peer.hashPubKey); - if (pr == NULL) + if (NULL == pr) { GNUNET_break (0); reconnect_later (h); return; } -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Received notification about transmission readiness to `%s'.\n", GNUNET_i2s (&smr->peer)); -#endif - if (pr->pending_head == NULL) + if (NULL == pr->pending_head) { /* request must have been cancelled between the original request * and the response from core, ignore core's readiness */ @@ -1088,7 +1046,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) * ignore! (we should have already sent another request) */ break; } - if ((pr->prev != NULL) || (pr->next != NULL) || (h->ready_peer_head == pr)) + if ((NULL != pr->prev) || (NULL != pr->next) || (h->ready_peer_head == pr)) { /* we should not already be on the ready list... */ GNUNET_break (0); @@ -1119,14 +1077,12 @@ init_done_task (void *cls, int success) { struct GNUNET_CORE_Handle *h = cls; - if (success == GNUNET_SYSERR) + if (GNUNET_SYSERR == success) return; /* shutdown */ - if (success == GNUNET_NO) + if (GNUNET_NO == success) { -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to exchange INIT with core, retrying\n"); -#endif if (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK) reconnect_later (h); return; @@ -1152,13 +1108,10 @@ reconnect (struct GNUNET_CORE_Handle *h) uint16_t *ts; unsigned int hpos; -#if DEBUG_CORE - LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to CORE service\n"); -#endif - GNUNET_assert (h->client == NULL); + GNUNET_assert (NULL == h->client); GNUNET_assert (h->currently_down == GNUNET_YES); h->client = GNUNET_CLIENT_connect ("core", h->cfg); - if (h->client == NULL) + if (NULL == h->client) { reconnect_later (h); return; @@ -1185,6 +1138,10 @@ reconnect (struct GNUNET_CORE_Handle *h) else opt |= GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND; } + LOG (GNUNET_ERROR_TYPE_INFO, + "(Re)connecting to CORE service, monitoring messages of type %u\n", + opt); + init->options = htonl (opt); ts = (uint16_t *) & init[1]; for (hpos = 0; hpos < h->hcnt; hpos++) @@ -1203,8 +1160,8 @@ reconnect (struct GNUNET_CORE_Handle *h) * @param cfg configuration to use * @param queue_size size of the per-peer message queue * @param cls closure for the various callbacks that follow (including handlers in the handlers array) - * @param init callback to call on timeout or once we have successfully - * connected to the core service; note that timeout is only meaningful if init is not NULL + * @param init callback to call once we have successfully + * connected to the core service * @param connects function to call on peer connect, can be NULL * @param disconnects function to call on peer disconnect / timeout, can be NULL * @param inbound_notify function to call for all inbound messages, can be NULL @@ -1255,9 +1212,7 @@ GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_assert (h->hcnt < (GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct InitMessage)) / sizeof (uint16_t)); -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service\n"); -#endif reconnect (h); return h; } @@ -1275,10 +1230,8 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle) { struct ControlMessage *cm; -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from CORE service\n"); -#endif - if (handle->cth != NULL) + if (NULL != handle->cth) { GNUNET_CLIENT_notify_transmit_ready_cancel (handle->cth); handle->cth = NULL; @@ -1287,15 +1240,15 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle) { GNUNET_CONTAINER_DLL_remove (handle->control_pending_head, handle->control_pending_tail, cm); - if (cm->th != NULL) + if (NULL != cm->th) cm->th->cm = NULL; - if (cm->cont != NULL) + if (NULL != cm->cont) cm->cont (cm->cont_cls, GNUNET_SYSERR); GNUNET_free (cm); } - if (handle->client != NULL) + if (NULL != handle->client) { - GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO); + GNUNET_CLIENT_disconnect (handle->client); handle->client = NULL; } GNUNET_CONTAINER_multihashmap_iterate (handle->peers, @@ -1340,8 +1293,7 @@ run_request_next_transmission (void *cls, * @param cork is corking allowed for this transmission? * @param priority how important is the message? * @param maxdelay how long can the message wait? - * @param target who should receive the message, - * use NULL for this peer (loopback) + * @param target who should receive the message, never NULL (can be this peer's identity for loopback) * @param notify_size how many bytes of buffer space does notify want? * @param notify function to call when buffer space is available * @param notify_cls closure for notify @@ -1402,18 +1354,14 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, int cork, GNUNET_break (handle->queue_size != 0); GNUNET_break (pr->queue_size == 1); GNUNET_free (th); -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Dropping transmission request: cannot drop queue head and limit is one\n"); -#endif return NULL; } if (priority <= minp->priority) { -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Dropping transmission request: priority too low\n"); -#endif GNUNET_free (th); return NULL; /* priority too low */ } @@ -1432,7 +1380,7 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, int cork, /* insertion sort */ prev = pos; - while ((pos != NULL) && (pos->timeout.abs_value < th->timeout.abs_value)) + while ((NULL != pos) && (pos->timeout.abs_value < th->timeout.abs_value)) { prev = pos; pos = pos->next; @@ -1441,9 +1389,7 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, int cork, th); pr->queue_size++; /* was the request queue previously empty? */ -#if DEBUG_CORE LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmission request added to queue\n"); -#endif if ((pr->pending_head == th) && (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK) && (pr->next == NULL) && (pr->prev == NULL) && (handle->ready_peer_head != pr)) @@ -1468,7 +1414,7 @@ GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle *th) was_head = (pr->pending_head == th); GNUNET_CONTAINER_DLL_remove (pr->pending_head, pr->pending_tail, th); pr->queue_size--; - if (th->cm != NULL) + if (NULL != th->cm) { /* we're currently in the control queue, remove */ GNUNET_CONTAINER_DLL_remove (h->control_pending_head, @@ -1478,14 +1424,15 @@ GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle *th) GNUNET_free (th); if (was_head) { - if ((pr->prev != NULL) || (pr->next != NULL) || (pr == h->ready_peer_head)) + if ((NULL != pr->prev) || (NULL != pr->next) || (pr == h->ready_peer_head)) { /* the request that was 'approved' by core was * canceled before it could be transmitted; remove * us from the 'ready' list */ GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr); } - request_next_transmission (pr); + if (NULL != h->client) + request_next_transmission (pr); } } diff --git a/src/core/core_api_is_connected.c b/src/core/core_api_is_connected.c new file mode 100644 index 0000000..2e01b36 --- /dev/null +++ b/src/core/core_api_is_connected.c @@ -0,0 +1,232 @@ +/* + This file is part of GNUnet. + (C) 2009, 2010, 2012 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file core/core_api_is_connected.c + * @brief implementation of the 'GNUNET_CORE_is_peer_connected function + * @author Christian Grothoff + * @author Nathan Evans + * + * TODO: + * - define nice structs for the IPC messages in core.h + * - consider NOT always sending the 'END' message -- it is redundant! + */ +#include "platform.h" +#include "gnunet_core_service.h" +#include "core.h" + + +/** + * Closure for 'transmit_is_connected_request" + */ +struct GNUNET_CORE_ConnectTestHandle +{ + + /** + * Our connection to the service. + */ + struct GNUNET_CLIENT_Connection *client; + + /** + * Handle for transmitting a request. + */ + struct GNUNET_CLIENT_TransmitHandle *th; + + /** + * Function called with the peer. + */ + GNUNET_CORE_ConnectEventHandler peer_cb; + + /** + * Peer to check for. + */ + struct GNUNET_PeerIdentity peer; + + /** + * Closure for peer_cb. + */ + void *cb_cls; + +}; + + +/** + * Receive reply from core service with information about a peer. + * + * @param cls our 'struct GNUNET_CORE_RequestContext *' + * @param msg NULL on error or last entry + */ +static void +receive_connect_info (void *cls, const struct GNUNET_MessageHeader *msg) +{ + struct GNUNET_CORE_ConnectTestHandle *cth = cls; + const struct ConnectNotifyMessage *connect_message; + uint32_t ats_count; + uint16_t msize; + + if (NULL == msg) + { + /* core died, failure */ + cth->peer_cb (cth->cb_cls, NULL, NULL, 0); + GNUNET_CORE_is_peer_connected_cancel (cth); + return; + } + if ((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END) && + (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader))) + { + /* end of transmissions */ + cth->peer_cb (cth->cb_cls, NULL, NULL, 0); + GNUNET_CORE_is_peer_connected_cancel (cth); + return; + } + msize = ntohs (msg->size); + /* Handle incorrect message type or size, disconnect and clean up */ + if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT) || + (msize < sizeof (struct ConnectNotifyMessage))) + { + GNUNET_break (0); + cth->peer_cb (cth->cb_cls, NULL, NULL, 0); + GNUNET_CORE_is_peer_connected_cancel (cth); + return; + } + connect_message = (const struct ConnectNotifyMessage *) msg; + ats_count = ntohl (connect_message->ats_count); + if (msize != + sizeof (struct ConnectNotifyMessage) + + ats_count * sizeof (struct GNUNET_ATS_Information)) + { + GNUNET_break (0); + cth->peer_cb (cth->cb_cls, NULL, NULL, 0); + GNUNET_CORE_is_peer_connected_cancel (cth); + return; + } + /* Normal case */ + cth->peer_cb (cth->cb_cls, &connect_message->peer, + (const struct GNUNET_ATS_Information *) + &connect_message[1], ats_count); + GNUNET_CLIENT_receive (cth->client, &receive_connect_info, + cth, GNUNET_TIME_UNIT_FOREVER_REL); +} + + +/** + * Function called to notify a client about the socket + * begin ready to queue more data. "buf" will be + * NULL and "size" zero if the socket was closed for + * writing in the meantime. + * + * @param cls closure + * @param size number of bytes available in buf + * @param buf where the callee should write the message + * @return number of bytes written to buf + */ +static size_t +transmit_is_connected_request (void *cls, size_t size, void *buf) +{ + struct GNUNET_CORE_ConnectTestHandle *cth = cls; + struct GNUNET_MessageHeader *msg; + unsigned int msize; + + cth->th = NULL; + msize = + sizeof (struct GNUNET_MessageHeader) + + sizeof (struct GNUNET_PeerIdentity); + if ( (NULL == buf) || (0 == size) ) + { + cth->peer_cb (cth->cb_cls, + NULL, + NULL, 0); + GNUNET_CLIENT_disconnect (cth->client); + GNUNET_free (cth); + return 0; + } + GNUNET_assert (size >= msize); + msg = (struct GNUNET_MessageHeader *) buf; + msg->size = htons (msize); + msg->type = htons (GNUNET_MESSAGE_TYPE_CORE_PEER_CONNECTED); + memcpy (&msg[1], &cth->peer, sizeof (struct GNUNET_PeerIdentity)); + GNUNET_CLIENT_receive (cth->client, &receive_connect_info, cth, + GNUNET_TIME_UNIT_FOREVER_REL); + return msize; +} + + +/** + * Iterate over all currently connected peers. + * Calls peer_cb with each connected peer, and then + * once with NULL to indicate that all peers have + * been handled. + * + * @param cfg configuration to use + * @param peer the specific peer to check for + * @param peer_cb function to call with the peer information + * @param cb_cls closure for peer_cb + * + * @return GNUNET_OK if iterating, GNUNET_SYSERR on error + */ +struct GNUNET_CORE_ConnectTestHandle * +GNUNET_CORE_is_peer_connected (const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_PeerIdentity *peer, + GNUNET_CORE_ConnectEventHandler peer_cb, + void *cb_cls) +{ + struct GNUNET_CORE_ConnectTestHandle *cth; + struct GNUNET_CLIENT_Connection *client; + + GNUNET_assert (NULL != peer); + GNUNET_assert (NULL != peer_cb); + client = GNUNET_CLIENT_connect ("core", cfg); + if (NULL == client) + return NULL; + cth = GNUNET_malloc (sizeof (struct GNUNET_CORE_ConnectTestHandle)); + cth->peer = *peer; + cth->client = client; + cth->peer_cb = peer_cb; + cth->cb_cls = cb_cls; + cth->th = + GNUNET_CLIENT_notify_transmit_ready (client, + sizeof (struct GNUNET_MessageHeader) + + sizeof (struct GNUNET_PeerIdentity), + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_YES, &transmit_is_connected_request, cth); + GNUNET_assert (NULL != cth->th); + return cth; +} + + +/** + * Abort 'is_connected' test operation. + * + * @param cth handle for operation to cancel + */ +void +GNUNET_CORE_is_peer_connected_cancel (struct GNUNET_CORE_ConnectTestHandle *cth) +{ + if (NULL != cth->th) + { + GNUNET_CLIENT_notify_transmit_ready_cancel (cth->th); + cth->th = NULL; + } + GNUNET_CLIENT_disconnect (cth->client); + GNUNET_free (cth); +} + + +/* end of core_api_is_connected.c */ diff --git a/src/core/core_api_iterate_peers.c b/src/core/core_api_iterate_peers.c index 7b28842..7db9486 100644 --- a/src/core/core_api_iterate_peers.c +++ b/src/core/core_api_iterate_peers.c @@ -80,7 +80,7 @@ receive_info (void *cls, const struct GNUNET_MessageHeader *msg) { if (request_context->peer_cb != NULL) request_context->peer_cb (request_context->cb_cls, NULL, NULL, 0); - GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO); + GNUNET_CLIENT_disconnect (request_context->client); GNUNET_free (request_context); return; } @@ -93,7 +93,7 @@ receive_info (void *cls, const struct GNUNET_MessageHeader *msg) GNUNET_break (0); if (request_context->peer_cb != NULL) request_context->peer_cb (request_context->cb_cls, NULL, NULL, 0); - GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO); + GNUNET_CLIENT_disconnect (request_context->client); GNUNET_free (request_context); return; } @@ -106,7 +106,7 @@ receive_info (void *cls, const struct GNUNET_MessageHeader *msg) GNUNET_break (0); if (request_context->peer_cb != NULL) request_context->peer_cb (request_context->cb_cls, NULL, NULL, 0); - GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO); + GNUNET_CLIENT_disconnect (request_context->client); GNUNET_free (request_context); return; } @@ -119,6 +119,7 @@ receive_info (void *cls, const struct GNUNET_MessageHeader *msg) request_context, GNUNET_TIME_UNIT_FOREVER_REL); } + /** * Function called to notify a client about the socket * begin ready to queue more data. "buf" will be @@ -143,10 +144,8 @@ transmit_request (void *cls, size_t size, void *buf) msize = sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_PeerIdentity); - if ((size < msize) || (buf == NULL)) return 0; - msg = (struct GNUNET_MessageHeader *) buf; msg->size = htons (msize); if (peer != NULL) @@ -160,50 +159,7 @@ transmit_request (void *cls, size_t size, void *buf) return msize; } -/** - * Iterate over all currently connected peers. - * Calls peer_cb with each connected peer, and then - * once with NULL to indicate that all peers have - * been handled. - * - * @param cfg configuration to use - * @param peer the specific peer to check for - * @param peer_cb function to call with the peer information - * @param cb_cls closure for peer_cb - * - * @return GNUNET_OK if iterating, GNUNET_SYSERR on error - */ -int -GNUNET_CORE_is_peer_connected (const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_PeerIdentity *peer, - GNUNET_CORE_ConnectEventHandler peer_cb, - void *cb_cls) -{ - struct GNUNET_CORE_RequestContext *request_context; - struct GNUNET_CLIENT_Connection *client; - - client = GNUNET_CLIENT_connect ("core", cfg); - if (client == NULL) - return GNUNET_SYSERR; - GNUNET_assert (peer != NULL); - request_context = GNUNET_malloc (sizeof (struct GNUNET_CORE_RequestContext)); - request_context->client = client; - request_context->peer_cb = peer_cb; - request_context->cb_cls = cb_cls; - request_context->peer = peer; - request_context->th = - GNUNET_CLIENT_notify_transmit_ready (client, - sizeof (struct GNUNET_MessageHeader) - + - sizeof (struct GNUNET_PeerIdentity), - GNUNET_TIME_relative_get_forever (), - GNUNET_YES, &transmit_request, peer); - GNUNET_assert (request_context->th != NULL); - GNUNET_CLIENT_receive (client, &receive_info, request_context, - GNUNET_TIME_relative_get_forever ()); - return GNUNET_OK; -} /** * Iterate over all currently connected peers. @@ -236,11 +192,11 @@ GNUNET_CORE_iterate_peers (const struct GNUNET_CONFIGURATION_Handle *cfg, request_context->th = GNUNET_CLIENT_notify_transmit_ready (client, sizeof (struct GNUNET_MessageHeader), - GNUNET_TIME_relative_get_forever (), + GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &transmit_request, NULL); GNUNET_CLIENT_receive (client, &receive_info, request_context, - GNUNET_TIME_relative_get_forever ()); + GNUNET_TIME_UNIT_FOREVER_REL); return GNUNET_OK; } diff --git a/src/core/gnunet-core-list-connections.c b/src/core/gnunet-core-list-connections.c deleted file mode 100644 index fcd0765..0000000 --- a/src/core/gnunet-core-list-connections.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ - -/** - * @file core/gnunet-core-list-connections.c - * @brief Print information about other known _connected_ peers. - * @author Nathan Evans - */ -#include "platform.h" -#include "gnunet_crypto_lib.h" -#include "gnunet_configuration_lib.h" -#include "gnunet_getopt_lib.h" -#include "gnunet_peerinfo_service.h" -#include "gnunet_transport_service.h" -#include "gnunet_core_service.h" -#include "gnunet_program_lib.h" - -#define VERBOSE 0 -static int no_resolve; - -#if VERBOSE -static unsigned int peer_count; -#endif - -static const struct GNUNET_CONFIGURATION_Handle *cfg; - -struct AddressStringList -{ - /** - * Pointer to previous element. - */ - struct AddressStringList *prev; - - /** - * Pointer to next element. - */ - struct AddressStringList *next; - - /** - * Address as string. - */ - char *address_string; -}; - -struct PrintContext -{ - struct GNUNET_PeerIdentity peer; - struct AddressStringList *address_list_head; - struct AddressStringList *address_list_tail; -}; - - -static void -dump_pc (struct PrintContext *pc) -{ - struct GNUNET_CRYPTO_HashAsciiEncoded enc; - struct AddressStringList *address; - - GNUNET_CRYPTO_hash_to_enc (&pc->peer.hashPubKey, &enc); - printf (_("Peer `%s'\n"), (const char *) &enc); - while (NULL != (address = pc->address_list_head)) - { - printf ("\t%s\n", address->address_string); - GNUNET_free (address->address_string); - GNUNET_CONTAINER_DLL_remove (pc->address_list_head, pc->address_list_tail, - address); - GNUNET_free (address); - } - - printf ("\n"); - - GNUNET_free (pc); -} - - -/** - * Function to call with a human-readable format of an address - * - * @param cls closure - * @param peer peer this update is about - * @param address NULL on error, otherwise 0-terminated printable UTF-8 string - */ -static void -process_resolved_address (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address) -{ - struct PrintContext *pc = cls; - -// struct AddressStringList *new_address; - - if (address == NULL) - { - dump_pc (pc); - return; - } - - /* This does exactly the same as gnunet-transport -i ! */ - /* - * new_address = GNUNET_malloc (sizeof (struct AddressStringList)); - * #if VERBOSE - * FPRINTF (stderr, "Received address %s\n", address); - * #endif - * - * new_address->address_string = GNUNET_strdup ("FIXME"); - * GNUNET_CONTAINER_DLL_insert (pc->address_list_head, pc->address_list_tail, - * new_address); - */ -} - - -/** - * Callback for retrieving a list of connected peers. - */ -static void -connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count) -{ - struct PrintContext *pc; - - if (peer != NULL) /* Not yet finished */ - { -#if VERBOSE - FPRINTF (stderr, "Learned about peer %s\n", GNUNET_i2s (peer)); - peer_count++; -#endif - pc = GNUNET_malloc (sizeof (struct PrintContext)); - pc->peer = *peer; - GNUNET_TRANSPORT_peer_get_active_addresses (cfg, peer, GNUNET_YES, - GNUNET_TIME_UNIT_MINUTES, - &process_resolved_address, pc); - } -#if VERBOSE - else - { - FPRINTF (stderr, "Counted %u total connected peers.\n", peer_count); - } -#endif -} - - -/** - * Main function that will be run by the scheduler. - * - * @param cls closure - * @param args remaining command-line arguments - * @param cfgfile name of the configuration file used (for saving, can be NULL!) - * @param c configuration - */ -static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) -{ - - cfg = c; - if (args[0] != NULL) - { - FPRINTF (stderr, _("Invalid command line argument `%s'\n"), args[0]); - return; - } - - GNUNET_CORE_iterate_peers (cfg, &connected_peer_callback, NULL); - -} - - -/** - * The main function to obtain peer information. - * - * @param argc number of arguments from the command line - * @param argv command line arguments - * @return 0 ok, 1 on error - */ -int -main (int argc, char *const *argv) -{ - static const struct GNUNET_GETOPT_CommandLineOption options[] = { - {'n', "numeric", NULL, - gettext_noop ("don't resolve host names"), - 0, &GNUNET_GETOPT_set_one, &no_resolve}, - GNUNET_GETOPT_OPTION_END - }; - return (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, "gnunet-list-connections", - gettext_noop - ("Print information about connected peers."), - options, &run, NULL)) ? 0 : 1; -} - -/* end of gnunet-core-list-connections.c */ diff --git a/src/core/gnunet-core.c b/src/core/gnunet-core.c new file mode 100644 index 0000000..4fe0a4f --- /dev/null +++ b/src/core/gnunet-core.c @@ -0,0 +1,99 @@ +/* + This file is part of GNUnet. + (C) 2011, 2012 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file core/gnunet-core.c + * @brief Print information about other known _connected_ peers. + * @author Nathan Evans + */ +#include "platform.h" +#include "gnunet_crypto_lib.h" +#include "gnunet_configuration_lib.h" +#include "gnunet_getopt_lib.h" +#include "gnunet_peerinfo_service.h" +#include "gnunet_transport_service.h" +#include "gnunet_core_service.h" +#include "gnunet_program_lib.h" + + +/** + * Callback for retrieving a list of connected peers. + * + * @param cls closure (unused) + * @param peer peer identity this notification is about + * @param atsi performance data for the connection + * @param atsi_count number of records in 'atsi' + */ +static void +connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) +{ + struct GNUNET_CRYPTO_HashAsciiEncoded enc; + + if (NULL == peer) + return; + GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &enc); + printf (_("Peer `%s'\n"), (const char *) &enc); +} + + +/** + * Main function that will be run by the scheduler. + * + * @param cls closure + * @param args remaining command-line arguments + * @param cfgfile name of the configuration file used (for saving, can be NULL!) + * @param cfg configuration + */ +static void +run (void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + if (args[0] != NULL) + { + FPRINTF (stderr, _("Invalid command line argument `%s'\n"), args[0]); + return; + } + GNUNET_CORE_iterate_peers (cfg, &connected_peer_callback, NULL); +} + + +/** + * The main function to obtain peer information. + * + * @param argc number of arguments from the command line + * @param argv command line arguments + * @return 0 ok, 1 on error + */ +int +main (int argc, char *const *argv) +{ + static const struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_OPTION_END + }; + return (GNUNET_OK == + GNUNET_PROGRAM_run (argc, argv, "gnunet-core", + gettext_noop + ("Print information about connected peers."), + options, &run, NULL)) ? 0 : 1; +} + +/* end of gnunet-core.c */ diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 2eb71c2..59d9383 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c @@ -56,9 +56,7 @@ struct GNUNET_STATISTICS_Handle *GSC_stats; static void cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n"); -#endif GSC_CLIENTS_done (); GSC_NEIGHBOURS_done (); GSC_SESSIONS_done (); diff --git a/src/core/gnunet-service-core_clients.c b/src/core/gnunet-service-core_clients.c index 4098b45..1076f34 100644 --- a/src/core/gnunet-service-core_clients.c +++ b/src/core/gnunet-service-core_clients.c @@ -96,6 +96,11 @@ struct GSC_Client /** + * Big "or" of all client options. + */ +static uint32_t all_client_options; + +/** * Head of linked list of our clients. */ static struct GSC_Client *client_head; @@ -146,12 +151,10 @@ static void send_to_client (struct GSC_Client *client, const struct GNUNET_MessageHeader *msg, int can_drop) { -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Preparing to send %u bytes of message of type %u to client.\n", (unsigned int) ntohs (msg->size), (unsigned int) ntohs (msg->type)); -#endif GNUNET_SERVER_notification_context_unicast (notifier, client->client_handle, msg, can_drop); } @@ -207,7 +210,7 @@ type_match (uint16_t type, struct GSC_Client *c) * Send a message to all of our current clients that have the right * options set. * - * @param sender origin of the message (used to check that this peer is + * @param partner origin (or destination) of the message (used to check that this peer is * known to be connected to the respective client) * @param msg message to multicast * @param can_drop can this message be discarded if the queue is too long @@ -215,27 +218,37 @@ type_match (uint16_t type, struct GSC_Client *c) * @param type type of the embedded message, 0 for none */ static void -send_to_all_clients (const struct GNUNET_PeerIdentity *sender, +send_to_all_clients (const struct GNUNET_PeerIdentity *partner, const struct GNUNET_MessageHeader *msg, int can_drop, - int options, uint16_t type) + uint32_t options, uint16_t type) { struct GSC_Client *c; + int tm; for (c = client_head; c != NULL; c = c->next) { - if ((0 == (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) && - (GNUNET_YES == type_match (type, c))) - continue; /* not the full message, but we'd like the full one! */ - if ((0 == (c->options & options)) && (GNUNET_YES != type_match (type, c))) - continue; /* neither options nor type match permit the message */ -#if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending message to client interested in messages of type %u.\n", + tm = type_match (type, c); + if (! ( (0 != (c->options & options)) || + ( (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) && + (GNUNET_YES == tm) ) ) ) + continue; /* neither options nor type match permit the message */ + if ( (0 != (options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND)) && + ( (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) || + (GNUNET_YES == tm) ) ) + continue; + if ( (0 != (options & GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND)) && + (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND)) ) + continue; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Sending %u message with %u bytes to client interested in messages of type %u.\n", + options, + ntohs (msg->size), (unsigned int) type); -#endif - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_contains (c->connectmap, - &sender->hashPubKey)); + GNUNET_assert ( (0 == (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) || + (GNUNET_YES != tm) || + (GNUNET_YES == + GNUNET_CONTAINER_multihashmap_contains (c->connectmap, + &partner->hashPubKey)) ); send_to_client (c, msg, can_drop); } } @@ -283,6 +296,7 @@ handle_client_init (void *cls, struct GNUNET_SERVER_Client *client, c->client_handle = client; c->tcnt = msize / sizeof (uint16_t); c->options = ntohl (im->options); + all_client_options |= c->options; c->types = (const uint16_t *) &c[1]; c->connectmap = GNUNET_CONTAINER_multihashmap_create (16); GNUNET_assert (GNUNET_YES == @@ -295,11 +309,9 @@ handle_client_init (void *cls, struct GNUNET_SERVER_Client *client, wtypes[i] = ntohs (types[i]); GSC_TYPEMAP_add (wtypes, c->tcnt); GNUNET_CONTAINER_DLL_insert (client_head, client_tail, c); -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client connecting to core service is interested in %u message types\n", (unsigned int) c->tcnt); -#endif /* send init reply message */ irm.header.size = htons (sizeof (struct InitReplyMessage)); irm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY); @@ -338,11 +350,9 @@ handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client, } if (c->requests == NULL) c->requests = GNUNET_CONTAINER_multihashmap_create (16); -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client asked for transmission to `%s'\n", GNUNET_i2s (&req->peer)); -#endif is_loopback = (0 == memcmp (&req->peer, &GSC_my_identity, @@ -472,11 +482,9 @@ handle_client_send (void *cls, struct GNUNET_SERVER_Client *client, &sm->peer.hashPubKey, tc.car)); tc.cork = ntohl (sm->cork); -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client asked for transmission of %u bytes to `%s' %s\n", msize, GNUNET_i2s (&sm->peer), tc.cork ? "now" : ""); -#endif GNUNET_SERVER_mst_receive (client_mst, &tc, (const char *) &sm[1], msize, GNUNET_YES, GNUNET_NO); if (0 != @@ -498,7 +506,7 @@ handle_client_send (void *cls, struct GNUNET_SERVER_Client *client, * @param client reservation request ('struct GSC_ClientActiveRequest') * @param message the actual message */ -static void +static int client_tokenizer_callback (void *cls, void *client, const struct GNUNET_MessageHeader *message) { @@ -509,29 +517,36 @@ client_tokenizer_callback (void *cls, void *client, memcmp (&car->target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) { -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Delivering message of type %u to myself\n", ntohs (message->type)); -#endif GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message, - ntohs (message->size), - GNUNET_CORE_OPTION_SEND_FULL_INBOUND | - GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); + ntohs (message->size), + GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); + GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message, + sizeof (struct GNUNET_MessageHeader), + GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); + GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message, + ntohs (message->size), + GNUNET_CORE_OPTION_SEND_FULL_INBOUND); GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message, - sizeof (struct GNUNET_MessageHeader), - GNUNET_CORE_OPTION_SEND_HDR_INBOUND | - GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); + sizeof (struct GNUNET_MessageHeader), + GNUNET_CORE_OPTION_SEND_HDR_INBOUND); } else { -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Delivering message of type %u to %s\n", ntohs (message->type), GNUNET_i2s (&car->target)); -#endif + GSC_CLIENTS_deliver_message (&car->target, NULL, 0, message, + ntohs (message->size), + GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); + GSC_CLIENTS_deliver_message (&car->target, NULL, 0, message, + sizeof (struct GNUNET_MessageHeader), + GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); GSC_SESSIONS_transmit (car, message, tc->cork); } + return GNUNET_OK; } @@ -573,10 +588,8 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) if (client == NULL) return; -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p has disconnected from core service.\n", client); -#endif c = find_client (client); if (c == NULL) return; /* client never sent INIT */ @@ -592,6 +605,11 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) c->connectmap = NULL; GSC_TYPEMAP_remove (c->types, c->tcnt); GNUNET_free (c); + + /* recalculate 'all_client_options' */ + all_client_options = 0; + for (c = client_head; NULL != c ; c = c->next) + all_client_options |= c->options; } @@ -673,7 +691,7 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, { struct ConnectNotifyMessage *cnm; size_t size; - char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; + char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN; struct GNUNET_ATS_Information *a; struct DisconnectNotifyMessage dcm; int old_match; @@ -715,10 +733,8 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, cnm->ats_count = htonl (atsi_count); a = (struct GNUNET_ATS_Information *) &cnm[1]; memcpy (a, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count); -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n", "NOTIFY_CONNECT"); -#endif cnm->peer = *neighbour; send_to_client (client, &cnm->header, GNUNET_NO); } @@ -786,12 +802,13 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count, const struct GNUNET_MessageHeader *msg, - uint16_t msize, int options) + uint16_t msize, + uint32_t options) { size_t size = msize + sizeof (struct NotifyTrafficMessage) + atsi_count * sizeof (struct GNUNET_ATS_Information); - char buf[size]; + char buf[size] GNUNET_ALIGN; struct NotifyTrafficMessage *ntm; struct GNUNET_ATS_Information *a; @@ -809,22 +826,24 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, atsi_count = 0; size = msize + sizeof (struct NotifyTrafficMessage); } -#if DEBUG_CORE + if (! ( (0 != (all_client_options & options)) || + (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) )) + return; /* no client cares about this message notification */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service passes message from `%4s' of type %u to client.\n", GNUNET_i2s (sender), (unsigned int) ntohs (msg->type)); -#endif GSC_SESSIONS_add_to_typemap (sender, ntohs (msg->type)); ntm = (struct NotifyTrafficMessage *) buf; ntm->header.size = htons (size); - ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND); + if (0 != (options & (GNUNET_CORE_OPTION_SEND_FULL_INBOUND | GNUNET_CORE_OPTION_SEND_HDR_INBOUND))) + ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND); + else + ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND); ntm->ats_count = htonl (atsi_count); ntm->peer = *sender; - a = &ntm->ats; + a = (struct GNUNET_ATS_Information*) &ntm[1]; memcpy (a, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count); - a[atsi_count].type = htonl (GNUNET_ATS_ARRAY_TERMINATOR); - a[atsi_count].value = htonl (0); - memcpy (&a[atsi_count + 1], msg, msize); + memcpy (&a[atsi_count], msg, msize); send_to_all_clients (sender, &ntm->header, GNUNET_YES, options, ntohs (msg->type)); } diff --git a/src/core/gnunet-service-core_clients.h b/src/core/gnunet-service-core_clients.h index bdad20d..8ece1ce 100644 --- a/src/core/gnunet-service-core_clients.h +++ b/src/core/gnunet-service-core_clients.h @@ -105,7 +105,8 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count, const struct GNUNET_MessageHeader *msg, - uint16_t msize, int options); + uint16_t msize, + uint32_t options); /** diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c index c2acc6b..1fce2e5 100644 --- a/src/core/gnunet-service-core_kx.c +++ b/src/core/gnunet-service-core_kx.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors) + (C) 2009, 2010, 2011, 2012 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -37,6 +37,12 @@ #include "gnunet_protocols.h" #include "core.h" + +/** + * Set to GNUNET_YES to perform some slightly expensive internal invariant checks. + */ +#define EXTRA_CHECKS GNUNET_YES + /** * How long do we wait for SET_KEY confirmation initially? */ @@ -48,6 +54,12 @@ #define MIN_PING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) /** + * How often do we rekey? + */ +#define REKEY_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 90) + + +/** * What is the maximum age of a message for us to consider processing * it? Note that this looks at the timestamp used by the other peer, * so clock skew between machines does come into play here. So this @@ -216,6 +228,8 @@ struct EncryptedMessage }; GNUNET_NETWORK_STRUCT_END + + /** * Number of bytes (at the beginning) of "struct EncryptedMessage" * that are NOT encrypted. @@ -253,7 +267,19 @@ enum KxStateMachine * encrypted with his session key (which we got). Key exchange * is done. */ - KX_STATE_UP + KX_STATE_UP, + + /** + * We're rekeying, so we have received the other peer's session + * key, but he didn't get ours yet. + */ + KX_STATE_REKEY, + + /** + * We're rekeying but have not yet received confirmation for our new + * key from the other peer. + */ + KX_STATE_REKEY_SENT }; @@ -391,7 +417,6 @@ struct GSC_KeyExchangeInfo }; - /** * Handle to peerinfo service. */ @@ -413,9 +438,45 @@ static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key; static struct GNUNET_SERVER_MessageStreamTokenizer *mst; +#if EXTRA_CHECKS +/** + * Check internal invariants of the given KX record. + * + * @param kx record to check + * @param file filename for error reporting + * @param line line number for error reporting + */ +static void +check_kx_record (struct GSC_KeyExchangeInfo *kx, + const char *file, + int line) +{ + struct GNUNET_HashCode hc; + + if (NULL == kx->public_key) + return; + GNUNET_CRYPTO_hash (kx->public_key, sizeof (*kx->public_key), &hc); + GNUNET_assert_at (0 == memcmp (&hc, &kx->peer, sizeof (struct GNUNET_HashCode)), file, line); +} + + +/** + * Check internal invariants of the given KX record. + * + * @param kx record to check + */ +#define CHECK_KX(kx) check_kx_record(kx, __FILE__, __LINE__) +#else +#define CHECK_KX(kx) +#endif /** * Derive an authentication key from "set key" information + * + * @param akey authentication key to derive + * @param skey session key to use + * @param seed seed to use + * @param creation_time creation time to use */ static void derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, @@ -425,7 +486,6 @@ derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, static const char ctx[] = "authentication key"; struct GNUNET_TIME_AbsoluteNBO ctbe; - ctbe = GNUNET_TIME_absolute_hton (creation_time); GNUNET_CRYPTO_hmac_derive_key (akey, skey, &seed, sizeof (seed), &skey->key, sizeof (skey->key), &ctbe, sizeof (ctbe), ctx, @@ -435,6 +495,11 @@ derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, /** * Derive an IV from packet information + * + * @param iv initialization vector to initialize + * @param skey session key to use + * @param seed seed to use + * @param identity identity of the other peer to use */ static void derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, @@ -449,8 +514,15 @@ derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, sizeof (ctx), NULL); } + /** * Derive an IV from pong packet information + * + * @param iv initialization vector to initialize + * @param skey session key to use + * @param seed seed to use + * @param challenge nonce to use + * @param identity identity of the other peer to use */ static void derive_pong_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, @@ -492,7 +564,9 @@ do_encrypt (struct GSC_KeyExchangeInfo *kx, &kx->encrypt_key, iv, out)); GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# bytes encrypted"), size, GNUNET_NO); -#if DEBUG_CORE > 2 + /* the following is too sensitive to write to log files by accident, + so we require manual intervention to get this one... */ +#if 0 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted %u bytes for `%4s' using key %u, IV %u\n", (unsigned int) size, GNUNET_i2s (&kx->peer), @@ -504,8 +578,6 @@ do_encrypt (struct GSC_KeyExchangeInfo *kx, } - - /** * Decrypt size bytes from in and write the result to out. Use the * key for inbound traffic of the given neighbour. This function does @@ -528,7 +600,9 @@ do_decrypt (struct GSC_KeyExchangeInfo *kx, GNUNET_break (0); return GNUNET_NO; } - if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP)) + if ( (kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP) && + (kx->status != KX_STATE_REKEY_SENT) && + (kx->status != KX_STATE_REKEY) ) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -542,7 +616,9 @@ do_decrypt (struct GSC_KeyExchangeInfo *kx, } GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# bytes decrypted"), size, GNUNET_NO); -#if DEBUG_CORE > 1 + /* the following is too sensitive to write to log files by accident, + so we require manual intervention to get this one... */ +#if 0 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypted %u bytes from `%4s' using key %u, IV %u\n", (unsigned int) size, GNUNET_i2s (&kx->peer), @@ -598,36 +674,40 @@ process_hello (void *cls, const struct GNUNET_PeerIdentity *peer, struct GSC_KeyExchangeInfo *kx = cls; struct SetKeyMessage *skm; - if (err_msg != NULL) + CHECK_KX (kx); + if (NULL != err_msg) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Error in communication with PEERINFO service\n")); kx->pitr = NULL; + if (GNUNET_SCHEDULER_NO_TASK != kx->retry_set_key_task) + GNUNET_SCHEDULER_cancel (kx->retry_set_key_task); kx->retry_set_key_task = GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, &set_key_retry_task, kx); return; } - if (peer == NULL) + if (NULL == peer) { kx->pitr = NULL; - if (kx->public_key != NULL) + if (NULL != kx->public_key) return; /* done here */ -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to obtain public key for peer `%4s', delaying processing of SET_KEY\n", GNUNET_i2s (&kx->peer)); -#endif GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# Delayed connecting due to lack of public key"), 1, GNUNET_NO); + if (GNUNET_SCHEDULER_NO_TASK != kx->retry_set_key_task) + GNUNET_SCHEDULER_cancel (kx->retry_set_key_task); kx->retry_set_key_task = GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, &set_key_retry_task, kx); return; } - if (kx->public_key != NULL) + GNUNET_break (0 == memcmp (peer, &kx->peer, sizeof (struct GNUNET_PeerIdentity))); + if (NULL != kx->public_key) { /* already have public key, why are we here? */ GNUNET_break (0); @@ -641,8 +721,10 @@ process_hello (void *cls, const struct GNUNET_PeerIdentity *peer, GNUNET_break (0); GNUNET_free (kx->public_key); kx->public_key = NULL; + CHECK_KX (kx); return; } + CHECK_KX (kx); send_key (kx); if (NULL != kx->skm_received) { @@ -665,10 +747,8 @@ GSC_KX_start (const struct GNUNET_PeerIdentity *pid) { struct GSC_KeyExchangeInfo *kx; -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initiating key exchange with `%s'\n", GNUNET_i2s (pid)); -#endif GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# key exchanges initiated"), 1, GNUNET_NO); @@ -679,6 +759,7 @@ GSC_KX_start (const struct GNUNET_PeerIdentity *pid) GNUNET_PEERINFO_iterate (peerinfo, pid, GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */ , &process_hello, kx); + CHECK_KX (kx); return kx; } @@ -693,7 +774,7 @@ GSC_KX_stop (struct GSC_KeyExchangeInfo *kx) { GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# key exchanges stopped"), 1, GNUNET_NO); - if (kx->pitr != NULL) + if (NULL != kx->pitr) { GNUNET_PEERINFO_iterate_cancel (kx->pitr); kx->pitr = NULL; @@ -735,7 +816,8 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, struct PongMessage *pong; enum KxStateMachine sender_status; uint16_t size; - + + CHECK_KX (kx); size = ntohs (msg->size); if (size != sizeof (struct SetKeyMessage)) { @@ -746,12 +828,10 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# session keys received"), 1, GNUNET_NO); -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service receives `%s' request from `%4s'.\n", "SET_KEY", GNUNET_i2s (&kx->peer)); -#endif - if (kx->public_key == NULL) + if (NULL == kx->public_key) { GNUNET_free_non_null (kx->skm_received); kx->skm_received = (struct SetKeyMessage *) GNUNET_copy_message (msg); @@ -776,6 +856,7 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, &m->signature, kx->public_key))) { /* invalid signature */ + CHECK_KX (kx); GNUNET_break_op (0); return; } @@ -796,16 +877,20 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, (GNUNET_OK != GNUNET_CRYPTO_aes_check_session_key (&k))) { /* failed to decrypt !? */ + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Invalid key %x decrypted by %s from message %u (origin: %s)\n", + (unsigned int) GNUNET_CRYPTO_crc32_n (&k, sizeof (struct GNUNET_CRYPTO_AesSessionKey)), + GNUNET_i2s (&GSC_my_identity), + (unsigned int) GNUNET_CRYPTO_crc32_n (&m->encrypted_key, sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)), + GNUNET_h2s (&kx->peer.hashPubKey)); GNUNET_break_op (0); return; } GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# SET_KEY messages decrypted"), 1, GNUNET_NO); -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received SET_KEY from `%s'\n", GNUNET_i2s (&kx->peer)); -#endif kx->decrypt_key = k; if (kx->decrypt_key_created.abs_value != t.abs_value) { @@ -815,7 +900,6 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, kx->decrypt_key_created = t; } sender_status = (enum KxStateMachine) ntohl (m->sender_status); - switch (kx->status) { case KX_STATE_DOWN: @@ -829,7 +913,17 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, case KX_STATE_KEY_RECEIVED: /* we're not up, so we are already doing 'send_key' */ break; - case KX_STATE_UP: + case KX_STATE_UP: + if ((sender_status == KX_STATE_DOWN) || + (sender_status == KX_STATE_KEY_SENT)) + send_key (kx); /* we are up, but other peer is not! */ + break; + case KX_STATE_REKEY: + if ((sender_status == KX_STATE_DOWN) || + (sender_status == KX_STATE_KEY_SENT)) + send_key (kx); /* we are up, but other peer is not! */ + break; + case KX_STATE_REKEY_SENT: if ((sender_status == KX_STATE_DOWN) || (sender_status == KX_STATE_KEY_SENT)) send_key (kx); /* we are up, but other peer is not! */ @@ -838,14 +932,14 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, GNUNET_break (0); break; } - if (kx->ping_received != NULL) + if (NULL != kx->ping_received) { ping = kx->ping_received; kx->ping_received = NULL; GSC_KX_handle_ping (kx, &ping->header); GNUNET_free (ping); } - if (kx->pong_received != NULL) + if (NULL != kx->pong_received) { pong = kx->pong_received; kx->pong_received = NULL; @@ -882,7 +976,8 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PING messages received"), 1, GNUNET_NO); - if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP)) + if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP) && + (kx->status != KX_STATE_REKEY_SENT)) { /* defer */ GNUNET_free_non_null (kx->ping_received); @@ -890,11 +985,9 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, return; } m = (const struct PingMessage *) msg; -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service receives `%s' request from `%4s'.\n", "PING", GNUNET_i2s (&kx->peer)); -#endif derive_iv (&iv, &kx->decrypt_key, m->iv_seed, &GSC_my_identity); if (GNUNET_OK != do_decrypt (kx, &iv, &m->target, &t.target, @@ -919,10 +1012,8 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, GNUNET_break_op (0); return; } -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received PING from `%s'\n", GNUNET_i2s (&kx->peer)); -#endif /* construct PONG */ tx.reserved = GNUNET_BANDWIDTH_VALUE_MAX; tx.challenge = t.challenge; @@ -966,12 +1057,20 @@ setup_fresh_setkey (struct GSC_KeyExchangeInfo *kx) skm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_KEY); skm->creation_time = GNUNET_TIME_absolute_hton (kx->encrypt_key_created); skm->target = kx->peer; + CHECK_KX (kx); GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_rsa_encrypt (&kx->encrypt_key, sizeof (struct GNUNET_CRYPTO_AesSessionKey), kx->public_key, &skm->encrypted_key)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Encrypting key %x for %s resulting in message %u (origin: %s)\n", + (unsigned int) GNUNET_CRYPTO_crc32_n (&kx->encrypt_key, sizeof (struct GNUNET_CRYPTO_AesSessionKey)), + GNUNET_i2s (&kx->peer), + (unsigned int) GNUNET_CRYPTO_crc32_n (&skm->encrypted_key, sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)), + GNUNET_h2s (&GSC_my_identity.hashPubKey)); + GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_rsa_sign (my_private_key, &skm->purpose, &skm->signature)); @@ -1020,19 +1119,18 @@ send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK; left = GNUNET_TIME_absolute_get_remaining (kx->timeout); - if (left.rel_value == 0) + if (0 == left.rel_value) { GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# sessions terminated by timeout"), 1, GNUNET_NO); GSC_SESSIONS_end (&kx->peer); kx->status = KX_STATE_DOWN; + send_key (kx); return; } -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending KEEPALIVE to `%s'\n", GNUNET_i2s (&kx->peer)); -#endif GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# keepalive messages sent"), 1, GNUNET_NO); @@ -1070,6 +1168,49 @@ update_timeout (struct GSC_KeyExchangeInfo *kx) /** + * Trigger rekeying event. + * + * @param cls the 'struct GSC_KeyExchangeInfo' + * @param tc schedule context (unused) + */ +static void +trigger_rekey (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GSC_KeyExchangeInfo *kx = cls; + + GNUNET_break (KX_STATE_UP == kx->status); + kx->status = KX_STATE_REKEY; + kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY; + kx->retry_set_key_task = + GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, + &set_key_retry_task, kx); +} + + +/** + * Schedule rekey operation. + * + * @param kx key exchange to schedule rekey for + */ +static void +schedule_rekey (struct GSC_KeyExchangeInfo *kx) +{ + struct GNUNET_TIME_Relative rdelay; + + if (GNUNET_SCHEDULER_NO_TASK != kx->retry_set_key_task) + GNUNET_SCHEDULER_cancel (kx->retry_set_key_task); + rdelay = REKEY_FREQUENCY; + /* randomize rekey frequency by one minute to avoid synchronization */ + rdelay.rel_value += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + 60 * 1000); + kx->retry_set_key_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY, + &trigger_rekey, + kx); +} + + +/** * We received a PONG message. Validate and update our status. * * @param kx key exchange context for the the PONG @@ -1086,7 +1227,7 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, uint16_t msize; msize = ntohs (msg->size); - if (msize != sizeof (struct PongMessage)) + if (sizeof (struct PongMessage) != msize) { GNUNET_break_op (0); return; @@ -1094,21 +1235,30 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages received"), 1, GNUNET_NO); - if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP)) + switch (kx->status) { - if (kx->status == KX_STATE_KEY_SENT) - { - GNUNET_free_non_null (kx->pong_received); - kx->pong_received = (struct PongMessage *) GNUNET_copy_message (msg); - } + case KX_STATE_DOWN: + return; + case KX_STATE_KEY_SENT: + GNUNET_free_non_null (kx->pong_received); + kx->pong_received = (struct PongMessage *) GNUNET_copy_message (msg); + return; + case KX_STATE_KEY_RECEIVED: + break; + case KX_STATE_UP: + break; + case KX_STATE_REKEY: + break; + case KX_STATE_REKEY_SENT: + break; + default: + GNUNET_break (0); return; } m = (const struct PongMessage *) msg; -#if DEBUG_HANDSHAKE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service receives `%s' response from `%4s'.\n", "PONG", GNUNET_i2s (&kx->peer)); -#endif /* mark as garbage, just to be sure */ memset (&t, 255, sizeof (t)); derive_pong_iv (&iv, &kx->decrypt_key, m->iv_seed, kx->ping_challenge, @@ -1128,7 +1278,6 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, || (kx->ping_challenge != t.challenge)) { /* PONG malformed */ -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received malformed `%s' wanted sender `%4s' with challenge %u\n", "PONG", GNUNET_i2s (&kx->peer), @@ -1136,13 +1285,10 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received malformed `%s' received from `%4s' with challenge %u\n", "PONG", GNUNET_i2s (&t.target), (unsigned int) t.challenge); -#endif return; } -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received PONG from `%s'\n", GNUNET_i2s (&kx->peer)); -#endif switch (kx->status) { case KX_STATE_DOWN: @@ -1158,13 +1304,10 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, GNUNET_NO); kx->status = KX_STATE_UP; GSC_SESSIONS_create (&kx->peer, kx); - if (GNUNET_SCHEDULER_NO_TASK != kx->retry_set_key_task) - { - GNUNET_SCHEDULER_cancel (kx->retry_set_key_task); - kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; - } - GNUNET_assert (kx->keep_alive_task == GNUNET_SCHEDULER_NO_TASK); - if (kx->emsg_received != NULL) + CHECK_KX (kx); + schedule_rekey (kx); + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task); + if (NULL != kx->emsg_received) { emsg = kx->emsg_received; kx->emsg_received = NULL; @@ -1177,6 +1320,18 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, case KX_STATE_UP: update_timeout (kx); break; + case KX_STATE_REKEY: + update_timeout (kx); + break; + case KX_STATE_REKEY_SENT: + GNUNET_STATISTICS_update (GSC_stats, + gettext_noop + ("# rekey operations confirmed via PONG"), 1, + GNUNET_NO); + kx->status = KX_STATE_UP; + schedule_rekey (kx); + update_timeout (kx); + break; default: GNUNET_break (0); break; @@ -1192,17 +1347,20 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, static void send_key (struct GSC_KeyExchangeInfo *kx) { - GNUNET_assert (kx->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK); + CHECK_KX (kx); + if (GNUNET_SCHEDULER_NO_TASK != kx->retry_set_key_task) + { + GNUNET_SCHEDULER_cancel (kx->retry_set_key_task); + kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; + } if (KX_STATE_UP == kx->status) return; /* nothing to do */ - if (kx->public_key == NULL) + if (NULL == kx->public_key) { /* lookup public key, then try again */ -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to obtain public key for `%s'\n", GNUNET_i2s (&kx->peer)); -#endif kx->pitr = GNUNET_PEERINFO_iterate (peerinfo, &kx->peer, GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */ , @@ -1230,17 +1388,33 @@ send_key (struct GSC_KeyExchangeInfo *kx) case KX_STATE_UP: GNUNET_break (0); return; + case KX_STATE_REKEY: + kx->status = KX_STATE_REKEY_SENT; + /* setup fresh SET KEY message */ + setup_fresh_setkey (kx); + setup_fresh_ping (kx); + GNUNET_STATISTICS_update (GSC_stats, + gettext_noop + ("# SET_KEY and PING messages created"), 1, + GNUNET_NO); + GNUNET_STATISTICS_update (GSC_stats, + gettext_noop + ("# REKEY operations performed"), 1, + GNUNET_NO); + break; + case KX_STATE_REKEY_SENT: + break; default: GNUNET_break (0); return; } /* always update sender status in SET KEY message */ - kx->skm.sender_status = htonl ((int32_t) kx->status); -#if DEBUG_CORE + /* Not sending rekey sent state to be compatible with GNUnet 0.9.2 */ + kx->skm.sender_status = htonl ((int32_t) ((kx->status == KX_STATE_REKEY_SENT) ? + KX_STATE_KEY_RECEIVED : kx->status)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SET_KEY and PING to `%s'\n", GNUNET_i2s (&kx->peer)); -#endif GSC_NEIGHBOURS_transmit (&kx->peer, &kx->skm.header, kx->set_key_retry_frequency); GSC_NEIGHBOURS_transmit (&kx->peer, &kx->ping.header, @@ -1288,10 +1462,8 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, do_encrypt (kx, &iv, &ph->sequence_number, &em->sequence_number, used - ENCRYPTED_HEADER_SIZE)); -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted %u bytes for %s\n", used - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer)); -#endif derive_auth_key (&auth_key, &kx->encrypt_key, ph->iv_seed, kx->encrypt_key_created); GNUNET_CRYPTO_hmac (&auth_key, &em->sequence_number, @@ -1348,7 +1520,7 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, struct GNUNET_CRYPTO_AuthKey auth_key; struct DeliverMessageContext dmc; uint16_t size = ntohs (msg->size); - char buf[size]; + char buf[size] GNUNET_ALIGN; if (size < sizeof (struct EncryptedMessage) + sizeof (struct GNUNET_MessageHeader)) @@ -1357,7 +1529,8 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, return; } m = (const struct EncryptedMessage *) msg; - if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP)) + if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP) && + (kx->status != KX_STATE_REKEY_SENT) ) { GNUNET_STATISTICS_update (GSC_stats, gettext_noop @@ -1365,10 +1538,10 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, 1, GNUNET_NO); return; } - if (kx->status == KX_STATE_KEY_RECEIVED) + if (KX_STATE_KEY_RECEIVED == kx->status) { /* defer */ - GNUNET_free_non_null (kx->ping_received); + GNUNET_free_non_null (kx->emsg_received); kx->emsg_received = (struct EncryptedMessage *) GNUNET_copy_message (msg); return; } @@ -1389,10 +1562,8 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, do_decrypt (kx, &iv, &m->sequence_number, &buf[ENCRYPTED_HEADER_SIZE], size - ENCRYPTED_HEADER_SIZE)) return; -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypted %u bytes from %s\n", size - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer)); -#endif pt = (struct EncryptedMessage *) buf; /* validate sequence number */ @@ -1487,7 +1658,7 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, * @param client who sent us the message (struct GSC_KeyExchangeInfo) * @param m the message */ -static void +static int deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m) { struct DeliverMessageContext *dmc = client; @@ -1497,7 +1668,7 @@ deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m) case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP: GSC_SESSIONS_set_typemap (dmc->peer, m); - return; + return GNUNET_OK; default: GSC_CLIENTS_deliver_message (dmc->peer, dmc->atsi, dmc->atsi_count, m, ntohs (m->size), @@ -1506,6 +1677,7 @@ deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m) sizeof (struct GNUNET_MessageHeader), GNUNET_CORE_OPTION_SEND_HDR_INBOUND); } + return GNUNET_OK; } @@ -1530,7 +1702,7 @@ GSC_KX_init () } my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); GNUNET_free (keyfile); - if (my_private_key == NULL) + if (NULL == my_private_key) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Core service could not access hostkey. Exiting.\n")); @@ -1559,17 +1731,17 @@ GSC_KX_init () void GSC_KX_done () { - if (my_private_key != NULL) + if (NULL != my_private_key) { GNUNET_CRYPTO_rsa_key_free (my_private_key); my_private_key = NULL; } - if (peerinfo != NULL) + if (NULL != peerinfo) { GNUNET_PEERINFO_disconnect (peerinfo); peerinfo = NULL; } - if (mst != NULL) + if (NULL != mst) { GNUNET_SERVER_mst_destroy (mst); mst = NULL; diff --git a/src/core/gnunet-service-core_neighbours.c b/src/core/gnunet-service-core_neighbours.c index c4db40a..97737a6 100644 --- a/src/core/gnunet-service-core_neighbours.c +++ b/src/core/gnunet-service-core_neighbours.c @@ -129,6 +129,8 @@ static struct GNUNET_TRANSPORT_Handle *transport; static struct Neighbour * find_neighbour (const struct GNUNET_PeerIdentity *peer) { + if (NULL == neighbours) + return NULL; return GNUNET_CONTAINER_multihashmap_get (neighbours, &peer->hashPubKey); } @@ -143,11 +145,9 @@ free_neighbour (struct Neighbour *n) { struct NeighbourMessageEntry *m; -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying neighbour entry for peer `%4s'\n", GNUNET_i2s (&n->peer)); -#endif while (NULL != (m = n->message_head)) { GNUNET_CONTAINER_DLL_remove (n->message_head, n->message_tail, m); @@ -222,13 +222,11 @@ transmit_ready (void *cls, size_t size, void *buf) GNUNET_CONTAINER_DLL_remove (n->message_head, n->message_tail, m); if (buf == NULL) { -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission of message of type %u and size %u failed\n", (unsigned int) ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), (unsigned int) m->size); -#endif GNUNET_free (m); process_queue (n); return 0; @@ -237,13 +235,11 @@ transmit_ready (void *cls, size_t size, void *buf) GNUNET_assert (size >= m->size); memcpy (cbuf, &m[1], m->size); ret = m->size; -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Copied message of type %u and size %u into transport buffer for `%4s'\n", (unsigned int) ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), (unsigned int) ret, GNUNET_i2s (&n->peer)); -#endif GNUNET_free (m); process_queue (n); GNUNET_STATISTICS_update (GSC_stats, @@ -275,13 +271,11 @@ process_queue (struct Neighbour *n) GSC_SESSIONS_solicit (&n->peer); return; } -#if DEBUG_CORE > 1 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking transport for transmission of %u bytes to `%4s' in next %llu ms\n", (unsigned int) m->size, GNUNET_i2s (&n->peer), (unsigned long long) GNUNET_TIME_absolute_get_remaining (m->deadline).rel_value); -#endif n->th = GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer, m->size, 0, GNUNET_TIME_absolute_get_remaining @@ -328,10 +322,8 @@ handle_transport_notify_connect (void *cls, GNUNET_break (0); return; } -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received connection from `%4s'.\n", GNUNET_i2s (peer)); -#endif n = GNUNET_malloc (sizeof (struct Neighbour)); n->peer = *peer; GNUNET_assert (GNUNET_OK == @@ -359,11 +351,9 @@ handle_transport_notify_disconnect (void *cls, { struct Neighbour *n; -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' disconnected from us; received notification from transport.\n", GNUNET_i2s (peer)); -#endif n = find_neighbour (peer); if (n == NULL) { @@ -392,11 +382,9 @@ handle_transport_receive (void *cls, const struct GNUNET_PeerIdentity *peer, struct Neighbour *n; uint16_t type; -#if DEBUG_CORE > 1 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %u from `%4s', demultiplexing.\n", (unsigned int) ntohs (message->type), GNUNET_i2s (peer)); -#endif if (0 == memcmp (peer, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) { GNUNET_break (0); diff --git a/src/core/gnunet-service-core_sessions.c b/src/core/gnunet-service-core_sessions.c index 1f697cf..054ad97 100644 --- a/src/core/gnunet-service-core_sessions.c +++ b/src/core/gnunet-service-core_sessions.c @@ -176,10 +176,8 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid) session = find_session (pid); if (NULL == session) return; -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying session for peer `%4s'\n", GNUNET_i2s (&session->peer)); -#endif if (GNUNET_SCHEDULER_NO_TASK != session->cork_task) { GNUNET_SCHEDULER_cancel (session->cork_task); @@ -205,7 +203,7 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid) &session-> peer.hashPubKey, session)); - GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# entries in session map"), + GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# peers connected"), GNUNET_CONTAINER_multihashmap_size (sessions), GNUNET_NO); GSC_TYPEMAP_destroy (session->tmap); @@ -255,10 +253,8 @@ GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer, { struct Session *session; -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating session for peer `%4s'\n", GNUNET_i2s (peer)); -#endif session = GNUNET_malloc (sizeof (struct Session)); session->tmap = GSC_TYPEMAP_create (); session->peer = *peer; @@ -270,7 +266,7 @@ GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer, GNUNET_CONTAINER_multihashmap_put (sessions, &peer->hashPubKey, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# entries in session map"), + GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# peers connected"), GNUNET_CONTAINER_multihashmap_size (sessions), GNUNET_NO); GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, 0 /* FIXME: ATSI */ , @@ -341,10 +337,8 @@ GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car) session = find_session (&car->target); if (session == NULL) { -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dropped client request for transmission (am disconnected)\n"); -#endif GNUNET_break (0); /* should have been rejected earlier */ GSC_CLIENTS_reject_request (car); return; @@ -355,10 +349,8 @@ GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car) GSC_CLIENTS_reject_request (car); return; } -#if DEBUG_CORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received client transmission request. queueing\n"); -#endif GNUNET_CONTAINER_DLL_insert (session->active_client_request_head, session->active_client_request_tail, car); try_transmission (session); diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c index 271c2ce..37d1669 100644 --- a/src/core/test_core_api.c +++ b/src/core/test_core_api.c @@ -362,7 +362,7 @@ stop_arm (struct PeerContext *p) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); - GNUNET_OS_process_close (p->arm_proc); + GNUNET_OS_process_destroy (p->arm_proc); p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); diff --git a/src/core/test_core_api_peer2.conf b/src/core/test_core_api_peer2.conf index 2e848b8..cd29e3f 100644 --- a/src/core/test_core_api_peer2.conf +++ b/src/core/test_core_api_peer2.conf @@ -3,33 +3,39 @@ SERVICEHOME = /tmp/test-gnunet-core-peer-2/ DEFAULTCONFIG = test_core_api_peer2.conf -[transport-tcp] -PORT = 22468 - [arm] -PORT = 22466 +PORT = 22460 UNIXPATH = /tmp/gnunet-p2-service-arm.sock [statistics] -PORT = 22467 +PORT = 22461 UNIXPATH = /tmp/gnunet-p2-service-statistics.sock [resolver] -PORT = 22464 +PORT = 22462 UNIXPATH = /tmp/gnunet-p2-service-resolver.sock [peerinfo] -PORT = 22469 +PORT = 22463 UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock [transport] -PORT = 22465 +PORT = 22464 UNIXPATH = /tmp/gnunet-p2-service-transport.sock [core] -PORT = 22470 +PORT = 22475 UNIXPATH = /tmp/gnunet-p2-service-core.sock [ats] -PORT = 22471 +PORT = 22476 UNIXPATH = /tmp/gnunet-p2-service-ats.sock + +[transport-tcp] +PORT = 22467 + +[transport-unix] +PORT = 22468 + +[transport-http] +PORT = 22469
\ No newline at end of file diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c index 645b27e..e18d8c4 100644 --- a/src/core/test_core_api_reliability.c +++ b/src/core/test_core_api_reliability.c @@ -33,8 +33,6 @@ #include "gnunet_transport_service.h" #include <gauger.h> -#define VERBOSE GNUNET_NO - #define START_ARM GNUNET_YES /** @@ -89,11 +87,7 @@ static int ok; static int32_t tr_n; -#if VERBOSE #define OKPP do { ok++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) -#else -#define OKPP do { ok++; } while (0) -#endif struct TestMessage { @@ -113,9 +107,11 @@ get_size (unsigned int iter) return sizeof (struct TestMessage) + (ret % 60000); } + static void process_hello (void *cls, const struct GNUNET_MessageHeader *message); + static void terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { @@ -183,6 +179,7 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); } + static size_t transmit_ready (void *cls, size_t size, void *buf) { @@ -210,10 +207,8 @@ transmit_ready (void *cls, size_t size, void *buf) cbuf = buf; do { -#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u of size %u at offset %u\n", tr_n, s, ret); -#endif hdr.header.size = htons (s); hdr.header.type = htons (MTYPE); hdr.num = htonl (tr_n); @@ -237,7 +232,6 @@ transmit_ready (void *cls, size_t size, void *buf) } - static void connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, @@ -289,10 +283,8 @@ inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) { -#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other)); -#endif return GNUNET_OK; } @@ -303,11 +295,9 @@ outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) { -#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core notifies about outbound data for `%4s'.\n", GNUNET_i2s (other)); -#endif return GNUNET_OK; } @@ -315,6 +305,7 @@ outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, static size_t transmit_ready (void *cls, size_t size, void *buf); + static int process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, @@ -347,10 +338,8 @@ process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL); return GNUNET_SYSERR; } -#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n", ntohl (hdr->num), ntohs (message->size)); -#endif n++; if (0 == (n % (TOTAL_MSGS / 100))) FPRINTF (stderr, "%s", "."); @@ -378,7 +367,6 @@ static struct GNUNET_CORE_MessageHandler handlers[] = { }; - static void init_notify (void *cls, struct GNUNET_CORE_Handle *server, const struct GNUNET_PeerIdentity *my_identity) @@ -435,7 +423,6 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message) } - static void setup_peer (struct PeerContext *p, const char *cfgname) { @@ -444,9 +431,6 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", -#if VERBOSE - "-L", "DEBUG", -#endif "-c", cfgname, NULL); #endif GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); @@ -482,7 +466,7 @@ stop_arm (struct PeerContext *p) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); - GNUNET_OS_process_close (p->arm_proc); + GNUNET_OS_process_destroy (p->arm_proc); p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); @@ -494,9 +478,6 @@ check () char *const argv[] = { "test-core-api-reliability", "-c", "test_core_api_data.conf", -#if VERBOSE - "-L", "DEBUG", -#endif NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { @@ -511,17 +492,14 @@ check () return ok; } + int main (int argc, char *argv[]) { int ret; GNUNET_log_setup ("test-core-api", -#if VERBOSE - "DEBUG", -#else "WARNING", -#endif NULL); ret = check (); GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); diff --git a/src/core/test_core_api_send_to_self.c b/src/core/test_core_api_send_to_self.c index 4fa73d9..b1340dc 100644 --- a/src/core/test_core_api_send_to_self.c +++ b/src/core/test_core_api_send_to_self.c @@ -81,7 +81,7 @@ cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tskctx) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", GNUNET_OS_process_get_pid (arm_proc)); - GNUNET_OS_process_close (arm_proc); + GNUNET_OS_process_destroy (arm_proc); arm_proc = NULL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n"); diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c index 2eca575..8c81320 100644 --- a/src/core/test_core_api_start_only.c +++ b/src/core/test_core_api_start_only.c @@ -208,7 +208,7 @@ stop_arm (struct PeerContext *p) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); - GNUNET_OS_process_close (p->arm_proc); + GNUNET_OS_process_destroy (p->arm_proc); p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); diff --git a/src/core/test_core_defaults.conf b/src/core/test_core_defaults.conf index 098c0ba..9525ca2 100644 --- a/src/core/test_core_defaults.conf +++ b/src/core/test_core_defaults.conf @@ -57,3 +57,9 @@ AUTOSTART = NO [vpn] AUTOSTART = NO + +[namestore] +AUTOSTART = NO + +[lockmanager] +AUTOSTART = NO diff --git a/src/core/test_core_quota_asymmetric_recv_limited_peer2.conf b/src/core/test_core_quota_asymmetric_recv_limited_peer2.conf index 0c89523..62fc69e 100644 --- a/src/core/test_core_quota_asymmetric_recv_limited_peer2.conf +++ b/src/core/test_core_quota_asymmetric_recv_limited_peer2.conf @@ -3,8 +3,6 @@ SERVICEHOME = /tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/ DEFAULTCONFIG = test_core_quota_asymmetric_recv_limited_peer2.conf -[transport-tcp] -PORT = 22488 [arm] PORT = 22486 @@ -37,3 +35,11 @@ UNIXPATH = /tmp/gnunet-core-asym-recv-p2-service-ats.sock WAN_QUOTA_IN = 10 kiB WAN_QUOTA_OUT = 10 kiB +[transport-tcp] +PORT = 22467 + +[transport-unix] +PORT = 22468 + +[transport-http] +PORT = 22469
\ No newline at end of file diff --git a/src/core/test_core_quota_asymmetric_send_limit_peer2.conf b/src/core/test_core_quota_asymmetric_send_limit_peer2.conf index 5474ce9..614358b 100644 --- a/src/core/test_core_quota_asymmetric_send_limit_peer2.conf +++ b/src/core/test_core_quota_asymmetric_send_limit_peer2.conf @@ -3,9 +3,6 @@ SERVICEHOME = /tmp/test-gnunet-core-quota-asym-send-lim-peer-2/ DEFAULTCONFIG = test_core_quota_asymmetric_send_limit_peer2.conf -[transport-tcp] -PORT = 22488 - [arm] PORT = 22486 UNIXPATH = /tmp/gnunet-core-asym-send-p2-service-arm.sock @@ -36,3 +33,12 @@ PORT = 22491 UNIXPATH = /tmp/gnunet-core-asym-send-p2-service-ats.sock WAN_QUOTA_IN = 1 MB WAN_QUOTA_OUT = 1 MB + +[transport-tcp] +PORT = 22467 + +[transport-unix] +PORT = 22468 + +[transport-http] +PORT = 22469
\ No newline at end of file diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c index 7c16531..df602b3 100644 --- a/src/core/test_core_quota_compliance.c +++ b/src/core/test_core_quota_compliance.c @@ -33,7 +33,6 @@ #include "gnunet_transport_service.h" #include "gnunet_statistics_service.h" -#define VERBOSE GNUNET_NO #define SYMMETRIC 0 #define ASYMMETRIC_SEND_LIMITED 1 @@ -126,6 +125,8 @@ terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct GNUNET_CORE_Handle *ch; err_task = GNUNET_SCHEDULER_NO_TASK; + GNUNET_STATISTICS_destroy (p1.stats, GNUNET_NO); + GNUNET_STATISTICS_destroy (p2.stats, GNUNET_NO); GNUNET_TRANSPORT_get_hello_cancel (p2.ghh); GNUNET_TRANSPORT_get_hello_cancel (p1.ghh); if (p1.nth != NULL) @@ -168,14 +169,17 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_TRANSPORT_get_hello_cancel (p1.ghh); GNUNET_TRANSPORT_get_hello_cancel (p2.ghh); - - GNUNET_CORE_disconnect (p1.ch); + if (NULL != p1.ch) + GNUNET_CORE_disconnect (p1.ch); p1.ch = NULL; - GNUNET_CORE_disconnect (p2.ch); + if (NULL != p2.ch) + GNUNET_CORE_disconnect (p2.ch); p2.ch = NULL; - GNUNET_TRANSPORT_disconnect (p1.th); + if (NULL != p1.th) + GNUNET_TRANSPORT_disconnect (p1.th); p1.th = NULL; - GNUNET_TRANSPORT_disconnect (p2.th); + if (NULL != p2.th) + GNUNET_TRANSPORT_disconnect (p2.th); p2.th = NULL; ok = 42; } @@ -237,15 +241,15 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) max_quota_in = GNUNET_MIN (current_quota_p1_in, current_quota_p2_in); max_quota_out = GNUNET_MIN (current_quota_p1_out, current_quota_p2_out); if (max_quota_out < max_quota_in) - quota_delta = max_quota_in / 5; + quota_delta = max_quota_in / 3; else - quota_delta = max_quota_out / 5; + quota_delta = max_quota_out / 3; if ((throughput_out > (max_quota_out + quota_delta)) || (throughput_in > (max_quota_in + quota_delta))) - ok = 1; + ok = 1; /* fail */ else - ok = 0; + ok = 0; /* pass */ GNUNET_STATISTICS_get (p1.stats, "core", "# discarded CORE_SEND requests", GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1); @@ -277,17 +281,17 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { case SYMMETRIC: GNUNET_log (kind, "Core quota compliance test with symmetric quotas: %s\n", - (ok != 0) ? "PASSED" : "FAILED"); + (0 == ok) ? "PASSED" : "FAILED"); break; case ASYMMETRIC_SEND_LIMITED: GNUNET_log (kind, "Core quota compliance test with limited sender quota: %s\n", - (ok != 0) ? "PASSED" : "FAILED"); + (0 == ok) ? "PASSED" : "FAILED"); break; case ASYMMETRIC_RECV_LIMITED: GNUNET_log (kind, "Core quota compliance test with limited receiver quota: %s\n", - (ok != 0) ? "PASSED" : "FAILED"); + (0 == ok) ? "PASSED" : "FAILED"); break; }; GNUNET_log (kind, "Peer 1 send rate: %llu b/s (%llu bytes in %llu ms)\n", @@ -571,9 +575,6 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", -#if VERBOSE - "-L", "DEBUG", -#endif "-c", cfgname, NULL); #endif GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); @@ -644,23 +645,19 @@ stop_arm (struct PeerContext *p) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); - GNUNET_OS_process_close (p->arm_proc); + GNUNET_OS_process_destroy (p->arm_proc); p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } + static int check () { - - char *const argv[] = { "test-core-quota-compliance", "-c", "test_core_api_data.conf", -#if VERBOSE - "-L", "DEBUG", -#endif NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { @@ -675,6 +672,7 @@ check () return ok; } + int main (int argc, char *argv[]) { @@ -715,11 +713,7 @@ main (int argc, char *argv[]) } GNUNET_log_setup ("test-core-quota-compliance", -#if VERBOSE - "DEBUG", -#else "WARNING", -#endif NULL); ret = check (); if (test == SYMMETRIC) @@ -741,10 +735,7 @@ main (int argc, char *argv[]) GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/"); } - - - return ret; } -/* end of test_core_api_reliability.c */ +/* end of test_core_quota_compliance.c */ diff --git a/src/core/test_core_quota_peer2.conf b/src/core/test_core_quota_peer2.conf index 61e03fb..1fd4ec8 100644 --- a/src/core/test_core_quota_peer2.conf +++ b/src/core/test_core_quota_peer2.conf @@ -3,9 +3,6 @@ SERVICEHOME = /tmp/test-gnunet-core-quota-sym-peer-2/ DEFAULTCONFIG = test_core_quota_peer2.conf -[transport-tcp] -PORT = 22478 - [arm] PORT = 22476 UNIXPATH = /tmp/gnunet-core-sym-p2-service-arm.sock @@ -36,3 +33,12 @@ PORT = 22482 UNIXPATH = /tmp/gnunet-core-sym-p2-service-ats.sock WAN_QUOTA_IN = 10 kiB WAN_QUOTA_OUT = 10 kiB + +[transport-tcp] +PORT = 22467 + +[transport-unix] +PORT = 22468 + +[transport-http] +PORT = 22469
\ No newline at end of file |