From e94c5914935ca0842ca762d343cb167c68b8a79a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 5 May 2019 14:02:24 +0200 Subject: [PATCH] use new PriorityPreferences consistently, note on deprecation --- src/include/gnunet_mq_lib.h | 4 ++ .../gnunet_transport_address_service.h | 15 +++--- .../gnunet_transport_application_service.h | 28 ++++++++++ src/include/gnunet_transport_hello_service.h | 29 ++++++----- src/transport/gnunet-service-tng.c | 14 +++-- src/transport/transport_api2_address.c | 52 +++++++------------ src/transport/transport_api2_application.c | 11 ++-- 7 files changed, 90 insertions(+), 63 deletions(-) diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h index 4fe5c8df9..81100d7d8 100644 --- a/src/include/gnunet_mq_lib.h +++ b/src/include/gnunet_mq_lib.h @@ -1043,6 +1043,8 @@ GNUNET_MQ_impl_current (struct GNUNET_MQ_Handle *mq); /** * Enum defining all known preference categories. + * + * @deprecated will be replaced by `enum GNUNET_MQ_PriorityPreference` */ enum GNUNET_MQ_PreferenceKind { @@ -1083,6 +1085,8 @@ enum GNUNET_MQ_PreferenceKind * * @param type the preference type * @return a string or NULL if invalid + * + * @deprecated will be replaced by `enum GNUNET_MQ_PriorityPreference` */ const char * GNUNET_MQ_preference_to_string (enum GNUNET_MQ_PreferenceKind type); diff --git a/src/include/gnunet_transport_address_service.h b/src/include/gnunet_transport_address_service.h index 9f0717d00..b33a11411 100644 --- a/src/include/gnunet_transport_address_service.h +++ b/src/include/gnunet_transport_address_service.h @@ -21,6 +21,9 @@ /** * @author Christian Grothoff * + * @deprecated NOTE: we may want to drop this API and + * only keep the gnunet_transport_application_service.h in the future! + * * @file * Provide addresses to transport for validation * @@ -36,9 +39,8 @@ #define GNUNET_TRANSPORT_ADDRESS_SERVICE_H #ifdef __cplusplus -extern "C" -{ -#if 0 /* keep Emacsens' auto-indent happy */ +extern "C" { +#if 0 /* keep Emacsens' auto-indent happy */ } #endif #endif @@ -65,7 +67,8 @@ struct GNUNET_TRANSPORT_AddressHandle; * @return NULL on error */ struct GNUNET_TRANSPORT_AddressHandle * -GNUNET_TRANSPORT_address_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); +GNUNET_TRANSPORT_address_connect ( + const struct GNUNET_CONFIGURATION_Handle *cfg); /** @@ -101,7 +104,7 @@ GNUNET_TRANSPORT_address_try (struct GNUNET_TRANSPORT_AddressHandle *ch, const size_t raw_size); -#if 0 /* keep Emacsens' auto-indent happy */ +#if 0 /* keep Emacsens' auto-indent happy */ { #endif #ifdef __cplusplus @@ -111,6 +114,6 @@ GNUNET_TRANSPORT_address_try (struct GNUNET_TRANSPORT_AddressHandle *ch, /* ifndef GNUNET_TRANSPORT_ADDRESS_SERVICE_H */ #endif -/** @} */ /* end of group */ +/** @} */ /* end of group */ /* end of gnunet_transport_address_service.h */ diff --git a/src/include/gnunet_transport_application_service.h b/src/include/gnunet_transport_application_service.h index 8c63a8234..c12bd7441 100644 --- a/src/include/gnunet_transport_application_service.h +++ b/src/include/gnunet_transport_application_service.h @@ -64,6 +64,34 @@ GNUNET_TRANSPORT_application_done ( struct GNUNET_TRANSPORT_ApplicationHandle *ch); +/** + * An application would like TRANSPORT to connect to a peer. + * + * @param ch handle + * @param peer identity of the peer we need an address for + * @param pk what kind of application will the application require (can be + * #GNUNET_MQ_PRIO_BACKGROUND, we will still try to connect) + * @param bw desired bandwith, can be zero (we will still try to connect) + * @return suggest handle, NULL if a request is already pending + */ +struct GNUNET_TRANSPORT_ApplicationSuggestHandle * +GNUNET_TRANSPORT_application_suggest ( + struct GNUNET_TRANSPORT_ApplicationHandle *ch, + const struct GNUNET_PeerIdentity *peer, + enum GNUNET_MQ_PriorityPreferences pk, + struct GNUNET_BANDWIDTH_Value32NBO bw); + + +/** + * We no longer care about being connected to a peer. + * + * @param sh handle to stop + */ +void +GNUNET_TRANSPORT_application_suggest_cancel ( + struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh); + + /** * An application (or a communicator) has received a HELLO (or other address * data of another peer) and wants TRANSPORT to validate that the address is diff --git a/src/include/gnunet_transport_hello_service.h b/src/include/gnunet_transport_hello_service.h index 58a1e9979..fe863c058 100644 --- a/src/include/gnunet_transport_hello_service.h +++ b/src/include/gnunet_transport_hello_service.h @@ -24,6 +24,8 @@ * @file * obtain information about our current address * + * @deprecated, in TNG applications should query PEERSTORE directly! + * * @defgroup transport Transport service * address information * @@ -35,9 +37,8 @@ #define GNUNET_TRANSPORT_HELLO_SERVICE_H #ifdef __cplusplus -extern "C" -{ -#if 0 /* keep Emacsens' auto-indent happy */ +extern "C" { +#if 0 /* keep Emacsens' auto-indent happy */ } #endif #endif @@ -118,9 +119,9 @@ enum GNUNET_TRANSPORT_AddressClass * @param cls closure * @param hello our updated HELLO */ -typedef void -(*GNUNET_TRANSPORT_HelloUpdateCallback) (void *cls, - const struct GNUNET_MessageHeader *hello); +typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback) ( + void *cls, + const struct GNUNET_MessageHeader *hello); /** @@ -164,12 +165,12 @@ GNUNET_TRANSPORT_hello_get_cancel (struct GNUNET_TRANSPORT_HelloGetHandle *ghh); * @param nt network type of the address * @param expiration when does this address expire? */ -typedef void -(*GNUNET_TRANSPORT_AddressCallback) (void *cls, - const struct GNUNET_PeerIdentity *peer, - const char *address, - enum GNUNET_NetworkType nt, - struct GNUNET_TIME_Absolute expiration); +typedef void (*GNUNET_TRANSPORT_AddressCallback) ( + void *cls, + const struct GNUNET_PeerIdentity *peer, + const char *address, + enum GNUNET_NetworkType nt, + struct GNUNET_TIME_Absolute expiration); /** @@ -187,7 +188,7 @@ GNUNET_TRANSPORT_hello_parse (const struct GNUNET_MessageHeader *hello, void *cb_cls); -#if 0 /* keep Emacsens' auto-indent happy */ +#if 0 /* keep Emacsens' auto-indent happy */ { #endif #ifdef __cplusplus @@ -197,6 +198,6 @@ GNUNET_TRANSPORT_hello_parse (const struct GNUNET_MessageHeader *hello, /* ifndef GNUNET_TRANSPORT_HELLO_SERVICE_H */ #endif -/** @} */ /* end of group */ +/** @} */ /* end of group */ /* end of gnunet_transport_hello_service.h */ diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c index 443c7f245..ab9159963 100644 --- a/src/transport/gnunet-service-tng.c +++ b/src/transport/gnunet-service-tng.c @@ -1757,8 +1757,10 @@ struct PeerRequest /** * What kind of performance preference does this @e tc have? + * + * TODO: use this! */ - enum GNUNET_MQ_PreferenceKind pk; + enum GNUNET_MQ_PriorityPreferences pk; /** * How much bandwidth would this @e tc like to see? @@ -1952,6 +1954,12 @@ struct PendingMessage */ enum PendingMessageType pmt; + /** + * Preferences for this message. + * TODO: actually use this! + */ + enum GNUNET_MQ_PriorityPreferences prefs; + /** * Size of the original message. */ @@ -3736,7 +3744,6 @@ handle_client_send (void *cls, const struct OutboundMessage *obm) obmm = (const struct GNUNET_MessageHeader *) &obm[1]; bytes_msg = ntohs (obmm->size); pp = (enum GNUNET_MQ_PriorityPreferences) ntohl (obm->priority); - /* FIXME: actually make use of pp */ (void) pp; vl = GNUNET_CONTAINER_multipeermap_get (links, &obm->peer); if (NULL == vl) { @@ -3790,6 +3797,7 @@ handle_client_send (void *cls, const struct OutboundMessage *obm) was_empty = (NULL == target->pending_msg_head); pm = GNUNET_malloc (sizeof (struct PendingMessage) + payload_size); + pm->prefs = pp; pm->client = tc; pm->target = target; pm->bytes_msg = payload_size; @@ -8559,7 +8567,7 @@ handle_suggest (void *cls, const struct ExpressPreferenceMessage *msg) pr->tc = tc; pr->pid = msg->peer; pr->bw = msg->bw; - pr->pk = (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk); + pr->pk = (enum GNUNET_MQ_PriorityPreferences) ntohl (msg->pk); if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_put ( tc->details.application.requests, &pr->pid, diff --git a/src/transport/transport_api2_address.c b/src/transport/transport_api2_address.c index 1ff599efb..d2cab27d5 100644 --- a/src/transport/transport_api2_address.c +++ b/src/transport/transport_api2_address.c @@ -31,7 +31,8 @@ #include "gnunet_ats_transport_service.h" #include "transport.h" -#define LOG(kind,...) GNUNET_log_from (kind, "transport-api-address",__VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log_from (kind, "transport-api-address", __VA_ARGS__) /** @@ -60,7 +61,6 @@ struct GNUNET_TRANSPORT_AddressHandle * Delay until we try to reconnect. */ struct GNUNET_TIME_Relative reconnect_delay; - }; @@ -84,8 +84,7 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_AddressHandle *h); * @param error error code */ static void -mq_error_handler (void *cls, - enum GNUNET_MQ_Error error) +mq_error_handler (void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_TRANSPORT_AddressHandle *h = cls; @@ -104,19 +103,13 @@ static void reconnect (void *cls) { struct GNUNET_TRANSPORT_AddressHandle *h = cls; - struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_handler_end () - }; + struct GNUNET_MQ_MessageHandler handlers[] = {GNUNET_MQ_handler_end ()}; h->reconnect_task = NULL; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Connecting to transport service.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); GNUNET_assert (NULL == h->mq); - h->mq = GNUNET_CLIENT_connect (h->cfg, - "transport", - handlers, - &mq_error_handler, - h); + h->mq = + GNUNET_CLIENT_connect (h->cfg, "transport", handlers, &mq_error_handler, h); } @@ -149,12 +142,9 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_AddressHandle *h) disconnect (h); LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduling task to reconnect to transport service in %s.\n", - GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, - GNUNET_YES)); + GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); h->reconnect_task = - GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, - &reconnect, - h); + GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); } @@ -173,8 +163,7 @@ GNUNET_TRANSPORT_address_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) h = GNUNET_new (struct GNUNET_TRANSPORT_AddressHandle); h->cfg = cfg; h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Connecting to transport service\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n"); reconnect (h); if (NULL == h->mq) { @@ -191,10 +180,10 @@ GNUNET_TRANSPORT_address_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) * @param handle handle to the service as returned from #GNUNET_TRANSPORT_address_connect() */ void -GNUNET_TRANSPORT_address_disconnect (struct GNUNET_TRANSPORT_AddressHandle *handle) +GNUNET_TRANSPORT_address_disconnect ( + struct GNUNET_TRANSPORT_AddressHandle *handle) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Transport disconnect called!\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); /* this disconnects all neighbours... */ disconnect (handle); /* and now we stop trying to connect again... */ @@ -233,17 +222,14 @@ GNUNET_TRANSPORT_address_try (struct GNUNET_TRANSPORT_AddressHandle *ch, struct GNUNET_MQ_Envelope *env; struct GNUNET_TRANSPORT_AddressToVerify *hdr; - env = GNUNET_MQ_msg_extra (hdr, - raw_size, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_CONSIDER_VERIFY); + env = + GNUNET_MQ_msg_extra (hdr, + raw_size, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_CONSIDER_VERIFY); hdr->peer = *pid; - memcpy (&hdr[1], - raw, - raw_size); - GNUNET_MQ_send (ch->mq, - env); + memcpy (&hdr[1], raw, raw_size); + GNUNET_MQ_send (ch->mq, env); } - /* end of transport_api2_address.c */ diff --git a/src/transport/transport_api2_application.c b/src/transport/transport_api2_application.c index 49f0f36c7..7d790d738 100644 --- a/src/transport/transport_api2_application.c +++ b/src/transport/transport_api2_application.c @@ -51,7 +51,7 @@ struct GNUNET_TRANSPORT_ApplicationSuggestHandle /** * What preference is being expressed? */ - enum GNUNET_MQ_PreferenceKind pk; + enum GNUNET_MQ_PriorityPreferences pk; /** * How much bandwidth does the client expect? @@ -277,15 +277,12 @@ GNUNET_TRANSPORT_application_done ( /** - * We would like to receive address suggestions for a peer. TRANSPORT will - * respond with a call to the continuation immediately containing an address or - * no address if none is available. TRANSPORT can suggest more addresses until we call - * #GNUNET_TRANSPORT_application_suggest_cancel(). + * An application would like TRANSPORT to connect to a peer. * * @param ch handle * @param peer identity of the peer we need an address for * @param pk what kind of application will the application require (can be - * #GNUNET_MQ_PREFERENCE_NONE, we will still try to connect) + * #GNUNET_MQ_PRIO_BACKGROUND, we will still try to connect) * @param bw desired bandwith, can be zero (we will still try to connect) * @return suggest handle, NULL if a request is already pending */ @@ -293,7 +290,7 @@ struct GNUNET_TRANSPORT_ApplicationSuggestHandle * GNUNET_TRANSPORT_application_suggest ( struct GNUNET_TRANSPORT_ApplicationHandle *ch, const struct GNUNET_PeerIdentity *peer, - enum GNUNET_MQ_PreferenceKind pk, + enum GNUNET_MQ_PriorityPreferences pk, struct GNUNET_BANDWIDTH_Value32NBO bw) { struct GNUNET_TRANSPORT_ApplicationSuggestHandle *s; -- 2.25.1