diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-05-03 21:11:14 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-05-03 21:11:14 +0000 |
commit | 4092583a7dcb0844d5957909ef81f6766b3f2603 (patch) | |
tree | 84ef0918fa8a3cbdac9d5844577958f2727967c8 /src/fs/fs_search.c | |
parent | 1d59315240c1d0667c9777caf6ff54c7ec1346ce (diff) | |
download | gnunet-4092583a7dcb0844d5957909ef81f6766b3f2603.tar.gz gnunet-4092583a7dcb0844d5957909ef81f6766b3f2603.zip |
allow linking of downloads to search results
Diffstat (limited to 'src/fs/fs_search.c')
-rw-r--r-- | src/fs/fs_search.c | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index a9670cb43..611a089c4 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c | |||
@@ -73,7 +73,7 @@ GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | |||
73 | * | 73 | * |
74 | * @param cls points to the URI we check against | 74 | * @param cls points to the URI we check against |
75 | * @param key not used | 75 | * @param key not used |
76 | * @param value a "struct SearchResult" who's URI we | 76 | * @param value a "struct GNUNET_FS_SearchResult" who's URI we |
77 | * should compare with | 77 | * should compare with |
78 | * @return GNUNET_SYSERR if the result is present, | 78 | * @return GNUNET_SYSERR if the result is present, |
79 | * GNUNET_OK otherwise | 79 | * GNUNET_OK otherwise |
@@ -84,7 +84,7 @@ test_result_present (void *cls, | |||
84 | void *value) | 84 | void *value) |
85 | { | 85 | { |
86 | const struct GNUNET_FS_Uri *uri = cls; | 86 | const struct GNUNET_FS_Uri *uri = cls; |
87 | struct SearchResult *sr = value; | 87 | struct GNUNET_FS_SearchResult *sr = value; |
88 | 88 | ||
89 | if (GNUNET_FS_uri_test_equal (uri, | 89 | if (GNUNET_FS_uri_test_equal (uri, |
90 | sr->uri)) | 90 | sr->uri)) |
@@ -102,13 +102,14 @@ test_result_present (void *cls, | |||
102 | */ | 102 | */ |
103 | static void | 103 | static void |
104 | notify_client_chk_result (struct GNUNET_FS_SearchContext *sc, | 104 | notify_client_chk_result (struct GNUNET_FS_SearchContext *sc, |
105 | struct SearchResult *sr) | 105 | struct GNUNET_FS_SearchResult *sr) |
106 | { | 106 | { |
107 | struct GNUNET_FS_ProgressInfo pi; | 107 | struct GNUNET_FS_ProgressInfo pi; |
108 | 108 | ||
109 | pi.status = GNUNET_FS_STATUS_SEARCH_RESULT; | 109 | pi.status = GNUNET_FS_STATUS_SEARCH_RESULT; |
110 | pi.value.search.specifics.result.meta = sr->meta; | 110 | pi.value.search.specifics.result.meta = sr->meta; |
111 | pi.value.search.specifics.result.uri = sr->uri; | 111 | pi.value.search.specifics.result.uri = sr->uri; |
112 | pi.value.search.specifics.result.result = sr; | ||
112 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc); | 113 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc); |
113 | } | 114 | } |
114 | 115 | ||
@@ -122,7 +123,7 @@ notify_client_chk_result (struct GNUNET_FS_SearchContext *sc, | |||
122 | */ | 123 | */ |
123 | static void | 124 | static void |
124 | notify_client_chk_update (struct GNUNET_FS_SearchContext *sc, | 125 | notify_client_chk_update (struct GNUNET_FS_SearchContext *sc, |
125 | struct SearchResult *sr) | 126 | struct GNUNET_FS_SearchResult *sr) |
126 | { | 127 | { |
127 | struct GNUNET_FS_ProgressInfo pi; | 128 | struct GNUNET_FS_ProgressInfo pi; |
128 | 129 | ||
@@ -154,7 +155,7 @@ struct GetResultContext | |||
154 | * Where to store a pointer to the search | 155 | * Where to store a pointer to the search |
155 | * result struct if we found a match. | 156 | * result struct if we found a match. |
156 | */ | 157 | */ |
157 | struct SearchResult *sr; | 158 | struct GNUNET_FS_SearchResult *sr; |
158 | }; | 159 | }; |
159 | 160 | ||
160 | 161 | ||
@@ -164,7 +165,7 @@ struct GetResultContext | |||
164 | * | 165 | * |
165 | * @param cls a "struct GetResultContext" | 166 | * @param cls a "struct GetResultContext" |
166 | * @param key not used | 167 | * @param key not used |
167 | * @param value a "struct SearchResult" who's URI we | 168 | * @param value a "struct GNUNET_FS_SearchResult" who's URI we |
168 | * should compare with | 169 | * should compare with |
169 | * @return GNUNET_OK | 170 | * @return GNUNET_OK |
170 | */ | 171 | */ |
@@ -174,7 +175,7 @@ get_result_present (void *cls, | |||
174 | void *value) | 175 | void *value) |
175 | { | 176 | { |
176 | struct GetResultContext *grc = cls; | 177 | struct GetResultContext *grc = cls; |
177 | struct SearchResult *sr = value; | 178 | struct GNUNET_FS_SearchResult *sr = value; |
178 | 179 | ||
179 | if (GNUNET_FS_uri_test_equal (grc->uri, | 180 | if (GNUNET_FS_uri_test_equal (grc->uri, |
180 | sr->uri)) | 181 | sr->uri)) |
@@ -188,7 +189,7 @@ get_result_present (void *cls, | |||
188 | * probe. | 189 | * probe. |
189 | */ | 190 | */ |
190 | static void | 191 | static void |
191 | signal_probe_result (struct SearchResult *sr) | 192 | signal_probe_result (struct GNUNET_FS_SearchResult *sr) |
192 | { | 193 | { |
193 | struct GNUNET_FS_ProgressInfo pi; | 194 | struct GNUNET_FS_ProgressInfo pi; |
194 | 195 | ||
@@ -207,14 +208,14 @@ signal_probe_result (struct SearchResult *sr) | |||
207 | /** | 208 | /** |
208 | * Handle the case where we have failed to receive a response for our probe. | 209 | * Handle the case where we have failed to receive a response for our probe. |
209 | * | 210 | * |
210 | * @param cls our 'struct SearchResult*' | 211 | * @param cls our 'struct GNUNET_FS_SearchResult*' |
211 | * @param tc scheduler context | 212 | * @param tc scheduler context |
212 | */ | 213 | */ |
213 | static void | 214 | static void |
214 | probe_failure_handler (void *cls, | 215 | probe_failure_handler (void *cls, |
215 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 216 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
216 | { | 217 | { |
217 | struct SearchResult *sr = cls; | 218 | struct GNUNET_FS_SearchResult *sr = cls; |
218 | sr->availability_trials++; | 219 | sr->availability_trials++; |
219 | signal_probe_result (sr); | 220 | signal_probe_result (sr); |
220 | } | 221 | } |
@@ -223,14 +224,14 @@ probe_failure_handler (void *cls, | |||
223 | /** | 224 | /** |
224 | * Handle the case where we have gotten a response for our probe. | 225 | * Handle the case where we have gotten a response for our probe. |
225 | * | 226 | * |
226 | * @param cls our 'struct SearchResult*' | 227 | * @param cls our 'struct GNUNET_FS_SearchResult*' |
227 | * @param tc scheduler context | 228 | * @param tc scheduler context |
228 | */ | 229 | */ |
229 | static void | 230 | static void |
230 | probe_success_handler (void *cls, | 231 | probe_success_handler (void *cls, |
231 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 232 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
232 | { | 233 | { |
233 | struct SearchResult *sr = cls; | 234 | struct GNUNET_FS_SearchResult *sr = cls; |
234 | sr->availability_trials++; | 235 | sr->availability_trials++; |
235 | sr->availability_success++; | 236 | sr->availability_success++; |
236 | signal_probe_result (sr); | 237 | signal_probe_result (sr); |
@@ -256,7 +257,7 @@ void* | |||
256 | GNUNET_FS_search_probe_progress_ (void *cls, | 257 | GNUNET_FS_search_probe_progress_ (void *cls, |
257 | const struct GNUNET_FS_ProgressInfo *info) | 258 | const struct GNUNET_FS_ProgressInfo *info) |
258 | { | 259 | { |
259 | struct SearchResult *sr = info->value.download.cctx; | 260 | struct GNUNET_FS_SearchResult *sr = info->value.download.cctx; |
260 | struct GNUNET_TIME_Relative dur; | 261 | struct GNUNET_TIME_Relative dur; |
261 | 262 | ||
262 | switch (info->status) | 263 | switch (info->status) |
@@ -336,7 +337,7 @@ GNUNET_FS_search_probe_progress_ (void *cls, | |||
336 | * @param sr the search result | 337 | * @param sr the search result |
337 | */ | 338 | */ |
338 | void | 339 | void |
339 | GNUNET_FS_search_start_probe_ (struct SearchResult *sr) | 340 | GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr) |
340 | { | 341 | { |
341 | uint64_t off; | 342 | uint64_t off; |
342 | uint64_t len; | 343 | uint64_t len; |
@@ -391,7 +392,7 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc, | |||
391 | const struct GNUNET_CONTAINER_MetaData *meta) | 392 | const struct GNUNET_CONTAINER_MetaData *meta) |
392 | { | 393 | { |
393 | GNUNET_HashCode key; | 394 | GNUNET_HashCode key; |
394 | struct SearchResult *sr; | 395 | struct GNUNET_FS_SearchResult *sr; |
395 | struct GetResultContext grc; | 396 | struct GetResultContext grc; |
396 | int is_new; | 397 | int is_new; |
397 | 398 | ||
@@ -414,7 +415,7 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc, | |||
414 | is_new = (NULL == sr) || (sr->mandatory_missing > 0); | 415 | is_new = (NULL == sr) || (sr->mandatory_missing > 0); |
415 | if (NULL == sr) | 416 | if (NULL == sr) |
416 | { | 417 | { |
417 | sr = GNUNET_malloc (sizeof (struct SearchResult)); | 418 | sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult)); |
418 | sr->sc = sc; | 419 | sr->sc = sc; |
419 | sr->uri = GNUNET_FS_uri_dup (uri); | 420 | sr->uri = GNUNET_FS_uri_dup (uri); |
420 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); | 421 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); |
@@ -481,7 +482,7 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc, | |||
481 | { | 482 | { |
482 | struct GNUNET_FS_Uri uu; | 483 | struct GNUNET_FS_Uri uu; |
483 | GNUNET_HashCode key; | 484 | GNUNET_HashCode key; |
484 | struct SearchResult *sr; | 485 | struct GNUNET_FS_SearchResult *sr; |
485 | 486 | ||
486 | /* check if new */ | 487 | /* check if new */ |
487 | GNUNET_FS_uri_to_key (uri, &key); | 488 | GNUNET_FS_uri_to_key (uri, &key); |
@@ -494,7 +495,7 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc, | |||
494 | &test_result_present, | 495 | &test_result_present, |
495 | (void*) uri)) | 496 | (void*) uri)) |
496 | return; /* duplicate result */ | 497 | return; /* duplicate result */ |
497 | sr = GNUNET_malloc (sizeof (struct SearchResult)); | 498 | sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult)); |
498 | sr->sc = sc; | 499 | sr->sc = sc; |
499 | sr->uri = GNUNET_FS_uri_dup (uri); | 500 | sr->uri = GNUNET_FS_uri_dup (uri); |
500 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); | 501 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); |
@@ -1243,9 +1244,17 @@ search_result_free (void *cls, | |||
1243 | struct GNUNET_FS_SearchContext *sc = cls; | 1244 | struct GNUNET_FS_SearchContext *sc = cls; |
1244 | struct GNUNET_FS_Handle *h = sc->h; | 1245 | struct GNUNET_FS_Handle *h = sc->h; |
1245 | char pbuf[32]; | 1246 | char pbuf[32]; |
1246 | struct SearchResult *sr = value; | 1247 | struct GNUNET_FS_SearchResult *sr = value; |
1247 | struct GNUNET_FS_ProgressInfo pi; | 1248 | struct GNUNET_FS_ProgressInfo pi; |
1248 | 1249 | ||
1250 | if (NULL != sr->download) | ||
1251 | { | ||
1252 | sr->download->search = NULL; | ||
1253 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT; | ||
1254 | GNUNET_FS_download_make_status_ (&pi, | ||
1255 | sr->download); | ||
1256 | sr->download = NULL; | ||
1257 | } | ||
1249 | pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED; | 1258 | pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED; |
1250 | pi.value.search.specifics.result_stopped.cctx = sr->client_info; | 1259 | pi.value.search.specifics.result_stopped.cctx = sr->client_info; |
1251 | pi.value.search.specifics.result_stopped.meta = sr->meta; | 1260 | pi.value.search.specifics.result_stopped.meta = sr->meta; |