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