diff options
Diffstat (limited to 'src/migration/gnunet-daemon-migration.c')
-rw-r--r-- | src/migration/gnunet-daemon-migration.c | 378 |
1 files changed, 0 insertions, 378 deletions
diff --git a/src/migration/gnunet-daemon-migration.c b/src/migration/gnunet-daemon-migration.c deleted file mode 100644 index 0f0dbaebc..000000000 --- a/src/migration/gnunet-daemon-migration.c +++ /dev/null | |||
@@ -1,378 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2010 Christian Grothoff (and other contributing authors) | ||
4 | |||
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 | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file migration/gnunet-daemon-migration.c | ||
23 | * @brief migrating (file-sharing) content through the network; this | ||
24 | * daemon is only responsible for pushing content out (not for | ||
25 | * processing inbound messages) | ||
26 | * @author Christian Grothoff | ||
27 | */ | ||
28 | #include <stdlib.h> | ||
29 | #include "platform.h" | ||
30 | #include "../fs/fs.h" | ||
31 | #include "gnunet_constants.h" | ||
32 | #include "gnunet_core_service.h" | ||
33 | #include "gnunet_datastore_service.h" | ||
34 | #include "gnunet_protocols.h" | ||
35 | #include "gnunet_statistics_service.h" | ||
36 | #include "gnunet_util_lib.h" | ||
37 | |||
38 | |||
39 | #define DEBUG_MIGRATION GNUNET_YES | ||
40 | |||
41 | /** | ||
42 | * Information we keep per peer. | ||
43 | */ | ||
44 | struct Peer | ||
45 | { | ||
46 | /** | ||
47 | * Last time we migrated data to this peer. | ||
48 | */ | ||
49 | struct GNUNET_TIME_Absolute last_migration; | ||
50 | |||
51 | }; | ||
52 | |||
53 | |||
54 | /** | ||
55 | * Our scheduler. | ||
56 | */ | ||
57 | static struct GNUNET_SCHEDULER_Handle *sched; | ||
58 | |||
59 | /** | ||
60 | * Our configuration. | ||
61 | */ | ||
62 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
63 | |||
64 | /** | ||
65 | * Handle to the core API. | ||
66 | */ | ||
67 | static struct GNUNET_CORE_Handle *handle; | ||
68 | |||
69 | /** | ||
70 | * Handle for reporting statistics. | ||
71 | */ | ||
72 | static struct GNUNET_STATISTICS_Handle *stats; | ||
73 | |||
74 | /** | ||
75 | * Handle for the core service. | ||
76 | */ | ||
77 | static struct GNUNET_CORE_Handle *handle; | ||
78 | |||
79 | /** | ||
80 | * Handle to the datastore. | ||
81 | */ | ||
82 | static struct GNUNET_DATASTORE_Handle *datastore; | ||
83 | |||
84 | /** | ||
85 | * Anonymity level for the current block. | ||
86 | */ | ||
87 | static unsigned int current_anonymity; | ||
88 | |||
89 | /** | ||
90 | * Type of the current block. | ||
91 | */ | ||
92 | static enum GNUNET_BLOCK_Type current_type; | ||
93 | |||
94 | /** | ||
95 | * Data of the current block (already encrypted). | ||
96 | */ | ||
97 | static char current_block[GNUNET_SERVER_MAX_MESSAGE_SIZE]; | ||
98 | |||
99 | /** | ||
100 | * Size of the current block. | ||
101 | */ | ||
102 | static size_t current_block_size; | ||
103 | |||
104 | /** | ||
105 | * Key of the current block. | ||
106 | */ | ||
107 | static GNUNET_HashCode current_key; | ||
108 | |||
109 | /** | ||
110 | * Task scheduled to receive content from the datastore (with some delay). | ||
111 | */ | ||
112 | static GNUNET_SCHEDULER_TaskIdentifier get_task; | ||
113 | |||
114 | |||
115 | /** | ||
116 | * Select a peer for transmitting the current block to. | ||
117 | */ | ||
118 | static void | ||
119 | select_peer () | ||
120 | { | ||
121 | /* FIXME: select a peer for transmission... */ | ||
122 | } | ||
123 | |||
124 | |||
125 | /** | ||
126 | * Method called whenever a peer connects. | ||
127 | * | ||
128 | * @param cls closure | ||
129 | * @param peer peer identity this notification is about | ||
130 | * @param latency reported latency of the connection with 'other' | ||
131 | * @param distance reported distance (DV) to 'other' | ||
132 | */ | ||
133 | static void | ||
134 | connect_notify (void *cls, | ||
135 | const struct | ||
136 | GNUNET_PeerIdentity * peer, | ||
137 | struct GNUNET_TIME_Relative latency, | ||
138 | uint32_t distance) | ||
139 | { | ||
140 | /* FIXME: track peer */ | ||
141 | } | ||
142 | |||
143 | |||
144 | /** | ||
145 | * Method called whenever a peer disconnects. | ||
146 | * | ||
147 | * @param cls closure | ||
148 | * @param peer peer identity this notification is about | ||
149 | */ | ||
150 | static void | ||
151 | disconnect_notify (void *cls, | ||
152 | const struct | ||
153 | GNUNET_PeerIdentity * peer) | ||
154 | { | ||
155 | /* FIXME: untrack peer */ | ||
156 | } | ||
157 | |||
158 | |||
159 | /** | ||
160 | * Ask datastore for more content. | ||
161 | * @param cls closure | ||
162 | * @param tc scheduler context | ||
163 | */ | ||
164 | static void | ||
165 | get_content (void *cls, | ||
166 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
167 | |||
168 | |||
169 | /** | ||
170 | * An iterator over a set of items stored in the datastore. | ||
171 | * | ||
172 | * @param cls closure | ||
173 | * @param key key for the content | ||
174 | * @param size number of bytes in data | ||
175 | * @param data content stored | ||
176 | * @param type type of the content | ||
177 | * @param priority priority of the content | ||
178 | * @param anonymity anonymity-level for the content | ||
179 | * @param expiration expiration time for the content | ||
180 | * @param uid unique identifier for the datum; | ||
181 | * maybe 0 if no unique identifier is available | ||
182 | */ | ||
183 | static void | ||
184 | content_processor (void *cls, | ||
185 | const GNUNET_HashCode * key, | ||
186 | uint32_t size, | ||
187 | const void *data, | ||
188 | enum GNUNET_BLOCK_Type type, | ||
189 | uint32_t priority, | ||
190 | uint32_t anonymity, | ||
191 | struct GNUNET_TIME_Absolute | ||
192 | expiration, uint64_t uid) | ||
193 | { | ||
194 | if (key != NULL) | ||
195 | { | ||
196 | memcpy (current_block, data, size); | ||
197 | current_block_size = size; | ||
198 | current_type = type; | ||
199 | current_anonymity = anonymity; | ||
200 | current_key = *key; | ||
201 | return; | ||
202 | } | ||
203 | if (current_block_size == 0) | ||
204 | { | ||
205 | get_task = GNUNET_SCHEDULER_add_delayed (sched, | ||
206 | GNUNET_TIME_UNIT_MINUTES, | ||
207 | &get_content, | ||
208 | NULL); | ||
209 | return; | ||
210 | } | ||
211 | if (current_type == GNUNET_BLOCK_TYPE_ONDEMAND) | ||
212 | { | ||
213 | /* FIXME: do on-demand encoding... */ | ||
214 | return; | ||
215 | } | ||
216 | select_peer (); | ||
217 | } | ||
218 | |||
219 | |||
220 | /** | ||
221 | * Ask datastore for more content. | ||
222 | * @param cls closure | ||
223 | * @param tc scheduler context | ||
224 | */ | ||
225 | static void | ||
226 | get_content (void *cls, | ||
227 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
228 | { | ||
229 | get_task = GNUNET_SCHEDULER_NO_TASK; | ||
230 | GNUNET_DATASTORE_get_random (datastore, | ||
231 | 0, 1, | ||
232 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, | ||
233 | &content_processor, | ||
234 | NULL); | ||
235 | } | ||
236 | |||
237 | |||
238 | /** | ||
239 | * Function called after GNUNET_CORE_connect has succeeded | ||
240 | * (or failed for good). | ||
241 | * | ||
242 | * @param cls closure | ||
243 | * @param server handle to the server, NULL if we failed | ||
244 | * @param my_id ID of this peer, NULL if we failed | ||
245 | * @param publicKey public key of this peer, NULL if we failed | ||
246 | */ | ||
247 | static void | ||
248 | core_init (void *cls, | ||
249 | struct GNUNET_CORE_Handle * server, | ||
250 | const struct GNUNET_PeerIdentity * | ||
251 | my_id, | ||
252 | const struct | ||
253 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * | ||
254 | publicKey) | ||
255 | { | ||
256 | handle = server; | ||
257 | if (datastore != NULL) | ||
258 | get_task = GNUNET_SCHEDULER_add_now (sched, | ||
259 | &get_content, | ||
260 | NULL); | ||
261 | } | ||
262 | |||
263 | |||
264 | /** | ||
265 | * Last task run during shutdown. Disconnects us from | ||
266 | * the core. | ||
267 | * | ||
268 | * @param cls unused, NULL | ||
269 | * @param tc scheduler context | ||
270 | */ | ||
271 | static void | ||
272 | cleaning_task (void *cls, | ||
273 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
274 | { | ||
275 | if (get_task != GNUNET_SCHEDULER_NO_TASK) | ||
276 | { | ||
277 | GNUNET_SCHEDULER_cancel (sched, | ||
278 | get_task); | ||
279 | get_task = GNUNET_SCHEDULER_NO_TASK; | ||
280 | } | ||
281 | if (handle != NULL) | ||
282 | { | ||
283 | GNUNET_CORE_disconnect (handle); | ||
284 | handle = NULL; | ||
285 | } | ||
286 | if (datastore != NULL) | ||
287 | { | ||
288 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_NO); | ||
289 | datastore = NULL; | ||
290 | } | ||
291 | if (stats != NULL) | ||
292 | { | ||
293 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
294 | stats = NULL; | ||
295 | } | ||
296 | } | ||
297 | |||
298 | |||
299 | /** | ||
300 | * Main function that will be run. | ||
301 | * | ||
302 | * @param cls closure | ||
303 | * @param s the scheduler to use | ||
304 | * @param args remaining command-line arguments | ||
305 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
306 | * @param c configuration | ||
307 | */ | ||
308 | static void | ||
309 | run (void *cls, | ||
310 | struct GNUNET_SCHEDULER_Handle * s, | ||
311 | char *const *args, | ||
312 | const char *cfgfile, | ||
313 | const struct GNUNET_CONFIGURATION_Handle * c) | ||
314 | { | ||
315 | struct GNUNET_CORE_MessageHandler handlers[] = | ||
316 | { | ||
317 | { NULL, 0, 0 } | ||
318 | }; | ||
319 | sched = s; | ||
320 | cfg = c; | ||
321 | stats = GNUNET_STATISTICS_create (sched, "topology", cfg); | ||
322 | handle = GNUNET_CORE_connect (sched, | ||
323 | cfg, | ||
324 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
325 | NULL, | ||
326 | &core_init, | ||
327 | &connect_notify, | ||
328 | &disconnect_notify, | ||
329 | NULL, GNUNET_NO, | ||
330 | NULL, GNUNET_NO, | ||
331 | handlers); | ||
332 | datastore = GNUNET_DATASTORE_connect (cfg, sched); | ||
333 | GNUNET_SCHEDULER_add_delayed (sched, | ||
334 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
335 | &cleaning_task, NULL); | ||
336 | if ( (NULL == handle) || | ||
337 | (NULL == datastore) ) | ||
338 | { | ||
339 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
340 | _("Failed to connect to `%s' service.\n"), | ||
341 | (NULL == handle) ? "core" : "datastore"); | ||
342 | GNUNET_SCHEDULER_shutdown (sched); | ||
343 | return; | ||
344 | } | ||
345 | } | ||
346 | |||
347 | |||
348 | /** | ||
349 | * gnunet-daemon-topology command line options. | ||
350 | */ | ||
351 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
352 | GNUNET_GETOPT_OPTION_END | ||
353 | }; | ||
354 | |||
355 | |||
356 | /** | ||
357 | * The main function for the topology daemon. | ||
358 | * | ||
359 | * @param argc number of arguments from the command line | ||
360 | * @param argv command line arguments | ||
361 | * @return 0 ok, 1 on error | ||
362 | */ | ||
363 | int | ||
364 | main (int argc, char *const *argv) | ||
365 | { | ||
366 | int ret; | ||
367 | |||
368 | ret = (GNUNET_OK == | ||
369 | GNUNET_PROGRAM_run (argc, | ||
370 | argv, | ||
371 | "migration", | ||
372 | _("Content migration for anonymous file-sharing"), | ||
373 | options, | ||
374 | &run, NULL)) ? 0 : 1; | ||
375 | return ret; | ||
376 | } | ||
377 | |||
378 | /* end of gnunet-daemon-migration.c */ | ||