diff options
Diffstat (limited to 'src/ats/gnunet-service-ats_reservations.c')
-rw-r--r-- | src/ats/gnunet-service-ats_reservations.c | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/src/ats/gnunet-service-ats_reservations.c b/src/ats/gnunet-service-ats_reservations.c index cb95ad80f..6e6c2b258 100644 --- a/src/ats/gnunet-service-ats_reservations.c +++ b/src/ats/gnunet-service-ats_reservations.c | |||
@@ -25,6 +25,8 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet-service-ats_reservations.h" | 27 | #include "gnunet-service-ats_reservations.h" |
28 | #include "gnunet-service-ats.h" | ||
29 | #include "ats.h" | ||
28 | 30 | ||
29 | /** | 31 | /** |
30 | * Number of seconds that available bandwidth carries over | 32 | * Number of seconds that available bandwidth carries over |
@@ -38,6 +40,11 @@ | |||
38 | */ | 40 | */ |
39 | static struct GNUNET_CONTAINER_MultiPeerMap *trackers; | 41 | static struct GNUNET_CONTAINER_MultiPeerMap *trackers; |
40 | 42 | ||
43 | /** | ||
44 | * Context for sending messages to performance clients without PIC. | ||
45 | */ | ||
46 | static struct GNUNET_SERVER_NotificationContext *nc; | ||
47 | |||
41 | 48 | ||
42 | /** | 49 | /** |
43 | * Reserve the given amount of incoming bandwidth (in bytes) from the | 50 | * Reserve the given amount of incoming bandwidth (in bytes) from the |
@@ -120,12 +127,59 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, | |||
120 | 127 | ||
121 | 128 | ||
122 | /** | 129 | /** |
130 | * Handle 'reservation request' messages from clients. | ||
131 | * | ||
132 | * @param cls unused, NULL | ||
133 | * @param client client that sent the request | ||
134 | * @param message the request message | ||
135 | */ | ||
136 | void | ||
137 | GAS_handle_reservation_request (void *cls, | ||
138 | struct GNUNET_SERVER_Client *client, | ||
139 | const struct GNUNET_MessageHeader *message) | ||
140 | { | ||
141 | const struct ReservationRequestMessage *msg = | ||
142 | (const struct ReservationRequestMessage *) message; | ||
143 | struct ReservationResultMessage result; | ||
144 | int32_t amount; | ||
145 | struct GNUNET_TIME_Relative res_delay; | ||
146 | |||
147 | GNUNET_SERVER_notification_context_add (nc, | ||
148 | client); | ||
149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
150 | "Received RESERVATION_REQUEST message\n"); | ||
151 | amount = (int32_t) ntohl (msg->amount); | ||
152 | res_delay = GAS_reservations_reserve (&msg->peer, amount); | ||
153 | if (res_delay.rel_value_us > 0) | ||
154 | amount = 0; | ||
155 | result.header.size = htons (sizeof (struct ReservationResultMessage)); | ||
156 | result.header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT); | ||
157 | result.amount = htonl (amount); | ||
158 | result.peer = msg->peer; | ||
159 | result.res_delay = GNUNET_TIME_relative_hton (res_delay); | ||
160 | GNUNET_STATISTICS_update (GSA_stats, | ||
161 | "# reservation requests processed", | ||
162 | 1, | ||
163 | GNUNET_NO); | ||
164 | GNUNET_SERVER_notification_context_unicast (nc, | ||
165 | client, | ||
166 | &result.header, | ||
167 | GNUNET_NO); | ||
168 | GNUNET_SERVER_receive_done (client, | ||
169 | GNUNET_OK); | ||
170 | } | ||
171 | |||
172 | |||
173 | /** | ||
123 | * Initialize reservations subsystem. | 174 | * Initialize reservations subsystem. |
175 | * | ||
176 | * @param server handle to our server | ||
124 | */ | 177 | */ |
125 | void | 178 | void |
126 | GAS_reservations_init () | 179 | GAS_reservations_init (struct GNUNET_SERVER_Handle *server) |
127 | { | 180 | { |
128 | trackers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); | 181 | trackers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); |
182 | nc = GNUNET_SERVER_notification_context_create (server, 128); | ||
129 | } | 183 | } |
130 | 184 | ||
131 | 185 | ||
@@ -134,8 +188,8 @@ GAS_reservations_init () | |||
134 | * | 188 | * |
135 | * @param cls NULL | 189 | * @param cls NULL |
136 | * @param key peer identity (unused) | 190 | * @param key peer identity (unused) |
137 | * @param value the 'struct GNUNET_BANDWIDTH_Tracker' to free | 191 | * @param value the `struct GNUNET_BANDWIDTH_Tracker` to free |
138 | * @return GNUNET_OK (continue to iterate) | 192 | * @return #GNUNET_OK (continue to iterate) |
139 | */ | 193 | */ |
140 | static int | 194 | static int |
141 | free_tracker (void *cls, | 195 | free_tracker (void *cls, |
@@ -154,8 +208,13 @@ free_tracker (void *cls, | |||
154 | void | 208 | void |
155 | GAS_reservations_done () | 209 | GAS_reservations_done () |
156 | { | 210 | { |
157 | GNUNET_CONTAINER_multipeermap_iterate (trackers, &free_tracker, NULL); | 211 | GNUNET_CONTAINER_multipeermap_iterate (trackers, |
212 | &free_tracker, | ||
213 | NULL); | ||
158 | GNUNET_CONTAINER_multipeermap_destroy (trackers); | 214 | GNUNET_CONTAINER_multipeermap_destroy (trackers); |
215 | GNUNET_SERVER_notification_context_destroy (nc); | ||
216 | nc = NULL; | ||
217 | |||
159 | } | 218 | } |
160 | 219 | ||
161 | /* end of gnunet-service-ats_reservations.c */ | 220 | /* end of gnunet-service-ats_reservations.c */ |