diff options
Diffstat (limited to 'src/cadet/gnunet-cadet.c')
-rw-r--r-- | src/cadet/gnunet-cadet.c | 101 |
1 files changed, 71 insertions, 30 deletions
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c index a9b02714b..13b04b885 100644 --- a/src/cadet/gnunet-cadet.c +++ b/src/cadet/gnunet-cadet.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2012, 2017 GNUnet e.V. | 3 | Copyright (C) 2012, 2017 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
@@ -29,6 +27,7 @@ | |||
29 | #include "gnunet_cadet_service.h" | 27 | #include "gnunet_cadet_service.h" |
30 | #include "cadet.h" | 28 | #include "cadet.h" |
31 | 29 | ||
30 | #define STREAM_BUFFER_SIZE 1024 // Pakets | ||
32 | 31 | ||
33 | /** | 32 | /** |
34 | * Option -P. | 33 | * Option -P. |
@@ -125,6 +124,8 @@ static struct GNUNET_SCHEDULER_Task *rd_task; | |||
125 | */ | 124 | */ |
126 | static struct GNUNET_SCHEDULER_Task *job; | 125 | static struct GNUNET_SCHEDULER_Task *job; |
127 | 126 | ||
127 | static unsigned int sent_pkt; | ||
128 | |||
128 | 129 | ||
129 | /** | 130 | /** |
130 | * Wait for input on STDIO and send it out over the #ch. | 131 | * Wait for input on STDIO and send it out over the #ch. |
@@ -198,6 +199,11 @@ shutdown_task (void *cls) | |||
198 | { | 199 | { |
199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
200 | "Shutdown\n"); | 201 | "Shutdown\n"); |
202 | if (NULL != lp) | ||
203 | { | ||
204 | GNUNET_CADET_close_port (lp); | ||
205 | lp = NULL; | ||
206 | } | ||
201 | if (NULL != ch) | 207 | if (NULL != ch) |
202 | { | 208 | { |
203 | GNUNET_CADET_channel_destroy (ch); | 209 | GNUNET_CADET_channel_destroy (ch); |
@@ -225,6 +231,12 @@ shutdown_task (void *cls) | |||
225 | } | 231 | } |
226 | } | 232 | } |
227 | 233 | ||
234 | void | ||
235 | mq_cb(void *cls) | ||
236 | { | ||
237 | listen_stdio (); | ||
238 | } | ||
239 | |||
228 | 240 | ||
229 | /** | 241 | /** |
230 | * Task run in stdio mode, after some data is available at stdin. | 242 | * Task run in stdio mode, after some data is available at stdin. |
@@ -245,6 +257,8 @@ read_stdio (void *cls) | |||
245 | 60000); | 257 | 60000); |
246 | if (data_size < 1) | 258 | if (data_size < 1) |
247 | { | 259 | { |
260 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
261 | "read() returned %s\n", strerror(errno)); | ||
248 | GNUNET_SCHEDULER_shutdown(); | 262 | GNUNET_SCHEDULER_shutdown(); |
249 | return; | 263 | return; |
250 | } | 264 | } |
@@ -259,9 +273,21 @@ read_stdio (void *cls) | |||
259 | data_size); | 273 | data_size); |
260 | GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), | 274 | GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), |
261 | env); | 275 | env); |
276 | |||
277 | sent_pkt++; | ||
278 | |||
262 | if (GNUNET_NO == echo) | 279 | if (GNUNET_NO == echo) |
263 | { | 280 | { |
264 | listen_stdio (); | 281 | // Use MQ's notification if too much data of stdin is pooring in too fast. |
282 | if (STREAM_BUFFER_SIZE < sent_pkt) | ||
283 | { | ||
284 | GNUNET_MQ_notify_sent (env, mq_cb, cls); | ||
285 | sent_pkt = 0; | ||
286 | } | ||
287 | else | ||
288 | { | ||
289 | listen_stdio (); | ||
290 | } | ||
265 | } | 291 | } |
266 | else | 292 | else |
267 | { | 293 | { |
@@ -375,6 +401,7 @@ send_echo (void *cls) | |||
375 | static void | 401 | static void |
376 | request_dump (void *cls) | 402 | request_dump (void *cls) |
377 | { | 403 | { |
404 | job = NULL; | ||
378 | GNUNET_CADET_request_dump (mh); | 405 | GNUNET_CADET_request_dump (mh); |
379 | GNUNET_SCHEDULER_shutdown (); | 406 | GNUNET_SCHEDULER_shutdown (); |
380 | } | 407 | } |
@@ -526,34 +553,48 @@ peer_callback (void *cls, | |||
526 | int tunnel, | 553 | int tunnel, |
527 | int neighbor, | 554 | int neighbor, |
528 | unsigned int n_paths, | 555 | unsigned int n_paths, |
529 | const struct GNUNET_PeerIdentity *paths) | 556 | const struct GNUNET_PeerIdentity *paths, |
557 | int offset, | ||
558 | int finished_with_paths) | ||
530 | { | 559 | { |
531 | unsigned int i; | 560 | unsigned int i; |
532 | const struct GNUNET_PeerIdentity *p; | 561 | const struct GNUNET_PeerIdentity *p; |
533 | 562 | ||
534 | FPRINTF (stdout, | 563 | |
535 | "%s [TUNNEL: %s, NEIGHBOR: %s, PATHS: %u]\n", | 564 | if (GNUNET_YES == finished_with_paths) |
536 | GNUNET_i2s_full (peer), | ||
537 | tunnel ? "Y" : "N", | ||
538 | neighbor ? "Y" : "N", | ||
539 | n_paths); | ||
540 | p = paths; | ||
541 | for (i = 0; i < n_paths && NULL != p;) | ||
542 | { | 565 | { |
566 | GNUNET_SCHEDULER_shutdown(); | ||
567 | return; | ||
568 | } | ||
569 | |||
570 | if (offset == 0){ | ||
571 | FPRINTF (stdout, | ||
572 | "%s [TUNNEL: %s, NEIGHBOR: %s, PATHS: %u]\n", | ||
573 | GNUNET_i2s_full (peer), | ||
574 | tunnel ? "Y" : "N", | ||
575 | neighbor ? "Y" : "N", | ||
576 | n_paths); | ||
577 | }else{ | ||
578 | p = paths; | ||
543 | FPRINTF (stdout, | 579 | FPRINTF (stdout, |
544 | "%s ", | 580 | "Indirekt path with offset %u: ", |
545 | GNUNET_i2s (p)); | 581 | offset); |
546 | if (0 == memcmp (p, | 582 | for (i = 0; i <= offset && NULL != p;) |
547 | peer, | ||
548 | sizeof (*p))) | ||
549 | { | 583 | { |
550 | FPRINTF (stdout, "\n"); | 584 | FPRINTF (stdout, |
551 | i++; | 585 | "%s ", |
586 | GNUNET_i2s (p)); | ||
587 | i++; | ||
588 | p++; | ||
552 | } | 589 | } |
553 | p++; | 590 | |
591 | FPRINTF (stdout, | ||
592 | "\n"); | ||
593 | |||
554 | } | 594 | } |
595 | |||
555 | 596 | ||
556 | GNUNET_SCHEDULER_shutdown(); | 597 | |
557 | } | 598 | } |
558 | 599 | ||
559 | 600 | ||