diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-12-16 17:34:18 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-12-16 17:34:18 +0000 |
commit | 0b92336e16fd941ec085c66579486244c6bd83f4 (patch) | |
tree | bbb47f96c7bba867018003de148654fd8ca0eab5 /src/fs/gnunet-service-fs_cp.c | |
parent | f1cc760d1c98e2738430ad24d8004c5c700c1c49 (diff) | |
download | gnunet-0b92336e16fd941ec085c66579486244c6bd83f4.tar.gz gnunet-0b92336e16fd941ec085c66579486244c6bd83f4.zip |
do not poll empty database every 100ms for migration, doxygen fixes, code cleanup
Diffstat (limited to 'src/fs/gnunet-service-fs_cp.c')
-rw-r--r-- | src/fs/gnunet-service-fs_cp.c | 114 |
1 files changed, 72 insertions, 42 deletions
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c index bca07db32..c1c3f01f1 100644 --- a/src/fs/gnunet-service-fs_cp.c +++ b/src/fs/gnunet-service-fs_cp.c | |||
@@ -368,13 +368,15 @@ GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp) | |||
368 | /** | 368 | /** |
369 | * Core is ready to transmit to a peer, get the message. | 369 | * Core is ready to transmit to a peer, get the message. |
370 | * | 370 | * |
371 | * @param cls the 'struct GSF_PeerTransmitHandle' of the message | 371 | * @param cls the `struct GSF_PeerTransmitHandle` of the message |
372 | * @param size number of bytes core is willing to take | 372 | * @param size number of bytes core is willing to take |
373 | * @param buf where to copy the message | 373 | * @param buf where to copy the message |
374 | * @return number of bytes copied to buf | 374 | * @return number of bytes copied to @a buf |
375 | */ | 375 | */ |
376 | static size_t | 376 | static size_t |
377 | peer_transmit_ready_cb (void *cls, size_t size, void *buf); | 377 | peer_transmit_ready_cb (void *cls, |
378 | size_t size, | ||
379 | void *buf); | ||
378 | 380 | ||
379 | 381 | ||
380 | /** | 382 | /** |
@@ -388,8 +390,10 @@ peer_transmit_ready_cb (void *cls, size_t size, void *buf); | |||
388 | * long should the client wait until re-trying? | 390 | * long should the client wait until re-trying? |
389 | */ | 391 | */ |
390 | static void | 392 | static void |
391 | ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | 393 | ats_reserve_callback (void *cls, |
392 | int32_t amount, struct GNUNET_TIME_Relative res_delay); | 394 | const struct GNUNET_PeerIdentity *peer, |
395 | int32_t amount, | ||
396 | struct GNUNET_TIME_Relative res_delay); | ||
393 | 397 | ||
394 | 398 | ||
395 | /** | 399 | /** |
@@ -447,10 +451,10 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth) | |||
447 | /** | 451 | /** |
448 | * Core is ready to transmit to a peer, get the message. | 452 | * Core is ready to transmit to a peer, get the message. |
449 | * | 453 | * |
450 | * @param cls the 'struct GSF_PeerTransmitHandle' of the message | 454 | * @param cls the `struct GSF_PeerTransmitHandle` of the message |
451 | * @param size number of bytes core is willing to take | 455 | * @param size number of bytes core is willing to take |
452 | * @param buf where to copy the message | 456 | * @param buf where to copy the message |
453 | * @return number of bytes copied to buf | 457 | * @return number of bytes copied to @a buf |
454 | */ | 458 | */ |
455 | static size_t | 459 | static size_t |
456 | peer_transmit_ready_cb (void *cls, size_t size, void *buf) | 460 | peer_transmit_ready_cb (void *cls, size_t size, void *buf) |
@@ -502,7 +506,7 @@ peer_transmit_ready_cb (void *cls, size_t size, void *buf) | |||
502 | /** | 506 | /** |
503 | * (re)try to reserve bandwidth from the given peer. | 507 | * (re)try to reserve bandwidth from the given peer. |
504 | * | 508 | * |
505 | * @param cls the 'struct GSF_ConnectedPeer' to reserve from | 509 | * @param cls the `struct GSF_ConnectedPeer` to reserve from |
506 | * @param tc scheduler context | 510 | * @param tc scheduler context |
507 | */ | 511 | */ |
508 | static void | 512 | static void |
@@ -564,6 +568,7 @@ ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
564 | } | 568 | } |
565 | } | 569 | } |
566 | 570 | ||
571 | |||
567 | /** | 572 | /** |
568 | * Function called by PEERSTORE with peer respect record | 573 | * Function called by PEERSTORE with peer respect record |
569 | * | 574 | * |
@@ -573,7 +578,9 @@ ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
573 | * @return #GNUNET_NO to stop iterating since we only expect 0 or 1 records | 578 | * @return #GNUNET_NO to stop iterating since we only expect 0 or 1 records |
574 | */ | 579 | */ |
575 | static int | 580 | static int |
576 | peer_respect_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) | 581 | peer_respect_cb (void *cls, |
582 | struct GNUNET_PEERSTORE_Record *record, | ||
583 | char *emsg) | ||
577 | { | 584 | { |
578 | struct GSF_ConnectedPeer *cp = cls; | 585 | struct GSF_ConnectedPeer *cp = cls; |
579 | 586 | ||
@@ -631,11 +638,12 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, | |||
631 | * It may be time to re-start migrating content to this | 638 | * It may be time to re-start migrating content to this |
632 | * peer. Check, and if so, restart migration. | 639 | * peer. Check, and if so, restart migration. |
633 | * | 640 | * |
634 | * @param cls the 'struct GSF_ConnectedPeer' | 641 | * @param cls the `struct GSF_ConnectedPeer` |
635 | * @param tc scheduler context | 642 | * @param tc scheduler context |
636 | */ | 643 | */ |
637 | static void | 644 | static void |
638 | revive_migration (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 645 | revive_migration (void *cls, |
646 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
639 | { | 647 | { |
640 | struct GSF_ConnectedPeer *cp = cls; | 648 | struct GSF_ConnectedPeer *cp = cls; |
641 | struct GNUNET_TIME_Relative bt; | 649 | struct GNUNET_TIME_Relative bt; |
@@ -675,8 +683,8 @@ GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer) | |||
675 | * @param other the other peer involved (sender or receiver, NULL | 683 | * @param other the other peer involved (sender or receiver, NULL |
676 | * for loopback messages where we are both sender and receiver) | 684 | * for loopback messages where we are both sender and receiver) |
677 | * @param message the actual message | 685 | * @param message the actual message |
678 | * @return GNUNET_OK to keep the connection open, | 686 | * @return #GNUNET_OK to keep the connection open, |
679 | * GNUNET_SYSERR to close it (signal serious error) | 687 | * #GNUNET_SYSERR to close it (signal serious error) |
680 | */ | 688 | */ |
681 | int | 689 | int |
682 | GSF_handle_p2p_migration_stop_ (void *cls, | 690 | GSF_handle_p2p_migration_stop_ (void *cls, |
@@ -707,7 +715,8 @@ GSF_handle_p2p_migration_stop_ (void *cls, | |||
707 | { | 715 | { |
708 | GSF_push_stop_ (cp); | 716 | GSF_push_stop_ (cp); |
709 | cp->mig_revive_task = | 717 | cp->mig_revive_task = |
710 | GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp); | 718 | GNUNET_SCHEDULER_add_delayed (bt, |
719 | &revive_migration, cp); | ||
711 | } | 720 | } |
712 | return GNUNET_OK; | 721 | return GNUNET_OK; |
713 | } | 722 | } |
@@ -716,8 +725,8 @@ GSF_handle_p2p_migration_stop_ (void *cls, | |||
716 | /** | 725 | /** |
717 | * Copy reply and free put message. | 726 | * Copy reply and free put message. |
718 | * | 727 | * |
719 | * @param cls the 'struct PutMessage' | 728 | * @param cls the `struct PutMessage` |
720 | * @param buf_size number of bytes available in buf | 729 | * @param buf_size number of bytes available in @a buf |
721 | * @param buf where to copy the message, NULL on error (peer disconnect) | 730 | * @param buf where to copy the message, NULL on error (peer disconnect) |
722 | * @return number of bytes copied to 'buf', can be 0 (without indicating an error) | 731 | * @return number of bytes copied to 'buf', can be 0 (without indicating an error) |
723 | */ | 732 | */ |
@@ -779,11 +788,13 @@ free_pending_request (struct PeerRequest *peerreq, | |||
779 | * | 788 | * |
780 | * @param cls unused | 789 | * @param cls unused |
781 | * @param query hash code of the request | 790 | * @param query hash code of the request |
782 | * @param value the 'struct GSF_PendingRequest' | 791 | * @param value the `struct GSF_PendingRequest` |
783 | * @return GNUNET_YES (continue to iterate) | 792 | * @return #GNUNET_YES (continue to iterate) |
784 | */ | 793 | */ |
785 | static int | 794 | static int |
786 | cancel_pending_request (void *cls, const struct GNUNET_HashCode * query, void *value) | 795 | cancel_pending_request (void *cls, |
796 | const struct GNUNET_HashCode *query, | ||
797 | void *value) | ||
787 | { | 798 | { |
788 | struct PeerRequest *peerreq = value; | 799 | struct PeerRequest *peerreq = value; |
789 | struct GSF_PendingRequest *pr = peerreq->pr; | 800 | struct GSF_PendingRequest *pr = peerreq->pr; |
@@ -803,7 +814,8 @@ cancel_pending_request (void *cls, const struct GNUNET_HashCode * query, void *v | |||
803 | * @param tc task context | 814 | * @param tc task context |
804 | */ | 815 | */ |
805 | static void | 816 | static void |
806 | peer_request_destroy (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 817 | peer_request_destroy (void *cls, |
818 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
807 | { | 819 | { |
808 | struct PeerRequest *peerreq = cls; | 820 | struct PeerRequest *peerreq = cls; |
809 | struct GSF_PendingRequest *pr = peerreq->pr; | 821 | struct GSF_PendingRequest *pr = peerreq->pr; |
@@ -822,7 +834,8 @@ peer_request_destroy (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
822 | * @param tc scheduler context | 834 | * @param tc scheduler context |
823 | */ | 835 | */ |
824 | static void | 836 | static void |
825 | transmit_delayed_now (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 837 | transmit_delayed_now (void *cls, |
838 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
826 | { | 839 | { |
827 | struct GSF_DelayedHandle *dh = cls; | 840 | struct GSF_DelayedHandle *dh = cls; |
828 | struct GSF_ConnectedPeer *cp = dh->cp; | 841 | struct GSF_ConnectedPeer *cp = dh->cp; |
@@ -873,22 +886,25 @@ get_randomized_delay () | |||
873 | * and will also not be called anymore after a call signalling | 886 | * and will also not be called anymore after a call signalling |
874 | * expiration. | 887 | * expiration. |
875 | * | 888 | * |
876 | * @param cls 'struct PeerRequest' this is an answer for | 889 | * @param cls `struct PeerRequest` this is an answer for |
877 | * @param eval evaluation of the result | 890 | * @param eval evaluation of the result |
878 | * @param pr handle to the original pending request | 891 | * @param pr handle to the original pending request |
879 | * @param reply_anonymity_level anonymity level for the reply, UINT32_MAX for "unknown" | 892 | * @param reply_anonymity_level anonymity level for the reply, UINT32_MAX for "unknown" |
880 | * @param expiration when does 'data' expire? | 893 | * @param expiration when does @a data expire? |
881 | * @param last_transmission when did we last transmit a request for this block | 894 | * @param last_transmission when did we last transmit a request for this block |
882 | * @param type type of the block | 895 | * @param type type of the block |
883 | * @param data response data, NULL on request expiration | 896 | * @param data response data, NULL on request expiration |
884 | * @param data_len number of bytes in data | 897 | * @param data_len number of bytes in @a data |
885 | */ | 898 | */ |
886 | static void | 899 | static void |
887 | handle_p2p_reply (void *cls, enum GNUNET_BLOCK_EvaluationResult eval, | 900 | handle_p2p_reply (void *cls, |
888 | struct GSF_PendingRequest *pr, uint32_t reply_anonymity_level, | 901 | enum GNUNET_BLOCK_EvaluationResult eval, |
902 | struct GSF_PendingRequest *pr, | ||
903 | uint32_t reply_anonymity_level, | ||
889 | struct GNUNET_TIME_Absolute expiration, | 904 | struct GNUNET_TIME_Absolute expiration, |
890 | struct GNUNET_TIME_Absolute last_transmission, | 905 | struct GNUNET_TIME_Absolute last_transmission, |
891 | enum GNUNET_BLOCK_Type type, const void *data, | 906 | enum GNUNET_BLOCK_Type type, |
907 | const void *data, | ||
892 | size_t data_len) | 908 | size_t data_len) |
893 | { | 909 | { |
894 | struct PeerRequest *peerreq = cls; | 910 | struct PeerRequest *peerreq = cls; |
@@ -1328,7 +1344,8 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other, | |||
1328 | * @param tc scheduler context | 1344 | * @param tc scheduler context |
1329 | */ | 1345 | */ |
1330 | static void | 1346 | static void |
1331 | peer_transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1347 | peer_transmit_timeout (void *cls, |
1348 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1332 | { | 1349 | { |
1333 | struct GSF_PeerTransmitHandle *pth = cls; | 1350 | struct GSF_PeerTransmitHandle *pth = cls; |
1334 | struct GSF_ConnectedPeer *cp; | 1351 | struct GSF_ConnectedPeer *cp; |
@@ -1369,9 +1386,12 @@ peer_transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1369 | * @return handle to cancel request | 1386 | * @return handle to cancel request |
1370 | */ | 1387 | */ |
1371 | struct GSF_PeerTransmitHandle * | 1388 | struct GSF_PeerTransmitHandle * |
1372 | GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, int is_query, | 1389 | GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, |
1373 | uint32_t priority, struct GNUNET_TIME_Relative timeout, | 1390 | int is_query, |
1374 | size_t size, GSF_GetMessageCallback gmc, void *gmc_cls) | 1391 | uint32_t priority, |
1392 | struct GNUNET_TIME_Relative timeout, | ||
1393 | size_t size, | ||
1394 | GSF_GetMessageCallback gmc, void *gmc_cls) | ||
1375 | { | 1395 | { |
1376 | struct GSF_PeerTransmitHandle *pth; | 1396 | struct GSF_PeerTransmitHandle *pth; |
1377 | struct GSF_PeerTransmitHandle *pos; | 1397 | struct GSF_PeerTransmitHandle *pos; |
@@ -1500,7 +1520,8 @@ GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp, | |||
1500 | * @param peer identity of peer that connected | 1520 | * @param peer identity of peer that connected |
1501 | */ | 1521 | */ |
1502 | void | 1522 | void |
1503 | GSF_peer_disconnect_handler_ (void *cls, const struct GNUNET_PeerIdentity *peer) | 1523 | GSF_peer_disconnect_handler_ (void *cls, |
1524 | const struct GNUNET_PeerIdentity *peer) | ||
1504 | { | 1525 | { |
1505 | struct GSF_ConnectedPeer *cp; | 1526 | struct GSF_ConnectedPeer *cp; |
1506 | struct GSF_PeerTransmitHandle *pth; | 1527 | struct GSF_PeerTransmitHandle *pth; |
@@ -1581,7 +1602,7 @@ GSF_peer_disconnect_handler_ (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
1581 | 1602 | ||
1582 | 1603 | ||
1583 | /** | 1604 | /** |
1584 | * Closure for 'call_iterator'. | 1605 | * Closure for #call_iterator(). |
1585 | */ | 1606 | */ |
1586 | struct IterationContext | 1607 | struct IterationContext |
1587 | { | 1608 | { |
@@ -1591,7 +1612,7 @@ struct IterationContext | |||
1591 | GSF_ConnectedPeerIterator it; | 1612 | GSF_ConnectedPeerIterator it; |
1592 | 1613 | ||
1593 | /** | 1614 | /** |
1594 | * Closure for 'it'. | 1615 | * Closure for @e it. |
1595 | */ | 1616 | */ |
1596 | void *it_cls; | 1617 | void *it_cls; |
1597 | }; | 1618 | }; |
@@ -1606,12 +1627,16 @@ struct IterationContext | |||
1606 | * @return #GNUNET_YES to continue iteration | 1627 | * @return #GNUNET_YES to continue iteration |
1607 | */ | 1628 | */ |
1608 | static int | 1629 | static int |
1609 | call_iterator (void *cls, const struct GNUNET_PeerIdentity * key, void *value) | 1630 | call_iterator (void *cls, |
1631 | const struct GNUNET_PeerIdentity *key, | ||
1632 | void *value) | ||
1610 | { | 1633 | { |
1611 | struct IterationContext *ic = cls; | 1634 | struct IterationContext *ic = cls; |
1612 | struct GSF_ConnectedPeer *cp = value; | 1635 | struct GSF_ConnectedPeer *cp = value; |
1613 | 1636 | ||
1614 | ic->it (ic->it_cls, (const struct GNUNET_PeerIdentity *) key, cp, &cp->ppd); | 1637 | ic->it (ic->it_cls, |
1638 | key, cp, | ||
1639 | &cp->ppd); | ||
1615 | return GNUNET_YES; | 1640 | return GNUNET_YES; |
1616 | } | 1641 | } |
1617 | 1642 | ||
@@ -1623,13 +1648,16 @@ call_iterator (void *cls, const struct GNUNET_PeerIdentity * key, void *value) | |||
1623 | * @param it_cls closure for @a it | 1648 | * @param it_cls closure for @a it |
1624 | */ | 1649 | */ |
1625 | void | 1650 | void |
1626 | GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, void *it_cls) | 1651 | GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, |
1652 | void *it_cls) | ||
1627 | { | 1653 | { |
1628 | struct IterationContext ic; | 1654 | struct IterationContext ic; |
1629 | 1655 | ||
1630 | ic.it = it; | 1656 | ic.it = it; |
1631 | ic.it_cls = it_cls; | 1657 | ic.it_cls = it_cls; |
1632 | GNUNET_CONTAINER_multipeermap_iterate (cp_map, &call_iterator, &ic); | 1658 | GNUNET_CONTAINER_multipeermap_iterate (cp_map, |
1659 | &call_iterator, | ||
1660 | &ic); | ||
1633 | } | 1661 | } |
1634 | 1662 | ||
1635 | 1663 | ||
@@ -1665,13 +1693,15 @@ GSF_connected_peer_get_identity2_ (const struct GSF_ConnectedPeer *cp) | |||
1665 | /** | 1693 | /** |
1666 | * Assemble a migration stop message for transmission. | 1694 | * Assemble a migration stop message for transmission. |
1667 | * | 1695 | * |
1668 | * @param cls the 'struct GSF_ConnectedPeer' to use | 1696 | * @param cls the `struct GSF_ConnectedPeer` to use |
1669 | * @param size number of bytes we're allowed to write to buf | 1697 | * @param size number of bytes we're allowed to write to @a buf |
1670 | * @param buf where to copy the message | 1698 | * @param buf where to copy the message |
1671 | * @return number of bytes copied to buf | 1699 | * @return number of bytes copied to @a buf |
1672 | */ | 1700 | */ |
1673 | static size_t | 1701 | static size_t |
1674 | create_migration_stop_message (void *cls, size_t size, void *buf) | 1702 | create_migration_stop_message (void *cls, |
1703 | size_t size, | ||
1704 | void *buf) | ||
1675 | { | 1705 | { |
1676 | struct GSF_ConnectedPeer *cp = cls; | 1706 | struct GSF_ConnectedPeer *cp = cls; |
1677 | struct MigrationStopMessage msm; | 1707 | struct MigrationStopMessage msm; |