From d86cd012c0372c1746fed2a50b7cccca9de99be3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 14 Oct 2011 08:46:34 +0000 Subject: [PATCH] parsing reservations --- src/ats/Makefile.am | 3 +- src/ats/gnunet-service-ats.c | 7 ++- src/ats/gnunet-service-ats_performance.c | 62 +++++++++++++++++++---- src/ats/gnunet-service-ats_performance.h | 19 ++++++- src/ats/gnunet-service-ats_reservations.c | 39 ++++++++++++++ src/ats/gnunet-service-ats_reservations.h | 37 ++++++++++++++ 6 files changed, 154 insertions(+), 13 deletions(-) create mode 100644 src/ats/gnunet-service-ats_reservations.c create mode 100644 src/ats/gnunet-service-ats_reservations.h diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index 77aa71b19..abec8e625 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am @@ -25,7 +25,8 @@ gnunet_service_ats_SOURCES = \ gnunet-service-ats.c \ gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ - gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h + gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \ + gnunet-service-ats_reservations.c gnunet-service-ats_reservations.h gnunet_service_ats_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(GN_LIBINTL) diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index 91ffd9c9d..10972190f 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c @@ -45,19 +45,22 @@ handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { const struct ClientStartMessage * msg = (const struct ClientStartMessage *) message; + enum StartFlag flag; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ATS_START"); - switch (ntohl (msg->start_flag)) + flag = ntohl (msg->start_flag); + switch (flag) { case START_FLAG_SCHEDULING: GAS_scheduling_add_client (client); break; case START_FLAG_PERFORMANCE_WITH_PIC: - GAS_performance_add_client (client); + GAS_performance_add_client (client, flag); break; case START_FLAG_PERFORMANCE_NO_PIC: + GAS_performance_add_client (client, flag); break; default: GNUNET_break (0); diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c index f68b1b8ae..1089b6a6d 100644 --- a/src/ats/gnunet-service-ats_performance.c +++ b/src/ats/gnunet-service-ats_performance.c @@ -26,14 +26,12 @@ */ #include "platform.h" #include "gnunet-service-ats_performance.h" +#include "gnunet-service-ats_reservations.h" #include "ats.h" /** - * We keep clients that are interested in performance notifications in a linked list. - * Note that not ALL clients that are handeled by this module also register for - * notifications. Only those clients that are in this list are managed by the - * notification context. + * We keep clients that are interested in performance in a linked list. */ struct PerformanceClient { @@ -52,6 +50,11 @@ struct PerformanceClient */ struct GNUNET_SERVER_Client *client; + /** + * Options for the client. + */ + enum StartFlag flag; + }; @@ -95,13 +98,15 @@ find_client (struct GNUNET_SERVER_Client *client) * @param client handle of the new client */ void -GAS_performance_add_client (struct GNUNET_SERVER_Client *client) +GAS_performance_add_client (struct GNUNET_SERVER_Client *client, + enum StartFlag flag) { struct PerformanceClient * pc; GNUNET_break (NULL == find_client (client)); pc = GNUNET_malloc (sizeof (struct PerformanceClient)); pc->client = client; + pc->flag = flag; GNUNET_SERVER_notification_context_add (nc, client); GNUNET_SERVER_client_keep (client); GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, pc); @@ -128,20 +133,59 @@ GAS_performance_remove_client (struct GNUNET_SERVER_Client *client) } +/** + * Handle 'reservation request' messages from clients. + * + * @param cls unused, NULL + * @param client client that sent the request + * @param message the request message + */ void GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { - // const struct ReservationRequestMessage * msg = (const struct ReservationRequestMessage *) message; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "RESERVATION_REQUEST"); - + const struct ReservationRequestMessage * msg = (const struct ReservationRequestMessage *) message; + struct ReservationResultMessage result; + int32_t amount; + struct GNUNET_TIME_Relative res_delay; + + if (NULL == find_client (client)) + { + /* missing start message! */ + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received `%s' message\n", + "RESERVATION_REQUEST"); + amount = (int32_t) ntohl (msg->amount); + res_delay = GAS_reservations_reserve (&msg->peer, + amount); + if (res_delay.rel_value > 0) + amount = 0; + result.header.size = htons (sizeof (struct ReservationResultMessage)); + result.header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT); + result.amount = htonl (amount); + result.res_delay = GNUNET_TIME_relative_hton (res_delay); + GNUNET_SERVER_notification_context_unicast (nc, + client, + &result.header, + GNUNET_NO); + GNUNET_SERVER_receive_done (client, GNUNET_OK); } +/** + * Handle 'preference change' messages from clients. + * + * @param cls unused, NULL + * @param client client that sent the request + * @param message the request message + */ void GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) - { // const struct ChangePreferenceMessage * msg = (const struct ChangePreferenceMessage *) message; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "PREFERENCE_CHANGE"); diff --git a/src/ats/gnunet-service-ats_performance.h b/src/ats/gnunet-service-ats_performance.h index e3a5aa394..24f65ed92 100644 --- a/src/ats/gnunet-service-ats_performance.h +++ b/src/ats/gnunet-service-ats_performance.h @@ -28,14 +28,17 @@ #define GNUNET_SERVICE_ATS_PERFORMANCE_H #include "gnunet_util_lib.h" +#include "ats.h" /** * Register a new performance client. * * @param client handle of the new client + * @param flag options for the client */ void -GAS_performance_add_client (struct GNUNET_SERVER_Client *client); +GAS_performance_add_client (struct GNUNET_SERVER_Client *client, + enum StartFlag flag); /** @@ -48,11 +51,25 @@ void GAS_performance_remove_client (struct GNUNET_SERVER_Client *client); +/** + * Handle 'reservation request' messages from clients. + * + * @param cls unused, NULL + * @param client client that sent the request + * @param message the request message + */ void GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message); +/** + * Handle 'preference change' messages from clients. + * + * @param cls unused, NULL + * @param client client that sent the request + * @param message the request message + */ void GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message); diff --git a/src/ats/gnunet-service-ats_reservations.c b/src/ats/gnunet-service-ats_reservations.c new file mode 100644 index 000000000..3356aefbd --- /dev/null +++ b/src/ats/gnunet-service-ats_reservations.c @@ -0,0 +1,39 @@ +/* + 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 ats/gnunet-service-ats_reservations.c + * @brief ats service, inbound bandwidth reservation management + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet-service-ats_reservations.h" + + +struct GNUNET_TIME_Relative +GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer, + int32_t amount) +{ + /* FIXME: implement... */ + /* permit all reservations instantly for now */ + return GNUNET_TIME_UNIT_ZERO; +} + +/* end of gnunet-service-ats_reservations.c */ diff --git a/src/ats/gnunet-service-ats_reservations.h b/src/ats/gnunet-service-ats_reservations.h new file mode 100644 index 000000000..63b9a5936 --- /dev/null +++ b/src/ats/gnunet-service-ats_reservations.h @@ -0,0 +1,37 @@ +/* + 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 ats/gnunet-service-ats_reservations.h + * @brief ats service, inbound bandwidth reservation management + * @author Christian Grothoff + */ +#ifndef GNUNET_SERVICE_ATS_RESERVATIONS_H +#define GNUNET_SERVICE_ATS_RESERVATIONS_H + +#include "gnunet_util_lib.h" + + +struct GNUNET_TIME_Relative +GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer, + int32_t amount); + + +#endif -- 2.25.1