From 2e92874cdda169f6337669d1bff9a5772aeae163 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 13 Oct 2011 21:16:04 +0000 Subject: [PATCH] more refactoring --- src/ats/ats.h | 7 +- src/ats/gnunet-service-ats_addresses.c | 46 +++++++++++++ src/ats/gnunet-service-ats_addresses.h | 11 +++- src/ats/gnunet-service-ats_scheduling.c | 87 +++++++++++-------------- 4 files changed, 97 insertions(+), 54 deletions(-) diff --git a/src/ats/ats.h b/src/ats/ats.h index 2bf16b125..bef63553e 100644 --- a/src/ats/ats.h +++ b/src/ats/ats.h @@ -41,7 +41,6 @@ enum StartFlag }; - struct ClientStartMessage { struct GNUNET_MessageHeader header; @@ -53,7 +52,6 @@ struct ClientStartMessage }; - struct RequestAddressMessage { struct GNUNET_MessageHeader header; @@ -63,6 +61,7 @@ struct RequestAddressMessage struct GNUNET_PeerIdentity peer; }; + struct AddressUpdateMessage { struct GNUNET_MessageHeader header; @@ -85,6 +84,7 @@ struct AddressUpdateMessage }; + struct AddressDestroyedMessage { struct GNUNET_MessageHeader header; @@ -134,7 +134,6 @@ struct AddressSuggestionMessage }; - struct PeerInformationMessage { struct GNUNET_MessageHeader header; @@ -160,8 +159,6 @@ struct PeerInformationMessage }; - - struct ReservationRequestMessage { struct GNUNET_MessageHeader header; diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index ff83f4fd8..4f9f877a5 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -81,6 +81,52 @@ free_address_it (void *cls, } +void +GAS_address_update (struct GNUNET_SERVER_Client *client, + const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, + const void *plugin_addr, size_t plugin_addr_len, + uint32_t session_id, + const struct GNUNET_TRANSPORT_ATS_Information *atsi, + uint32_t atsi_count) +{ + struct ATS_Address * aa; + + aa = GNUNET_malloc (sizeof (struct ATS_Address) + + atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) + + plugin_addr_len); + aa->peer = *peer; + aa->addr_len = plugin_addr_len; + aa->ats_count = atsi_count; + aa->ats = (struct GNUNET_TRANSPORT_ATS_Information *) &aa[1]; + memcpy (&aa->ats, atsi, atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); + memcpy (aa->addr, plugin_addr, plugin_addr_len); + aa->plugin = GNUNET_strdup (plugin_name); + aa->session_id = session_id; + + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put(addresses, + &peer->hashPubKey, + aa, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); +} + + +void +GAS_address_destroyed (struct GNUNET_SERVER_Client *client, + ...) +{ +#if 0 + // struct AddressDestroyedMessage * msg = (struct AddressDestroyedMessage *) message; +/* + struct GNUNET_PeerIdentity *peer = &msg->peer; + struct ATS_Address * aa = find_address_by_addr (peer); + GNUNET_CONTAINER_multihashmap_remove(addresses, peer, aa); + GNUNET_free (aa);*/ +#endif +} + + /** */ void diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index 1bc6b65c2..299619c6f 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h @@ -27,7 +27,7 @@ #define GNUNET_SERVICE_ATS_ADDRESSES_H #include "gnunet_util_lib.h" - +#include "gnunet_transport_service.h" // FIXME... /** */ @@ -41,4 +41,13 @@ void GAS_addresses_done (void); +void +GAS_address_update (struct GNUNET_SERVER_Client *client, + const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, + const void *plugin_addr, size_t plugin_addr_len, + uint32_t session_id, + const struct GNUNET_TRANSPORT_ATS_Information *atsi, + uint32_t atsi_count); + #endif diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c index bf2c6187a..60305bac9 100644 --- a/src/ats/gnunet-service-ats_scheduling.c +++ b/src/ats/gnunet-service-ats_scheduling.c @@ -24,6 +24,7 @@ * @author Matthias Wachs */ #include "platform.h" +#include "gnunet-service-ats_addresses.h" #include "gnunet-service-ats_scheduling.h" #include "ats.h" @@ -105,54 +106,52 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { -#if 0 - struct AddressUpdateMessage * msg = (struct AddressUpdateMessage *) message; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ADDRESS_UPDATE"); - - struct GNUNET_TRANSPORT_ATS_Information *am; - char *pm; - - size_t size = ntohs (msg->header.size); - if ((size <= sizeof (struct AddressUpdateMessage)) || (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)) + const struct AddressUpdateMessage * m; + const struct GNUNET_TRANSPORT_ATS_Information *atsi; + const char *address; + const char *plugin_name; + uint16_t address_length; + uint16_t plugin_name_length; + uint32_t ats_count; + uint16_t size; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received `%s' message\n", + "ADDRESS_UPDATE"); + size = ntohs (message->size); + if (size <= sizeof (struct AddressUpdateMessage)) { GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } - - size_t ats_count = ntohs (msg->ats_count); - size_t addr_len = ntohs (msg->address_length); - size_t plugin_len = ntohs (msg->plugin_name_length) + 1 ; - - if ( - (plugin_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || - (addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || - (addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ) + m = (const struct AddressUpdateMessage*) message; + ats_count = ntohl (m->ats_count); + address_length = ntohs (m->address_length); + plugin_name_length = ntohs (m->plugin_name_length); + atsi = (const struct GNUNET_TRANSPORT_ATS_Information*) &m[1]; + address = (const char*) &atsi[ats_count]; + plugin_name = &address[address_length]; + if ( (address_length + + plugin_name_length + + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) + + sizeof (struct AddressSuggestionMessage) != ntohs (message->size)) || + (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_TRANSPORT_ATS_Information)) || + (plugin_name[plugin_name_length - 1] != '\0') ) { GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } - - struct ATS_Address * aa = GNUNET_malloc (sizeof (struct ATS_Address) + - ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) + - addr_len + - plugin_len); - - - - memcpy (&aa->peer, &msg->peer, sizeof (struct GNUNET_PeerIdentity)); - aa->addr_len = addr_len; - aa->ats_count = ats_count; - aa->ats = (struct GNUNET_TRANSPORT_ATS_Information *) &aa[1]; - - am = (struct GNUNET_TRANSPORT_ATS_Information*) &msg[1]; - memcpy (&aa->ats, am, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); - pm = (char *) &am[ats_count]; - memcpy (aa->addr, pm, addr_len); - memcpy (aa->plugin, &pm[plugin_len], plugin_len); - aa->session_id = ntohl(msg->session_id); - - GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(addresses, &aa->peer.hashPubKey, aa, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); -#endif + GAS_address_update (client, + &m->peer, + plugin_name, + address, + address_length, + ntohl (m->session_id), + atsi, + ats_count); + GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -161,15 +160,7 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { -#if 0 - // struct AddressDestroyedMessage * msg = (struct AddressDestroyedMessage *) message; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ADDRESS_DESTROYED"); -/* - struct GNUNET_PeerIdentity *peer = &msg->peer; - struct ATS_Address * aa = find_address_by_addr (peer); - GNUNET_CONTAINER_multihashmap_remove(addresses, peer, aa); - GNUNET_free (aa);*/ -#endif } /* end of gnunet-service-ats_scheduling.c */ -- 2.25.1