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)
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);
*/
#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
{
*/
struct GNUNET_SERVER_Client *client;
+ /**
+ * Options for the client.
+ */
+ enum StartFlag flag;
+
};
* @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);
}
+/**
+ * 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");
#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);
/**
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);
--- /dev/null
+/*
+ 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 */
--- /dev/null
+/*
+ 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