diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-09 20:30:31 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-09 20:30:31 +0000 |
commit | 409ce81945b301f64dc1bb29c2a919135c9db1ed (patch) | |
tree | 4420b6b6122032ccac554e2ca48bf14c0368d87e /src/fs/gnunet-service-fs_cp.c | |
parent | 1a2fec7a210bd41778d39fb544944b2dff98bc47 (diff) | |
download | gnunet-409ce81945b301f64dc1bb29c2a919135c9db1ed.tar.gz gnunet-409ce81945b301f64dc1bb29c2a919135c9db1ed.zip |
-misc fixes
Diffstat (limited to 'src/fs/gnunet-service-fs_cp.c')
-rw-r--r-- | src/fs/gnunet-service-fs_cp.c | 112 |
1 files changed, 54 insertions, 58 deletions
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c index 2f1ba1a28..9c229251d 100644 --- a/src/fs/gnunet-service-fs_cp.c +++ b/src/fs/gnunet-service-fs_cp.c | |||
@@ -68,12 +68,6 @@ struct GSF_PeerTransmitHandle | |||
68 | struct GSF_PeerTransmitHandle *prev; | 68 | struct GSF_PeerTransmitHandle *prev; |
69 | 69 | ||
70 | /** | 70 | /** |
71 | * Handle for an active request for transmission to this | ||
72 | * peer, or NULL (if core queue was full). | ||
73 | */ | ||
74 | struct GNUNET_CORE_TransmitHandle *cth; | ||
75 | |||
76 | /** | ||
77 | * Time when this transmission request was issued. | 71 | * Time when this transmission request was issued. |
78 | */ | 72 | */ |
79 | struct GNUNET_TIME_Absolute transmission_request_start_time; | 73 | struct GNUNET_TIME_Absolute transmission_request_start_time; |
@@ -109,14 +103,6 @@ struct GSF_PeerTransmitHandle | |||
109 | size_t size; | 103 | size_t size; |
110 | 104 | ||
111 | /** | 105 | /** |
112 | * Set to 1 if we're currently in the process of calling | ||
113 | * 'GNUNET_CORE_notify_transmit_ready' (so while cth is | ||
114 | * NULL, we should not call notify_transmit_ready for this | ||
115 | * handle right now). | ||
116 | */ | ||
117 | unsigned int cth_in_progress; | ||
118 | |||
119 | /** | ||
120 | * GNUNET_YES if this is a query, GNUNET_NO for content. | 106 | * GNUNET_YES if this is a query, GNUNET_NO for content. |
121 | */ | 107 | */ |
122 | int is_query; | 108 | int is_query; |
@@ -264,12 +250,26 @@ struct GSF_ConnectedPeer | |||
264 | struct GNUNET_CONTAINER_MultiHashMap *request_map; | 250 | struct GNUNET_CONTAINER_MultiHashMap *request_map; |
265 | 251 | ||
266 | /** | 252 | /** |
253 | * Handle for an active request for transmission to this | ||
254 | * peer, or NULL (if core queue was full). | ||
255 | */ | ||
256 | struct GNUNET_CORE_TransmitHandle *cth; | ||
257 | |||
258 | /** | ||
267 | * Increase in traffic preference still to be submitted | 259 | * Increase in traffic preference still to be submitted |
268 | * to the core service for this peer. | 260 | * to the core service for this peer. |
269 | */ | 261 | */ |
270 | uint64_t inc_preference; | 262 | uint64_t inc_preference; |
271 | 263 | ||
272 | /** | 264 | /** |
265 | * Set to 1 if we're currently in the process of calling | ||
266 | * 'GNUNET_CORE_notify_transmit_ready' (so while cth is | ||
267 | * NULL, we should not call notify_transmit_ready for this | ||
268 | * handle right now). | ||
269 | */ | ||
270 | unsigned int cth_in_progress; | ||
271 | |||
272 | /** | ||
273 | * Trust rating for this peer on disk. | 273 | * Trust rating for this peer on disk. |
274 | */ | 274 | */ |
275 | uint32_t disk_trust; | 275 | uint32_t disk_trust; |
@@ -423,9 +423,9 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth) | |||
423 | struct GSF_ConnectedPeer *cp; | 423 | struct GSF_ConnectedPeer *cp; |
424 | struct GNUNET_PeerIdentity target; | 424 | struct GNUNET_PeerIdentity target; |
425 | 425 | ||
426 | if ((NULL != pth->cth) || (0 != pth->cth_in_progress)) | ||
427 | return; /* already done */ | ||
428 | cp = pth->cp; | 426 | cp = pth->cp; |
427 | if ((NULL != cp->cth) || (0 != cp->cth_in_progress)) | ||
428 | return; /* already done */ | ||
429 | GNUNET_assert (0 != cp->ppd.pid); | 429 | GNUNET_assert (0 != cp->ppd.pid); |
430 | GNUNET_PEER_resolve (cp->ppd.pid, &target); | 430 | GNUNET_PEER_resolve (cp->ppd.pid, &target); |
431 | 431 | ||
@@ -448,15 +448,17 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth) | |||
448 | cp->rc = | 448 | cp->rc = |
449 | GNUNET_ATS_reserve_bandwidth (ats, &target, DBLOCK_SIZE, | 449 | GNUNET_ATS_reserve_bandwidth (ats, &target, DBLOCK_SIZE, |
450 | &ats_reserve_callback, cp); | 450 | &ats_reserve_callback, cp); |
451 | return; | ||
451 | } | 452 | } |
452 | GNUNET_assert (pth->cth == NULL); | 453 | GNUNET_assert (cp->cth == NULL); |
453 | pth->cth_in_progress++; | 454 | cp->cth_in_progress++; |
454 | pth->cth = | 455 | cp->cth = |
455 | GNUNET_CORE_notify_transmit_ready (GSF_core, GNUNET_YES, pth->priority, | 456 | GNUNET_CORE_notify_transmit_ready (GSF_core, GNUNET_YES, pth->priority, |
456 | GNUNET_TIME_absolute_get_remaining | 457 | GNUNET_TIME_absolute_get_remaining |
457 | (pth->timeout), &target, pth->size, | 458 | (pth->timeout), &target, pth->size, |
458 | &peer_transmit_ready_cb, pth); | 459 | &peer_transmit_ready_cb, cp); |
459 | GNUNET_assert (0 < pth->cth_in_progress--); | 460 | GNUNET_assert (NULL != cp->cth); |
461 | GNUNET_assert (0 < cp->cth_in_progress--); | ||
460 | } | 462 | } |
461 | 463 | ||
462 | 464 | ||
@@ -471,19 +473,24 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth) | |||
471 | static size_t | 473 | static size_t |
472 | peer_transmit_ready_cb (void *cls, size_t size, void *buf) | 474 | peer_transmit_ready_cb (void *cls, size_t size, void *buf) |
473 | { | 475 | { |
474 | struct GSF_PeerTransmitHandle *pth = cls; | 476 | struct GSF_ConnectedPeer *cp = cls; |
477 | struct GSF_PeerTransmitHandle *pth = cp->pth_head; | ||
475 | struct GSF_PeerTransmitHandle *pos; | 478 | struct GSF_PeerTransmitHandle *pos; |
476 | struct GSF_ConnectedPeer *cp; | ||
477 | size_t ret; | 479 | size_t ret; |
478 | 480 | ||
479 | GNUNET_assert ((NULL == buf) || (pth->size <= size)); | 481 | cp->cth = NULL; |
480 | pth->cth = NULL; | 482 | if (NULL == pth) |
483 | return 0; | ||
484 | if (pth->size > size) | ||
485 | { | ||
486 | schedule_transmission (pth); | ||
487 | return 0; | ||
488 | } | ||
481 | if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK) | 489 | if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK) |
482 | { | 490 | { |
483 | GNUNET_SCHEDULER_cancel (pth->timeout_task); | 491 | GNUNET_SCHEDULER_cancel (pth->timeout_task); |
484 | pth->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 492 | pth->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
485 | } | 493 | } |
486 | cp = pth->cp; | ||
487 | GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth); | 494 | GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth); |
488 | if (GNUNET_YES == pth->is_query) | 495 | if (GNUNET_YES == pth->is_query) |
489 | { | 496 | { |
@@ -500,14 +507,11 @@ peer_transmit_ready_cb (void *cls, size_t size, void *buf) | |||
500 | GNUNET_TIME_absolute_get_duration | 507 | GNUNET_TIME_absolute_get_duration |
501 | (pth->transmission_request_start_time).rel_value); | 508 | (pth->transmission_request_start_time).rel_value); |
502 | ret = pth->gmc (pth->gmc_cls, size, buf); | 509 | ret = pth->gmc (pth->gmc_cls, size, buf); |
503 | GNUNET_assert (NULL == pth->cth); | 510 | if (NULL != (pos = cp->pth_head)) |
504 | for (pos = cp->pth_head; pos != NULL; pos = pos->next) | ||
505 | { | 511 | { |
506 | GNUNET_assert (pos != pth); | 512 | GNUNET_assert (pos != pth); |
507 | schedule_transmission (pos); | 513 | schedule_transmission (pos); |
508 | } | 514 | } |
509 | GNUNET_assert (pth->cth == NULL); | ||
510 | GNUNET_assert (pth->cth_in_progress == 0); | ||
511 | GNUNET_free (pth); | 515 | GNUNET_free (pth); |
512 | return ret; | 516 | return ret; |
513 | } | 517 | } |
@@ -562,16 +566,17 @@ ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
562 | } | 566 | } |
563 | cp->did_reserve = GNUNET_YES; | 567 | cp->did_reserve = GNUNET_YES; |
564 | pth = cp->pth_head; | 568 | pth = cp->pth_head; |
565 | if ((NULL != pth) && (NULL == pth->cth) && (0 == pth->cth_in_progress)) | 569 | if ((NULL != pth) && (NULL == cp->cth) && (0 == cp->cth_in_progress)) |
566 | { | 570 | { |
567 | /* reservation success, try transmission now! */ | 571 | /* reservation success, try transmission now! */ |
568 | pth->cth_in_progress++; | 572 | cp->cth_in_progress++; |
569 | pth->cth = | 573 | cp->cth = |
570 | GNUNET_CORE_notify_transmit_ready (GSF_core, GNUNET_YES, pth->priority, | 574 | GNUNET_CORE_notify_transmit_ready (GSF_core, GNUNET_YES, pth->priority, |
571 | GNUNET_TIME_absolute_get_remaining | 575 | GNUNET_TIME_absolute_get_remaining |
572 | (pth->timeout), peer, pth->size, | 576 | (pth->timeout), peer, pth->size, |
573 | &peer_transmit_ready_cb, pth); | 577 | &peer_transmit_ready_cb, cp); |
574 | GNUNET_assert (0 < pth->cth_in_progress--); | 578 | GNUNET_assert (NULL != cp->cth); |
579 | GNUNET_assert (0 < cp->cth_in_progress--); | ||
575 | } | 580 | } |
576 | } | 581 | } |
577 | 582 | ||
@@ -1350,13 +1355,13 @@ peer_transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1350 | else if (GNUNET_NO == pth->is_query) | 1355 | else if (GNUNET_NO == pth->is_query) |
1351 | GNUNET_assert (0 < cp->ppd.pending_replies--); | 1356 | GNUNET_assert (0 < cp->ppd.pending_replies--); |
1352 | GNUNET_LOAD_update (cp->ppd.transmission_delay, UINT64_MAX); | 1357 | GNUNET_LOAD_update (cp->ppd.transmission_delay, UINT64_MAX); |
1353 | if (NULL != pth->cth) | 1358 | if (NULL != cp->cth) |
1354 | { | 1359 | { |
1355 | GNUNET_CORE_notify_transmit_ready_cancel (pth->cth); | 1360 | GNUNET_CORE_notify_transmit_ready_cancel (cp->cth); |
1356 | pth->cth = NULL; | 1361 | cp->cth = NULL; |
1357 | } | 1362 | } |
1358 | pth->gmc (pth->gmc_cls, 0, NULL); | 1363 | pth->gmc (pth->gmc_cls, 0, NULL); |
1359 | GNUNET_assert (0 == pth->cth_in_progress); | 1364 | GNUNET_assert (0 == cp->cth_in_progress); |
1360 | GNUNET_free (pth); | 1365 | GNUNET_free (pth); |
1361 | } | 1366 | } |
1362 | 1367 | ||
@@ -1401,10 +1406,7 @@ GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, int is_query, | |||
1401 | prev = pos; | 1406 | prev = pos; |
1402 | pos = pos->next; | 1407 | pos = pos->next; |
1403 | } | 1408 | } |
1404 | if (prev == NULL) | 1409 | GNUNET_CONTAINER_DLL_insert_after (cp->pth_head, cp->pth_tail, prev, pth); |
1405 | GNUNET_CONTAINER_DLL_insert (cp->pth_head, cp->pth_tail, pth); | ||
1406 | else | ||
1407 | GNUNET_CONTAINER_DLL_insert_after (cp->pth_head, cp->pth_tail, prev, pth); | ||
1408 | if (GNUNET_YES == is_query) | 1410 | if (GNUNET_YES == is_query) |
1409 | cp->ppd.pending_queries++; | 1411 | cp->ppd.pending_queries++; |
1410 | else if (GNUNET_NO == is_query) | 1412 | else if (GNUNET_NO == is_query) |
@@ -1431,18 +1433,12 @@ GSF_peer_transmit_cancel_ (struct GSF_PeerTransmitHandle *pth) | |||
1431 | GNUNET_SCHEDULER_cancel (pth->timeout_task); | 1433 | GNUNET_SCHEDULER_cancel (pth->timeout_task); |
1432 | pth->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1434 | pth->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
1433 | } | 1435 | } |
1434 | if (NULL != pth->cth) | ||
1435 | { | ||
1436 | GNUNET_CORE_notify_transmit_ready_cancel (pth->cth); | ||
1437 | pth->cth = NULL; | ||
1438 | } | ||
1439 | cp = pth->cp; | 1436 | cp = pth->cp; |
1440 | GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth); | 1437 | GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth); |
1441 | if (GNUNET_YES == pth->is_query) | 1438 | if (GNUNET_YES == pth->is_query) |
1442 | GNUNET_assert (0 < cp->ppd.pending_queries--); | 1439 | GNUNET_assert (0 < cp->ppd.pending_queries--); |
1443 | else if (GNUNET_NO == pth->is_query) | 1440 | else if (GNUNET_NO == pth->is_query) |
1444 | GNUNET_assert (0 < cp->ppd.pending_replies--); | 1441 | GNUNET_assert (0 < cp->ppd.pending_replies--); |
1445 | GNUNET_assert (0 == pth->cth_in_progress); | ||
1446 | GNUNET_free (pth); | 1442 | GNUNET_free (pth); |
1447 | } | 1443 | } |
1448 | 1444 | ||
@@ -1556,20 +1552,20 @@ GSF_peer_disconnect_handler_ (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
1556 | GNUNET_PEER_decrement_rcs (cp->ppd.last_p2p_replies, P2P_SUCCESS_LIST_SIZE); | 1552 | GNUNET_PEER_decrement_rcs (cp->ppd.last_p2p_replies, P2P_SUCCESS_LIST_SIZE); |
1557 | memset (cp->ppd.last_p2p_replies, 0, sizeof (cp->ppd.last_p2p_replies)); | 1553 | memset (cp->ppd.last_p2p_replies, 0, sizeof (cp->ppd.last_p2p_replies)); |
1558 | GSF_push_stop_ (cp); | 1554 | GSF_push_stop_ (cp); |
1555 | if (NULL != cp->cth) | ||
1556 | { | ||
1557 | GNUNET_CORE_notify_transmit_ready_cancel (cp->cth); | ||
1558 | cp->cth = NULL; | ||
1559 | } | ||
1560 | GNUNET_assert (0 == cp->cth_in_progress); | ||
1559 | while (NULL != (pth = cp->pth_head)) | 1561 | while (NULL != (pth = cp->pth_head)) |
1560 | { | 1562 | { |
1561 | if (NULL != pth->cth) | ||
1562 | { | ||
1563 | GNUNET_CORE_notify_transmit_ready_cancel (pth->cth); | ||
1564 | pth->cth = NULL; | ||
1565 | } | ||
1566 | if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK) | 1563 | if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK) |
1567 | { | 1564 | { |
1568 | GNUNET_SCHEDULER_cancel (pth->timeout_task); | 1565 | GNUNET_SCHEDULER_cancel (pth->timeout_task); |
1569 | pth->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1566 | pth->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
1570 | } | 1567 | } |
1571 | GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth); | 1568 | GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth); |
1572 | GNUNET_assert (0 == pth->cth_in_progress); | ||
1573 | pth->gmc (pth->gmc_cls, 0, NULL); | 1569 | pth->gmc (pth->gmc_cls, 0, NULL); |
1574 | GNUNET_free (pth); | 1570 | GNUNET_free (pth); |
1575 | } | 1571 | } |