aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-17 11:28:28 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-17 11:28:28 +0000
commit0418c2046354ff332e9d63d123513087788e5b45 (patch)
tree6d5eb3f025086e889c2e9bea024a110e36c489fd /src/ats
parenta085abbe93a63d872c711ae2d63d7eb78a2357aa (diff)
downloadgnunet-0418c2046354ff332e9d63d123513087788e5b45.tar.gz
gnunet-0418c2046354ff332e9d63d123513087788e5b45.zip
fix
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/ats_api_performance.c58
1 files changed, 37 insertions, 21 deletions
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c
index c3a5d2bed..f7b9f5d87 100644
--- a/src/ats/ats_api_performance.c
+++ b/src/ats/ats_api_performance.c
@@ -156,6 +156,11 @@ struct GNUNET_ATS_PerformanceHandle
156 */ 156 */
157 struct GNUNET_CLIENT_TransmitHandle *th; 157 struct GNUNET_CLIENT_TransmitHandle *th;
158 158
159 /**
160 * Task to trigger reconnect.
161 */
162 GNUNET_SCHEDULER_TaskIdentifier task;
163
159}; 164};
160 165
161 166
@@ -169,6 +174,23 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph);
169 174
170 175
171/** 176/**
177 * Re-establish the connection to the ATS service.
178 *
179 * @param cls handle to use to re-connect.
180 * @param tc scheduler context
181 */
182static void
183reconnect_task (void *cls,
184 const struct GNUNET_SCHEDULER_TaskContext *tc)
185{
186 struct GNUNET_ATS_PerformanceHandle *ph = cls;
187
188 ph->task = GNUNET_SCHEDULER_NO_TASK;
189 reconnect (ph);
190}
191
192
193/**
172 * Transmit messages from the message queue to the service 194 * Transmit messages from the message queue to the service
173 * (if there are any, and if we are not already trying). 195 * (if there are any, and if we are not already trying).
174 * 196 *
@@ -372,42 +394,31 @@ process_ats_message (void *cls,
372 struct GNUNET_ATS_PerformanceHandle *ph = cls; 394 struct GNUNET_ATS_PerformanceHandle *ph = cls;
373 395
374 if (NULL == msg) 396 if (NULL == msg)
375 { 397 goto reconnect;
376 GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO);
377 ph->client = NULL;
378 reconnect (ph);
379 return;
380 }
381 switch (ntohs (msg->type)) 398 switch (ntohs (msg->type))
382 { 399 {
383 case GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION: 400 case GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION:
384 if (GNUNET_OK != process_pi_message (ph, msg)) 401 if (GNUNET_OK != process_pi_message (ph, msg))
385 { 402 goto reconnect;
386 GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO);
387 ph->client = NULL;
388 reconnect (ph);
389 return;
390 }
391 break; 403 break;
392 case GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT: 404 case GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT:
393 if (GNUNET_OK != process_rr_message (ph, msg)) 405 if (GNUNET_OK != process_rr_message (ph, msg))
394 { 406 goto reconnect;
395 GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO);
396 ph->client = NULL;
397 reconnect (ph);
398 return;
399 }
400 break; 407 break;
401 default: 408 default:
402 GNUNET_break (0); 409 GNUNET_break (0);
403 GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO); 410 goto reconnect;
404 ph->client = NULL;
405 reconnect (ph);
406 return; 411 return;
407 } 412 }
408 GNUNET_CLIENT_receive (ph->client, 413 GNUNET_CLIENT_receive (ph->client,
409 &process_ats_message, ph, 414 &process_ats_message, ph,
410 GNUNET_TIME_UNIT_FOREVER_REL); 415 GNUNET_TIME_UNIT_FOREVER_REL);
416 return;
417 reconnect:
418 GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO);
419 ph->client = NULL;
420 ph->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
421 &reconnect_task, ph);
411} 422}
412 423
413 424
@@ -500,6 +511,11 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph)
500 GNUNET_break (NULL == rc->rcb); 511 GNUNET_break (NULL == rc->rcb);
501 GNUNET_free (p); 512 GNUNET_free (p);
502 } 513 }
514 if (GNUNET_SCHEDULER_NO_TASK != ph->task)
515 {
516 GNUNET_SCHEDULER_cancel (ph->task);
517 ph->task = GNUNET_SCHEDULER_NO_TASK;
518 }
503 GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO); 519 GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO);
504 GNUNET_free (ph); 520 GNUNET_free (ph);
505} 521}