diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-09-16 15:44:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-09-16 15:44:32 +0000 |
commit | 7d1c10c4b0cf298d12eeac4425f27207d28ab428 (patch) | |
tree | ba8c24881610c23fd414a6df03798f13a1d1bed4 | |
parent | b7d63eaae6bfb3e72a452d1841e808a0159be173 (diff) | |
download | gnunet-7d1c10c4b0cf298d12eeac4425f27207d28ab428.tar.gz gnunet-7d1c10c4b0cf298d12eeac4425f27207d28ab428.zip |
stuff
-rw-r--r-- | src/fs/gnunet-service-fs.c | 185 | ||||
-rw-r--r-- | src/util/Makefile.am | 1 | ||||
-rw-r--r-- | src/util/container_heap.c | 11 |
3 files changed, 182 insertions, 15 deletions
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 5237cee04..0a9fbcefe 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c | |||
@@ -24,7 +24,7 @@ | |||
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | * | 25 | * |
26 | * TODO: | 26 | * TODO: |
27 | * - tracking of PendingRequests (and defining that struct...) | 27 | * - tracking of PendingRequests |
28 | * - setup P2P search on CS request | 28 | * - setup P2P search on CS request |
29 | * - setup P2P search on P2P GET | 29 | * - setup P2P search on P2P GET |
30 | * - forward replies based on tracked requests | 30 | * - forward replies based on tracked requests |
@@ -342,6 +342,13 @@ struct ProcessGetContext | |||
342 | 342 | ||
343 | 343 | ||
344 | /** | 344 | /** |
345 | * All requests from a client are | ||
346 | * kept in a doubly-linked list. | ||
347 | */ | ||
348 | struct ClientRequestList; | ||
349 | |||
350 | |||
351 | /** | ||
345 | * Information we keep for each pending request. We should try to | 352 | * Information we keep for each pending request. We should try to |
346 | * keep this struct as small as possible since its memory consumption | 353 | * keep this struct as small as possible since its memory consumption |
347 | * is key to how many requests we can have pending at once. | 354 | * is key to how many requests we can have pending at once. |
@@ -356,6 +363,13 @@ struct PendingRequest | |||
356 | struct GNUNET_SERVER_Client *client; | 363 | struct GNUNET_SERVER_Client *client; |
357 | 364 | ||
358 | /** | 365 | /** |
366 | * If this request was made by a client, | ||
367 | * this is our entry in the client request | ||
368 | * list; otherwise NULL. | ||
369 | */ | ||
370 | struct ClientRequestList *crl_entry; | ||
371 | |||
372 | /** | ||
359 | * If this is a namespace query, pointer to the hash of the public | 373 | * If this is a namespace query, pointer to the hash of the public |
360 | * key of the namespace; otherwise NULL. | 374 | * key of the namespace; otherwise NULL. |
361 | */ | 375 | */ |
@@ -452,6 +466,60 @@ struct PendingRequest | |||
452 | 466 | ||
453 | 467 | ||
454 | /** | 468 | /** |
469 | * All requests from a client are | ||
470 | * kept in a doubly-linked list. | ||
471 | */ | ||
472 | struct ClientRequestList | ||
473 | { | ||
474 | /** | ||
475 | * This is a doubly-linked list. | ||
476 | */ | ||
477 | struct ClientRequestList *next; | ||
478 | |||
479 | /** | ||
480 | * This is a doubly-linked list. | ||
481 | */ | ||
482 | struct ClientRequestList *prev; | ||
483 | |||
484 | /** | ||
485 | * A request from this client. | ||
486 | */ | ||
487 | struct PendingRequest *req; | ||
488 | |||
489 | }; | ||
490 | |||
491 | |||
492 | /** | ||
493 | * Linked list of all clients that we are | ||
494 | * currently processing requests for. | ||
495 | */ | ||
496 | struct ClientList | ||
497 | { | ||
498 | |||
499 | /** | ||
500 | * This is a linked list. | ||
501 | */ | ||
502 | struct ClientList *next; | ||
503 | |||
504 | /** | ||
505 | * What client is this entry for? | ||
506 | */ | ||
507 | struct GNUNET_SERVER_Client* client; | ||
508 | |||
509 | /** | ||
510 | * Head of the DLL of requests from this client. | ||
511 | */ | ||
512 | struct ClientRequestList *head; | ||
513 | |||
514 | /** | ||
515 | * Tail of the DLL of requests from this client. | ||
516 | */ | ||
517 | struct ClientRequestList *tail; | ||
518 | |||
519 | }; | ||
520 | |||
521 | |||
522 | /** | ||
455 | * Closure for "process_reply" function. | 523 | * Closure for "process_reply" function. |
456 | */ | 524 | */ |
457 | struct ProcessReplyClosure | 525 | struct ProcessReplyClosure |
@@ -505,8 +573,7 @@ static struct GNUNET_SCHEDULER_Handle *sched; | |||
505 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 573 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
506 | 574 | ||
507 | /** | 575 | /** |
508 | * Handle to the core service (NULL until we've | 576 | * Handle to the core service (NULL until we've connected to it). |
509 | * connected to it). | ||
510 | */ | 577 | */ |
511 | struct GNUNET_CORE_Handle *core; | 578 | struct GNUNET_CORE_Handle *core; |
512 | 579 | ||
@@ -543,6 +610,27 @@ static struct IndexInfo *indexed_files; | |||
543 | */ | 610 | */ |
544 | static struct GNUNET_CONTAINER_MultiHashMap *ifm; | 611 | static struct GNUNET_CONTAINER_MultiHashMap *ifm; |
545 | 612 | ||
613 | /** | ||
614 | * Map of query hash codes to requests. | ||
615 | */ | ||
616 | static struct GNUNET_CONTAINER_MultiHashMap *requests_by_query; | ||
617 | |||
618 | /** | ||
619 | * Map of peer IDs to requests (for those requests coming | ||
620 | * from other peers). | ||
621 | */ | ||
622 | static struct GNUNET_CONTAINER_MultiHashMap *requests_by_peer; | ||
623 | |||
624 | /** | ||
625 | * Linked list of all of our clients and their requests. | ||
626 | */ | ||
627 | static struct ClientList *clients; | ||
628 | |||
629 | /** | ||
630 | * Heap with the request that will expire next at the top. | ||
631 | */ | ||
632 | static struct GNUNET_CONTAINER_Heap *requests_by_expiration; | ||
633 | |||
546 | 634 | ||
547 | /** | 635 | /** |
548 | * Write the current index information list to disk. | 636 | * Write the current index information list to disk. |
@@ -1468,6 +1556,35 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = { | |||
1468 | 1556 | ||
1469 | 1557 | ||
1470 | /** | 1558 | /** |
1559 | * Clean up the memory used by the PendingRequest | ||
1560 | * structure (except for the client or peer list | ||
1561 | * that the request may be part of). | ||
1562 | * | ||
1563 | * @param pr request to clean up | ||
1564 | */ | ||
1565 | static void | ||
1566 | destroy_pending_request (struct PendingRequest *pr) | ||
1567 | { | ||
1568 | GNUNET_CONTAINER_multihashmap_remove (requests_by_query, | ||
1569 | &pr->query, | ||
1570 | pr); | ||
1571 | // FIXME: not sure how this can work (efficiently) | ||
1572 | // also, what does the return value mean? | ||
1573 | GNUNET_CONTAINER_heap_remove_node (requests_by_expiration, | ||
1574 | pr); | ||
1575 | if (NULL != pr->bf) | ||
1576 | GNUNET_CONTAINER_bloomfilter_free (pr->bf); | ||
1577 | GNUNET_PEER_change_rc (pr->source_pid, -1); | ||
1578 | GNUNET_PEER_change_rc (pr->target_pid, -1); | ||
1579 | GNUNET_PEER_decrement_rcs (pr->used_pids, pr->used_pids_off); | ||
1580 | GNUNET_free_non_null (pr->used_pids); | ||
1581 | GNUNET_free_non_null (pr->replies_seen); | ||
1582 | GNUNET_free_non_null (pr->namespace); | ||
1583 | GNUNET_free (pr); | ||
1584 | } | ||
1585 | |||
1586 | |||
1587 | /** | ||
1471 | * A client disconnected. Remove all of its pending queries. | 1588 | * A client disconnected. Remove all of its pending queries. |
1472 | * | 1589 | * |
1473 | * @param cls closure, NULL | 1590 | * @param cls closure, NULL |
@@ -1479,14 +1596,38 @@ handle_client_disconnect (void *cls, | |||
1479 | * client) | 1596 | * client) |
1480 | { | 1597 | { |
1481 | struct LocalGetContext *lgc; | 1598 | struct LocalGetContext *lgc; |
1599 | struct ClientList *cpos; | ||
1600 | struct ClientList *cprev; | ||
1601 | struct ClientRequestList *rl; | ||
1482 | 1602 | ||
1483 | lgc = lgc_head; | 1603 | lgc = lgc_head; |
1484 | while ( (NULL != lgc) && | 1604 | while ( (NULL != lgc) && |
1485 | (lgc->client != client) ) | 1605 | (lgc->client != client) ) |
1486 | lgc = lgc->next; | 1606 | lgc = lgc->next; |
1487 | if (lgc == NULL) | 1607 | if (lgc != NULL) |
1488 | return; /* not one of our clients */ | 1608 | local_get_context_free (lgc); |
1489 | local_get_context_free (lgc); | 1609 | cprev = NULL; |
1610 | cpos = clients; | ||
1611 | while ( (NULL != cpos) && | ||
1612 | (clients->client != client) ) | ||
1613 | { | ||
1614 | cprev = cpos; | ||
1615 | cpos = cpos->next; | ||
1616 | } | ||
1617 | if (cpos != NULL) | ||
1618 | { | ||
1619 | if (cprev == NULL) | ||
1620 | clients = cpos->next; | ||
1621 | else | ||
1622 | cprev->next = cpos->next; | ||
1623 | while (NULL != (rl = cpos->head)) | ||
1624 | { | ||
1625 | cpos->head = rl->next; | ||
1626 | destroy_pending_request (rl->req); | ||
1627 | GNUNET_free (rl); | ||
1628 | } | ||
1629 | GNUNET_free (cpos); | ||
1630 | } | ||
1490 | } | 1631 | } |
1491 | 1632 | ||
1492 | 1633 | ||
@@ -1521,6 +1662,30 @@ shutdown_task (void *cls, | |||
1521 | 1662 | ||
1522 | 1663 | ||
1523 | /** | 1664 | /** |
1665 | * Free (each) request made by the peer. | ||
1666 | * | ||
1667 | * @param cls closure, points to peer that the request belongs to | ||
1668 | * @param key current key code | ||
1669 | * @param value value in the hash map | ||
1670 | * @return GNUNET_YES (we should continue to iterate) | ||
1671 | */ | ||
1672 | static int | ||
1673 | destroy_request (void *cls, | ||
1674 | const GNUNET_HashCode * key, | ||
1675 | void *value) | ||
1676 | { | ||
1677 | const struct GNUNET_PeerIdentity * peer = cls; | ||
1678 | struct PendingRequest *pr = value; | ||
1679 | |||
1680 | GNUNET_CONTAINER_multihashmap_remove (requests_by_peer, | ||
1681 | &peer->hashPubKey, | ||
1682 | pr); | ||
1683 | destroy_pending_request (pr); | ||
1684 | return GNUNET_YES; | ||
1685 | } | ||
1686 | |||
1687 | |||
1688 | /** | ||
1524 | * Method called whenever a peer disconnects. | 1689 | * Method called whenever a peer disconnects. |
1525 | * | 1690 | * |
1526 | * @param cls closure, not used | 1691 | * @param cls closure, not used |
@@ -1531,9 +1696,10 @@ peer_disconnect_handler (void *cls, | |||
1531 | const struct | 1696 | const struct |
1532 | GNUNET_PeerIdentity * peer) | 1697 | GNUNET_PeerIdentity * peer) |
1533 | { | 1698 | { |
1534 | // FIXME: remove all pending requests from this | 1699 | GNUNET_CONTAINER_multihashmap_get_multiple (requests_by_peer, |
1535 | // peer from our memory | 1700 | &peer->hashPubKey, |
1536 | // (iterate over request_map) | 1701 | &destroy_request, |
1702 | (void*) peer); | ||
1537 | } | 1703 | } |
1538 | 1704 | ||
1539 | 1705 | ||
@@ -1565,6 +1731,7 @@ forward_get_request (void *cls, | |||
1565 | * the target buffer "buf". "buf" will be | 1731 | * the target buffer "buf". "buf" will be |
1566 | * NULL and "size" zero if the socket was closed for | 1732 | * NULL and "size" zero if the socket was closed for |
1567 | * writing in the meantime. In that case, only | 1733 | * writing in the meantime. In that case, only |
1734 | |||
1568 | * free the message | 1735 | * free the message |
1569 | * | 1736 | * |
1570 | * @param cls closure, pointer to the message | 1737 | * @param cls closure, pointer to the message |
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index d7e5ada54..c0e64b3f4 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -24,6 +24,7 @@ libgnunetutil_la_SOURCES = \ | |||
24 | configuration.c \ | 24 | configuration.c \ |
25 | connection.c \ | 25 | connection.c \ |
26 | container_bloomfilter.c \ | 26 | container_bloomfilter.c \ |
27 | container_heap.c \ | ||
27 | container_meta_data.c \ | 28 | container_meta_data.c \ |
28 | container_multihashmap.c \ | 29 | container_multihashmap.c \ |
29 | crypto_aes.c \ | 30 | crypto_aes.c \ |
diff --git a/src/util/container_heap.c b/src/util/container_heap.c index b5ccd7950..7e41c40f2 100644 --- a/src/util/container_heap.c +++ b/src/util/container_heap.c | |||
@@ -26,8 +26,7 @@ | |||
26 | 26 | ||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_protocols.h" | 28 | #include "gnunet_protocols.h" |
29 | #include "gnunet_util.h" | 29 | #include "gnunet_util_lib.h" |
30 | #include "gnunet_util_containers.h" | ||
31 | 30 | ||
32 | /* | 31 | /* |
33 | * Struct that is stored in hashmap, pointers to | 32 | * Struct that is stored in hashmap, pointers to |
@@ -65,7 +64,7 @@ struct GNUNET_CONTAINER_Heap | |||
65 | 64 | ||
66 | unsigned int max_size; | 65 | unsigned int max_size; |
67 | 66 | ||
68 | enum type; | 67 | enum GNUNET_CONTAINER_HeapOrder type; |
69 | 68 | ||
70 | struct GNUNET_CONTAINER_heap_node *root; | 69 | struct GNUNET_CONTAINER_heap_node *root; |
71 | 70 | ||
@@ -96,7 +95,7 @@ printTree (struct GNUNET_CONTAINER_Heap *root) | |||
96 | } | 95 | } |
97 | 96 | ||
98 | struct GNUNET_CONTAINER_Heap * | 97 | struct GNUNET_CONTAINER_Heap * |
99 | GNUNET_CONTAINER_heap_create (enum type) | 98 | GNUNET_CONTAINER_heap_create (enum GNUNET_CONTAINER_HeapOrder type) |
100 | { | 99 | { |
101 | struct GNUNET_CONTAINER_Heap *heap; | 100 | struct GNUNET_CONTAINER_Heap *heap; |
102 | heap = malloc (sizeof (struct GNUNET_CONTAINER_Heap)); | 101 | heap = malloc (sizeof (struct GNUNET_CONTAINER_Heap)); |
@@ -491,7 +490,7 @@ internal_iterator (struct GNUNET_CONTAINER_Heap *root, | |||
491 | return; | 490 | return; |
492 | internal_iterator (root, node->left_child, iterator, cls); | 491 | internal_iterator (root, node->left_child, iterator, cls); |
493 | internal_iterator (root, node->right_child, iterator, cls); | 492 | internal_iterator (root, node->right_child, iterator, cls); |
494 | iterator (node->element, node->cost, root, cls); | 493 | iterator (cls, node->element, node->cost); |
495 | } | 494 | } |
496 | 495 | ||
497 | int | 496 | int |
@@ -519,7 +518,7 @@ GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *root) | |||
519 | 518 | ||
520 | element = root->traversal_pos->element; | 519 | element = root->traversal_pos->element; |
521 | 520 | ||
522 | choice = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 2); | 521 | choice = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2); |
523 | 522 | ||
524 | switch (choice) | 523 | switch (choice) |
525 | { | 524 | { |