diff options
Diffstat (limited to 'src/ats/gnunet-service-ats-new.c')
-rw-r--r-- | src/ats/gnunet-service-ats-new.c | 658 |
1 files changed, 324 insertions, 334 deletions
diff --git a/src/ats/gnunet-service-ats-new.c b/src/ats/gnunet-service-ats-new.c index b451c8c67..1061c28c2 100644 --- a/src/ats/gnunet-service-ats-new.c +++ b/src/ats/gnunet-service-ats-new.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/gnunet-service-ats-new.c | 21 | * @file ats/gnunet-service-ats-new.c |
22 | * @brief ats service | 22 | * @brief ats service |
@@ -59,8 +59,7 @@ struct Client; | |||
59 | /** | 59 | /** |
60 | * Preferences expressed by a client are kept in a DLL per client. | 60 | * Preferences expressed by a client are kept in a DLL per client. |
61 | */ | 61 | */ |
62 | struct ClientPreference | 62 | struct ClientPreference { |
63 | { | ||
64 | /** | 63 | /** |
65 | * DLL pointer. | 64 | * DLL pointer. |
66 | */ | 65 | */ |
@@ -91,9 +90,7 @@ struct ClientPreference | |||
91 | /** | 90 | /** |
92 | * Information about ongoing sessions of the transport client. | 91 | * Information about ongoing sessions of the transport client. |
93 | */ | 92 | */ |
94 | struct GNUNET_ATS_Session | 93 | struct GNUNET_ATS_Session { |
95 | { | ||
96 | |||
97 | /** | 94 | /** |
98 | * Session data exposed to the plugin. | 95 | * Session data exposed to the plugin. |
99 | */ | 96 | */ |
@@ -113,15 +110,13 @@ struct GNUNET_ATS_Session | |||
113 | * Unique ID for the session when talking with the client. | 110 | * Unique ID for the session when talking with the client. |
114 | */ | 111 | */ |
115 | uint32_t session_id; | 112 | uint32_t session_id; |
116 | |||
117 | }; | 113 | }; |
118 | 114 | ||
119 | 115 | ||
120 | /** | 116 | /** |
121 | * Information we track per client. | 117 | * Information we track per client. |
122 | */ | 118 | */ |
123 | struct Client | 119 | struct Client { |
124 | { | ||
125 | /** | 120 | /** |
126 | * Type of the client, initially #CT_NONE. | 121 | * Type of the client, initially #CT_NONE. |
127 | */ | 122 | */ |
@@ -141,9 +136,7 @@ struct Client | |||
141 | * Details depending on @e type. | 136 | * Details depending on @e type. |
142 | */ | 137 | */ |
143 | union { | 138 | union { |
144 | |||
145 | struct { | 139 | struct { |
146 | |||
147 | /** | 140 | /** |
148 | * Head of DLL of preferences expressed by this client. | 141 | * Head of DLL of preferences expressed by this client. |
149 | */ | 142 | */ |
@@ -153,20 +146,15 @@ struct Client | |||
153 | * Tail of DLL of preferences expressed by this client. | 146 | * Tail of DLL of preferences expressed by this client. |
154 | */ | 147 | */ |
155 | struct ClientPreference *cp_tail; | 148 | struct ClientPreference *cp_tail; |
156 | |||
157 | } application; | 149 | } application; |
158 | 150 | ||
159 | struct { | 151 | struct { |
160 | |||
161 | /** | 152 | /** |
162 | * Map from session IDs to `struct GNUNET_ATS_Session` objects. | 153 | * Map from session IDs to `struct GNUNET_ATS_Session` objects. |
163 | */ | 154 | */ |
164 | struct GNUNET_CONTAINER_MultiHashMap32 *sessions; | 155 | struct GNUNET_CONTAINER_MultiHashMap32 *sessions; |
165 | |||
166 | } transport; | 156 | } transport; |
167 | |||
168 | } details; | 157 | } details; |
169 | |||
170 | }; | 158 | }; |
171 | 159 | ||
172 | 160 | ||
@@ -200,32 +188,32 @@ static struct Client *transport_client; | |||
200 | * @param address address the transport should try | 188 | * @param address address the transport should try |
201 | */ | 189 | */ |
202 | static void | 190 | static void |
203 | suggest_cb (void *cls, | 191 | suggest_cb(void *cls, |
204 | const struct GNUNET_PeerIdentity *pid, | 192 | const struct GNUNET_PeerIdentity *pid, |
205 | const char *address) | 193 | const char *address) |
206 | { | 194 | { |
207 | struct GNUNET_MQ_Envelope *env; | 195 | struct GNUNET_MQ_Envelope *env; |
208 | size_t slen = strlen (address) + 1; | 196 | size_t slen = strlen(address) + 1; |
209 | struct AddressSuggestionMessage *as; | 197 | struct AddressSuggestionMessage *as; |
210 | 198 | ||
211 | if (NULL == transport_client) | 199 | if (NULL == transport_client) |
212 | { | 200 | { |
213 | // FIXME: stats! | 201 | // FIXME: stats! |
214 | return; | 202 | return; |
215 | } | 203 | } |
216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 204 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
217 | "Suggesting address `%s' of peer `%s'\n", | 205 | "Suggesting address `%s' of peer `%s'\n", |
218 | address, | 206 | address, |
219 | GNUNET_i2s (pid)); | 207 | GNUNET_i2s(pid)); |
220 | env = GNUNET_MQ_msg_extra (as, | 208 | env = GNUNET_MQ_msg_extra(as, |
221 | slen, | 209 | slen, |
222 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION); | 210 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION); |
223 | as->peer = *pid; | 211 | as->peer = *pid; |
224 | memcpy (&as[1], | 212 | memcpy(&as[1], |
225 | address, | 213 | address, |
226 | slen); | 214 | slen); |
227 | GNUNET_MQ_send (transport_client->mq, | 215 | GNUNET_MQ_send(transport_client->mq, |
228 | env); | 216 | env); |
229 | } | 217 | } |
230 | 218 | ||
231 | 219 | ||
@@ -240,37 +228,37 @@ suggest_cb (void *cls, | |||
240 | * @param bw_out suggested bandwidth for transmission | 228 | * @param bw_out suggested bandwidth for transmission |
241 | */ | 229 | */ |
242 | static void | 230 | static void |
243 | allocate_cb (void *cls, | 231 | allocate_cb(void *cls, |
244 | struct GNUNET_ATS_Session *session, | 232 | struct GNUNET_ATS_Session *session, |
245 | const struct GNUNET_PeerIdentity *peer, | 233 | const struct GNUNET_PeerIdentity *peer, |
246 | struct GNUNET_BANDWIDTH_Value32NBO bw_in, | 234 | struct GNUNET_BANDWIDTH_Value32NBO bw_in, |
247 | struct GNUNET_BANDWIDTH_Value32NBO bw_out) | 235 | struct GNUNET_BANDWIDTH_Value32NBO bw_out) |
248 | { | 236 | { |
249 | struct GNUNET_MQ_Envelope *env; | 237 | struct GNUNET_MQ_Envelope *env; |
250 | struct SessionAllocationMessage *sam; | 238 | struct SessionAllocationMessage *sam; |
251 | 239 | ||
252 | (void) cls; | 240 | (void)cls; |
253 | if ( (NULL == transport_client) || | 241 | if ((NULL == transport_client) || |
254 | (session->client != transport_client) ) | 242 | (session->client != transport_client)) |
255 | { | 243 | { |
256 | /* transport must have just died and solver is addressing the | 244 | /* transport must have just died and solver is addressing the |
257 | losses of sessions (possibly of previous transport), ignore! */ | 245 | losses of sessions (possibly of previous transport), ignore! */ |
258 | return; | 246 | return; |
259 | } | 247 | } |
260 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 248 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
261 | "Allocating %u/%u bytes for %p of peer `%s'\n", | 249 | "Allocating %u/%u bytes for %p of peer `%s'\n", |
262 | ntohl (bw_in.value__), | 250 | ntohl(bw_in.value__), |
263 | ntohl (bw_out.value__), | 251 | ntohl(bw_out.value__), |
264 | session, | 252 | session, |
265 | GNUNET_i2s (peer)); | 253 | GNUNET_i2s(peer)); |
266 | env = GNUNET_MQ_msg (sam, | 254 | env = GNUNET_MQ_msg(sam, |
267 | GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION); | 255 | GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION); |
268 | sam->session_id = session->session_id; | 256 | sam->session_id = session->session_id; |
269 | sam->peer = *peer; | 257 | sam->peer = *peer; |
270 | sam->bandwidth_in = bw_in; | 258 | sam->bandwidth_in = bw_in; |
271 | sam->bandwidth_out = bw_out; | 259 | sam->bandwidth_out = bw_out; |
272 | GNUNET_MQ_send (transport_client->mq, | 260 | GNUNET_MQ_send(transport_client->mq, |
273 | env); | 261 | env); |
274 | } | 262 | } |
275 | 263 | ||
276 | 264 | ||
@@ -281,18 +269,18 @@ allocate_cb (void *cls, | |||
281 | * @param prop[out] in HBO | 269 | * @param prop[out] in HBO |
282 | */ | 270 | */ |
283 | static void | 271 | static void |
284 | prop_ntoh (const struct PropertiesNBO *properties, | 272 | prop_ntoh(const struct PropertiesNBO *properties, |
285 | struct GNUNET_ATS_Properties *prop) | 273 | struct GNUNET_ATS_Properties *prop) |
286 | { | 274 | { |
287 | prop->delay = GNUNET_TIME_relative_ntoh (properties->delay); | 275 | prop->delay = GNUNET_TIME_relative_ntoh(properties->delay); |
288 | prop->goodput_out = ntohl (properties->goodput_out); | 276 | prop->goodput_out = ntohl(properties->goodput_out); |
289 | prop->goodput_in = ntohl (properties->goodput_in); | 277 | prop->goodput_in = ntohl(properties->goodput_in); |
290 | prop->utilization_out = ntohl (properties->utilization_out); | 278 | prop->utilization_out = ntohl(properties->utilization_out); |
291 | prop->utilization_in = ntohl (properties->utilization_in); | 279 | prop->utilization_in = ntohl(properties->utilization_in); |
292 | prop->distance = ntohl (properties->distance); | 280 | prop->distance = ntohl(properties->distance); |
293 | prop->mtu = ntohl (properties->mtu); | 281 | prop->mtu = ntohl(properties->mtu); |
294 | prop->nt = (enum GNUNET_NetworkType) ntohl (properties->nt); | 282 | prop->nt = (enum GNUNET_NetworkType)ntohl(properties->nt); |
295 | prop->cc = (enum GNUNET_TRANSPORT_CommunicatorCharacteristics) ntohl (properties->cc); | 283 | prop->cc = (enum GNUNET_TRANSPORT_CommunicatorCharacteristics)ntohl(properties->cc); |
296 | } | 284 | } |
297 | 285 | ||
298 | 286 | ||
@@ -303,8 +291,8 @@ prop_ntoh (const struct PropertiesNBO *properties, | |||
303 | * @param msg the start message | 291 | * @param msg the start message |
304 | */ | 292 | */ |
305 | static void | 293 | static void |
306 | handle_suggest (void *cls, | 294 | handle_suggest(void *cls, |
307 | const struct ExpressPreferenceMessage *msg) | 295 | const struct ExpressPreferenceMessage *msg) |
308 | { | 296 | { |
309 | struct Client *c = cls; | 297 | struct Client *c = cls; |
310 | struct ClientPreference *cp; | 298 | struct ClientPreference *cp; |
@@ -312,27 +300,27 @@ handle_suggest (void *cls, | |||
312 | if (CT_NONE == c->type) | 300 | if (CT_NONE == c->type) |
313 | c->type = CT_APPLICATION; | 301 | c->type = CT_APPLICATION; |
314 | if (CT_APPLICATION != c->type) | 302 | if (CT_APPLICATION != c->type) |
315 | { | 303 | { |
316 | GNUNET_break (0); | 304 | GNUNET_break(0); |
317 | GNUNET_SERVICE_client_drop (c->client); | 305 | GNUNET_SERVICE_client_drop(c->client); |
318 | return; | 306 | return; |
319 | } | 307 | } |
320 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 308 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
321 | "Client suggested we talk to %s with preference %d at rate %u\n", | 309 | "Client suggested we talk to %s with preference %d at rate %u\n", |
322 | GNUNET_i2s (&msg->peer), | 310 | GNUNET_i2s(&msg->peer), |
323 | (int) ntohl (msg->pk), | 311 | (int)ntohl(msg->pk), |
324 | (int) ntohl (msg->bw.value__)); | 312 | (int)ntohl(msg->bw.value__)); |
325 | cp = GNUNET_new (struct ClientPreference); | 313 | cp = GNUNET_new(struct ClientPreference); |
326 | cp->client = c; | 314 | cp->client = c; |
327 | cp->pref.peer = msg->peer; | 315 | cp->pref.peer = msg->peer; |
328 | cp->pref.bw = msg->bw; | 316 | cp->pref.bw = msg->bw; |
329 | cp->pref.pk = (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk); | 317 | cp->pref.pk = (enum GNUNET_MQ_PreferenceKind)ntohl(msg->pk); |
330 | cp->ph = plugin->preference_add (plugin->cls, | 318 | cp->ph = plugin->preference_add(plugin->cls, |
331 | &cp->pref); | 319 | &cp->pref); |
332 | GNUNET_CONTAINER_DLL_insert (c->details.application.cp_head, | 320 | GNUNET_CONTAINER_DLL_insert(c->details.application.cp_head, |
333 | c->details.application.cp_tail, | 321 | c->details.application.cp_tail, |
334 | cp); | 322 | cp); |
335 | GNUNET_SERVICE_client_continue (c->client); | 323 | GNUNET_SERVICE_client_continue(c->client); |
336 | } | 324 | } |
337 | 325 | ||
338 | 326 | ||
@@ -343,8 +331,8 @@ handle_suggest (void *cls, | |||
343 | * @param msg the start message | 331 | * @param msg the start message |
344 | */ | 332 | */ |
345 | static void | 333 | static void |
346 | handle_suggest_cancel (void *cls, | 334 | handle_suggest_cancel(void *cls, |
347 | const struct ExpressPreferenceMessage *msg) | 335 | const struct ExpressPreferenceMessage *msg) |
348 | { | 336 | { |
349 | struct Client *c = cls; | 337 | struct Client *c = cls; |
350 | struct ClientPreference *cp; | 338 | struct ClientPreference *cp; |
@@ -352,33 +340,33 @@ handle_suggest_cancel (void *cls, | |||
352 | if (CT_NONE == c->type) | 340 | if (CT_NONE == c->type) |
353 | c->type = CT_APPLICATION; | 341 | c->type = CT_APPLICATION; |
354 | if (CT_APPLICATION != c->type) | 342 | if (CT_APPLICATION != c->type) |
355 | { | 343 | { |
356 | GNUNET_break (0); | 344 | GNUNET_break(0); |
357 | GNUNET_SERVICE_client_drop (c->client); | 345 | GNUNET_SERVICE_client_drop(c->client); |
358 | return; | 346 | return; |
359 | } | 347 | } |
360 | for (cp = c->details.application.cp_head; | 348 | for (cp = c->details.application.cp_head; |
361 | NULL != cp; | 349 | NULL != cp; |
362 | cp = cp->next) | 350 | cp = cp->next) |
363 | if ( (cp->pref.pk == (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk)) && | 351 | if ((cp->pref.pk == (enum GNUNET_MQ_PreferenceKind)ntohl(msg->pk)) && |
364 | (cp->pref.bw.value__ == msg->bw.value__) && | 352 | (cp->pref.bw.value__ == msg->bw.value__) && |
365 | (0 == GNUNET_memcmp (&cp->pref.peer, | 353 | (0 == GNUNET_memcmp(&cp->pref.peer, |
366 | &msg->peer)) ) | 354 | &msg->peer))) |
367 | break; | 355 | break; |
368 | if (NULL == cp) | 356 | if (NULL == cp) |
369 | { | 357 | { |
370 | GNUNET_break (0); | 358 | GNUNET_break(0); |
371 | GNUNET_SERVICE_client_drop (c->client); | 359 | GNUNET_SERVICE_client_drop(c->client); |
372 | return; | 360 | return; |
373 | } | 361 | } |
374 | plugin->preference_del (plugin->cls, | 362 | plugin->preference_del(plugin->cls, |
375 | cp->ph, | 363 | cp->ph, |
376 | &cp->pref); | 364 | &cp->pref); |
377 | GNUNET_CONTAINER_DLL_remove (c->details.application.cp_head, | 365 | GNUNET_CONTAINER_DLL_remove(c->details.application.cp_head, |
378 | c->details.application.cp_tail, | 366 | c->details.application.cp_tail, |
379 | cp); | 367 | cp); |
380 | GNUNET_free (cp); | 368 | GNUNET_free(cp); |
381 | GNUNET_SERVICE_client_continue (c->client); | 369 | GNUNET_SERVICE_client_continue(c->client); |
382 | } | 370 | } |
383 | 371 | ||
384 | 372 | ||
@@ -389,27 +377,27 @@ handle_suggest_cancel (void *cls, | |||
389 | * @param message the request message | 377 | * @param message the request message |
390 | */ | 378 | */ |
391 | static void | 379 | static void |
392 | handle_start (void *cls, | 380 | handle_start(void *cls, |
393 | const struct GNUNET_MessageHeader *hdr) | 381 | const struct GNUNET_MessageHeader *hdr) |
394 | { | 382 | { |
395 | struct Client *c = cls; | 383 | struct Client *c = cls; |
396 | 384 | ||
397 | if (CT_NONE != c->type) | 385 | if (CT_NONE != c->type) |
398 | { | 386 | { |
399 | GNUNET_break (0); | 387 | GNUNET_break(0); |
400 | GNUNET_SERVICE_client_drop (c->client); | 388 | GNUNET_SERVICE_client_drop(c->client); |
401 | return; | 389 | return; |
402 | } | 390 | } |
403 | c->type = CT_TRANSPORT; | 391 | c->type = CT_TRANSPORT; |
404 | c->details.transport.sessions | 392 | c->details.transport.sessions |
405 | = GNUNET_CONTAINER_multihashmap32_create (128); | 393 | = GNUNET_CONTAINER_multihashmap32_create(128); |
406 | if (NULL != transport_client) | 394 | if (NULL != transport_client) |
407 | { | 395 | { |
408 | GNUNET_SERVICE_client_drop (transport_client->client); | 396 | GNUNET_SERVICE_client_drop(transport_client->client); |
409 | transport_client = NULL; | 397 | transport_client = NULL; |
410 | } | 398 | } |
411 | transport_client = c; | 399 | transport_client = c; |
412 | GNUNET_SERVICE_client_continue (c->client); | 400 | GNUNET_SERVICE_client_continue(c->client); |
413 | } | 401 | } |
414 | 402 | ||
415 | 403 | ||
@@ -422,17 +410,17 @@ handle_start (void *cls, | |||
422 | * @return #GNUNET_OK if @a message is well-formed | 410 | * @return #GNUNET_OK if @a message is well-formed |
423 | */ | 411 | */ |
424 | static int | 412 | static int |
425 | check_session_add (void *cls, | 413 | check_session_add(void *cls, |
426 | const struct SessionAddMessage *message) | 414 | const struct SessionAddMessage *message) |
427 | { | 415 | { |
428 | struct Client *c = cls; | 416 | struct Client *c = cls; |
429 | 417 | ||
430 | GNUNET_MQ_check_zero_termination (message); | 418 | GNUNET_MQ_check_zero_termination(message); |
431 | if (CT_TRANSPORT != c->type) | 419 | if (CT_TRANSPORT != c->type) |
432 | { | 420 | { |
433 | GNUNET_break (0); | 421 | GNUNET_break(0); |
434 | return GNUNET_SYSERR; | 422 | return GNUNET_SYSERR; |
435 | } | 423 | } |
436 | return GNUNET_OK; | 424 | return GNUNET_OK; |
437 | } | 425 | } |
438 | 426 | ||
@@ -444,45 +432,45 @@ check_session_add (void *cls, | |||
444 | * @param message the request message | 432 | * @param message the request message |
445 | */ | 433 | */ |
446 | static void | 434 | static void |
447 | handle_session_add (void *cls, | 435 | handle_session_add(void *cls, |
448 | const struct SessionAddMessage *message) | 436 | const struct SessionAddMessage *message) |
449 | { | 437 | { |
450 | struct Client *c = cls; | 438 | struct Client *c = cls; |
451 | const char *address = (const char *) &message[1]; | 439 | const char *address = (const char *)&message[1]; |
452 | struct GNUNET_ATS_Session *session; | 440 | struct GNUNET_ATS_Session *session; |
453 | int inbound_only = (GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY == | 441 | int inbound_only = (GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY == |
454 | ntohs (message->header.type)); | 442 | ntohs(message->header.type)); |
455 | 443 | ||
456 | session = GNUNET_CONTAINER_multihashmap32_get (c->details.transport.sessions, | 444 | session = GNUNET_CONTAINER_multihashmap32_get(c->details.transport.sessions, |
457 | message->session_id); | 445 | message->session_id); |
458 | if (NULL != session) | 446 | if (NULL != session) |
459 | { | 447 | { |
460 | GNUNET_break (0); | 448 | GNUNET_break(0); |
461 | GNUNET_SERVICE_client_drop (c->client); | 449 | GNUNET_SERVICE_client_drop(c->client); |
462 | return; | 450 | return; |
463 | } | 451 | } |
464 | session = GNUNET_new (struct GNUNET_ATS_Session); | 452 | session = GNUNET_new(struct GNUNET_ATS_Session); |
465 | session->data.session = session; | 453 | session->data.session = session; |
466 | session->client = c; | 454 | session->client = c; |
467 | session->session_id = message->session_id; | 455 | session->session_id = message->session_id; |
468 | session->data.peer = message->peer; | 456 | session->data.peer = message->peer; |
469 | prop_ntoh (&message->properties, | 457 | prop_ntoh(&message->properties, |
470 | &session->data.prop); | 458 | &session->data.prop); |
471 | session->data.inbound_only = inbound_only; | 459 | session->data.inbound_only = inbound_only; |
472 | GNUNET_assert (GNUNET_YES == | 460 | GNUNET_assert(GNUNET_YES == |
473 | GNUNET_CONTAINER_multihashmap32_put (c->details.transport.sessions, | 461 | GNUNET_CONTAINER_multihashmap32_put(c->details.transport.sessions, |
474 | message->session_id, | 462 | message->session_id, |
475 | session, | 463 | session, |
476 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 464 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
477 | session->sh = plugin->session_add (plugin->cls, | 465 | session->sh = plugin->session_add(plugin->cls, |
478 | &session->data, | 466 | &session->data, |
479 | address); | 467 | address); |
480 | GNUNET_assert (NULL != session->sh); | 468 | GNUNET_assert(NULL != session->sh); |
481 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 469 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
482 | "Transport has new session %p to %s\n", | 470 | "Transport has new session %p to %s\n", |
483 | session, | 471 | session, |
484 | GNUNET_i2s (&message->peer)); | 472 | GNUNET_i2s(&message->peer)); |
485 | GNUNET_SERVICE_client_continue (c->client); | 473 | GNUNET_SERVICE_client_continue(c->client); |
486 | } | 474 | } |
487 | 475 | ||
488 | 476 | ||
@@ -493,32 +481,32 @@ handle_session_add (void *cls, | |||
493 | * @param msg the request message | 481 | * @param msg the request message |
494 | */ | 482 | */ |
495 | static void | 483 | static void |
496 | handle_session_update (void *cls, | 484 | handle_session_update(void *cls, |
497 | const struct SessionUpdateMessage *msg) | 485 | const struct SessionUpdateMessage *msg) |
498 | { | 486 | { |
499 | struct Client *c = cls; | 487 | struct Client *c = cls; |
500 | struct GNUNET_ATS_Session *session; | 488 | struct GNUNET_ATS_Session *session; |
501 | 489 | ||
502 | if (CT_TRANSPORT != c->type) | 490 | if (CT_TRANSPORT != c->type) |
503 | { | 491 | { |
504 | GNUNET_break (0); | 492 | GNUNET_break(0); |
505 | GNUNET_SERVICE_client_drop (c->client); | 493 | GNUNET_SERVICE_client_drop(c->client); |
506 | return; | 494 | return; |
507 | } | 495 | } |
508 | session = GNUNET_CONTAINER_multihashmap32_get (c->details.transport.sessions, | 496 | session = GNUNET_CONTAINER_multihashmap32_get(c->details.transport.sessions, |
509 | msg->session_id); | 497 | msg->session_id); |
510 | if (NULL == session) | 498 | if (NULL == session) |
511 | { | 499 | { |
512 | GNUNET_break (0); | 500 | GNUNET_break(0); |
513 | GNUNET_SERVICE_client_drop (c->client); | 501 | GNUNET_SERVICE_client_drop(c->client); |
514 | return; | 502 | return; |
515 | } | 503 | } |
516 | prop_ntoh (&msg->properties, | 504 | prop_ntoh(&msg->properties, |
517 | &session->data.prop); | 505 | &session->data.prop); |
518 | plugin->session_update (plugin->cls, | 506 | plugin->session_update(plugin->cls, |
519 | session->sh, | 507 | session->sh, |
520 | &session->data); | 508 | &session->data); |
521 | GNUNET_SERVICE_client_continue (c->client); | 509 | GNUNET_SERVICE_client_continue(c->client); |
522 | } | 510 | } |
523 | 511 | ||
524 | 512 | ||
@@ -529,41 +517,41 @@ handle_session_update (void *cls, | |||
529 | * @param message the request message | 517 | * @param message the request message |
530 | */ | 518 | */ |
531 | static void | 519 | static void |
532 | handle_session_del (void *cls, | 520 | handle_session_del(void *cls, |
533 | const struct SessionDelMessage *message) | 521 | const struct SessionDelMessage *message) |
534 | { | 522 | { |
535 | struct Client *c = cls; | 523 | struct Client *c = cls; |
536 | struct GNUNET_ATS_Session *session; | 524 | struct GNUNET_ATS_Session *session; |
537 | 525 | ||
538 | if (CT_TRANSPORT != c->type) | 526 | if (CT_TRANSPORT != c->type) |
539 | { | 527 | { |
540 | GNUNET_break (0); | 528 | GNUNET_break(0); |
541 | GNUNET_SERVICE_client_drop (c->client); | 529 | GNUNET_SERVICE_client_drop(c->client); |
542 | return; | 530 | return; |
543 | } | 531 | } |
544 | session = GNUNET_CONTAINER_multihashmap32_get (c->details.transport.sessions, | 532 | session = GNUNET_CONTAINER_multihashmap32_get(c->details.transport.sessions, |
545 | message->session_id); | 533 | message->session_id); |
546 | if (NULL == session) | 534 | if (NULL == session) |
547 | { | 535 | { |
548 | GNUNET_break (0); | 536 | GNUNET_break(0); |
549 | GNUNET_SERVICE_client_drop (c->client); | 537 | GNUNET_SERVICE_client_drop(c->client); |
550 | return; | 538 | return; |
551 | } | 539 | } |
552 | GNUNET_assert (NULL != session->sh); | 540 | GNUNET_assert(NULL != session->sh); |
553 | plugin->session_del (plugin->cls, | 541 | plugin->session_del(plugin->cls, |
554 | session->sh, | 542 | session->sh, |
555 | &session->data); | 543 | &session->data); |
556 | session->sh = NULL; | 544 | session->sh = NULL; |
557 | GNUNET_assert (GNUNET_YES == | 545 | GNUNET_assert(GNUNET_YES == |
558 | GNUNET_CONTAINER_multihashmap32_remove (c->details.transport.sessions, | 546 | GNUNET_CONTAINER_multihashmap32_remove(c->details.transport.sessions, |
559 | session->session_id, | 547 | session->session_id, |
560 | session)); | 548 | session)); |
561 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 549 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
562 | "Transport lost session %p to %s\n", | 550 | "Transport lost session %p to %s\n", |
563 | session, | 551 | session, |
564 | GNUNET_i2s (&session->data.peer)); | 552 | GNUNET_i2s(&session->data.peer)); |
565 | GNUNET_free (session); | 553 | GNUNET_free(session); |
566 | GNUNET_SERVICE_client_continue (c->client); | 554 | GNUNET_SERVICE_client_continue(c->client); |
567 | } | 555 | } |
568 | 556 | ||
569 | 557 | ||
@@ -577,11 +565,11 @@ handle_session_del (void *cls, | |||
577 | * @return @a client | 565 | * @return @a client |
578 | */ | 566 | */ |
579 | static void * | 567 | static void * |
580 | client_connect_cb (void *cls, | 568 | client_connect_cb(void *cls, |
581 | struct GNUNET_SERVICE_Client *client, | 569 | struct GNUNET_SERVICE_Client *client, |
582 | struct GNUNET_MQ_Handle *mq) | 570 | struct GNUNET_MQ_Handle *mq) |
583 | { | 571 | { |
584 | struct Client *c = GNUNET_new (struct Client); | 572 | struct Client *c = GNUNET_new(struct Client); |
585 | 573 | ||
586 | c->client = client; | 574 | c->client = client; |
587 | c->mq = mq; | 575 | c->mq = mq; |
@@ -598,21 +586,21 @@ client_connect_cb (void *cls, | |||
598 | * @param value a `struct GNUNET_ATS_Session` | 586 | * @param value a `struct GNUNET_ATS_Session` |
599 | */ | 587 | */ |
600 | static int | 588 | static int |
601 | free_session (void *cls, | 589 | free_session(void *cls, |
602 | uint32_t key, | 590 | uint32_t key, |
603 | void *value) | 591 | void *value) |
604 | { | 592 | { |
605 | struct Client *c = cls; | 593 | struct Client *c = cls; |
606 | struct GNUNET_ATS_Session *session = value; | 594 | struct GNUNET_ATS_Session *session = value; |
607 | 595 | ||
608 | (void) key; | 596 | (void)key; |
609 | GNUNET_assert (c == session->client); | 597 | GNUNET_assert(c == session->client); |
610 | GNUNET_assert (NULL != session->sh); | 598 | GNUNET_assert(NULL != session->sh); |
611 | plugin->session_del (plugin->cls, | 599 | plugin->session_del(plugin->cls, |
612 | session->sh, | 600 | session->sh, |
613 | &session->data); | 601 | &session->data); |
614 | session->sh = NULL; | 602 | session->sh = NULL; |
615 | GNUNET_free (session); | 603 | GNUNET_free(session); |
616 | return GNUNET_OK; | 604 | return GNUNET_OK; |
617 | } | 605 | } |
618 | 606 | ||
@@ -626,42 +614,44 @@ free_session (void *cls, | |||
626 | * @param app_ctx our `struct Client` | 614 | * @param app_ctx our `struct Client` |
627 | */ | 615 | */ |
628 | static void | 616 | static void |
629 | client_disconnect_cb (void *cls, | 617 | client_disconnect_cb(void *cls, |
630 | struct GNUNET_SERVICE_Client *client, | 618 | struct GNUNET_SERVICE_Client *client, |
631 | void *app_ctx) | 619 | void *app_ctx) |
632 | { | 620 | { |
633 | struct Client *c = app_ctx; | 621 | struct Client *c = app_ctx; |
634 | 622 | ||
635 | (void) cls; | 623 | (void)cls; |
636 | GNUNET_assert (c->client == client); | 624 | GNUNET_assert(c->client == client); |
637 | switch (c->type) | 625 | switch (c->type) |
638 | { | ||
639 | case CT_NONE: | ||
640 | break; | ||
641 | case CT_APPLICATION: | ||
642 | for (struct ClientPreference *cp = c->details.application.cp_head; | ||
643 | NULL != cp; | ||
644 | cp = c->details.application.cp_head) | ||
645 | { | 626 | { |
646 | plugin->preference_del (plugin->cls, | 627 | case CT_NONE: |
647 | cp->ph, | 628 | break; |
648 | &cp->pref); | 629 | |
649 | GNUNET_CONTAINER_DLL_remove (c->details.application.cp_head, | 630 | case CT_APPLICATION: |
650 | c->details.application.cp_tail, | 631 | for (struct ClientPreference *cp = c->details.application.cp_head; |
651 | cp); | 632 | NULL != cp; |
652 | GNUNET_free (cp); | 633 | cp = c->details.application.cp_head) |
634 | { | ||
635 | plugin->preference_del(plugin->cls, | ||
636 | cp->ph, | ||
637 | &cp->pref); | ||
638 | GNUNET_CONTAINER_DLL_remove(c->details.application.cp_head, | ||
639 | c->details.application.cp_tail, | ||
640 | cp); | ||
641 | GNUNET_free(cp); | ||
642 | } | ||
643 | break; | ||
644 | |||
645 | case CT_TRANSPORT: | ||
646 | if (transport_client == c) | ||
647 | transport_client = NULL; | ||
648 | GNUNET_CONTAINER_multihashmap32_iterate(c->details.transport.sessions, | ||
649 | &free_session, | ||
650 | c); | ||
651 | GNUNET_CONTAINER_multihashmap32_destroy(c->details.transport.sessions); | ||
652 | break; | ||
653 | } | 653 | } |
654 | break; | 654 | GNUNET_free(c); |
655 | case CT_TRANSPORT: | ||
656 | if (transport_client == c) | ||
657 | transport_client = NULL; | ||
658 | GNUNET_CONTAINER_multihashmap32_iterate (c->details.transport.sessions, | ||
659 | &free_session, | ||
660 | c); | ||
661 | GNUNET_CONTAINER_multihashmap32_destroy (c->details.transport.sessions); | ||
662 | break; | ||
663 | } | ||
664 | GNUNET_free (c); | ||
665 | } | 655 | } |
666 | 656 | ||
667 | 657 | ||
@@ -671,26 +661,26 @@ client_disconnect_cb (void *cls, | |||
671 | * @param cls unused | 661 | * @param cls unused |
672 | */ | 662 | */ |
673 | static void | 663 | static void |
674 | final_cleanup (void *cls) | 664 | final_cleanup(void *cls) |
675 | { | 665 | { |
676 | (void) cls; | 666 | (void)cls; |
677 | if (NULL != stats) | 667 | if (NULL != stats) |
678 | { | 668 | { |
679 | GNUNET_STATISTICS_destroy (stats, | 669 | GNUNET_STATISTICS_destroy(stats, |
680 | GNUNET_NO); | 670 | GNUNET_NO); |
681 | stats = NULL; | 671 | stats = NULL; |
682 | } | 672 | } |
683 | if (NULL != plugin) | 673 | if (NULL != plugin) |
684 | { | 674 | { |
685 | GNUNET_PLUGIN_unload (plugin_name, | 675 | GNUNET_PLUGIN_unload(plugin_name, |
686 | plugin); | 676 | plugin); |
687 | plugin = NULL; | 677 | plugin = NULL; |
688 | } | 678 | } |
689 | if (NULL != plugin_name) | 679 | if (NULL != plugin_name) |
690 | { | 680 | { |
691 | GNUNET_free (plugin_name); | 681 | GNUNET_free(plugin_name); |
692 | plugin_name = NULL; | 682 | plugin_name = NULL; |
693 | } | 683 | } |
694 | } | 684 | } |
695 | 685 | ||
696 | 686 | ||
@@ -700,13 +690,13 @@ final_cleanup (void *cls) | |||
700 | * @param cls unused | 690 | * @param cls unused |
701 | */ | 691 | */ |
702 | static void | 692 | static void |
703 | cleanup_task (void *cls) | 693 | cleanup_task(void *cls) |
704 | { | 694 | { |
705 | (void) cls; | 695 | (void)cls; |
706 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 696 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
707 | "ATS shutdown initiated\n"); | 697 | "ATS shutdown initiated\n"); |
708 | GNUNET_SCHEDULER_add_now (&final_cleanup, | 698 | GNUNET_SCHEDULER_add_now(&final_cleanup, |
709 | NULL); | 699 | NULL); |
710 | } | 700 | } |
711 | 701 | ||
712 | 702 | ||
@@ -718,45 +708,45 @@ cleanup_task (void *cls) | |||
718 | * @param service the initialized service | 708 | * @param service the initialized service |
719 | */ | 709 | */ |
720 | static void | 710 | static void |
721 | run (void *cls, | 711 | run(void *cls, |
722 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 712 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
723 | struct GNUNET_SERVICE_Handle *service) | 713 | struct GNUNET_SERVICE_Handle *service) |
724 | { | 714 | { |
725 | static struct GNUNET_ATS_PluginEnvironment env; | 715 | static struct GNUNET_ATS_PluginEnvironment env; |
726 | char *solver; | 716 | char *solver; |
727 | 717 | ||
728 | stats = GNUNET_STATISTICS_create ("ats", | 718 | stats = GNUNET_STATISTICS_create("ats", |
729 | cfg); | 719 | cfg); |
730 | if (GNUNET_SYSERR == | 720 | if (GNUNET_SYSERR == |
731 | GNUNET_CONFIGURATION_get_value_string (cfg, | 721 | GNUNET_CONFIGURATION_get_value_string(cfg, |
732 | "ats", | 722 | "ats", |
733 | "SOLVER", | 723 | "SOLVER", |
734 | &solver)) | 724 | &solver)) |
735 | { | 725 | { |
736 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 726 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
737 | "No ATS solver configured, using 'simple' approach\n"); | 727 | "No ATS solver configured, using 'simple' approach\n"); |
738 | solver = GNUNET_strdup ("simple"); | 728 | solver = GNUNET_strdup("simple"); |
739 | } | 729 | } |
740 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, | 730 | GNUNET_SCHEDULER_add_shutdown(&cleanup_task, |
741 | NULL); | 731 | NULL); |
742 | env.cls = NULL; | 732 | env.cls = NULL; |
743 | env.cfg = cfg; | 733 | env.cfg = cfg; |
744 | env.stats = stats; | 734 | env.stats = stats; |
745 | env.suggest_cb = &suggest_cb; | 735 | env.suggest_cb = &suggest_cb; |
746 | env.allocate_cb = &allocate_cb; | 736 | env.allocate_cb = &allocate_cb; |
747 | GNUNET_asprintf (&plugin_name, | 737 | GNUNET_asprintf(&plugin_name, |
748 | "libgnunet_plugin_ats2_%s", | 738 | "libgnunet_plugin_ats2_%s", |
749 | solver); | 739 | solver); |
750 | GNUNET_free (solver); | 740 | GNUNET_free(solver); |
751 | if (NULL == (plugin = GNUNET_PLUGIN_load (plugin_name, | 741 | if (NULL == (plugin = GNUNET_PLUGIN_load(plugin_name, |
752 | &env))) | 742 | &env))) |
753 | { | 743 | { |
754 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 744 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
755 | _("Failed to initialize solver `%s'!\n"), | 745 | _("Failed to initialize solver `%s'!\n"), |
756 | plugin_name); | 746 | plugin_name); |
757 | GNUNET_SCHEDULER_shutdown (); | 747 | GNUNET_SCHEDULER_shutdown(); |
758 | return; | 748 | return; |
759 | } | 749 | } |
760 | } | 750 | } |
761 | 751 | ||
762 | 752 | ||
@@ -764,41 +754,41 @@ run (void *cls, | |||
764 | * Define "main" method using service macro. | 754 | * Define "main" method using service macro. |
765 | */ | 755 | */ |
766 | GNUNET_SERVICE_MAIN | 756 | GNUNET_SERVICE_MAIN |
767 | ("ats", | 757 | ("ats", |
768 | GNUNET_SERVICE_OPTION_NONE, | 758 | GNUNET_SERVICE_OPTION_NONE, |
769 | &run, | 759 | &run, |
770 | &client_connect_cb, | 760 | &client_connect_cb, |
771 | &client_disconnect_cb, | 761 | &client_disconnect_cb, |
772 | NULL, | 762 | NULL, |
773 | GNUNET_MQ_hd_fixed_size (suggest, | 763 | GNUNET_MQ_hd_fixed_size(suggest, |
774 | GNUNET_MESSAGE_TYPE_ATS_SUGGEST, | 764 | GNUNET_MESSAGE_TYPE_ATS_SUGGEST, |
775 | struct ExpressPreferenceMessage, | 765 | struct ExpressPreferenceMessage, |
776 | NULL), | 766 | NULL), |
777 | GNUNET_MQ_hd_fixed_size (suggest_cancel, | 767 | GNUNET_MQ_hd_fixed_size(suggest_cancel, |
778 | GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL, | 768 | GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL, |
779 | struct ExpressPreferenceMessage, | 769 | struct ExpressPreferenceMessage, |
780 | NULL), | 770 | NULL), |
781 | GNUNET_MQ_hd_fixed_size (start, | 771 | GNUNET_MQ_hd_fixed_size(start, |
782 | GNUNET_MESSAGE_TYPE_ATS_START, | 772 | GNUNET_MESSAGE_TYPE_ATS_START, |
783 | struct GNUNET_MessageHeader, | 773 | struct GNUNET_MessageHeader, |
784 | NULL), | 774 | NULL), |
785 | GNUNET_MQ_hd_var_size (session_add, | 775 | GNUNET_MQ_hd_var_size(session_add, |
786 | GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD, | 776 | GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD, |
787 | struct SessionAddMessage, | 777 | struct SessionAddMessage, |
788 | NULL), | 778 | NULL), |
789 | GNUNET_MQ_hd_var_size (session_add, | 779 | GNUNET_MQ_hd_var_size(session_add, |
790 | GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY, | 780 | GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY, |
791 | struct SessionAddMessage, | 781 | struct SessionAddMessage, |
792 | NULL), | 782 | NULL), |
793 | GNUNET_MQ_hd_fixed_size (session_update, | 783 | GNUNET_MQ_hd_fixed_size(session_update, |
794 | GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE, | 784 | GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE, |
795 | struct SessionUpdateMessage, | 785 | struct SessionUpdateMessage, |
796 | NULL), | 786 | NULL), |
797 | GNUNET_MQ_hd_fixed_size (session_del, | 787 | GNUNET_MQ_hd_fixed_size(session_del, |
798 | GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL, | 788 | GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL, |
799 | struct SessionDelMessage, | 789 | struct SessionDelMessage, |
800 | NULL), | 790 | NULL), |
801 | GNUNET_MQ_handler_end ()); | 791 | GNUNET_MQ_handler_end()); |
802 | 792 | ||
803 | 793 | ||
804 | /* end of gnunet-service-ats.c */ | 794 | /* end of gnunet-service-ats.c */ |