diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-09-07 20:00:18 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-09-07 20:00:18 +0000 |
commit | 97ae3ebc7d3fe74c7a64b38be16e18a613b6d2c0 (patch) | |
tree | b8a61f427c2ba3c119e2140e27e41edb966b5069 /src | |
parent | d22616e71b8ef07254ae09c37ff4f75c446d8213 (diff) | |
download | gnunet-97ae3ebc7d3fe74c7a64b38be16e18a613b6d2c0.tar.gz gnunet-97ae3ebc7d3fe74c7a64b38be16e18a613b6d2c0.zip |
prep work
Diffstat (limited to 'src')
-rw-r--r-- | src/fs/Makefile.am | 33 | ||||
-rw-r--r-- | src/fs/gnunet-directory.c | 167 | ||||
-rw-r--r-- | src/fs/gnunet-pseudonym.c | 78 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs.c | 100 | ||||
-rw-r--r-- | src/include/gnunet_fs_service.h | 1 |
5 files changed, 371 insertions, 8 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index 0948b349f..f2bcab615 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am | |||
@@ -39,19 +39,20 @@ libgnunetfs_la_LDFLAGS = \ | |||
39 | 39 | ||
40 | 40 | ||
41 | bin_PROGRAMS = \ | 41 | bin_PROGRAMS = \ |
42 | gnunet-directory \ | ||
42 | gnunet-download \ | 43 | gnunet-download \ |
43 | gnunet-publish \ | 44 | gnunet-publish \ |
45 | gnunet-pseudonym \ | ||
44 | gnunet-search \ | 46 | gnunet-search \ |
47 | gnunet-service-fs \ | ||
45 | gnunet-unindex | 48 | gnunet-unindex |
46 | # gnunet-directory | ||
47 | # gnunet-pseudonym | ||
48 | 49 | ||
49 | #gnunet_directory_SOURCES = | 50 | gnunet_directory_SOURCES = \ |
50 | # gnunet-directory.c | 51 | gnunet-directory.c |
51 | #gnunet_directory_LDADD = | 52 | gnunet_directory_LDADD = \ |
52 | # $(top_builddir)/src/fs/libgnunetfs.la | 53 | $(top_builddir)/src/fs/libgnunetfs.la \ |
53 | # $(top_builddir)/src/util/libgnunetutil.la | 54 | $(top_builddir)/src/util/libgnunetutil.la \ |
54 | # $(GN_LIBINTL) | 55 | $(GN_LIBINTL) |
55 | 56 | ||
56 | gnunet_download_SOURCES = \ | 57 | gnunet_download_SOURCES = \ |
57 | gnunet-download.c | 58 | gnunet-download.c |
@@ -67,6 +68,13 @@ gnunet_publish_LDADD = \ | |||
67 | $(top_builddir)/src/util/libgnunetutil.la \ | 68 | $(top_builddir)/src/util/libgnunetutil.la \ |
68 | $(GN_LIBINTL) | 69 | $(GN_LIBINTL) |
69 | 70 | ||
71 | gnunet_pseudonym_SOURCES = \ | ||
72 | gnunet-pseudonym.c | ||
73 | gnunet_pseudonym_LDADD = \ | ||
74 | $(top_builddir)/src/fs/libgnunetfs.la \ | ||
75 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
76 | $(GN_LIBINTL) | ||
77 | |||
70 | gnunet_search_SOURCES = \ | 78 | gnunet_search_SOURCES = \ |
71 | gnunet-search.c | 79 | gnunet-search.c |
72 | gnunet_search_LDADD = \ | 80 | gnunet_search_LDADD = \ |
@@ -74,6 +82,15 @@ gnunet_search_LDADD = \ | |||
74 | $(top_builddir)/src/util/libgnunetutil.la \ | 82 | $(top_builddir)/src/util/libgnunetutil.la \ |
75 | $(GN_LIBINTL) | 83 | $(GN_LIBINTL) |
76 | 84 | ||
85 | gnunet_service_fs_SOURCES = \ | ||
86 | gnunet-service-fs.c | ||
87 | gnunet_service_fs_LDADD = \ | ||
88 | $(top_builddir)/src/fs/libgnunetfs.la \ | ||
89 | $(top_builddir)/src/datastore/libgnunetdatastore.la \ | ||
90 | $(top_builddir)/src/core/libgnunetcore.la \ | ||
91 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
92 | $(GN_LIBINTL) | ||
93 | |||
77 | gnunet_unindex_SOURCES = \ | 94 | gnunet_unindex_SOURCES = \ |
78 | gnunet-unindex.c | 95 | gnunet-unindex.c |
79 | gnunet_unindex_LDADD = \ | 96 | gnunet_unindex_LDADD = \ |
diff --git a/src/fs/gnunet-directory.c b/src/fs/gnunet-directory.c new file mode 100644 index 000000000..0cbf700d1 --- /dev/null +++ b/src/fs/gnunet-directory.c | |||
@@ -0,0 +1,167 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 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 | * @file fs/gnunet-directory.c | ||
22 | * @brief display content of GNUnet directories | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_fs_service.h" | ||
27 | |||
28 | static int ret; | ||
29 | |||
30 | /** | ||
31 | * Print a meta data entry. | ||
32 | */ | ||
33 | static int | ||
34 | item_printer (void *cls, | ||
35 | EXTRACTOR_KeywordType type, | ||
36 | const char *data) | ||
37 | { | ||
38 | printf ("\t%20s: %s\n", | ||
39 | dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, | ||
40 | EXTRACTOR_getKeywordTypeAsString (type)), data); | ||
41 | return GNUNET_OK; | ||
42 | } | ||
43 | |||
44 | |||
45 | |||
46 | /** | ||
47 | * Print an entry in a directory. | ||
48 | * | ||
49 | * @param cls closure (not used) | ||
50 | * @param filename name of the file in the directory | ||
51 | * @param uri URI of the file | ||
52 | * @param metadata metadata for the file; metadata for | ||
53 | * the directory if everything else is NULL/zero | ||
54 | * @param length length of the available data for the file | ||
55 | * (of type size_t since data must certainly fit | ||
56 | * into memory; if files are larger than size_t | ||
57 | * permits, then they will certainly not be | ||
58 | * embedded with the directory itself). | ||
59 | * @param data data available for the file (length bytes) | ||
60 | */ | ||
61 | static void | ||
62 | print_entry (void *cls, | ||
63 | const char *filename, | ||
64 | const struct GNUNET_FS_Uri *uri, | ||
65 | const struct GNUNET_CONTAINER_MetaData *meta, | ||
66 | size_t length, | ||
67 | const void *data) | ||
68 | { | ||
69 | char *string; | ||
70 | |||
71 | string = GNUNET_FS_uri_to_string (uri); | ||
72 | printf ("%s:\n", string); | ||
73 | GNUNET_free (string); | ||
74 | GNUNET_CONTAINER_meta_data_get_contents (meta, | ||
75 | &item_printer, | ||
76 | NULL); | ||
77 | } | ||
78 | |||
79 | |||
80 | /** | ||
81 | * Main function that will be run by the scheduler. | ||
82 | * | ||
83 | * @param cls closure | ||
84 | * @param sched the scheduler to use | ||
85 | * @param args remaining command-line arguments | ||
86 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
87 | * @param cfg configuration | ||
88 | */ | ||
89 | static void | ||
90 | run (void *cls, | ||
91 | struct GNUNET_SCHEDULER_Handle *sched, | ||
92 | char *const *args, | ||
93 | const char *cfgfile, | ||
94 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
95 | { | ||
96 | struct GNUNET_DISK_MapHandle *map; | ||
97 | struct GNUNET_DISK_FileHandle *h; | ||
98 | void *data; | ||
99 | size_t len; | ||
100 | uint64_t size; | ||
101 | const char *filename = args[0]; | ||
102 | |||
103 | if (NULL == filename) | ||
104 | { | ||
105 | fprintf (stderr, | ||
106 | _("You must specify a filename to inspect.")); | ||
107 | ret = 1; | ||
108 | return; | ||
109 | } | ||
110 | if ( (GNUNET_OK != | ||
111 | GNUNET_DISK_file_size (filename, | ||
112 | &size, | ||
113 | GNUNET_YES)) || | ||
114 | (NULL == (h = GNUNET_DISK_file_open (filename, | ||
115 | GNUNET_DISK_OPEN_READ))) ) | ||
116 | { | ||
117 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
118 | _("Failed to read directory `%s'\n"), | ||
119 | filename); | ||
120 | ret = 1; | ||
121 | return; | ||
122 | } | ||
123 | len = (size_t) size; | ||
124 | data = GNUNET_DISK_file_map (h, | ||
125 | &map, | ||
126 | GNUNET_DISK_MAP_READ, | ||
127 | len); | ||
128 | GNUNET_assert (NULL != data); | ||
129 | GNUNET_FS_directory_list_contents (len, | ||
130 | data, | ||
131 | 0, | ||
132 | &print_entry, | ||
133 | NULL); | ||
134 | GNUNET_DISK_file_unmap (map); | ||
135 | GNUNET_DISK_file_close (h); | ||
136 | } | ||
137 | |||
138 | |||
139 | /** | ||
140 | * gnunet-directory command line options | ||
141 | */ | ||
142 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
143 | // FIXME: options! | ||
144 | GNUNET_GETOPT_OPTION_END | ||
145 | }; | ||
146 | |||
147 | |||
148 | /** | ||
149 | * The main function to inspect GNUnet directories. | ||
150 | * | ||
151 | * @param argc number of arguments from the command line | ||
152 | * @param argv command line arguments | ||
153 | * @return 0 ok, 1 on error | ||
154 | */ | ||
155 | int | ||
156 | main (int argc, char *const *argv) | ||
157 | { | ||
158 | return (GNUNET_OK == | ||
159 | GNUNET_PROGRAM_run (argc, | ||
160 | argv, | ||
161 | "gnunet-directory", | ||
162 | gettext_noop | ||
163 | ("Display GNUnet directories."), | ||
164 | options, &run, NULL)) ? ret : 1; | ||
165 | } | ||
166 | |||
167 | /* end of gnunet-directory.c */ | ||
diff --git a/src/fs/gnunet-pseudonym.c b/src/fs/gnunet-pseudonym.c new file mode 100644 index 000000000..e443d1e32 --- /dev/null +++ b/src/fs/gnunet-pseudonym.c | |||
@@ -0,0 +1,78 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 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 | * @file fs/gnunet-pseudonym.c | ||
22 | * @brief manage GNUnet namespaces / pseudonyms | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_fs_service.h" | ||
27 | |||
28 | static int ret; | ||
29 | |||
30 | /** | ||
31 | * Main function that will be run by the scheduler. | ||
32 | * | ||
33 | * @param cls closure | ||
34 | * @param sched the scheduler to use | ||
35 | * @param args remaining command-line arguments | ||
36 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
37 | * @param cfg configuration | ||
38 | */ | ||
39 | static void | ||
40 | run (void *cls, | ||
41 | struct GNUNET_SCHEDULER_Handle *sched, | ||
42 | char *const *args, | ||
43 | const char *cfgfile, | ||
44 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
45 | { | ||
46 | // FIXME | ||
47 | } | ||
48 | |||
49 | |||
50 | /** | ||
51 | * gnunet-pseudonym command line options | ||
52 | */ | ||
53 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
54 | // FIXME: options! | ||
55 | GNUNET_GETOPT_OPTION_END | ||
56 | }; | ||
57 | |||
58 | |||
59 | /** | ||
60 | * The main function to inspect GNUnet directories. | ||
61 | * | ||
62 | * @param argc number of arguments from the command line | ||
63 | * @param argv command line arguments | ||
64 | * @return 0 ok, 1 on error | ||
65 | */ | ||
66 | int | ||
67 | main (int argc, char *const *argv) | ||
68 | { | ||
69 | return (GNUNET_OK == | ||
70 | GNUNET_PROGRAM_run (argc, | ||
71 | argv, | ||
72 | "gnunet-pseudonym", | ||
73 | gettext_noop | ||
74 | ("Manage GNUnet pseudonyms."), | ||
75 | options, &run, NULL)) ? ret : 1; | ||
76 | } | ||
77 | |||
78 | /* end of gnunet-pseudonym.c */ | ||
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c new file mode 100644 index 000000000..253fd24b2 --- /dev/null +++ b/src/fs/gnunet-service-fs.c | |||
@@ -0,0 +1,100 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009 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 statistics/gnunet-service-fs.c | ||
23 | * @brief program that provides the file-sharing service | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_protocols.h" | ||
28 | #include "gnunet_core_service.h" | ||
29 | #include "gnunet_datastore_service.h" | ||
30 | #include "gnunet_util_lib.h" | ||
31 | #include "fs.h" | ||
32 | |||
33 | |||
34 | |||
35 | /** | ||
36 | * Handle GET-message. | ||
37 | * | ||
38 | * @param cls closure | ||
39 | * @param client identification of the client | ||
40 | * @param message the actual message | ||
41 | * @return GNUNET_OK to keep the connection open, | ||
42 | * GNUNET_SYSERR to close it (signal serious error) | ||
43 | */ | ||
44 | static void | ||
45 | handle_xxx (void *cls, | ||
46 | struct GNUNET_SERVER_Client *client, | ||
47 | const struct GNUNET_MessageHeader *message) | ||
48 | { | ||
49 | } | ||
50 | |||
51 | |||
52 | /** | ||
53 | * List of handlers for the messages understood by this | ||
54 | * service. | ||
55 | */ | ||
56 | static struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
57 | {&handle_xxx, NULL, GNUNET_MESSAGE_TYPE_FS_INDEX_START, 0}, | ||
58 | {&handle_xxx, NULL, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, 0}, | ||
59 | {&handle_xxx, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX, 0}, | ||
60 | {&handle_xxx, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH, 0}, | ||
61 | {NULL, NULL, 0, 0} | ||
62 | }; | ||
63 | |||
64 | |||
65 | /** | ||
66 | * Process fs requests. | ||
67 | * | ||
68 | * @param cls closure | ||
69 | * @param sched scheduler to use | ||
70 | * @param server the initialized server | ||
71 | * @param cfg configuration to use | ||
72 | */ | ||
73 | static void | ||
74 | run (void *cls, | ||
75 | struct GNUNET_SCHEDULER_Handle *sched, | ||
76 | struct GNUNET_SERVER_Handle *server, | ||
77 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
78 | { | ||
79 | GNUNET_SERVER_add_handlers (server, handlers); | ||
80 | // FIXME: also handle P2P messages! | ||
81 | } | ||
82 | |||
83 | |||
84 | /** | ||
85 | * The main function for the fs service. | ||
86 | * | ||
87 | * @param argc number of arguments from the command line | ||
88 | * @param argv command line arguments | ||
89 | * @return 0 ok, 1 on error | ||
90 | */ | ||
91 | int | ||
92 | main (int argc, char *const *argv) | ||
93 | { | ||
94 | return (GNUNET_OK == | ||
95 | GNUNET_SERVICE_run (argc, | ||
96 | argv, | ||
97 | "fs", &run, NULL, NULL, NULL)) ? 0 : 1; | ||
98 | } | ||
99 | |||
100 | /* end of gnunet-service-fs.c */ | ||
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index 114128823..210455311 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h | |||
@@ -117,6 +117,7 @@ GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri); | |||
117 | char * | 117 | char * |
118 | GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri); | 118 | GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri); |
119 | 119 | ||
120 | |||
120 | /** | 121 | /** |
121 | * Convert a UTF-8 String to a URI. | 122 | * Convert a UTF-8 String to a URI. |
122 | * | 123 | * |