diff options
Diffstat (limited to 'src/cadet/gnunet-cadet.c')
-rw-r--r-- | src/cadet/gnunet-cadet.c | 685 |
1 files changed, 342 insertions, 343 deletions
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c index f5cf86211..d85a3c6ba 100644 --- a/src/cadet/gnunet-cadet.c +++ b/src/cadet/gnunet-cadet.c | |||
@@ -143,7 +143,7 @@ static unsigned int sent_pkt; | |||
143 | * Wait for input on STDIO and send it out over the #ch. | 143 | * Wait for input on STDIO and send it out over the #ch. |
144 | */ | 144 | */ |
145 | static void | 145 | static void |
146 | listen_stdio(void); | 146 | listen_stdio (void); |
147 | 147 | ||
148 | 148 | ||
149 | /** | 149 | /** |
@@ -154,25 +154,25 @@ listen_stdio(void); | |||
154 | * @return Human readable string. | 154 | * @return Human readable string. |
155 | */ | 155 | */ |
156 | static const char * | 156 | static const char * |
157 | enc_2s(uint16_t status) | 157 | enc_2s (uint16_t status) |
158 | { | 158 | { |
159 | switch (status) | 159 | switch (status) |
160 | { | 160 | { |
161 | case 0: | 161 | case 0: |
162 | return "NULL "; | 162 | return "NULL "; |
163 | 163 | ||
164 | case 1: | 164 | case 1: |
165 | return "KSENT"; | 165 | return "KSENT"; |
166 | 166 | ||
167 | case 2: | 167 | case 2: |
168 | return "KRECV"; | 168 | return "KRECV"; |
169 | 169 | ||
170 | case 3: | 170 | case 3: |
171 | return "READY"; | 171 | return "READY"; |
172 | 172 | ||
173 | default: | 173 | default: |
174 | return ""; | 174 | return ""; |
175 | } | 175 | } |
176 | } | 176 | } |
177 | 177 | ||
178 | 178 | ||
@@ -184,28 +184,28 @@ enc_2s(uint16_t status) | |||
184 | * @return Human readable string. | 184 | * @return Human readable string. |
185 | */ | 185 | */ |
186 | static const char * | 186 | static const char * |
187 | conn_2s(uint16_t status) | 187 | conn_2s (uint16_t status) |
188 | { | 188 | { |
189 | switch (status) | 189 | switch (status) |
190 | { | 190 | { |
191 | case 0: | 191 | case 0: |
192 | return "NEW "; | 192 | return "NEW "; |
193 | 193 | ||
194 | case 1: | 194 | case 1: |
195 | return "SRCH "; | 195 | return "SRCH "; |
196 | 196 | ||
197 | case 2: | 197 | case 2: |
198 | return "WAIT "; | 198 | return "WAIT "; |
199 | 199 | ||
200 | case 3: | 200 | case 3: |
201 | return "READY"; | 201 | return "READY"; |
202 | 202 | ||
203 | case 4: | 203 | case 4: |
204 | return "SHUTD"; | 204 | return "SHUTD"; |
205 | 205 | ||
206 | default: | 206 | default: |
207 | return ""; | 207 | return ""; |
208 | } | 208 | } |
209 | } | 209 | } |
210 | 210 | ||
211 | 211 | ||
@@ -215,60 +215,60 @@ conn_2s(uint16_t status) | |||
215 | * @param cls Closure (unused). | 215 | * @param cls Closure (unused). |
216 | */ | 216 | */ |
217 | static void | 217 | static void |
218 | shutdown_task(void *cls) | 218 | shutdown_task (void *cls) |
219 | { | 219 | { |
220 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n"); | 220 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n"); |
221 | if (NULL != lp) | 221 | if (NULL != lp) |
222 | { | 222 | { |
223 | GNUNET_CADET_close_port(lp); | 223 | GNUNET_CADET_close_port (lp); |
224 | lp = NULL; | 224 | lp = NULL; |
225 | } | 225 | } |
226 | if (NULL != ch) | 226 | if (NULL != ch) |
227 | { | 227 | { |
228 | GNUNET_CADET_channel_destroy(ch); | 228 | GNUNET_CADET_channel_destroy (ch); |
229 | ch = NULL; | 229 | ch = NULL; |
230 | } | 230 | } |
231 | if (NULL != gpo) | 231 | if (NULL != gpo) |
232 | { | 232 | { |
233 | GNUNET_CADET_get_path_cancel(gpo); | 233 | GNUNET_CADET_get_path_cancel (gpo); |
234 | gpo = NULL; | 234 | gpo = NULL; |
235 | } | 235 | } |
236 | if (NULL != plo) | 236 | if (NULL != plo) |
237 | { | 237 | { |
238 | GNUNET_CADET_list_peers_cancel(plo); | 238 | GNUNET_CADET_list_peers_cancel (plo); |
239 | plo = NULL; | 239 | plo = NULL; |
240 | } | 240 | } |
241 | if (NULL != tio) | 241 | if (NULL != tio) |
242 | { | 242 | { |
243 | GNUNET_CADET_list_tunnels_cancel(tio); | 243 | GNUNET_CADET_list_tunnels_cancel (tio); |
244 | tio = NULL; | 244 | tio = NULL; |
245 | } | 245 | } |
246 | if (NULL != mh) | 246 | if (NULL != mh) |
247 | { | 247 | { |
248 | GNUNET_CADET_disconnect(mh); | 248 | GNUNET_CADET_disconnect (mh); |
249 | mh = NULL; | 249 | mh = NULL; |
250 | } | 250 | } |
251 | if (NULL != rd_task) | 251 | if (NULL != rd_task) |
252 | { | 252 | { |
253 | GNUNET_SCHEDULER_cancel(rd_task); | 253 | GNUNET_SCHEDULER_cancel (rd_task); |
254 | rd_task = NULL; | 254 | rd_task = NULL; |
255 | } | 255 | } |
256 | if (NULL != echo_task) | 256 | if (NULL != echo_task) |
257 | { | 257 | { |
258 | GNUNET_SCHEDULER_cancel(echo_task); | 258 | GNUNET_SCHEDULER_cancel (echo_task); |
259 | echo_task = NULL; | 259 | echo_task = NULL; |
260 | } | 260 | } |
261 | if (NULL != job) | 261 | if (NULL != job) |
262 | { | 262 | { |
263 | GNUNET_SCHEDULER_cancel(job); | 263 | GNUNET_SCHEDULER_cancel (job); |
264 | job = NULL; | 264 | job = NULL; |
265 | } | 265 | } |
266 | } | 266 | } |
267 | 267 | ||
268 | void | 268 | void |
269 | mq_cb(void *cls) | 269 | mq_cb (void *cls) |
270 | { | 270 | { |
271 | listen_stdio(); | 271 | listen_stdio (); |
272 | } | 272 | } |
273 | 273 | ||
274 | 274 | ||
@@ -278,7 +278,7 @@ mq_cb(void *cls) | |||
278 | * @param cls Closure (unused). | 278 | * @param cls Closure (unused). |
279 | */ | 279 | */ |
280 | static void | 280 | static void |
281 | read_stdio(void *cls) | 281 | read_stdio (void *cls) |
282 | { | 282 | { |
283 | struct GNUNET_MQ_Envelope *env; | 283 | struct GNUNET_MQ_Envelope *env; |
284 | struct GNUNET_MessageHeader *msg; | 284 | struct GNUNET_MessageHeader *msg; |
@@ -286,41 +286,41 @@ read_stdio(void *cls) | |||
286 | ssize_t data_size; | 286 | ssize_t data_size; |
287 | 287 | ||
288 | rd_task = NULL; | 288 | rd_task = NULL; |
289 | data_size = read(0, buf, 60000); | 289 | data_size = read (0, buf, 60000); |
290 | if (data_size < 1) | 290 | if (data_size < 1) |
291 | { | 291 | { |
292 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
293 | "read() returned %s\n", | 293 | "read() returned %s\n", |
294 | strerror(errno)); | 294 | strerror (errno)); |
295 | GNUNET_SCHEDULER_shutdown(); | 295 | GNUNET_SCHEDULER_shutdown (); |
296 | return; | 296 | return; |
297 | } | 297 | } |
298 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 298 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
299 | "Read %u bytes from stdio\n", | 299 | "Read %u bytes from stdio\n", |
300 | (unsigned int)data_size); | 300 | (unsigned int) data_size); |
301 | env = GNUNET_MQ_msg_extra(msg, data_size, GNUNET_MESSAGE_TYPE_CADET_CLI); | 301 | env = GNUNET_MQ_msg_extra (msg, data_size, GNUNET_MESSAGE_TYPE_CADET_CLI); |
302 | GNUNET_memcpy(&msg[1], buf, data_size); | 302 | GNUNET_memcpy (&msg[1], buf, data_size); |
303 | GNUNET_MQ_send(GNUNET_CADET_get_mq(ch), env); | 303 | GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env); |
304 | 304 | ||
305 | sent_pkt++; | 305 | sent_pkt++; |
306 | 306 | ||
307 | if (GNUNET_NO == echo) | 307 | if (GNUNET_NO == echo) |
308 | { | ||
309 | // Use MQ's notification if too much data of stdin is pooring in too fast. | ||
310 | if (STREAM_BUFFER_SIZE < sent_pkt) | ||
308 | { | 311 | { |
309 | // Use MQ's notification if too much data of stdin is pooring in too fast. | 312 | GNUNET_MQ_notify_sent (env, mq_cb, cls); |
310 | if (STREAM_BUFFER_SIZE < sent_pkt) | 313 | sent_pkt = 0; |
311 | { | ||
312 | GNUNET_MQ_notify_sent(env, mq_cb, cls); | ||
313 | sent_pkt = 0; | ||
314 | } | ||
315 | else | ||
316 | { | ||
317 | listen_stdio(); | ||
318 | } | ||
319 | } | 314 | } |
320 | else | 315 | else |
321 | { | 316 | { |
322 | echo_time = GNUNET_TIME_absolute_get(); | 317 | listen_stdio (); |
323 | } | 318 | } |
319 | } | ||
320 | else | ||
321 | { | ||
322 | echo_time = GNUNET_TIME_absolute_get (); | ||
323 | } | ||
324 | } | 324 | } |
325 | 325 | ||
326 | 326 | ||
@@ -328,20 +328,20 @@ read_stdio(void *cls) | |||
328 | * Wait for input on STDIO and send it out over the #ch. | 328 | * Wait for input on STDIO and send it out over the #ch. |
329 | */ | 329 | */ |
330 | static void | 330 | static void |
331 | listen_stdio() | 331 | listen_stdio () |
332 | { | 332 | { |
333 | struct GNUNET_NETWORK_FDSet *rs; | 333 | struct GNUNET_NETWORK_FDSet *rs; |
334 | 334 | ||
335 | /* FIXME: why use 'rs' here, seems overly complicated... */ | 335 | /* FIXME: why use 'rs' here, seems overly complicated... */ |
336 | rs = GNUNET_NETWORK_fdset_create(); | 336 | rs = GNUNET_NETWORK_fdset_create (); |
337 | GNUNET_NETWORK_fdset_set_native(rs, 0); /* STDIN */ | 337 | GNUNET_NETWORK_fdset_set_native (rs, 0); /* STDIN */ |
338 | rd_task = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 338 | rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
339 | GNUNET_TIME_UNIT_FOREVER_REL, | 339 | GNUNET_TIME_UNIT_FOREVER_REL, |
340 | rs, | 340 | rs, |
341 | NULL, | 341 | NULL, |
342 | &read_stdio, | 342 | &read_stdio, |
343 | NULL); | 343 | NULL); |
344 | GNUNET_NETWORK_fdset_destroy(rs); | 344 | GNUNET_NETWORK_fdset_destroy (rs); |
345 | } | 345 | } |
346 | 346 | ||
347 | 347 | ||
@@ -355,12 +355,12 @@ listen_stdio() | |||
355 | * @param channel connection to the other end (henceforth invalid) | 355 | * @param channel connection to the other end (henceforth invalid) |
356 | */ | 356 | */ |
357 | static void | 357 | static void |
358 | channel_ended(void *cls, const struct GNUNET_CADET_Channel *channel) | 358 | channel_ended (void *cls, const struct GNUNET_CADET_Channel *channel) |
359 | { | 359 | { |
360 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel ended!\n"); | 360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel ended!\n"); |
361 | GNUNET_assert(channel == ch); | 361 | GNUNET_assert (channel == ch); |
362 | ch = NULL; | 362 | ch = NULL; |
363 | GNUNET_SCHEDULER_shutdown(); | 363 | GNUNET_SCHEDULER_shutdown (); |
364 | } | 364 | } |
365 | 365 | ||
366 | 366 | ||
@@ -379,20 +379,20 @@ channel_ended(void *cls, const struct GNUNET_CADET_Channel *channel) | |||
379 | * @return initial channel context for the channel, we use @a channel | 379 | * @return initial channel context for the channel, we use @a channel |
380 | */ | 380 | */ |
381 | static void * | 381 | static void * |
382 | channel_incoming(void *cls, | 382 | channel_incoming (void *cls, |
383 | struct GNUNET_CADET_Channel *channel, | 383 | struct GNUNET_CADET_Channel *channel, |
384 | const struct GNUNET_PeerIdentity *initiator) | 384 | const struct GNUNET_PeerIdentity *initiator) |
385 | { | 385 | { |
386 | GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE, | 386 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
387 | "Incoming connection from %s\n", | 387 | "Incoming connection from %s\n", |
388 | GNUNET_i2s_full(initiator)); | 388 | GNUNET_i2s_full (initiator)); |
389 | GNUNET_assert(NULL == ch); | 389 | GNUNET_assert (NULL == ch); |
390 | GNUNET_assert(NULL != lp); | 390 | GNUNET_assert (NULL != lp); |
391 | GNUNET_CADET_close_port(lp); | 391 | GNUNET_CADET_close_port (lp); |
392 | lp = NULL; | 392 | lp = NULL; |
393 | ch = channel; | 393 | ch = channel; |
394 | if (GNUNET_NO == echo) | 394 | if (GNUNET_NO == echo) |
395 | listen_stdio(); | 395 | listen_stdio (); |
396 | return channel; | 396 | return channel; |
397 | } | 397 | } |
398 | 398 | ||
@@ -403,7 +403,7 @@ channel_incoming(void *cls, | |||
403 | * @param cls Closure (NULL). | 403 | * @param cls Closure (NULL). |
404 | */ | 404 | */ |
405 | static void | 405 | static void |
406 | send_echo(void *cls) | 406 | send_echo (void *cls) |
407 | { | 407 | { |
408 | struct GNUNET_MQ_Envelope *env; | 408 | struct GNUNET_MQ_Envelope *env; |
409 | struct GNUNET_MessageHeader *msg; | 409 | struct GNUNET_MessageHeader *msg; |
@@ -411,8 +411,8 @@ send_echo(void *cls) | |||
411 | echo_task = NULL; | 411 | echo_task = NULL; |
412 | if (NULL == ch) | 412 | if (NULL == ch) |
413 | return; | 413 | return; |
414 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_CLI); | 414 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CLI); |
415 | GNUNET_MQ_send(GNUNET_CADET_get_mq(ch), env); | 415 | GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env); |
416 | } | 416 | } |
417 | 417 | ||
418 | 418 | ||
@@ -425,7 +425,7 @@ send_echo(void *cls) | |||
425 | * #GNUNET_SYSERR to close it (signal serious error). | 425 | * #GNUNET_SYSERR to close it (signal serious error). |
426 | */ | 426 | */ |
427 | static int | 427 | static int |
428 | check_data(void *cls, const struct GNUNET_MessageHeader *message) | 428 | check_data (void *cls, const struct GNUNET_MessageHeader *message) |
429 | { | 429 | { |
430 | return GNUNET_OK; /* all is well-formed */ | 430 | return GNUNET_OK; /* all is well-formed */ |
431 | } | 431 | } |
@@ -442,59 +442,59 @@ check_data(void *cls, const struct GNUNET_MessageHeader *message) | |||
442 | * @param message The actual message. | 442 | * @param message The actual message. |
443 | */ | 443 | */ |
444 | static void | 444 | static void |
445 | handle_data(void *cls, const struct GNUNET_MessageHeader *message) | 445 | handle_data (void *cls, const struct GNUNET_MessageHeader *message) |
446 | { | 446 | { |
447 | size_t payload_size = ntohs(message->size) - sizeof(*message); | 447 | size_t payload_size = ntohs (message->size) - sizeof(*message); |
448 | uint16_t len; | 448 | uint16_t len; |
449 | ssize_t done; | 449 | ssize_t done; |
450 | uint16_t off; | 450 | uint16_t off; |
451 | const char *buf; | 451 | const char *buf; |
452 | 452 | ||
453 | GNUNET_CADET_receive_done(ch); | 453 | GNUNET_CADET_receive_done (ch); |
454 | if (GNUNET_YES == echo) | 454 | if (GNUNET_YES == echo) |
455 | { | ||
456 | if (NULL != listen_port) | ||
455 | { | 457 | { |
456 | if (NULL != listen_port) | 458 | struct GNUNET_MQ_Envelope *env; |
457 | { | 459 | struct GNUNET_MessageHeader *msg; |
458 | struct GNUNET_MQ_Envelope *env; | 460 | |
459 | struct GNUNET_MessageHeader *msg; | 461 | env = |
460 | 462 | GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MESSAGE_TYPE_CADET_CLI); | |
461 | env = | 463 | GNUNET_memcpy (&msg[1], &message[1], payload_size); |
462 | GNUNET_MQ_msg_extra(msg, payload_size, GNUNET_MESSAGE_TYPE_CADET_CLI); | 464 | GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env); |
463 | GNUNET_memcpy(&msg[1], &message[1], payload_size); | 465 | return; |
464 | GNUNET_MQ_send(GNUNET_CADET_get_mq(ch), env); | ||
465 | return; | ||
466 | } | ||
467 | else | ||
468 | { | ||
469 | struct GNUNET_TIME_Relative latency; | ||
470 | |||
471 | latency = GNUNET_TIME_absolute_get_duration(echo_time); | ||
472 | echo_time = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
473 | GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE, | ||
474 | "time: %s\n", | ||
475 | GNUNET_STRINGS_relative_time_to_string(latency, GNUNET_NO)); | ||
476 | echo_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, | ||
477 | &send_echo, | ||
478 | NULL); | ||
479 | } | ||
480 | } | 466 | } |
467 | else | ||
468 | { | ||
469 | struct GNUNET_TIME_Relative latency; | ||
470 | |||
471 | latency = GNUNET_TIME_absolute_get_duration (echo_time); | ||
472 | echo_time = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
473 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | ||
474 | "time: %s\n", | ||
475 | GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO)); | ||
476 | echo_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
477 | &send_echo, | ||
478 | NULL); | ||
479 | } | ||
480 | } | ||
481 | 481 | ||
482 | len = ntohs(message->size) - sizeof(*message); | 482 | len = ntohs (message->size) - sizeof(*message); |
483 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len); | 483 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len); |
484 | buf = (const char *)&message[1]; | 484 | buf = (const char *) &message[1]; |
485 | off = 0; | 485 | off = 0; |
486 | while (off < len) | 486 | while (off < len) |
487 | { | ||
488 | done = write (1, &buf[off], len - off); | ||
489 | if (done <= 0) | ||
487 | { | 490 | { |
488 | done = write(1, &buf[off], len - off); | 491 | if (-1 == done) |
489 | if (done <= 0) | 492 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write"); |
490 | { | 493 | GNUNET_SCHEDULER_shutdown (); |
491 | if (-1 == done) | 494 | return; |
492 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "write"); | ||
493 | GNUNET_SCHEDULER_shutdown(); | ||
494 | return; | ||
495 | } | ||
496 | off += done; | ||
497 | } | 495 | } |
496 | off += done; | ||
497 | } | ||
498 | } | 498 | } |
499 | 499 | ||
500 | 500 | ||
@@ -508,19 +508,19 @@ handle_data(void *cls, const struct GNUNET_MessageHeader *message) | |||
508 | * @param ple information about peer, or NULL on "EOF". | 508 | * @param ple information about peer, or NULL on "EOF". |
509 | */ | 509 | */ |
510 | static void | 510 | static void |
511 | peers_callback(void *cls, const struct GNUNET_CADET_PeerListEntry *ple) | 511 | peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple) |
512 | { | 512 | { |
513 | if (NULL == ple) | 513 | if (NULL == ple) |
514 | { | 514 | { |
515 | plo = NULL; | 515 | plo = NULL; |
516 | GNUNET_SCHEDULER_shutdown(); | 516 | GNUNET_SCHEDULER_shutdown (); |
517 | return; | 517 | return; |
518 | } | 518 | } |
519 | fprintf(stdout, | 519 | fprintf (stdout, |
520 | "%s tunnel: %c, paths: %u\n", | 520 | "%s tunnel: %c, paths: %u\n", |
521 | GNUNET_i2s_full(&ple->peer), | 521 | GNUNET_i2s_full (&ple->peer), |
522 | ple->have_tunnel ? 'Y' : 'N', | 522 | ple->have_tunnel ? 'Y' : 'N', |
523 | ple->n_paths); | 523 | ple->n_paths); |
524 | } | 524 | } |
525 | 525 | ||
526 | 526 | ||
@@ -532,20 +532,20 @@ peers_callback(void *cls, const struct GNUNET_CADET_PeerListEntry *ple) | |||
532 | * @param ppd path detail | 532 | * @param ppd path detail |
533 | */ | 533 | */ |
534 | static void | 534 | static void |
535 | path_callback(void *cls, const struct GNUNET_CADET_PeerPathDetail *ppd) | 535 | path_callback (void *cls, const struct GNUNET_CADET_PeerPathDetail *ppd) |
536 | { | 536 | { |
537 | if (NULL == ppd) | 537 | if (NULL == ppd) |
538 | { | 538 | { |
539 | gpo = NULL; | 539 | gpo = NULL; |
540 | GNUNET_SCHEDULER_shutdown(); | 540 | GNUNET_SCHEDULER_shutdown (); |
541 | return; | 541 | return; |
542 | } | 542 | } |
543 | fprintf(stdout, "Path of length %u: ", ppd->path_length); | 543 | fprintf (stdout, "Path of length %u: ", ppd->path_length); |
544 | for (unsigned int i = 0; i < ppd->path_length; i++) | 544 | for (unsigned int i = 0; i < ppd->path_length; i++) |
545 | fprintf(stdout, | 545 | fprintf (stdout, |
546 | (i == ppd->target_offset) ? "*%s* " : "%s ", | 546 | (i == ppd->target_offset) ? "*%s* " : "%s ", |
547 | GNUNET_i2s(&ppd->path[i])); | 547 | GNUNET_i2s (&ppd->path[i])); |
548 | fprintf(stdout, "\n"); | 548 | fprintf (stdout, "\n"); |
549 | } | 549 | } |
550 | 550 | ||
551 | 551 | ||
@@ -556,21 +556,21 @@ path_callback(void *cls, const struct GNUNET_CADET_PeerPathDetail *ppd) | |||
556 | * @param td tunnel details | 556 | * @param td tunnel details |
557 | */ | 557 | */ |
558 | static void | 558 | static void |
559 | tunnels_callback(void *cls, const struct GNUNET_CADET_TunnelDetails *td) | 559 | tunnels_callback (void *cls, const struct GNUNET_CADET_TunnelDetails *td) |
560 | { | 560 | { |
561 | if (NULL == td) | 561 | if (NULL == td) |
562 | { | 562 | { |
563 | tio = NULL; | 563 | tio = NULL; |
564 | GNUNET_SCHEDULER_shutdown(); | 564 | GNUNET_SCHEDULER_shutdown (); |
565 | return; | 565 | return; |
566 | } | 566 | } |
567 | fprintf(stdout, | 567 | fprintf (stdout, |
568 | "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n", | 568 | "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n", |
569 | GNUNET_i2s_full(&td->peer), | 569 | GNUNET_i2s_full (&td->peer), |
570 | enc_2s(td->estate), | 570 | enc_2s (td->estate), |
571 | conn_2s(td->cstate), | 571 | conn_2s (td->cstate), |
572 | td->channels, | 572 | td->channels, |
573 | td->connections); | 573 | td->connections); |
574 | } | 574 | } |
575 | 575 | ||
576 | 576 | ||
@@ -580,10 +580,10 @@ tunnels_callback(void *cls, const struct GNUNET_CADET_TunnelDetails *td) | |||
580 | * @param cls Closure (unused). | 580 | * @param cls Closure (unused). |
581 | */ | 581 | */ |
582 | static void | 582 | static void |
583 | get_peers(void *cls) | 583 | get_peers (void *cls) |
584 | { | 584 | { |
585 | job = NULL; | 585 | job = NULL; |
586 | plo = GNUNET_CADET_list_peers(my_cfg, &peers_callback, NULL); | 586 | plo = GNUNET_CADET_list_peers (my_cfg, &peers_callback, NULL); |
587 | } | 587 | } |
588 | 588 | ||
589 | 589 | ||
@@ -593,20 +593,20 @@ get_peers(void *cls) | |||
593 | * @param cls Closure (unused). | 593 | * @param cls Closure (unused). |
594 | */ | 594 | */ |
595 | static void | 595 | static void |
596 | show_peer(void *cls) | 596 | show_peer (void *cls) |
597 | { | 597 | { |
598 | struct GNUNET_PeerIdentity pid; | 598 | struct GNUNET_PeerIdentity pid; |
599 | 599 | ||
600 | job = NULL; | 600 | job = NULL; |
601 | if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string(peer_id, | 601 | if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, |
602 | strlen(peer_id), | 602 | strlen (peer_id), |
603 | &pid.public_key)) | 603 | &pid.public_key)) |
604 | { | 604 | { |
605 | fprintf(stderr, _("Invalid peer ID `%s'\n"), peer_id); | 605 | fprintf (stderr, _ ("Invalid peer ID `%s'\n"), peer_id); |
606 | GNUNET_SCHEDULER_shutdown(); | 606 | GNUNET_SCHEDULER_shutdown (); |
607 | return; | 607 | return; |
608 | } | 608 | } |
609 | gpo = GNUNET_CADET_get_path(my_cfg, &pid, &path_callback, NULL); | 609 | gpo = GNUNET_CADET_get_path (my_cfg, &pid, &path_callback, NULL); |
610 | } | 610 | } |
611 | 611 | ||
612 | 612 | ||
@@ -616,10 +616,10 @@ show_peer(void *cls) | |||
616 | * @param cls Closure (unused). | 616 | * @param cls Closure (unused). |
617 | */ | 617 | */ |
618 | static void | 618 | static void |
619 | get_tunnels(void *cls) | 619 | get_tunnels (void *cls) |
620 | { | 620 | { |
621 | job = NULL; | 621 | job = NULL; |
622 | tio = GNUNET_CADET_list_tunnels(my_cfg, &tunnels_callback, NULL); | 622 | tio = GNUNET_CADET_list_tunnels (my_cfg, &tunnels_callback, NULL); |
623 | } | 623 | } |
624 | 624 | ||
625 | 625 | ||
@@ -629,10 +629,10 @@ get_tunnels(void *cls) | |||
629 | * @param cls Closure (unused). | 629 | * @param cls Closure (unused). |
630 | */ | 630 | */ |
631 | static void | 631 | static void |
632 | show_channel(void *cls) | 632 | show_channel (void *cls) |
633 | { | 633 | { |
634 | job = NULL; | 634 | job = NULL; |
635 | GNUNET_break(0); | 635 | GNUNET_break (0); |
636 | } | 636 | } |
637 | 637 | ||
638 | 638 | ||
@@ -642,10 +642,10 @@ show_channel(void *cls) | |||
642 | * @param cls Closure (unused). | 642 | * @param cls Closure (unused). |
643 | */ | 643 | */ |
644 | static void | 644 | static void |
645 | show_connection(void *cls) | 645 | show_connection (void *cls) |
646 | { | 646 | { |
647 | job = NULL; | 647 | job = NULL; |
648 | GNUNET_break(0); | 648 | GNUNET_break (0); |
649 | } | 649 | } |
650 | 650 | ||
651 | 651 | ||
@@ -658,17 +658,17 @@ show_connection(void *cls) | |||
658 | * @param cfg configuration | 658 | * @param cfg configuration |
659 | */ | 659 | */ |
660 | static void | 660 | static void |
661 | run(void *cls, | 661 | run (void *cls, |
662 | char *const *args, | 662 | char *const *args, |
663 | const char *cfgfile, | 663 | const char *cfgfile, |
664 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 664 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
665 | { | 665 | { |
666 | struct GNUNET_MQ_MessageHandler handlers[] = | 666 | struct GNUNET_MQ_MessageHandler handlers[] = |
667 | { GNUNET_MQ_hd_var_size(data, | 667 | { GNUNET_MQ_hd_var_size (data, |
668 | GNUNET_MESSAGE_TYPE_CADET_CLI, | 668 | GNUNET_MESSAGE_TYPE_CADET_CLI, |
669 | struct GNUNET_MessageHeader, | 669 | struct GNUNET_MessageHeader, |
670 | NULL), | 670 | NULL), |
671 | GNUNET_MQ_handler_end() }; | 671 | GNUNET_MQ_handler_end () }; |
672 | 672 | ||
673 | /* FIXME add option to monitor apps */ | 673 | /* FIXME add option to monitor apps */ |
674 | my_cfg = cfg; | 674 | my_cfg = cfg; |
@@ -676,105 +676,105 @@ run(void *cls, | |||
676 | if (target_id && args[1]) | 676 | if (target_id && args[1]) |
677 | target_port = args[1]; | 677 | target_port = args[1]; |
678 | 678 | ||
679 | if ((0 != (request_peers | request_tunnels) || NULL != conn_id || | 679 | if (((0 != (request_peers | request_tunnels))||(NULL != conn_id)|| |
680 | NULL != channel_id) && | 680 | (NULL != channel_id) ) && |
681 | target_id != NULL) | 681 | (target_id != NULL) ) |
682 | { | 682 | { |
683 | fprintf(stderr, | 683 | fprintf (stderr, |
684 | _("Extra arguments are not applicable " | 684 | _ ("Extra arguments are not applicable " |
685 | "in combination with this option.\n")); | 685 | "in combination with this option.\n")); |
686 | return; | 686 | return; |
687 | } | 687 | } |
688 | 688 | ||
689 | if (NULL != peer_id) | 689 | if (NULL != peer_id) |
690 | { | 690 | { |
691 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show peer\n"); | 691 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n"); |
692 | job = GNUNET_SCHEDULER_add_now(&show_peer, NULL); | 692 | job = GNUNET_SCHEDULER_add_now (&show_peer, NULL); |
693 | } | 693 | } |
694 | else if (NULL != channel_id) | 694 | else if (NULL != channel_id) |
695 | { | 695 | { |
696 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show channel\n"); | 696 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show channel\n"); |
697 | job = GNUNET_SCHEDULER_add_now(&show_channel, NULL); | 697 | job = GNUNET_SCHEDULER_add_now (&show_channel, NULL); |
698 | } | 698 | } |
699 | else if (NULL != conn_id) | 699 | else if (NULL != conn_id) |
700 | { | 700 | { |
701 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show connection\n"); | 701 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n"); |
702 | job = GNUNET_SCHEDULER_add_now(&show_connection, NULL); | 702 | job = GNUNET_SCHEDULER_add_now (&show_connection, NULL); |
703 | } | 703 | } |
704 | else if (GNUNET_YES == request_peers) | 704 | else if (GNUNET_YES == request_peers) |
705 | { | 705 | { |
706 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n"); | 706 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n"); |
707 | job = GNUNET_SCHEDULER_add_now(&get_peers, NULL); | 707 | job = GNUNET_SCHEDULER_add_now (&get_peers, NULL); |
708 | } | 708 | } |
709 | else if (GNUNET_YES == request_tunnels) | 709 | else if (GNUNET_YES == request_tunnels) |
710 | { | 710 | { |
711 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n"); | 711 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n"); |
712 | job = GNUNET_SCHEDULER_add_now(&get_tunnels, NULL); | 712 | job = GNUNET_SCHEDULER_add_now (&get_tunnels, NULL); |
713 | } | 713 | } |
714 | 714 | ||
715 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting to CADET service\n"); | 715 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CADET service\n"); |
716 | mh = GNUNET_CADET_connect(cfg); | 716 | mh = GNUNET_CADET_connect (cfg); |
717 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); | 717 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
718 | if (NULL == mh) | 718 | if (NULL == mh) |
719 | { | ||
720 | GNUNET_SCHEDULER_shutdown (); | ||
721 | return; | ||
722 | } | ||
723 | if (NULL != listen_port) | ||
724 | { | ||
725 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opening CADET listen port\n"); | ||
726 | GNUNET_CRYPTO_hash (listen_port, strlen (listen_port), &porthash); | ||
727 | lp = GNUNET_CADET_open_port (mh, | ||
728 | &porthash, | ||
729 | &channel_incoming, | ||
730 | NULL, | ||
731 | NULL /* window changes */, | ||
732 | &channel_ended, | ||
733 | handlers); | ||
734 | } | ||
735 | if (NULL != target_id) | ||
736 | { | ||
737 | struct GNUNET_PeerIdentity pid; | ||
738 | |||
739 | if (GNUNET_OK != | ||
740 | GNUNET_CRYPTO_eddsa_public_key_from_string (target_id, | ||
741 | strlen (target_id), | ||
742 | &pid.public_key)) | ||
719 | { | 743 | { |
720 | GNUNET_SCHEDULER_shutdown(); | 744 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
745 | _ ("Invalid target `%s'\n"), | ||
746 | target_id); | ||
747 | GNUNET_SCHEDULER_shutdown (); | ||
721 | return; | 748 | return; |
722 | } | 749 | } |
723 | if (NULL != listen_port) | 750 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
751 | "Connecting to `%s:%s'\n", | ||
752 | target_id, | ||
753 | target_port); | ||
754 | GNUNET_CRYPTO_hash (target_port, strlen (target_port), &porthash); | ||
755 | ch = GNUNET_CADET_channel_create (mh, | ||
756 | NULL, | ||
757 | &pid, | ||
758 | &porthash, | ||
759 | NULL /* window changes */, | ||
760 | &channel_ended, | ||
761 | handlers); | ||
762 | if (GNUNET_YES == echo) | ||
724 | { | 763 | { |
725 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Opening CADET listen port\n"); | 764 | echo_task = GNUNET_SCHEDULER_add_now (&send_echo, NULL); |
726 | GNUNET_CRYPTO_hash(listen_port, strlen(listen_port), &porthash); | ||
727 | lp = GNUNET_CADET_open_port(mh, | ||
728 | &porthash, | ||
729 | &channel_incoming, | ||
730 | NULL, | ||
731 | NULL /* window changes */, | ||
732 | &channel_ended, | ||
733 | handlers); | ||
734 | } | 765 | } |
735 | if (NULL != target_id) | 766 | else |
736 | { | 767 | { |
737 | struct GNUNET_PeerIdentity pid; | 768 | listen_stdio (); |
738 | |||
739 | if (GNUNET_OK != | ||
740 | GNUNET_CRYPTO_eddsa_public_key_from_string(target_id, | ||
741 | strlen(target_id), | ||
742 | &pid.public_key)) | ||
743 | { | ||
744 | GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE, | ||
745 | _("Invalid target `%s'\n"), | ||
746 | target_id); | ||
747 | GNUNET_SCHEDULER_shutdown(); | ||
748 | return; | ||
749 | } | ||
750 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
751 | "Connecting to `%s:%s'\n", | ||
752 | target_id, | ||
753 | target_port); | ||
754 | GNUNET_CRYPTO_hash(target_port, strlen(target_port), &porthash); | ||
755 | ch = GNUNET_CADET_channel_create(mh, | ||
756 | NULL, | ||
757 | &pid, | ||
758 | &porthash, | ||
759 | NULL /* window changes */, | ||
760 | &channel_ended, | ||
761 | handlers); | ||
762 | if (GNUNET_YES == echo) | ||
763 | { | ||
764 | echo_task = GNUNET_SCHEDULER_add_now(&send_echo, NULL); | ||
765 | } | ||
766 | else | ||
767 | { | ||
768 | listen_stdio(); | ||
769 | } | ||
770 | } | 769 | } |
770 | } | ||
771 | 771 | ||
772 | if ((NULL == lp) && (NULL == job) && (NULL == ch)) | 772 | if ((NULL == lp) && (NULL == job) && (NULL == ch)) |
773 | { | 773 | { |
774 | GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE, _("No action requested\n")); | 774 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, _ ("No action requested\n")); |
775 | GNUNET_SCHEDULER_shutdown(); | 775 | GNUNET_SCHEDULER_shutdown (); |
776 | return; | 776 | return; |
777 | } | 777 | } |
778 | } | 778 | } |
779 | 779 | ||
780 | 780 | ||
@@ -786,61 +786,60 @@ run(void *cls, | |||
786 | * @return 0 ok, 1 on error | 786 | * @return 0 ok, 1 on error |
787 | */ | 787 | */ |
788 | int | 788 | int |
789 | main(int argc, char *const *argv) | 789 | main (int argc, char *const *argv) |
790 | { | 790 | { |
791 | int res; | 791 | int res; |
792 | const char helpstr[] = | 792 | const char helpstr[] = |
793 | "Create tunnels and retrieve info about CADET's status."; | 793 | "Create tunnels and retrieve info about CADET's status."; |
794 | struct GNUNET_GETOPT_CommandLineOption options[] = | 794 | struct GNUNET_GETOPT_CommandLineOption options[] = { /* I would use the terminology 'circuit' here... --lynX */ |
795 | { /* I would use the terminology 'circuit' here... --lynX */ | 795 | GNUNET_GETOPT_option_string ( |
796 | GNUNET_GETOPT_option_string( | ||
797 | 'C', | 796 | 'C', |
798 | "connection", | 797 | "connection", |
799 | "CONNECTION_ID", | 798 | "CONNECTION_ID", |
800 | gettext_noop("Provide information about a particular connection"), | 799 | gettext_noop ("Provide information about a particular connection"), |
801 | &conn_id), | 800 | &conn_id), |
802 | GNUNET_GETOPT_option_flag('e', | 801 | GNUNET_GETOPT_option_flag ('e', |
803 | "echo", | 802 | "echo", |
804 | gettext_noop("Activate echo mode"), | 803 | gettext_noop ("Activate echo mode"), |
805 | &echo), | 804 | &echo), |
806 | GNUNET_GETOPT_option_string( | 805 | GNUNET_GETOPT_option_string ( |
807 | 'o', | 806 | 'o', |
808 | "open-port", | 807 | "open-port", |
809 | "SHARED_SECRET", | 808 | "SHARED_SECRET", |
810 | gettext_noop( | 809 | gettext_noop ( |
811 | "Listen for connections using a shared secret among sender and recipient"), | 810 | "Listen for connections using a shared secret among sender and recipient"), |
812 | &listen_port), | 811 | &listen_port), |
813 | GNUNET_GETOPT_option_string('p', | 812 | GNUNET_GETOPT_option_string ('p', |
814 | "peer", | 813 | "peer", |
815 | "PEER_ID", | 814 | "PEER_ID", |
816 | gettext_noop( | 815 | gettext_noop ( |
817 | "Provide information about a patricular peer"), | 816 | "Provide information about a patricular peer"), |
818 | &peer_id), | 817 | &peer_id), |
819 | GNUNET_GETOPT_option_flag('P', | 818 | GNUNET_GETOPT_option_flag ('P', |
820 | "peers", | 819 | "peers", |
821 | gettext_noop( | 820 | gettext_noop ( |
822 | "Provide information about all peers"), | 821 | "Provide information about all peers"), |
823 | &request_peers), | 822 | &request_peers), |
824 | GNUNET_GETOPT_option_flag('T', | 823 | GNUNET_GETOPT_option_flag ('T', |
825 | "tunnels", | 824 | "tunnels", |
826 | gettext_noop( | 825 | gettext_noop ( |
827 | "Provide information about all tunnels"), | 826 | "Provide information about all tunnels"), |
828 | &request_tunnels), | 827 | &request_tunnels), |
829 | GNUNET_GETOPT_OPTION_END | 828 | GNUNET_GETOPT_OPTION_END |
830 | }; | 829 | }; |
831 | 830 | ||
832 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 831 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
833 | return 2; | 832 | return 2; |
834 | 833 | ||
835 | res = GNUNET_PROGRAM_run(argc, | 834 | res = GNUNET_PROGRAM_run (argc, |
836 | argv, | 835 | argv, |
837 | "gnunet-cadet (OPTIONS | PEER_ID SHARED_SECRET)", | 836 | "gnunet-cadet (OPTIONS | PEER_ID SHARED_SECRET)", |
838 | gettext_noop(helpstr), | 837 | gettext_noop (helpstr), |
839 | options, | 838 | options, |
840 | &run, | 839 | &run, |
841 | NULL); | 840 | NULL); |
842 | 841 | ||
843 | GNUNET_free((void *)argv); | 842 | GNUNET_free ((void *) argv); |
844 | 843 | ||
845 | if (GNUNET_OK == res) | 844 | if (GNUNET_OK == res) |
846 | return 0; | 845 | return 0; |