aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-08-30 21:37:12 +0000
committerChristian Grothoff <christian@grothoff.org>2009-08-30 21:37:12 +0000
commit0634957156088bc3c53d787c13ba3006307d8ca5 (patch)
tree5610330dc34ec07c8cc72e2a12d011006c00275c /src
parentc3d7c40c3cd0ec03c7f6b27e6b5f7eac1aa80ed5 (diff)
downloadgnunet-0634957156088bc3c53d787c13ba3006307d8ca5.tar.gz
gnunet-0634957156088bc3c53d787c13ba3006307d8ca5.zip
adding listing of indexed files
Diffstat (limited to 'src')
-rw-r--r--src/fs/fs.h23
-rw-r--r--src/fs/fs_unindex.c211
-rw-r--r--src/include/gnunet_fs_service.h12
-rw-r--r--src/include/gnunet_protocols.h17
4 files changed, 258 insertions, 5 deletions
diff --git a/src/fs/fs.h b/src/fs/fs.h
index e4eee7fd0..9fc15e62f 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -671,6 +671,29 @@ struct IndexStartMessage
671}; 671};
672 672
673 673
674/**
675 * Message send by FS service in response to a request
676 * asking for a list of all indexed files.
677 */
678struct IndexInfoMessage
679{
680 /**
681 * Message type will be
682 * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
683 */
684 struct GNUNET_MessageHeader header;
685
686 /**
687 * Hash of the indexed file.
688 */
689 GNUNET_HashCode file_id;
690
691 /* this is followed by a 0-terminated
692 filename of a file with the hash
693 "file_id" as seen by the client */
694
695};
696
674 697
675#endif 698#endif
676 699
diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c
index 8fb13a644..c32a10cbf 100644
--- a/src/fs/fs_unindex.c
+++ b/src/fs/fs_unindex.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2003, 2004, 2006 Christian Grothoff (and other contributing authors) 3 (C) 2003, 2004, 2006, 2009 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -29,21 +29,228 @@
29 */ 29 */
30 30
31#include "platform.h" 31#include "platform.h"
32#include "gnunet_constants.h"
32#include "gnunet_fs_service.h" 33#include "gnunet_fs_service.h"
34#include "gnunet_protocols.h"
33#include "fs.h" 35#include "fs.h"
34 36
37
38/**
39 * Context for "GNUNET_FS_get_indexed_files".
40 */
41struct GetIndexedContext
42{
43 /**
44 * Handle to global FS context.
45 */
46 struct GNUNET_FS_Handle *h;
47
48 /**
49 * Connection to the FS service.
50 */
51 struct GNUNET_CLIENT_Connection *client;
52
53 /**
54 * Function to call for each indexed file.
55 */
56 GNUNET_FS_IndexedFileProcessor iterator;
57
58 /**
59 * Closure for iterator.
60 */
61 void *iterator_cls;
62
63 /**
64 * Continuation to trigger at the end.
65 */
66 GNUNET_SCHEDULER_Task cont;
67
68 /**
69 * Closure for cont.
70 */
71 void *cont_cls;
72};
73
74
75/**
76 * Function called on each response from the FS
77 * service with information about indexed files.
78 *
79 * @param cls closure (of type "struct GetIndexedContext*")
80 * @param msg message with indexing information
81 */
82static void
83handle_index_info (void *cls,
84 const struct GNUNET_MessageHeader *msg)
85{
86 struct GetIndexedContext *gic = cls;
87 const struct IndexInfoMessage *iim;
88 uint16_t msize;
89 const char *filename;
90
91 if (NULL == msg)
92 {
93 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
94 _("Failed to receive response for `%s' request from `%s' service.\n"),
95 "GET_INDEXED",
96 "fs");
97 GNUNET_SCHEDULER_add_continuation (gic->h->sched,
98 GNUNET_NO,
99 gic->cont,
100 gic->cont_cls,
101 GNUNET_SCHEDULER_REASON_TIMEOUT);
102 GNUNET_CLIENT_disconnect (gic->client);
103 GNUNET_free (gic);
104 return;
105 }
106 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END)
107 {
108 /* normal end-of-list */
109 GNUNET_SCHEDULER_add_continuation (gic->h->sched,
110 GNUNET_NO,
111 gic->cont,
112 gic->cont_cls,
113 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
114 GNUNET_CLIENT_disconnect (gic->client);
115 GNUNET_free (gic);
116 return;
117 }
118 msize = ntohs (msg->size);
119 iim = (const struct IndexInfoMessage*) msg;
120 filename = (const char*) &iim[1];
121 if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY) ||
122 (msize <= sizeof (struct IndexInfoMessage)) ||
123 (filename[msize-sizeof (struct IndexInfoMessage) -1] != '\0') )
124 {
125 /* bogus reply */
126 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
127 _("Failed to receive valid response for `%s' request from `%s' service.\n"),
128 "GET_INDEXED",
129 "fs");
130 GNUNET_SCHEDULER_add_continuation (gic->h->sched,
131 GNUNET_NO,
132 gic->cont,
133 gic->cont_cls,
134 GNUNET_SCHEDULER_REASON_TIMEOUT);
135 GNUNET_CLIENT_disconnect (gic->client);
136 GNUNET_free (gic);
137 return;
138 }
139 if (GNUNET_OK !=
140 gic->iterator (gic->iterator_cls,
141 filename,
142 &iim->file_id))
143 {
144 GNUNET_SCHEDULER_add_continuation (gic->h->sched,
145 GNUNET_NO,
146 gic->cont,
147 gic->cont_cls,
148 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
149 GNUNET_CLIENT_disconnect (gic->client);
150 GNUNET_free (gic);
151 return;
152 }
153 /* get more */
154 GNUNET_CLIENT_receive (gic->client,
155 &handle_index_info,
156 gic,
157 GNUNET_CONSTANTS_SERVICE_TIMEOUT);
158}
159
160
161/**
162 * Transmit the request to get a list of all
163 * indexed files to the "FS" service.
164 *
165 * @param cls closure (of type "struct GetIndexedContext*")
166 * @param size number of bytes availabe in buf
167 * @param buf where to write the message, NULL on error
168 * @return number of bytes written to buf
169 */
170static size_t
171transmit_get_indexed (void *cls,
172 size_t size,
173 void *buf)
174{
175 struct GetIndexedContext *gic = cls;
176 struct GNUNET_MessageHeader *hdr;
177
178 if (NULL == buf)
179 {
180 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
181 _("Failed to transmit `%s' request to `%s' service.\n"),
182 "GET_INDEXED",
183 "fs");
184 GNUNET_SCHEDULER_add_continuation (gic->h->sched,
185 GNUNET_NO,
186 gic->cont,
187 gic->cont_cls,
188 GNUNET_SCHEDULER_REASON_TIMEOUT);
189 GNUNET_CLIENT_disconnect (gic->client);
190 GNUNET_free (gic);
191 return 0;
192 }
193 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
194 hdr = buf;
195 hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
196 hdr->type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET);
197 GNUNET_CLIENT_receive (gic->client,
198 &handle_index_info,
199 gic,
200 GNUNET_CONSTANTS_SERVICE_TIMEOUT);
201 return sizeof (struct GNUNET_MessageHeader);
202}
203
204
35/** 205/**
36 * Iterate over all indexed files. 206 * Iterate over all indexed files.
37 * 207 *
38 * @param h handle to the file sharing subsystem 208 * @param h handle to the file sharing subsystem
39 * @param iterator function to call on each indexed file 209 * @param iterator function to call on each indexed file
40 * @param iterator_cls closure for iterator 210 * @param iterator_cls closure for iterator
211 * @param cont continuation to call when done;
212 * reason should be "TIMEOUT" (on
213 * error) or "PREREQ_DONE" (on success)
214 * @param cont_cls closure for cont
41 */ 215 */
42void 216void
43GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h, 217GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
44 GNUNET_FS_IndexedFileProcessor iterator, 218 GNUNET_FS_IndexedFileProcessor iterator,
45 void *iterator_cls) 219 void *iterator_cls,
220 GNUNET_SCHEDULER_Task cont,
221 void *cont_cls)
46{ 222{
223 struct GNUNET_CLIENT_Connection *client;
224 struct GetIndexedContext *gic;
225
226 client = GNUNET_CLIENT_connect (h->sched,
227 "fs",
228 h->cfg);
229 if (NULL == client)
230 {
231 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
232 _("Failed to not connect to `%s' service.\n"),
233 "fs");
234 GNUNET_SCHEDULER_add_continuation (h->sched,
235 GNUNET_NO,
236 cont,
237 cont_cls,
238 GNUNET_SCHEDULER_REASON_TIMEOUT);
239 return;
240 }
241
242 gic = GNUNET_malloc (sizeof (struct GetIndexedContext));
243 gic->h = h;
244 gic->client = client;
245 gic->iterator = iterator;
246 gic->iterator_cls = iterator_cls;
247 gic->cont = cont;
248 gic->cont_cls = cont_cls;
249 GNUNET_CLIENT_notify_transmit_ready (client,
250 sizeof (struct GNUNET_MessageHeader),
251 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
252 &transmit_get_indexed,
253 gic);
47} 254}
48 255
49 256
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h
index d0032f72d..994c6eb15 100644
--- a/src/include/gnunet_fs_service.h
+++ b/src/include/gnunet_fs_service.h
@@ -1897,10 +1897,12 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
1897 * 1897 *
1898 * @param cls closure 1898 * @param cls closure
1899 * @param filename the name of the file 1899 * @param filename the name of the file
1900 * @param file_id hash of the contents of the indexed file
1900 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort 1901 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
1901 */ 1902 */
1902typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls, 1903typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls,
1903 const char *filename); 1904 const char *filename,
1905 const GNUNET_HashCode *file_id);
1904 1906
1905 1907
1906/** 1908/**
@@ -1909,11 +1911,17 @@ typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls,
1909 * @param h handle to the file sharing subsystem 1911 * @param h handle to the file sharing subsystem
1910 * @param iterator function to call on each indexed file 1912 * @param iterator function to call on each indexed file
1911 * @param iterator_cls closure for iterator 1913 * @param iterator_cls closure for iterator
1914 * @param cont continuation to call when done;
1915 * reason should be "TIMEOUT" (on
1916 * error) or "PREREQ_DONE" (on success)
1917 * @param cont_cls closure for cont
1912 */ 1918 */
1913void 1919void
1914GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h, 1920GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
1915 GNUNET_FS_IndexedFileProcessor iterator, 1921 GNUNET_FS_IndexedFileProcessor iterator,
1916 void *iterator_cls); 1922 void *iterator_cls,
1923 GNUNET_SCHEDULER_Task cont,
1924 void *cont_cls);
1917 1925
1918 1926
1919/** 1927/**
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 686205c31..5a11f29e9 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -378,13 +378,28 @@ extern "C"
378 */ 378 */
379#define GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK 129 379#define GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK 129
380 380
381
382/** 381/**
383 * Response to a request for start indexing that 382 * Response to a request for start indexing that
384 * refuses. 383 * refuses.
385 */ 384 */
386#define GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED 130 385#define GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED 130
387 386
387/**
388 * Request from client for list of indexed files.
389 */
390#define GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET 131
391
392/**
393 * Reply to client with an indexed file name.
394 */
395#define GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY 132
396
397/**
398 * Reply to client indicating end of list.
399 */
400#define GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END 133
401
402
388/* 403/*
389 TODO: 404 TODO:
390 - DV 405 - DV