diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-12-07 10:34:30 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-12-07 10:34:30 +0000 |
commit | 437fe3754cd6370cfbaf7e822fa14c5a908e3f69 (patch) | |
tree | 7efe28e54fa8f57e1bca1b7f5dcc93c1492dbb3f /src/fs/gnunet-daemon-fsprofiler.c | |
parent | d90628063e670fe2670b20e85a1ba29c45081955 (diff) | |
download | gnunet-437fe3754cd6370cfbaf7e822fa14c5a908e3f69.tar.gz gnunet-437fe3754cd6370cfbaf7e822fa14c5a908e3f69.zip |
-skeleton for the fsprofiler daemon
Diffstat (limited to 'src/fs/gnunet-daemon-fsprofiler.c')
-rw-r--r-- | src/fs/gnunet-daemon-fsprofiler.c | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/src/fs/gnunet-daemon-fsprofiler.c b/src/fs/gnunet-daemon-fsprofiler.c new file mode 100644 index 000000000..fa9bfd3b2 --- /dev/null +++ b/src/fs/gnunet-daemon-fsprofiler.c | |||
@@ -0,0 +1,179 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012 Christian Grothoff | ||
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 3, 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 fs/gnunet-daemon-fsprofiler.c | ||
23 | * @brief daemon that publishes and downloads (random) files | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_fs_service.h" | ||
28 | #include "gnunet_statistics_service.h" | ||
29 | |||
30 | /** | ||
31 | * Return value from 'main'. | ||
32 | */ | ||
33 | static int global_ret; | ||
34 | |||
35 | /** | ||
36 | * Configuration we use. | ||
37 | */ | ||
38 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
39 | |||
40 | /** | ||
41 | * Handle to the statistics service. | ||
42 | */ | ||
43 | static struct GNUNET_STATISTICS_Handle *stats_handle; | ||
44 | |||
45 | /** | ||
46 | * Peer's FS handle. | ||
47 | */ | ||
48 | static struct GNUNET_FS_Handle *fs_handle; | ||
49 | |||
50 | /** | ||
51 | * Unique number for this peer in the testbed. | ||
52 | */ | ||
53 | static unsigned long long my_peerid; | ||
54 | |||
55 | |||
56 | |||
57 | |||
58 | |||
59 | /** | ||
60 | * Task run during shutdown. | ||
61 | * | ||
62 | * @param cls unused | ||
63 | * @param tc unused | ||
64 | */ | ||
65 | static void | ||
66 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
67 | { | ||
68 | if (NULL != fs_handle) | ||
69 | { | ||
70 | GNUNET_FS_stop (fs_handle); | ||
71 | fs_handle = NULL; | ||
72 | } | ||
73 | |||
74 | if (NULL != stats_handle) | ||
75 | { | ||
76 | GNUNET_STATISTICS_destroy (stats_handle, GNUNET_YES); | ||
77 | stats_handle = NULL; | ||
78 | } | ||
79 | } | ||
80 | |||
81 | |||
82 | /** | ||
83 | * Notification of FS to a client about the progress of an | ||
84 | * operation. Callbacks of this type will be used for uploads, | ||
85 | * downloads and searches. Some of the arguments depend a bit | ||
86 | * in their meaning on the context in which the callback is used. | ||
87 | * | ||
88 | * @param cls closure | ||
89 | * @param info details about the event, specifying the event type | ||
90 | * and various bits about the event | ||
91 | * @return client-context (for the next progress call | ||
92 | * for this operation; should be set to NULL for | ||
93 | * SUSPEND and STOPPED events). The value returned | ||
94 | * will be passed to future callbacks in the respective | ||
95 | * field in the GNUNET_FS_ProgressInfo struct. | ||
96 | */ | ||
97 | static void * | ||
98 | progress_cb (void *cls, | ||
99 | const struct GNUNET_FS_ProgressInfo *info) | ||
100 | { | ||
101 | return NULL; | ||
102 | } | ||
103 | |||
104 | |||
105 | /** | ||
106 | * @brief Main function that will be run by the scheduler. | ||
107 | * | ||
108 | * @param cls closure | ||
109 | * @param args remaining command-line arguments | ||
110 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
111 | * @param cfg_ configuration | ||
112 | */ | ||
113 | static void | ||
114 | run (void *cls, char *const *args GNUNET_UNUSED, | ||
115 | const char *cfgfile GNUNET_UNUSED, | ||
116 | const struct GNUNET_CONFIGURATION_Handle *cfg_) | ||
117 | { | ||
118 | cfg = cfg_; | ||
119 | /* Scheduled the task to clean up when shutdown is called */ | ||
120 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, | ||
121 | NULL); | ||
122 | |||
123 | if (GNUNET_OK != | ||
124 | GNUNET_CONFIGURATION_get_value_number (cfg, | ||
125 | "TESTBED", "PEERID", | ||
126 | &my_peerid)) | ||
127 | { | ||
128 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
129 | "TESTBED", "PEERID"); | ||
130 | global_ret = GNUNET_SYSERR; | ||
131 | GNUNET_SCHEDULER_shutdown (); | ||
132 | return; | ||
133 | } | ||
134 | |||
135 | stats_handle = GNUNET_STATISTICS_create ("fsprofiler", cfg); | ||
136 | fs_handle = | ||
137 | GNUNET_FS_start (cfg, | ||
138 | "fsprofiler", | ||
139 | &progress_cb, NULL, | ||
140 | GNUNET_FS_FLAGS_NONE, | ||
141 | GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, 1, | ||
142 | GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, 1, | ||
143 | GNUNET_FS_OPTIONS_END); | ||
144 | |||
145 | if (NULL == fs_handle) | ||
146 | { | ||
147 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not acquire FS handle. Exiting.\n"); | ||
148 | global_ret = GNUNET_SYSERR; | ||
149 | GNUNET_SCHEDULER_shutdown (); | ||
150 | return; | ||
151 | } | ||
152 | |||
153 | } | ||
154 | |||
155 | |||
156 | /** | ||
157 | * Program that performs various "random" FS activities. | ||
158 | * | ||
159 | * @param argc number of arguments from the command line | ||
160 | * @param argv command line arguments | ||
161 | * @return 0 ok, 1 on error | ||
162 | */ | ||
163 | int | ||
164 | main (int argc, char *const *argv) | ||
165 | { | ||
166 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
167 | GNUNET_GETOPT_OPTION_END | ||
168 | }; | ||
169 | |||
170 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | ||
171 | return 2; | ||
172 | return (GNUNET_OK == | ||
173 | GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-fsprofiler", | ||
174 | gettext_noop | ||
175 | ("Daemon to use file-sharing to measure its performance."), | ||
176 | options, &run, NULL)) ? global_ret : 1; | ||
177 | } | ||
178 | |||
179 | /* end of gnunet-daemon-fsprofiler.c */ | ||