aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_performance.c
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 /src/ats/gnunet-service-ats_performance.c
parent530b88b4942a070b1ab2ee43f9d1e084497dd769 (diff)
downloadgnunet-d86cd012c0372c1746fed2a50b7cccca9de99be3.tar.gz
gnunet-d86cd012c0372c1746fed2a50b7cccca9de99be3.zip
parsing reservations
Diffstat (limited to 'src/ats/gnunet-service-ats_performance.c')
-rw-r--r--src/ats/gnunet-service-ats_performance.c62
1 files changed, 53 insertions, 9 deletions
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");