aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-09-11 09:09:39 +0000
committerChristian Grothoff <christian@grothoff.org>2009-09-11 09:09:39 +0000
commitfa9d1957520372ba3575296f1edb53f48fe2b000 (patch)
tree0504977c793fd7b6494b80ae4627d8a4e087a618 /src/fs
parent6806de7c91b4221d161a71e2d6c20049a943781d (diff)
downloadgnunet-fa9d1957520372ba3575296f1edb53f48fe2b000.tar.gz
gnunet-fa9d1957520372ba3575296f1edb53f48fe2b000.zip
fs
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/gnunet-service-fs.c236
-rw-r--r--src/fs/test_fs_directory.c10
2 files changed, 232 insertions, 14 deletions
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c
index 253fd24b2..18cb69d68 100644
--- a/src/fs/gnunet-service-fs.c
+++ b/src/fs/gnunet-service-fs.c
@@ -30,22 +30,202 @@
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "fs.h" 31#include "fs.h"
32 32
33static struct GNUNET_DATASTORE_Handle *dsh;
34
35/**
36 * Handle INDEX_START-message.
37 *
38 * @param cls closure
39 * @param client identification of the client
40 * @param message the actual message
41 */
42static void
43handle_index_start (void *cls,
44 struct GNUNET_SERVER_Client *client,
45 const struct GNUNET_MessageHeader *message)
46{
47 const struct IndexStartMessage *ism;
48 const char *fn;
49 uint16_t msize;
50
51 msize = ntohs(message->size);
52 if ( (msize <= sizeof (struct IndexStartMessage)) ||
53 ( ((const char *)message)[msize-1] != '\0') )
54 {
55 GNUNET_break (0);
56 GNUNET_SERVER_receive_done (client,
57 GNUNET_SYSERR);
58 return;
59 }
60 ism = (const struct IndexStartMessage*) message;
61 fn = (const char*) &ism[1];
62 // FIXME: store fn, hash, check, respond to client, etc.
63}
33 64
34 65
35/** 66/**
36 * Handle GET-message. 67 * Handle INDEX_LIST_GET-message.
37 * 68 *
38 * @param cls closure 69 * @param cls closure
39 * @param client identification of the client 70 * @param client identification of the client
40 * @param message the actual message 71 * @param message the actual message
41 * @return GNUNET_OK to keep the connection open,
42 * GNUNET_SYSERR to close it (signal serious error)
43 */ 72 */
44static void 73static void
45handle_xxx (void *cls, 74handle_index_list_get (void *cls,
46 struct GNUNET_SERVER_Client *client, 75 struct GNUNET_SERVER_Client *client,
47 const struct GNUNET_MessageHeader *message) 76 const struct GNUNET_MessageHeader *message)
48{ 77{
78 struct GNUNET_SERVER_TransmitContext *tc;
79 struct IndexInfoMessage *iim;
80 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
81 size_t slen;
82 char *fn;
83 struct GNUNET_MessageHeader *msg;
84
85 tc = GNUNET_SERVER_transmit_context_create (client);
86 iim = (struct IndexInfoMessage*) buf;
87 msg = &iim->header;
88 while (0)
89 {
90 iim->reserved = 0;
91 // FIXME: read actual list of indexed files...
92 // iim->file_id = id;
93 fn = "FIXME";
94 slen = strlen (fn) + 1;
95 if (slen + sizeof (struct IndexInfoMessage) >
96 GNUNET_SERVER_MAX_MESSAGE_SIZE)
97 {
98 GNUNET_break (0);
99 break;
100 }
101 memcpy (&iim[1], fn, slen);
102 GNUNET_SERVER_transmit_context_append
103 (tc,
104 &msg[1],
105 sizeof (struct IndexInfoMessage)
106 - sizeof (struct GNUNET_MessageHeader) + slen,
107 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
108 }
109 GNUNET_SERVER_transmit_context_append (tc,
110 NULL, 0,
111 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
112 GNUNET_SERVER_transmit_context_run (tc,
113 GNUNET_TIME_UNIT_MINUTES);
114}
115
116
117/**
118 * Handle UNINDEX-message.
119 *
120 * @param cls closure
121 * @param client identification of the client
122 * @param message the actual message
123 */
124static void
125handle_unindex (void *cls,
126 struct GNUNET_SERVER_Client *client,
127 const struct GNUNET_MessageHeader *message)
128{
129 const struct UnindexMessage *um;
130 struct GNUNET_SERVER_TransmitContext *tc;
131
132 um = (const struct UnindexMessage*) message;
133 // fixme: process!
134 tc = GNUNET_SERVER_transmit_context_create (client);
135 GNUNET_SERVER_transmit_context_append (tc,
136 NULL, 0,
137 GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK);
138 GNUNET_SERVER_transmit_context_run (tc,
139 GNUNET_TIME_UNIT_MINUTES);
140}
141
142
143/**
144 * FIXME
145 *
146 * @param cls closure
147 * @param ok GNUNET_OK if DS is ready, GNUNET_SYSERR on timeout
148 */
149typedef void (*RequestFunction)(void *cls,
150 int ok);
151
152
153/**
154 * Run the next DS request in our
155 * queue, we're done with the current one.
156 */
157static void
158next_ds_request ()
159{
160}
161
162
163/**
164 * FIXME.
165 */
166static void
167queue_ds_request (struct GNUNET_TIME_Relative deadline,
168 RequestFunction fun,
169 void *fun_cls)
170{
171}
172
173
174
175/**
176 * Closure for processing START_SEARCH
177 * messages from a client.
178 */
179struct LocalGetContext
180{
181 /**
182 * Client that initiated the search.
183 */
184 struct GNUNET_SERVER_Client *client;
185
186};
187
188
189/**
190 * Handle START_SEARCH-message.
191 *
192 * @param cls closure
193 * @param client identification of the client
194 * @param message the actual message
195 */
196static void
197handle_start_search (void *cls,
198 struct GNUNET_SERVER_Client *client,
199 const struct GNUNET_MessageHeader *message)
200{
201 const struct SearchMessage *sm;
202 struct LocalGetContext *lgc;
203
204 sm = (const struct SearchMessage*) message;
205 GNUNET_SERVER_client_keep (client);
206 lgc = GNUNET_malloc (sizeof (struct LocalGetContext));
207 lgc->client = client;
208 lgc->x = y;
209 queue_ds_request (&transmit_local_get,
210 lgc);
211}
212
213
214static void
215transmit_local_get (void *cls,
216 int ok)
217{
218 struct LocalGetContext *lgc = cls;
219 // FIXME: search locally
220
221 GNUNET_assert (GNUNET_OK == ok);
222 GNUNET_SERVER_receive_done (lgc->client,
223 GNUNET_OK);
224
225 // FIXME: if not found, initiate P2P search
226
227 // FIXME: once done with "client" handle:
228 GNUNET_SERVER_client_drop (lgc->client);
49} 229}
50 230
51 231
@@ -54,15 +234,35 @@ handle_xxx (void *cls,
54 * service. 234 * service.
55 */ 235 */
56static struct GNUNET_SERVER_MessageHandler handlers[] = { 236static struct GNUNET_SERVER_MessageHandler handlers[] = {
57 {&handle_xxx, NULL, GNUNET_MESSAGE_TYPE_FS_INDEX_START, 0}, 237 {&handle_index_start, NULL,
58 {&handle_xxx, NULL, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, 0}, 238 GNUNET_MESSAGE_TYPE_FS_INDEX_START, 0},
59 {&handle_xxx, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX, 0}, 239 {&handle_index_list_get, NULL,
60 {&handle_xxx, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH, 0}, 240 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, sizeof(struct GNUNET_MessageHeader) },
241 {&handle_unindex, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX,
242 sizeof (struct UnindexMessage) },
243 {&handle_start_search, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH,
244 sizeof (struct SearchMessage) },
61 {NULL, NULL, 0, 0} 245 {NULL, NULL, 0, 0}
62}; 246};
63 247
64 248
65/** 249/**
250 * Task run during shutdown.
251 *
252 * @param cls unused
253 * @param tc unused
254 */
255static void
256shutdown_task (void *cls,
257 const struct GNUNET_SCHEDULER_TaskContext *tc)
258{
259 GNUNET_DATASTORE_disconnect (dsh,
260 GNUNET_NO);
261 dsh = NULL;
262}
263
264
265/**
66 * Process fs requests. 266 * Process fs requests.
67 * 267 *
68 * @param cls closure 268 * @param cls closure
@@ -76,8 +276,24 @@ run (void *cls,
76 struct GNUNET_SERVER_Handle *server, 276 struct GNUNET_SERVER_Handle *server,
77 const struct GNUNET_CONFIGURATION_Handle *cfg) 277 const struct GNUNET_CONFIGURATION_Handle *cfg)
78{ 278{
279 dsh = GNUNET_DATASTORE_connect (cfg,
280 sched);
281 if (NULL == dsh)
282 {
283 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
284 _("Failed to connect to datastore service.\n"));
285 return;
286 }
79 GNUNET_SERVER_add_handlers (server, handlers); 287 GNUNET_SERVER_add_handlers (server, handlers);
80 // FIXME: also handle P2P messages! 288 // FIXME: also handle P2P messages!
289
290 GNUNET_SCHEDULER_add_delayed (sched,
291 GNUNET_YES,
292 GNUNET_SCHEDULER_PRIORITY_IDLE,
293 GNUNET_SCHEDULER_NO_TASK,
294 GNUNET_TIME_UNIT_FOREVER_REL,
295 &shutdown_task,
296 NULL);
81} 297}
82 298
83 299
diff --git a/src/fs/test_fs_directory.c b/src/fs/test_fs_directory.c
index 31a9869f3..1f77dcf14 100644
--- a/src/fs/test_fs_directory.c
+++ b/src/fs/test_fs_directory.c
@@ -91,7 +91,6 @@ testDirectory (unsigned int i)
91 meta = GNUNET_CONTAINER_meta_data_create (); 91 meta = GNUNET_CONTAINER_meta_data_create ();
92 GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_TITLE, "A title"); 92 GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_TITLE, "A title");
93 GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_AUTHOR, "An author"); 93 GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_AUTHOR, "An author");
94 db = GNUNET_FS_directory_builder_create (meta);
95 for (p = 0; p < i; p++) 94 for (p = 0; p < i; p++)
96 { 95 {
97 mds[p] = GNUNET_CONTAINER_meta_data_create (); 96 mds[p] = GNUNET_CONTAINER_meta_data_create ();
@@ -120,16 +119,19 @@ testDirectory (unsigned int i)
120 GNUNET_free (uris); 119 GNUNET_free (uris);
121 ABORT (); /* error in testcase */ 120 ABORT (); /* error in testcase */
122 } 121 }
123 GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL);
124 } 122 }
125 start = GNUNET_TIME_absolute_get (); 123 start = GNUNET_TIME_absolute_get ();
124 db = GNUNET_FS_directory_builder_create (meta);
125 for (p = 0; p < i; p++)
126 GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL);
126 GNUNET_FS_directory_builder_finish (db, 127 GNUNET_FS_directory_builder_finish (db,
127 &dlen, 128 &dlen,
128 (void**) &data); 129 (void**) &data);
129 s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start)); 130 s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start));
130 fprintf (stdout, 131 fprintf (stdout,
131 "Creating directory with %u entires took %s\n", 132 "Creating directory with %u entires and total size %llu took %s\n",
132 i, 133 i,
134 (unsigned long long) dlen,
133 s); 135 s);
134 GNUNET_free (s); 136 GNUNET_free (s);
135 if (i < 1000) 137 if (i < 1000)
@@ -167,7 +169,7 @@ main (int argc, char *argv[])
167 "WARNING", 169 "WARNING",
168#endif 170#endif
169 NULL); 171 NULL);
170 for (i = 17; i < 10000; i *= 2) 172 for (i = 17; i < 4000; i *= 2)
171 failureCount += testDirectory (i); 173 failureCount += testDirectory (i);
172 fprintf (stderr, "\n"); 174 fprintf (stderr, "\n");
173 175