From 623df97886da9ee06724b7860a1a2463737b750e Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Tue, 29 Nov 2011 09:37:54 +0000 Subject: first steps to transport_api cleanup compiles but no guarante to work! --- src/transport/gnunet-transport.c | 14 ++++++--- src/transport/transport_api_address_iterate.c | 29 +++++++------------ src/transport/transport_api_address_lookup.c | 35 +++++++++++------------ src/transport/transport_api_peer_address_lookup.c | 25 ++++++++-------- 4 files changed, 51 insertions(+), 52 deletions(-) (limited to 'src/transport') 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) { -- cgit v1.2.3