From: Matthias Wachs Date: Tue, 29 Nov 2011 09:37:54 +0000 (+0000) Subject: first steps to transport_api cleanup X-Git-Tag: initial-import-from-subversion-38251~15761 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=623df97886da9ee06724b7860a1a2463737b750e;p=oweals%2Fgnunet.git first steps to transport_api cleanup compiles but no guarante to work! --- diff --git a/src/core/gnunet-core-list-connections.c b/src/core/gnunet-core-list-connections.c index 79490bcc5..3f3288d79 100644 --- a/src/core/gnunet-core-list-connections.c +++ b/src/core/gnunet-core-list-connections.c @@ -97,7 +97,7 @@ dump_pc (struct PrintContext *pc) * @param address NULL on error, otherwise 0-terminated printable UTF-8 string */ static void -process_resolved_address (void *cls, const char *address) +process_resolved_address (void *cls, const struct GNUNET_HELLO_Address *address) { struct PrintContext *pc = cls; struct AddressStringList *new_address; @@ -112,7 +112,8 @@ process_resolved_address (void *cls, const char *address) #if VERBOSE fprintf (stderr, "Received address %s\n", address); #endif - new_address->address_string = GNUNET_strdup (address); + // FIXME : GNUNET_TRANSPORT_address_to_string + new_address->address_string = GNUNET_strdup ("FIXME"); GNUNET_CONTAINER_DLL_insert (pc->address_list_head, pc->address_list_tail, new_address); } @@ -136,7 +137,7 @@ connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer, #endif pc = GNUNET_malloc (sizeof (struct PrintContext)); pc->peer = *peer; - GNUNET_TRANSPORT_peer_address_lookup (cfg, peer, GNUNET_TIME_UNIT_MINUTES, + GNUNET_TRANSPORT_peer_get_active_addresses (cfg, peer, GNUNET_TIME_UNIT_MINUTES, &process_resolved_address, pc); } #if VERBOSE diff --git a/src/hello/address.c b/src/hello/address.c index 5cfa10185..b511ca9df 100644 --- a/src/hello/address.c +++ b/src/hello/address.c @@ -62,6 +62,21 @@ GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer, } +/** + * Get the size of an address struct. + * + * @param address address + * @return the size + */ +size_t +GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address) +{ + return sizeof (struct GNUNET_HELLO_Address) + + address->address_length + + strlen(address->transport_name) + 1; +} + + /** * Copy an address struct. * diff --git a/src/include/gnunet_hello_lib.h b/src/include/gnunet_hello_lib.h index 886a41093..09f5f1c7d 100644 --- a/src/include/gnunet_hello_lib.h +++ b/src/include/gnunet_hello_lib.h @@ -111,6 +111,14 @@ GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2); +/** + * Get the size of an address struct. + * + * @param address address + * @return the size + */ +size_t +GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address); /** * Free an address. diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index 1de59d796..b0d9e34b0 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h @@ -104,8 +104,7 @@ typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls, * @param cls closure * @param address NULL on error, otherwise 0-terminated printable UTF-8 string */ -// RENAME: AddressToStringCallback -typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls, +typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls, const char *address); @@ -119,16 +118,9 @@ typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls, * @param addrlen address length */ // FIXME: use GNUNET_HELLO_Address (as 2nd arg, replacing others) -// FIXME: rename: remove "Binary" // FIXME: use NULL for address on disconnect IF in monitor mode (one_shot = NO) -typedef void (*GNUNET_TRANSPORT_AddressLookUpBinaryCallback) (void *cls, - const struct - GNUNET_PeerIdentity - * peer, - const char - *transport, - const void *addr, - size_t addrlen); +typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls, + const struct GNUNET_HELLO_Address *address); /** @@ -280,7 +272,7 @@ GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle, /** * Handle to cancel a pending address lookup. */ -struct GNUNET_TRANSPORT_AddressLookupContext; +struct GNUNET_TRANSPORT_AddressToStringContext; /** @@ -297,14 +289,12 @@ struct GNUNET_TRANSPORT_AddressLookupContext; * @param aluc_cls closure for aluc * @return handle to cancel the operation, NULL on error */ -// FIXME: use 'GNUNET_HELLO_Address' here! -// => rename: address_to_string -struct GNUNET_TRANSPORT_AddressLookupContext * -GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *address, size_t addressLen, - int numeric, const char *nameTrans, +struct GNUNET_TRANSPORT_AddressToStringContext * +GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_HELLO_Address *address, + int numeric, struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressLookUpCallback aluc, + GNUNET_TRANSPORT_AddressToStringCallback aluc, void *aluc_cls); @@ -314,17 +304,11 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, * @param alc handle for the request to cancel */ void -GNUNET_TRANSPORT_address_lookup_cancel (struct - GNUNET_TRANSPORT_AddressLookupContext +GNUNET_TRANSPORT_address_to_string_cancel (struct + GNUNET_TRANSPORT_AddressToStringContext *alc); -/** - * Handle to cancel a pending address lookup. - */ -struct GNUNET_TRANSPORT_AddressLookupContext; - - /** * Return all the known addresses for a peer. FIXME: document better! * FIXME: use better name! @@ -342,17 +326,12 @@ struct GNUNET_TRANSPORT_AddressLookupContext; * @param peer_address_callback function to call with the results * @param peer_address_callback_cls closure for peer_address_callback */ -// RENAME: peer_get_active_addresses struct GNUNET_TRANSPORT_PeerAddressLookupContext * -GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle - *cfg, +GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *peer, // FIXME: add argument: one_shot struct GNUNET_TIME_Relative timeout, - // FIXME: change to the 'Binary' lookup callback (which will - // be renamed, so the argument type actually won't change) - GNUNET_TRANSPORT_AddressLookUpCallback - peer_address_callback, + GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, void *peer_address_callback_cls); @@ -362,9 +341,9 @@ GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle * @param alc handle for the request to cancel */ void -GNUNET_TRANSPORT_peer_address_lookup_cancel (struct +GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct GNUNET_TRANSPORT_PeerAddressLookupContext - *alc); +*alc); /** @@ -381,7 +360,7 @@ GNUNET_TRANSPORT_peer_address_lookup_cancel (struct void GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressLookUpBinaryCallback + GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, void *peer_address_callback_cls); diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c index e40615a9b..d54eb1081 100644 --- a/src/peerinfo-tool/gnunet-peerinfo.c +++ b/src/peerinfo-tool/gnunet-peerinfo.c @@ -126,11 +126,9 @@ print_address (void *cls, struct GNUNET_TIME_Absolute expiration) { struct PrintContext *pc = cls; - - GNUNET_TRANSPORT_address_lookup (cfg, - address->address, - address->address_length, no_resolve, - address->transport_name, + GNUNET_TRANSPORT_address_to_string (cfg, + address, + no_resolve, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), &process_resolved_address, pc); diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 4c9e8566c..1dc85a903 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c @@ -443,11 +443,15 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, * @param addrlen number of bytes in addr */ static void -process_address (void *cls, const struct GNUNET_PeerIdentity *peer, - const char *transport, const void *addr, size_t addrlen) +process_address (void *cls, const struct GNUNET_HELLO_Address *address) { - if ((peer != NULL) || (transport != NULL) || - ((addr != NULL) && (addrlen > 0))) + if ((address->transport_name != NULL) || + ((address->address != NULL) && (address->address_length > 0))) + { + /* Call GNUNET_TRANSPORT_address_to_string to convert to human readable */ + //GNUNET_TRANSPORT_address_to_string(cfg, address, GNUNET_NO) + +#if 0 fprintf (stdout, _("Peer `%s' plugin: `%s' address `%s'\n"), (peer != NULL) ? GNUNET_i2s (peer) : "", (transport != NULL) ? transport : "", ((addr != NULL) && @@ -456,6 +460,8 @@ process_address (void *cls, const struct GNUNET_PeerIdentity *peer, NULL)) ? "how do i resolve the name without transport service?" : ""); +#endif + } } diff --git a/src/transport/transport_api_address_iterate.c b/src/transport/transport_api_address_iterate.c index 3c3f97c28..a79319163 100644 --- a/src/transport/transport_api_address_iterate.c +++ b/src/transport/transport_api_address_iterate.c @@ -47,7 +47,7 @@ struct AddressLookupCtx /** * Function to call with the human-readable address. */ - GNUNET_TRANSPORT_AddressLookUpBinaryCallback cb; + GNUNET_TRANSPORT_AddressLookUpCallback cb; /** * Closure for cb. @@ -78,17 +78,13 @@ peer_address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) { struct AddressLookupCtx *alucb = cls; - struct AddressIterateResponseMessage *address; + struct AddressIterateResponseMessage *arm; + struct GNUNET_HELLO_Address * address; uint16_t size; - char *transport; - - //size_t transport_len; - //void * addr; - size_t addrlen; if (msg == NULL) { - alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0); + alucb->cb (alucb->cb_cls, NULL); GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); GNUNET_free (alucb); return; @@ -102,7 +98,7 @@ peer_address_response_processor (void *cls, if (size == sizeof (struct GNUNET_MessageHeader)) { /* done! */ - alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0); + alucb->cb (alucb->cb_cls, NULL); GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); GNUNET_free (alucb); return; @@ -111,22 +107,19 @@ peer_address_response_processor (void *cls, { /* invalid reply */ GNUNET_break (0); - alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0); + alucb->cb (alucb->cb_cls, NULL); GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); GNUNET_free (alucb); return; } - address = (struct AddressIterateResponseMessage *) &msg[1]; - - transport = (char *) &address[0]; - //transport_len = ntohs(address->pluginlen); - addrlen = ntohs (address->addrlen); + arm = (struct AddressIterateResponseMessage *) &msg[1]; + address = (struct GNUNET_HELLO_Address *) &arm[1]; /* expect more replies */ GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, GNUNET_TIME_absolute_get_remaining (alucb->timeout)); - alucb->cb (alucb->cb_cls, &address->peer, transport, NULL, addrlen); + alucb->cb (alucb->cb_cls, address); } @@ -141,7 +134,7 @@ peer_address_response_processor (void *cls, void GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressLookUpBinaryCallback + GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, void *peer_address_callback_cls) { @@ -153,7 +146,7 @@ GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, client = GNUNET_CLIENT_connect ("transport", cfg); if (client == NULL) { - peer_address_callback (peer_address_callback_cls, NULL, NULL, NULL, 0); + peer_address_callback (peer_address_callback_cls, NULL); return; } abs_timeout = GNUNET_TIME_relative_to_absolute (timeout); diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c index 968a4324f..259c77152 100644 --- a/src/transport/transport_api_address_lookup.c +++ b/src/transport/transport_api_address_lookup.c @@ -30,12 +30,12 @@ /** * Context for the address lookup. */ -struct GNUNET_TRANSPORT_AddressLookupContext +struct GNUNET_TRANSPORT_AddressToStringContext { /** * Function to call with the human-readable address. */ - GNUNET_TRANSPORT_AddressLookUpCallback cb; + GNUNET_TRANSPORT_AddressToStringCallback cb; /** * Closure for cb. @@ -64,7 +64,7 @@ struct GNUNET_TRANSPORT_AddressLookupContext static void address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) { - struct GNUNET_TRANSPORT_AddressLookupContext *alucb = cls; + struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls; const char *address; uint16_t size; @@ -117,23 +117,23 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) * @param aluc_cls closure for aluc * @return handle to cancel the operation, NULL on error */ -struct GNUNET_TRANSPORT_AddressLookupContext * -GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *address, size_t addressLen, - int numeric, const char *nameTrans, +struct GNUNET_TRANSPORT_AddressToStringContext * +GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_HELLO_Address *address, + int numeric, struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressLookUpCallback aluc, + GNUNET_TRANSPORT_AddressToStringCallback aluc, void *aluc_cls) { - size_t slen; size_t len; + size_t alen; struct AddressLookupMessage *msg; - struct GNUNET_TRANSPORT_AddressLookupContext *alc; + struct GNUNET_TRANSPORT_AddressToStringContext *alc; struct GNUNET_CLIENT_Connection *client; char *addrbuf; - slen = strlen (nameTrans) + 1; - len = sizeof (struct AddressLookupMessage) + addressLen + slen; + alen = GNUNET_HELLO_address_get_size (address); + len = sizeof (struct AddressLookupMessage) + alen; if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) { GNUNET_break (0); @@ -147,11 +147,10 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP); msg->numeric_only = htonl (numeric); msg->timeout = GNUNET_TIME_relative_hton (timeout); - msg->addrlen = htonl (addressLen); + msg->addrlen = htonl (alen); addrbuf = (char *) &msg[1]; - memcpy (addrbuf, address, addressLen); - memcpy (&addrbuf[addressLen], nameTrans, slen); - alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressLookupContext)); + memcpy (addrbuf, address, alen); + alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressToStringContext)); alc->cb = aluc; alc->cb_cls = aluc_cls; alc->timeout = GNUNET_TIME_relative_to_absolute (timeout); @@ -172,8 +171,8 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, * @param alc handle for the request to cancel */ void -GNUNET_TRANSPORT_address_lookup_cancel (struct - GNUNET_TRANSPORT_AddressLookupContext +GNUNET_TRANSPORT_address_to_string_cancel (struct + GNUNET_TRANSPORT_AddressToStringContext *alc) { GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO); diff --git a/src/transport/transport_api_peer_address_lookup.c b/src/transport/transport_api_peer_address_lookup.c index 0df922085..66af497f5 100644 --- a/src/transport/transport_api_peer_address_lookup.c +++ b/src/transport/transport_api_peer_address_lookup.c @@ -78,7 +78,7 @@ peer_address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) { struct GNUNET_TRANSPORT_PeerAddressLookupContext *alucb = cls; - const char *address; + const struct GNUNET_HELLO_Address *address; uint16_t size; if (msg == NULL) @@ -94,25 +94,29 @@ peer_address_response_processor (void *cls, if (size == sizeof (struct GNUNET_MessageHeader)) { /* done! */ - alucb->cb (alucb->cb_cls, NULL); + alucb->cb (alucb->cb_cls, NULL ); GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); GNUNET_free (alucb); return; } - address = (const char *) &msg[1]; + address = (const struct GNUNET_HELLO_Address *) &msg[1]; +#if 0 if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') { /* invalid reply */ GNUNET_break (0); - alucb->cb (alucb->cb_cls, NULL); + alucb->cb (alucb->cb_cls, NULL ); GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); GNUNET_free (alucb); return; } +#endif /* expect more replies */ GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, GNUNET_TIME_absolute_get_remaining (alucb->timeout)); - alucb->cb (alucb->cb_cls, address); + + /* REFACTOR FIX THIS */ + alucb->cb (alucb->cb_cls, address ); } @@ -127,12 +131,10 @@ peer_address_response_processor (void *cls, * @return handle to cancel the operation, NULL on error */ struct GNUNET_TRANSPORT_PeerAddressLookupContext * -GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle - *cfg, +GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *peer, struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressLookUpCallback - peer_address_callback, + GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, void *peer_address_callback_cls) { struct PeerAddressLookupMessage msg; @@ -147,8 +149,7 @@ GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle msg.reserved = htonl (0); msg.timeout = GNUNET_TIME_relative_hton (timeout); memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity)); - alc = - GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext)); + alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext)); alc->cb = peer_address_callback; alc->cb_cls = peer_address_callback_cls; alc->timeout = GNUNET_TIME_relative_to_absolute (timeout); @@ -168,7 +169,7 @@ GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle * @param alc handle for the request to cancel */ void -GNUNET_TRANSPORT_peer_address_lookup_cancel (struct +GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct GNUNET_TRANSPORT_PeerAddressLookupContext *alc) {