summaryrefslogtreecommitdiff
path: root/src/dht/gnunet-dht-get.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/gnunet-dht-get.c')
-rw-r--r--src/dht/gnunet-dht-get.c226
1 files changed, 113 insertions, 113 deletions
diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c
index af667584b..901641660 100644
--- a/src/dht/gnunet-dht-get.c
+++ b/src/dht/gnunet-dht-get.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file dht/gnunet-dht-get.c 21 * @file dht/gnunet-dht-get.c
22 * @brief search for data in DHT 22 * @brief search for data in DHT
@@ -26,7 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_dht_service.h" 27#include "gnunet_dht_service.h"
28 28
29#define LOG(kind, ...) GNUNET_log_from (kind, "dht-clients", __VA_ARGS__) 29#define LOG(kind, ...) GNUNET_log_from(kind, "dht-clients", __VA_ARGS__)
30/** 30/**
31 * The type of the query 31 * The type of the query
32 */ 32 */
@@ -45,7 +45,7 @@ static char *query_key;
45/** 45/**
46 * User supplied timeout value 46 * User supplied timeout value
47 */ 47 */
48static struct GNUNET_TIME_Relative timeout_request = {60000}; 48static struct GNUNET_TIME_Relative timeout_request = { 60000 };
49 49
50/** 50/**
51 * Be verbose 51 * Be verbose
@@ -94,23 +94,23 @@ static struct GNUNET_SCHEDULER_Task *tt;
94 * @param cls unused 94 * @param cls unused
95 */ 95 */
96static void 96static void
97cleanup_task (void *cls) 97cleanup_task(void *cls)
98{ 98{
99 if (NULL != get_handle) 99 if (NULL != get_handle)
100 { 100 {
101 GNUNET_DHT_get_stop (get_handle); 101 GNUNET_DHT_get_stop(get_handle);
102 get_handle = NULL; 102 get_handle = NULL;
103 } 103 }
104 if (NULL != dht_handle) 104 if (NULL != dht_handle)
105 { 105 {
106 GNUNET_DHT_disconnect (dht_handle); 106 GNUNET_DHT_disconnect(dht_handle);
107 dht_handle = NULL; 107 dht_handle = NULL;
108 } 108 }
109 if (NULL != tt) 109 if (NULL != tt)
110 { 110 {
111 GNUNET_SCHEDULER_cancel (tt); 111 GNUNET_SCHEDULER_cancel(tt);
112 tt = NULL; 112 tt = NULL;
113 } 113 }
114} 114}
115 115
116 116
@@ -120,10 +120,10 @@ cleanup_task (void *cls)
120 * @param cls unused 120 * @param cls unused
121 */ 121 */
122static void 122static void
123timeout_task (void *cls) 123timeout_task(void *cls)
124{ 124{
125 tt = NULL; 125 tt = NULL;
126 GNUNET_SCHEDULER_shutdown (); 126 GNUNET_SCHEDULER_shutdown();
127} 127}
128 128
129 129
@@ -143,34 +143,34 @@ timeout_task (void *cls)
143 * @param data pointer to the result data 143 * @param data pointer to the result data
144 */ 144 */
145static void 145static void
146get_result_iterator (void *cls, 146get_result_iterator(void *cls,
147 struct GNUNET_TIME_Absolute exp, 147 struct GNUNET_TIME_Absolute exp,
148 const struct GNUNET_HashCode *key, 148 const struct GNUNET_HashCode *key,
149 const struct GNUNET_PeerIdentity *get_path, 149 const struct GNUNET_PeerIdentity *get_path,
150 unsigned int get_path_length, 150 unsigned int get_path_length,
151 const struct GNUNET_PeerIdentity *put_path, 151 const struct GNUNET_PeerIdentity *put_path,
152 unsigned int put_path_length, 152 unsigned int put_path_length,
153 enum GNUNET_BLOCK_Type type, 153 enum GNUNET_BLOCK_Type type,
154 size_t size, 154 size_t size,
155 const void *data) 155 const void *data)
156{ 156{
157 fprintf (stdout, 157 fprintf(stdout,
158 (GNUNET_BLOCK_TYPE_TEST == type) ? _ ("Result %d, type %d:\n%.*s\n") 158 (GNUNET_BLOCK_TYPE_TEST == type) ? _("Result %d, type %d:\n%.*s\n")
159 : _ ("Result %d, type %d:\n"), 159 : _("Result %d, type %d:\n"),
160 result_count, 160 result_count,
161 type, 161 type,
162 (unsigned int) size, 162 (unsigned int)size,
163 (char *) data); 163 (char *)data);
164 if (verbose) 164 if (verbose)
165 { 165 {
166 fprintf (stdout, " GET path: "); 166 fprintf(stdout, " GET path: ");
167 for (unsigned int i = 0; i < get_path_length; i++) 167 for (unsigned int i = 0; i < get_path_length; i++)
168 fprintf (stdout, "%s%s", (0 == i) ? "" : "-", GNUNET_i2s (&get_path[i])); 168 fprintf(stdout, "%s%s", (0 == i) ? "" : "-", GNUNET_i2s(&get_path[i]));
169 fprintf (stdout, "\n PUT path: "); 169 fprintf(stdout, "\n PUT path: ");
170 for (unsigned int i = 0; i < put_path_length; i++) 170 for (unsigned int i = 0; i < put_path_length; i++)
171 fprintf (stdout, "%s%s", (0 == i) ? "" : "-", GNUNET_i2s (&put_path[i])); 171 fprintf(stdout, "%s%s", (0 == i) ? "" : "-", GNUNET_i2s(&put_path[i]));
172 fprintf (stdout, "\n"); 172 fprintf(stdout, "\n");
173 } 173 }
174 result_count++; 174 result_count++;
175} 175}
176 176
@@ -184,47 +184,47 @@ get_result_iterator (void *cls,
184 * @param c configuration 184 * @param c configuration
185 */ 185 */
186static void 186static void
187run (void *cls, 187run(void *cls,
188 char *const *args, 188 char *const *args,
189 const char *cfgfile, 189 const char *cfgfile,
190 const struct GNUNET_CONFIGURATION_Handle *c) 190 const struct GNUNET_CONFIGURATION_Handle *c)
191{ 191{
192 struct GNUNET_HashCode key; 192 struct GNUNET_HashCode key;
193 193
194 cfg = c; 194 cfg = c;
195 if (NULL == query_key) 195 if (NULL == query_key)
196 { 196 {
197 fprintf (stderr, "%s", _ ("Must provide key for DHT GET!\n")); 197 fprintf(stderr, "%s", _("Must provide key for DHT GET!\n"));
198 ret = 1; 198 ret = 1;
199 return; 199 return;
200 } 200 }
201 if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1))) 201 if (NULL == (dht_handle = GNUNET_DHT_connect(cfg, 1)))
202 { 202 {
203 fprintf (stderr, "%s", _ ("Failed to connect to DHT service!\n")); 203 fprintf(stderr, "%s", _("Failed to connect to DHT service!\n"));
204 ret = 1; 204 ret = 1;
205 return; 205 return;
206 } 206 }
207 if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */ 207 if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */
208 query_type = GNUNET_BLOCK_TYPE_TEST; 208 query_type = GNUNET_BLOCK_TYPE_TEST;
209 GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key); 209 GNUNET_CRYPTO_hash(query_key, strlen(query_key), &key);
210 if (verbose) 210 if (verbose)
211 fprintf (stderr, 211 fprintf(stderr,
212 "%s `%s' \n", 212 "%s `%s' \n",
213 _ ("Issuing DHT GET with key"), 213 _("Issuing DHT GET with key"),
214 GNUNET_h2s_full (&key)); 214 GNUNET_h2s_full(&key));
215 GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); 215 GNUNET_SCHEDULER_add_shutdown(&cleanup_task, NULL);
216 tt = GNUNET_SCHEDULER_add_delayed (timeout_request, &timeout_task, NULL); 216 tt = GNUNET_SCHEDULER_add_delayed(timeout_request, &timeout_task, NULL);
217 get_handle = GNUNET_DHT_get_start (dht_handle, 217 get_handle = GNUNET_DHT_get_start(dht_handle,
218 query_type, 218 query_type,
219 &key, 219 &key,
220 replication, 220 replication,
221 (demultixplex_everywhere) 221 (demultixplex_everywhere)
222 ? GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE 222 ? GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
223 : GNUNET_DHT_RO_NONE, 223 : GNUNET_DHT_RO_NONE,
224 NULL, 224 NULL,
225 0, 225 0,
226 &get_result_iterator, 226 &get_result_iterator,
227 NULL); 227 NULL);
228} 228}
229 229
230 230
@@ -236,54 +236,54 @@ run (void *cls,
236 * @return 0 ok, 1 on error 236 * @return 0 ok, 1 on error
237 */ 237 */
238int 238int
239main (int argc, char *const *argv) 239main(int argc, char *const *argv)
240{ 240{
241 struct GNUNET_GETOPT_CommandLineOption options[] = 241 struct GNUNET_GETOPT_CommandLineOption options[] =
242 {GNUNET_GETOPT_option_string ('k', 242 { GNUNET_GETOPT_option_string('k',
243 "key", 243 "key",
244 "KEY", 244 "KEY",
245 gettext_noop ("the query key"), 245 gettext_noop("the query key"),
246 &query_key), 246 &query_key),
247 GNUNET_GETOPT_option_uint ( 247 GNUNET_GETOPT_option_uint(
248 'r', 248 'r',
249 "replication", 249 "replication",
250 "LEVEL", 250 "LEVEL",
251 gettext_noop ("how many parallel requests (replicas) to create"), 251 gettext_noop("how many parallel requests (replicas) to create"),
252 &replication), 252 &replication),
253 GNUNET_GETOPT_option_uint ('t', 253 GNUNET_GETOPT_option_uint('t',
254 "type", 254 "type",
255 "TYPE", 255 "TYPE",
256 gettext_noop ("the type of data to look for"), 256 gettext_noop("the type of data to look for"),
257 &query_type), 257 &query_type),
258 GNUNET_GETOPT_option_relative_time ( 258 GNUNET_GETOPT_option_relative_time(
259 'T', 259 'T',
260 "timeout", 260 "timeout",
261 "TIMEOUT", 261 "TIMEOUT",
262 gettext_noop ("how long to execute this query before giving up?"), 262 gettext_noop("how long to execute this query before giving up?"),
263 &timeout_request), 263 &timeout_request),
264 GNUNET_GETOPT_option_flag ('x', 264 GNUNET_GETOPT_option_flag('x',
265 "demultiplex", 265 "demultiplex",
266 gettext_noop ( 266 gettext_noop(
267 "use DHT's demultiplex everywhere option"), 267 "use DHT's demultiplex everywhere option"),
268 &demultixplex_everywhere), 268 &demultixplex_everywhere),
269 GNUNET_GETOPT_option_verbose (&verbose), 269 GNUNET_GETOPT_option_verbose(&verbose),
270 GNUNET_GETOPT_OPTION_END}; 270 GNUNET_GETOPT_OPTION_END };
271 271
272 272
273 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 273 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
274 return 2; 274 return 2;
275 return (GNUNET_OK == 275 return (GNUNET_OK ==
276 GNUNET_PROGRAM_run ( 276 GNUNET_PROGRAM_run(
277 argc, 277 argc,
278 argv, 278 argv,
279 "gnunet-dht-get", 279 "gnunet-dht-get",
280 gettext_noop ( 280 gettext_noop(
281 "Issue a GET request to the GNUnet DHT, prints results."), 281 "Issue a GET request to the GNUnet DHT, prints results."),
282 options, 282 options,
283 &run, 283 &run,
284 NULL)) 284 NULL))
285 ? ret 285 ? ret
286 : 1; 286 : 1;
287} 287}
288 288
289/* end of gnunet-dht-get.c */ 289/* end of gnunet-dht-get.c */