diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-02-01 13:02:01 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-02-01 13:02:01 +0000 |
commit | 36b60a0ac26d8102667c590587b8a0d33c203cc9 (patch) | |
tree | 42c455f1e79e8d06f33df822c6af1fd85877ed78 /src/fs | |
parent | 824c06e61fbd03c1680379670fb72dfc3a0f79ca (diff) | |
download | gnunet-36b60a0ac26d8102667c590587b8a0d33c203cc9.tar.gz gnunet-36b60a0ac26d8102667c590587b8a0d33c203cc9.zip |
die nicely
Diffstat (limited to 'src/fs')
-rw-r--r-- | src/fs/fs_download.c | 3 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs.c | 47 | ||||
-rw-r--r-- | src/fs/test_fs_download.c | 57 |
3 files changed, 88 insertions, 19 deletions
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 4b3d96082..b0e981b80 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c | |||
@@ -627,8 +627,7 @@ transmit_download_request (void *cls, | |||
627 | 627 | ||
628 | 628 | ||
629 | /** | 629 | /** |
630 | * Reconnect to the FS service and transmit | 630 | * Reconnect to the FS service and transmit our queries NOW. |
631 | * our queries NOW. | ||
632 | * | 631 | * |
633 | * @param cls our download context | 632 | * @param cls our download context |
634 | * @param tc unused | 633 | * @param tc unused |
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 6860c377a..ead8ea17d 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c | |||
@@ -46,6 +46,8 @@ | |||
46 | #include "gnunet-service-fs_indexing.h" | 46 | #include "gnunet-service-fs_indexing.h" |
47 | #include "fs.h" | 47 | #include "fs.h" |
48 | 48 | ||
49 | #define DEBUG_FS GNUNET_YES | ||
50 | |||
49 | /** | 51 | /** |
50 | * Maximum number of outgoing messages we queue per peer. | 52 | * Maximum number of outgoing messages we queue per peer. |
51 | * FIXME: set to a tiny value for testing; make configurable. | 53 | * FIXME: set to a tiny value for testing; make configurable. |
@@ -53,7 +55,6 @@ | |||
53 | #define MAX_QUEUE_PER_PEER 2 | 55 | #define MAX_QUEUE_PER_PEER 2 |
54 | 56 | ||
55 | 57 | ||
56 | |||
57 | /** | 58 | /** |
58 | * Maximum number of requests (from other peers) that we're | 59 | * Maximum number of requests (from other peers) that we're |
59 | * willing to have pending at any given point in time. | 60 | * willing to have pending at any given point in time. |
@@ -1661,7 +1662,11 @@ process_reply (void *cls, | |||
1661 | size_t msize; | 1662 | size_t msize; |
1662 | uint32_t prio; | 1663 | uint32_t prio; |
1663 | 1664 | ||
1664 | 1665 | #if DEBUG_FS | |
1666 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1667 | "Matched result for query `%s' with pending request\n", | ||
1668 | GNUNET_h2s (key)); | ||
1669 | #endif | ||
1665 | GNUNET_CRYPTO_hash (prq->data, | 1670 | GNUNET_CRYPTO_hash (prq->data, |
1666 | prq->size, | 1671 | prq->size, |
1667 | &chash); | 1672 | &chash); |
@@ -1717,6 +1722,11 @@ process_reply (void *cls, | |||
1717 | pr->remaining_priority = 0; | 1722 | pr->remaining_priority = 0; |
1718 | if (pr->client_request_list != NULL) | 1723 | if (pr->client_request_list != NULL) |
1719 | { | 1724 | { |
1725 | #if DEBUG_FS | ||
1726 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1727 | "Transmitting result for query `%s' to local client\n", | ||
1728 | GNUNET_h2s (key)); | ||
1729 | #endif | ||
1720 | cl = pr->client_request_list->client_list; | 1730 | cl = pr->client_request_list->client_list; |
1721 | msize = sizeof (struct PutMessage) + prq->size; | 1731 | msize = sizeof (struct PutMessage) + prq->size; |
1722 | creply = GNUNET_malloc (msize + sizeof (struct ClientResponseMessage)); | 1732 | creply = GNUNET_malloc (msize + sizeof (struct ClientResponseMessage)); |
@@ -1743,6 +1753,12 @@ process_reply (void *cls, | |||
1743 | else | 1753 | else |
1744 | { | 1754 | { |
1745 | cp = pr->pht_entry->cp; | 1755 | cp = pr->pht_entry->cp; |
1756 | #if DEBUG_FS | ||
1757 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1758 | "Transmitting result for query `%s' to other peer (PID=%u)\n", | ||
1759 | GNUNET_h2s (key), | ||
1760 | (unsigned int) cp->pid); | ||
1761 | #endif | ||
1746 | msize = sizeof (struct ContentMessage) + prq->size; | 1762 | msize = sizeof (struct ContentMessage) + prq->size; |
1747 | reply = GNUNET_malloc (msize + sizeof (struct PendingMessage)); | 1763 | reply = GNUNET_malloc (msize + sizeof (struct PendingMessage)); |
1748 | reply->cont = &transmit_reply_continuation; | 1764 | reply->cont = &transmit_reply_continuation; |
@@ -1834,6 +1850,12 @@ handle_p2p_put (void *cls, | |||
1834 | return GNUNET_SYSERR; | 1850 | return GNUNET_SYSERR; |
1835 | } | 1851 | } |
1836 | 1852 | ||
1853 | #if DEBUG_FS | ||
1854 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1855 | "Received result for query `%s' from peer `%4s'\n", | ||
1856 | GNUNET_h2s (&query), | ||
1857 | GNUNET_i2s (other)); | ||
1858 | #endif | ||
1837 | /* now, lookup 'query' */ | 1859 | /* now, lookup 'query' */ |
1838 | prq.data = (const void*) &put[1]; | 1860 | prq.data = (const void*) &put[1]; |
1839 | prq.size = dsize; | 1861 | prq.size = dsize; |
@@ -1921,11 +1943,16 @@ process_local_reply (void *cls, | |||
1921 | { | 1943 | { |
1922 | #if DEBUG_FS | 1944 | #if DEBUG_FS |
1923 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1945 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1924 | "Result from datastore filtered by bloomfilter.\n"); | 1946 | "Result from datastore filtered by bloomfilter (duplicate).\n"); |
1925 | #endif | 1947 | #endif |
1926 | GNUNET_FS_drq_get_next (GNUNET_YES); | 1948 | GNUNET_FS_drq_get_next (GNUNET_YES); |
1927 | return; | 1949 | return; |
1928 | } | 1950 | } |
1951 | #if DEBUG_FS | ||
1952 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1953 | "Found result for query `%s' in local datastore\n", | ||
1954 | GNUNET_h2s (key)); | ||
1955 | #endif | ||
1929 | pr->results_found++; | 1956 | pr->results_found++; |
1930 | if ( (pr->type == GNUNET_DATASTORE_BLOCKTYPE_KBLOCK) || | 1957 | if ( (pr->type == GNUNET_DATASTORE_BLOCKTYPE_KBLOCK) || |
1931 | (pr->type == GNUNET_DATASTORE_BLOCKTYPE_SBLOCK) || | 1958 | (pr->type == GNUNET_DATASTORE_BLOCKTYPE_SBLOCK) || |
@@ -2104,6 +2131,13 @@ handle_p2p_get (void *cls, | |||
2104 | return GNUNET_OK; | 2131 | return GNUNET_OK; |
2105 | } | 2132 | } |
2106 | 2133 | ||
2134 | #if DEBUG_FS | ||
2135 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2136 | "Received request for `%s' of type %u from peer `%4s'\n", | ||
2137 | GNUNET_h2s (&gm->query), | ||
2138 | (unsigned int) ntohl (gm->type), | ||
2139 | GNUNET_i2s (other)); | ||
2140 | #endif | ||
2107 | pr = GNUNET_malloc (sizeof (struct PendingRequest) + | 2141 | pr = GNUNET_malloc (sizeof (struct PendingRequest) + |
2108 | (bm & GET_MESSAGE_BIT_SKS_NAMESPACE)?sizeof(GNUNET_HashCode):0); | 2142 | (bm & GET_MESSAGE_BIT_SKS_NAMESPACE)?sizeof(GNUNET_HashCode):0); |
2109 | if ((bm & GET_MESSAGE_BIT_SKS_NAMESPACE)) | 2143 | if ((bm & GET_MESSAGE_BIT_SKS_NAMESPACE)) |
@@ -2259,7 +2293,12 @@ handle_start_search (void *cls, | |||
2259 | client_list = cl; | 2293 | client_list = cl; |
2260 | } | 2294 | } |
2261 | type = ntohl (sm->type); | 2295 | type = ntohl (sm->type); |
2262 | 2296 | #if DEBUG_FS | |
2297 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2298 | "Received request for `%s' of type %u from local client\n", | ||
2299 | GNUNET_h2s (&sm->query), | ||
2300 | (unsigned int) type); | ||
2301 | #endif | ||
2263 | /* FIXME: detect duplicate request; if duplicate, simply update (merge) | 2302 | /* FIXME: detect duplicate request; if duplicate, simply update (merge) |
2264 | 'pr->replies_seen'! */ | 2303 | 'pr->replies_seen'! */ |
2265 | pr = GNUNET_malloc (sizeof (struct PendingRequest) + | 2304 | pr = GNUNET_malloc (sizeof (struct PendingRequest) + |
diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c index f528203ad..5cb9e4111 100644 --- a/src/fs/test_fs_download.c +++ b/src/fs/test_fs_download.c | |||
@@ -68,15 +68,39 @@ static struct GNUNET_FS_DownloadContext *download; | |||
68 | 68 | ||
69 | static struct GNUNET_FS_PublishContext *publish; | 69 | static struct GNUNET_FS_PublishContext *publish; |
70 | 70 | ||
71 | static GNUNET_SCHEDULER_TaskIdentifier timeout_kill; | ||
72 | |||
71 | static char *fn; | 73 | static char *fn; |
72 | 74 | ||
75 | static int err; | ||
76 | |||
77 | static void | ||
78 | timeout_kill_task (void *cls, | ||
79 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
80 | { | ||
81 | if (publish != NULL) | ||
82 | { | ||
83 | GNUNET_FS_publish_stop (publish); | ||
84 | publish = NULL; | ||
85 | } | ||
86 | if (download != NULL) | ||
87 | { | ||
88 | GNUNET_FS_download_stop (download, GNUNET_YES); | ||
89 | download = NULL; | ||
90 | } | ||
91 | timeout_kill = GNUNET_SCHEDULER_NO_TASK; | ||
92 | err = 1; | ||
93 | } | ||
73 | 94 | ||
74 | static void | 95 | static void |
75 | abort_publish_task (void *cls, | 96 | abort_publish_task (void *cls, |
76 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 97 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
77 | { | 98 | { |
78 | GNUNET_FS_publish_stop (publish); | 99 | if (publish != NULL) |
79 | publish = NULL; | 100 | { |
101 | GNUNET_FS_publish_stop (publish); | ||
102 | publish = NULL; | ||
103 | } | ||
80 | } | 104 | } |
81 | 105 | ||
82 | 106 | ||
@@ -86,13 +110,18 @@ abort_download_task (void *cls, | |||
86 | { | 110 | { |
87 | uint64_t size; | 111 | uint64_t size; |
88 | 112 | ||
89 | GNUNET_FS_download_stop (download, GNUNET_YES); | 113 | if (download != NULL) |
90 | download = NULL; | 114 | { |
115 | GNUNET_FS_download_stop (download, GNUNET_YES); | ||
116 | download = NULL; | ||
117 | } | ||
91 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES)); | 118 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES)); |
92 | GNUNET_assert (size == FILESIZE); | 119 | GNUNET_assert (size == FILESIZE); |
93 | GNUNET_DISK_directory_remove (fn); | 120 | GNUNET_DISK_directory_remove (fn); |
94 | GNUNET_free (fn); | 121 | GNUNET_free (fn); |
95 | fn = NULL; | 122 | fn = NULL; |
123 | GNUNET_SCHEDULER_cancel (sched, timeout_kill); | ||
124 | timeout_kill = GNUNET_SCHEDULER_NO_TASK; | ||
96 | } | 125 | } |
97 | 126 | ||
98 | 127 | ||
@@ -132,10 +161,9 @@ progress_cb (void *cls, | |||
132 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 161 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
133 | printf ("Download complete, %llu kbps.\n", | 162 | printf ("Download complete, %llu kbps.\n", |
134 | (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024)); | 163 | (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024)); |
135 | GNUNET_SCHEDULER_add_continuation (sched, | 164 | GNUNET_SCHEDULER_add_now (sched, |
136 | &abort_download_task, | 165 | &abort_download_task, |
137 | NULL, | 166 | NULL); |
138 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
139 | break; | 167 | break; |
140 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 168 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
141 | GNUNET_assert (download == event->value.download.dc); | 169 | GNUNET_assert (download == event->value.download.dc); |
@@ -161,10 +189,9 @@ progress_cb (void *cls, | |||
161 | fprintf (stderr, | 189 | fprintf (stderr, |
162 | "Error downloading file: %s\n", | 190 | "Error downloading file: %s\n", |
163 | event->value.download.specifics.error.message); | 191 | event->value.download.specifics.error.message); |
164 | GNUNET_SCHEDULER_add_continuation (sched, | 192 | GNUNET_SCHEDULER_add_now (sched, |
165 | &abort_download_task, | 193 | &abort_download_task, |
166 | NULL, | 194 | NULL); |
167 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
168 | break; | 195 | break; |
169 | case GNUNET_FS_STATUS_PUBLISH_START: | 196 | case GNUNET_FS_STATUS_PUBLISH_START: |
170 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); | 197 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); |
@@ -282,6 +309,10 @@ run (void *cls, | |||
282 | GNUNET_FS_uri_destroy (kuri); | 309 | GNUNET_FS_uri_destroy (kuri); |
283 | GNUNET_CONTAINER_meta_data_destroy (meta); | 310 | GNUNET_CONTAINER_meta_data_destroy (meta); |
284 | GNUNET_assert (NULL != fi); | 311 | GNUNET_assert (NULL != fi); |
312 | timeout_kill = GNUNET_SCHEDULER_add_delayed (sched, | ||
313 | TIMEOUT, | ||
314 | &timeout_kill_task, | ||
315 | NULL); | ||
285 | start = GNUNET_TIME_absolute_get (); | 316 | start = GNUNET_TIME_absolute_get (); |
286 | publish = GNUNET_FS_publish_start (fs, | 317 | publish = GNUNET_FS_publish_start (fs, |
287 | fi, | 318 | fi, |
@@ -319,7 +350,7 @@ main (int argc, char *argv[]) | |||
319 | "nohelp", options, &run, NULL); | 350 | "nohelp", options, &run, NULL); |
320 | stop_arm (&p1); | 351 | stop_arm (&p1); |
321 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); | 352 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); |
322 | return 0; | 353 | return err; |
323 | } | 354 | } |
324 | 355 | ||
325 | /* end of test_fs_download.c */ | 356 | /* end of test_fs_download.c */ |