aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-14 08:46:34 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-14 08:46:34 +0000
commitd86cd012c0372c1746fed2a50b7cccca9de99be3 (patch)
tree4adf4679c8cd5c961e8dea5167843a6301fa0398
parent530b88b4942a070b1ab2ee43f9d1e084497dd769 (diff)
downloadgnunet-d86cd012c0372c1746fed2a50b7cccca9de99be3.tar.gz
gnunet-d86cd012c0372c1746fed2a50b7cccca9de99be3.zip
parsing reservations
-rw-r--r--src/ats/Makefile.am3
-rw-r--r--src/ats/gnunet-service-ats.c7
-rw-r--r--src/ats/gnunet-service-ats_performance.c62
-rw-r--r--src/ats/gnunet-service-ats_performance.h19
-rw-r--r--src/ats/gnunet-service-ats_reservations.c39
-rw-r--r--src/ats/gnunet-service-ats_reservations.h37
6 files changed, 154 insertions, 13 deletions
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 = \
25 gnunet-service-ats.c \ 25 gnunet-service-ats.c \
26 gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ 26 gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \
27 gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ 27 gnunet-service-ats_performance.c gnunet-service-ats_performance.h \
28 gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h 28 gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \
29 gnunet-service-ats_reservations.c gnunet-service-ats_reservations.h
29gnunet_service_ats_LDADD = \ 30gnunet_service_ats_LDADD = \
30 $(top_builddir)/src/util/libgnunetutil.la \ 31 $(top_builddir)/src/util/libgnunetutil.la \
31 $(GN_LIBINTL) 32 $(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,
45 const struct GNUNET_MessageHeader *message) 45 const struct GNUNET_MessageHeader *message)
46{ 46{
47 const struct ClientStartMessage * msg = (const struct ClientStartMessage *) message; 47 const struct ClientStartMessage * msg = (const struct ClientStartMessage *) message;
48 enum StartFlag flag;
48 49
49 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 50 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
50 "Received `%s' message\n", 51 "Received `%s' message\n",
51 "ATS_START"); 52 "ATS_START");
52 switch (ntohl (msg->start_flag)) 53 flag = ntohl (msg->start_flag);
54 switch (flag)
53 { 55 {
54 case START_FLAG_SCHEDULING: 56 case START_FLAG_SCHEDULING:
55 GAS_scheduling_add_client (client); 57 GAS_scheduling_add_client (client);
56 break; 58 break;
57 case START_FLAG_PERFORMANCE_WITH_PIC: 59 case START_FLAG_PERFORMANCE_WITH_PIC:
58 GAS_performance_add_client (client); 60 GAS_performance_add_client (client, flag);
59 break; 61 break;
60 case START_FLAG_PERFORMANCE_NO_PIC: 62 case START_FLAG_PERFORMANCE_NO_PIC:
63 GAS_performance_add_client (client, flag);
61 break; 64 break;
62 default: 65 default:
63 GNUNET_break (0); 66 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 @@
26 */ 26 */
27#include "platform.h" 27#include "platform.h"
28#include "gnunet-service-ats_performance.h" 28#include "gnunet-service-ats_performance.h"
29#include "gnunet-service-ats_reservations.h"
29#include "ats.h" 30#include "ats.h"
30 31
31 32
32/** 33/**
33 * We keep clients that are interested in performance notifications in a linked list. 34 * We keep clients that are interested in performance in a linked list.
34 * Note that not ALL clients that are handeled by this module also register for
35 * notifications. Only those clients that are in this list are managed by the
36 * notification context.
37 */ 35 */
38struct PerformanceClient 36struct PerformanceClient
39{ 37{
@@ -52,6 +50,11 @@ struct PerformanceClient
52 */ 50 */
53 struct GNUNET_SERVER_Client *client; 51 struct GNUNET_SERVER_Client *client;
54 52
53 /**
54 * Options for the client.
55 */
56 enum StartFlag flag;
57
55}; 58};
56 59
57 60
@@ -95,13 +98,15 @@ find_client (struct GNUNET_SERVER_Client *client)
95 * @param client handle of the new client 98 * @param client handle of the new client
96 */ 99 */
97void 100void
98GAS_performance_add_client (struct GNUNET_SERVER_Client *client) 101GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
102 enum StartFlag flag)
99{ 103{
100 struct PerformanceClient * pc; 104 struct PerformanceClient * pc;
101 105
102 GNUNET_break (NULL == find_client (client)); 106 GNUNET_break (NULL == find_client (client));
103 pc = GNUNET_malloc (sizeof (struct PerformanceClient)); 107 pc = GNUNET_malloc (sizeof (struct PerformanceClient));
104 pc->client = client; 108 pc->client = client;
109 pc->flag = flag;
105 GNUNET_SERVER_notification_context_add (nc, client); 110 GNUNET_SERVER_notification_context_add (nc, client);
106 GNUNET_SERVER_client_keep (client); 111 GNUNET_SERVER_client_keep (client);
107 GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, pc); 112 GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, pc);
@@ -128,20 +133,59 @@ GAS_performance_remove_client (struct GNUNET_SERVER_Client *client)
128} 133}
129 134
130 135
136/**
137 * Handle 'reservation request' messages from clients.
138 *
139 * @param cls unused, NULL
140 * @param client client that sent the request
141 * @param message the request message
142 */
131void 143void
132GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client, 144GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
133 const struct GNUNET_MessageHeader *message) 145 const struct GNUNET_MessageHeader *message)
134{ 146{
135 // const struct ReservationRequestMessage * msg = (const struct ReservationRequestMessage *) message; 147 const struct ReservationRequestMessage * msg = (const struct ReservationRequestMessage *) message;
136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "RESERVATION_REQUEST"); 148 struct ReservationResultMessage result;
137 149 int32_t amount;
150 struct GNUNET_TIME_Relative res_delay;
151
152 if (NULL == find_client (client))
153 {
154 /* missing start message! */
155 GNUNET_break (0);
156 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
157 return;
158 }
159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
160 "Received `%s' message\n",
161 "RESERVATION_REQUEST");
162 amount = (int32_t) ntohl (msg->amount);
163 res_delay = GAS_reservations_reserve (&msg->peer,
164 amount);
165 if (res_delay.rel_value > 0)
166 amount = 0;
167 result.header.size = htons (sizeof (struct ReservationResultMessage));
168 result.header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT);
169 result.amount = htonl (amount);
170 result.res_delay = GNUNET_TIME_relative_hton (res_delay);
171 GNUNET_SERVER_notification_context_unicast (nc,
172 client,
173 &result.header,
174 GNUNET_NO);
175 GNUNET_SERVER_receive_done (client, GNUNET_OK);
138} 176}
139 177
140 178
179/**
180 * Handle 'preference change' messages from clients.
181 *
182 * @param cls unused, NULL
183 * @param client client that sent the request
184 * @param message the request message
185 */
141void 186void
142GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client, 187GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client,
143 const struct GNUNET_MessageHeader *message) 188 const struct GNUNET_MessageHeader *message)
144
145{ 189{
146 // const struct ChangePreferenceMessage * msg = (const struct ChangePreferenceMessage *) message; 190 // const struct ChangePreferenceMessage * msg = (const struct ChangePreferenceMessage *) message;
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "PREFERENCE_CHANGE"); 191 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 @@
28#define GNUNET_SERVICE_ATS_PERFORMANCE_H 28#define GNUNET_SERVICE_ATS_PERFORMANCE_H
29 29
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "ats.h"
31 32
32/** 33/**
33 * Register a new performance client. 34 * Register a new performance client.
34 * 35 *
35 * @param client handle of the new client 36 * @param client handle of the new client
37 * @param flag options for the client
36 */ 38 */
37void 39void
38GAS_performance_add_client (struct GNUNET_SERVER_Client *client); 40GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
41 enum StartFlag flag);
39 42
40 43
41/** 44/**
@@ -48,11 +51,25 @@ void
48GAS_performance_remove_client (struct GNUNET_SERVER_Client *client); 51GAS_performance_remove_client (struct GNUNET_SERVER_Client *client);
49 52
50 53
54/**
55 * Handle 'reservation request' messages from clients.
56 *
57 * @param cls unused, NULL
58 * @param client client that sent the request
59 * @param message the request message
60 */
51void 61void
52GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client, 62GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
53 const struct GNUNET_MessageHeader *message); 63 const struct GNUNET_MessageHeader *message);
54 64
55 65
66/**
67 * Handle 'preference change' messages from clients.
68 *
69 * @param cls unused, NULL
70 * @param client client that sent the request
71 * @param message the request message
72 */
56void 73void
57GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client, 74GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client,
58 const struct GNUNET_MessageHeader *message); 75 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 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file ats/gnunet-service-ats_reservations.c
23 * @brief ats service, inbound bandwidth reservation management
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet-service-ats_reservations.h"
28
29
30struct GNUNET_TIME_Relative
31GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer,
32 int32_t amount)
33{
34 /* FIXME: implement... */
35 /* permit all reservations instantly for now */
36 return GNUNET_TIME_UNIT_ZERO;
37}
38
39/* 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 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file ats/gnunet-service-ats_reservations.h
23 * @brief ats service, inbound bandwidth reservation management
24 * @author Christian Grothoff
25 */
26#ifndef GNUNET_SERVICE_ATS_RESERVATIONS_H
27#define GNUNET_SERVICE_ATS_RESERVATIONS_H
28
29#include "gnunet_util_lib.h"
30
31
32struct GNUNET_TIME_Relative
33GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer,
34 int32_t amount);
35
36
37#endif