aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-02-17 20:22:54 +0100
committerChristian Grothoff <christian@grothoff.org>2017-02-17 20:22:54 +0100
commitcbafa8e54f0399bf4213c313a72907ba92250375 (patch)
tree63eb66a2c878048527e99ba3eb2b24c0797774eb /src/cadet
parent89d3a0ad2a64c027af5a1a9ac4f3ec23a8ae8868 (diff)
downloadgnunet-cbafa8e54f0399bf4213c313a72907ba92250375.tar.gz
gnunet-cbafa8e54f0399bf4213c313a72907ba92250375.zip
misc fixes in new CADET API, porting gnunet-cadet to new API
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/Makefile.am4
-rw-r--r--src/cadet/cadet_api_new.c405
-rw-r--r--src/cadet/gnunet-cadet.c559
3 files changed, 422 insertions, 546 deletions
diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am
index 9b593b486..1a51453c9 100644
--- a/src/cadet/Makefile.am
+++ b/src/cadet/Makefile.am
@@ -58,7 +58,7 @@ libgnunetcadetnew_la_LDFLAGS = \
58gnunet_cadet_SOURCES = \ 58gnunet_cadet_SOURCES = \
59 gnunet-cadet.c 59 gnunet-cadet.c
60gnunet_cadet_LDADD = \ 60gnunet_cadet_LDADD = \
61 libgnunetcadet.la \ 61 libgnunetcadetnew.la \
62 $(top_builddir)/src/util/libgnunetutil.la 62 $(top_builddir)/src/util/libgnunetutil.la
63 63
64gnunet_service_cadet_new_SOURCES = \ 64gnunet_service_cadet_new_SOURCES = \
@@ -175,7 +175,7 @@ test_cadet_local_LDADD = $(ld_cadet_test_lib)
175test_cadet_local_mq_SOURCES = \ 175test_cadet_local_mq_SOURCES = \
176 test_cadet_local_mq.c 176 test_cadet_local_mq.c
177test_cadet_local_mq_LDADD = \ 177test_cadet_local_mq_LDADD = \
178 libgnunetcadet.la \ 178 libgnunetcadetnew.la \
179 $(top_builddir)/src/testing/libgnunettesting.la \ 179 $(top_builddir)/src/testing/libgnunettesting.la \
180 $(top_builddir)/src/util/libgnunetutil.la 180 $(top_builddir)/src/util/libgnunetutil.la
181 181
diff --git a/src/cadet/cadet_api_new.c b/src/cadet/cadet_api_new.c
index e9ab3ea57..8d778e10e 100644
--- a/src/cadet/cadet_api_new.c
+++ b/src/cadet/cadet_api_new.c
@@ -146,7 +146,7 @@ struct GNUNET_CADET_Channel
146 void *ctx; 146 void *ctx;
147 147
148 /** 148 /**
149 * Message Queue for the channel. 149 * Message Queue for the channel (which we are implementing).
150 */ 150 */
151 struct GNUNET_MQ_Handle *mq; 151 struct GNUNET_MQ_Handle *mq;
152 152
@@ -156,7 +156,9 @@ struct GNUNET_CADET_Channel
156 struct GNUNET_SCHEDULER_Task *mq_cont; 156 struct GNUNET_SCHEDULER_Task *mq_cont;
157 157
158 /** 158 /**
159 * Pending envelope in case we don't have an ACK from the service. 159 * Pending envelope with a message to be transmitted to the
160 * service as soon as we are allowed to. Should only be
161 * non-NULL if @e allow_send is 0.
160 */ 162 */
161 struct GNUNET_MQ_Envelope *pending_env; 163 struct GNUNET_MQ_Envelope *pending_env;
162 164
@@ -181,7 +183,7 @@ struct GNUNET_CADET_Channel
181 enum GNUNET_CADET_ChannelOption options; 183 enum GNUNET_CADET_ChannelOption options;
182 184
183 /** 185 /**
184 * Are we allowed to send to the service? 186 * How many messages are we allowed to send to the service right now?
185 */ 187 */
186 unsigned int allow_send; 188 unsigned int allow_send;
187 189
@@ -193,6 +195,12 @@ struct GNUNET_CADET_Channel
193 */ 195 */
194struct GNUNET_CADET_Port 196struct GNUNET_CADET_Port
195{ 197{
198
199 /**
200 * Port "number"
201 */
202 struct GNUNET_HashCode id;
203
196 /** 204 /**
197 * Handle to the CADET session this port belongs to. 205 * Handle to the CADET session this port belongs to.
198 */ 206 */
@@ -209,11 +217,6 @@ struct GNUNET_CADET_Port
209 void *cls; 217 void *cls;
210 218
211 /** 219 /**
212 * Port "number"
213 */
214 struct GNUNET_HashCode id;
215
216 /**
217 * Handler for incoming channels on this port 220 * Handler for incoming channels on this port
218 */ 221 */
219 GNUNET_CADET_ConnectEventHandler connects; 222 GNUNET_CADET_ConnectEventHandler connects;
@@ -229,7 +232,7 @@ struct GNUNET_CADET_Port
229 GNUNET_CADET_WindowSizeEventHandler window_changes; 232 GNUNET_CADET_WindowSizeEventHandler window_changes;
230 233
231 /** 234 /**
232 * Handler called when an incoming channel is destroyed.. 235 * Handler called when an incoming channel is destroyed.
233 */ 236 */
234 GNUNET_CADET_DisconnectEventHandler disconnects; 237 GNUNET_CADET_DisconnectEventHandler disconnects;
235 238
@@ -327,7 +330,7 @@ destroy_channel (struct GNUNET_CADET_Channel *ch)
327 struct GNUNET_CADET_Handle *h = ch->cadet; 330 struct GNUNET_CADET_Handle *h = ch->cadet;
328 331
329 LOG (GNUNET_ERROR_TYPE_DEBUG, 332 LOG (GNUNET_ERROR_TYPE_DEBUG,
330 " destroy_channel %X of %p\n", 333 "Destroying channel %X of %p\n",
331 ch->ccn, 334 ch->ccn,
332 h); 335 h);
333 GNUNET_assert (GNUNET_YES == 336 GNUNET_assert (GNUNET_YES ==
@@ -343,6 +346,7 @@ destroy_channel (struct GNUNET_CADET_Channel *ch)
343 if (NULL != ch->disconnects) 346 if (NULL != ch->disconnects)
344 ch->disconnects (ch->ctx, 347 ch->disconnects (ch->ctx,
345 ch); 348 ch);
349 GNUNET_MQ_destroy (ch->mq);
346 GNUNET_free (ch); 350 GNUNET_free (ch);
347} 351}
348 352
@@ -374,6 +378,28 @@ reconnect_cbk (void *cls)
374 378
375 379
376/** 380/**
381 * Function called during #reconnect() to destroy
382 * all channels that are still open.
383 *
384 * @param cls the `struct GNUNET_CADET_Handle`
385 * @param cid chanenl ID
386 * @param value a `struct GNUNET_CADET_Channel` to destroy
387 * @return #GNUNET_OK (continue to iterate)
388 */
389static int
390destroy_channel_on_reconnect_cb (void *cls,
391 uint32_t cid,
392 void *value)
393{
394 /* struct GNUNET_CADET_Handle *handle = cls; */
395 struct GNUNET_CADET_Channel *ch = value;
396
397 destroy_channel (ch);
398 return GNUNET_OK;
399}
400
401
402/**
377 * Reconnect to the service, retransmit all infomation to try to restore the 403 * Reconnect to the service, retransmit all infomation to try to restore the
378 * original state. 404 * original state.
379 * 405 *
@@ -384,12 +410,17 @@ reconnect_cbk (void *cls)
384static void 410static void
385schedule_reconnect (struct GNUNET_CADET_Handle *h) 411schedule_reconnect (struct GNUNET_CADET_Handle *h)
386{ 412{
387 if (NULL == h->reconnect_task) 413 if (NULL != h->reconnect_task)
388 { 414 return;
389 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_time, 415 GNUNET_CONTAINER_multihashmap32_iterate (h->channels,
390 &reconnect_cbk, h); 416 &destroy_channel_on_reconnect_cb,
391 h->reconnect_time = GNUNET_TIME_STD_BACKOFF (h->reconnect_time); 417 h);
392 } 418 h->reconnect_task
419 = GNUNET_SCHEDULER_add_delayed (h->reconnect_time,
420 &reconnect_cbk,
421 h);
422 h->reconnect_time
423 = GNUNET_TIME_STD_BACKOFF (h->reconnect_time);
393} 424}
394 425
395 426
@@ -402,7 +433,8 @@ static void
402notify_window_size (struct GNUNET_CADET_Channel *ch) 433notify_window_size (struct GNUNET_CADET_Channel *ch)
403{ 434{
404 if (NULL != ch->window_changes) 435 if (NULL != ch->window_changes)
405 ch->window_changes (ch->ctx, ch, 436 ch->window_changes (ch->ctx,
437 ch, /* FIXME: remove 'ch'? */
406 ch->allow_send); 438 ch->allow_send);
407} 439}
408 440
@@ -418,9 +450,46 @@ cadet_mq_send_continue (void *cls)
418 struct GNUNET_CADET_Channel *ch = cls; 450 struct GNUNET_CADET_Channel *ch = cls;
419 451
420 ch->mq_cont = NULL; 452 ch->mq_cont = NULL;
453 GNUNET_assert (NULL == ch->pending_env);
421 GNUNET_MQ_impl_send_continue (ch->mq); 454 GNUNET_MQ_impl_send_continue (ch->mq);
422} 455}
423 456
457
458/**
459 * Transmit the next message from our queue.
460 *
461 * @param cls Closure (channel whose mq to activate).
462 */
463static void
464cadet_mq_send_now (void *cls)
465{
466 struct GNUNET_CADET_Channel *ch = cls;
467 struct GNUNET_MQ_Envelope *env = ch->pending_env;
468
469 ch->mq_cont = NULL;
470 if (0 == ch->allow_send)
471 {
472 /* how did we get here? */
473 GNUNET_break (0);
474 return;
475 }
476 if (NULL == env)
477 {
478 /* how did we get here? */
479 GNUNET_break (0);
480 return;
481 }
482 ch->allow_send--;
483 GNUNET_MQ_impl_send_in_flight (ch->mq);
484 ch->pending_env = NULL;
485 GNUNET_MQ_notify_sent (env,
486 &cadet_mq_send_continue,
487 ch);
488 GNUNET_MQ_send (ch->cadet->mq,
489 env);
490}
491
492
424/** 493/**
425 * Implement sending functionality of a message queue for 494 * Implement sending functionality of a message queue for
426 * us sending messages to a peer. 495 * us sending messages to a peer.
@@ -444,7 +513,6 @@ cadet_mq_send_impl (struct GNUNET_MQ_Handle *mq,
444 struct GNUNET_MQ_Envelope *env; 513 struct GNUNET_MQ_Envelope *env;
445 struct GNUNET_CADET_LocalData *cadet_msg; 514 struct GNUNET_CADET_LocalData *cadet_msg;
446 515
447
448 if (NULL == h->mq) 516 if (NULL == h->mq)
449 { 517 {
450 /* We're currently reconnecting, pretend this worked */ 518 /* We're currently reconnecting, pretend this worked */
@@ -460,26 +528,16 @@ cadet_mq_send_impl (struct GNUNET_MQ_Handle *mq,
460 GNUNET_MQ_impl_send_continue (mq); 528 GNUNET_MQ_impl_send_continue (mq);
461 return; 529 return;
462 } 530 }
463
464 env = GNUNET_MQ_msg_nested_mh (cadet_msg, 531 env = GNUNET_MQ_msg_nested_mh (cadet_msg,
465 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, 532 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA,
466 msg); 533 msg);
467 cadet_msg->ccn = ch->ccn; 534 cadet_msg->ccn = ch->ccn;
468 535 GNUNET_assert (NULL == ch->pending_env);
536 ch->pending_env = env;
469 if (0 < ch->allow_send) 537 if (0 < ch->allow_send)
470 { 538 ch->mq_cont
471 /* Service has allowed this message, just send it and continue accepting */ 539 = GNUNET_SCHEDULER_add_now (&cadet_mq_send_now,
472 GNUNET_MQ_send (h->mq, env); 540 ch);
473 ch->allow_send--;
474 ch->mq_cont = GNUNET_SCHEDULER_add_now (&cadet_mq_send_continue, ch);
475 // notify_window_size (ch); /* FIXME add "verbose" setting? */
476 }
477 else
478 {
479 /* Service has NOT allowed this message, queue it and wait for an ACK */
480 GNUNET_assert (NULL == ch->pending_env);
481 ch->pending_env = env;
482 }
483} 541}
484 542
485 543
@@ -515,12 +573,16 @@ cadet_mq_error_handler (void *cls,
515{ 573{
516 struct GNUNET_CADET_Channel *ch = cls; 574 struct GNUNET_CADET_Channel *ch = cls;
517 575
518 GNUNET_break_op (0); 576 GNUNET_break (0);
519 if (GNUNET_MQ_ERROR_NO_MATCH) 577 if (GNUNET_MQ_ERROR_NO_MATCH == error)
520 { 578 {
521 /* Got a message we did not understand, still try to continue! */ 579 /* Got a message we did not understand, still try to continue! */
522 GNUNET_CADET_receive_done (ch); 580 GNUNET_CADET_receive_done (ch);
523 } 581 }
582 else
583 {
584 schedule_reconnect (ch->cadet);
585 }
524} 586}
525 587
526 588
@@ -537,11 +599,9 @@ cadet_mq_cancel_impl (struct GNUNET_MQ_Handle *mq,
537{ 599{
538 struct GNUNET_CADET_Channel *ch = impl_state; 600 struct GNUNET_CADET_Channel *ch = impl_state;
539 601
540 LOG (GNUNET_ERROR_TYPE_WARNING, 602 GNUNET_assert (NULL != ch->pending_env);
541 "Cannot cancel mq message on channel %X of %p\n", 603 GNUNET_MQ_discard (ch->pending_env);
542 ch->ccn.channel_of_client, 604 ch->pending_env = NULL;
543 ch->cadet);
544 GNUNET_break (0);
545} 605}
546 606
547 607
@@ -568,7 +628,8 @@ handle_channel_created (void *cls,
568 GNUNET_break (0); 628 GNUNET_break (0);
569 return; 629 return;
570 } 630 }
571 port = find_port (h, port_number); 631 port = find_port (h,
632 port_number);
572 if (NULL == port) 633 if (NULL == port)
573 { 634 {
574 /* We could have closed the port but the service didn't know about it yet 635 /* We could have closed the port but the service didn't know about it yet
@@ -666,7 +727,7 @@ check_local_data (void *cls,
666 size = ntohs (message->header.size); 727 size = ntohs (message->header.size);
667 if (sizeof (*message) + sizeof (struct GNUNET_MessageHeader) > size) 728 if (sizeof (*message) + sizeof (struct GNUNET_MessageHeader) > size)
668 { 729 {
669 GNUNET_break_op (0); 730 GNUNET_break (0);
670 return GNUNET_SYSERR; 731 return GNUNET_SYSERR;
671 } 732 }
672 733
@@ -674,7 +735,7 @@ check_local_data (void *cls,
674 message->ccn); 735 message->ccn);
675 if (NULL == ch) 736 if (NULL == ch)
676 { 737 {
677 GNUNET_break_op (0); 738 GNUNET_break (0);
678 return GNUNET_SYSERR; 739 return GNUNET_SYSERR;
679 } 740 }
680 741
@@ -702,7 +763,7 @@ handle_local_data (void *cls,
702 message->ccn); 763 message->ccn);
703 if (NULL == ch) 764 if (NULL == ch)
704 { 765 {
705 GNUNET_break_op (0); 766 GNUNET_break (0);
706 reconnect (h); 767 reconnect (h);
707 return; 768 return;
708 } 769 }
@@ -752,19 +813,16 @@ handle_local_ack (void *cls,
752 ntohl (ch->ccn.channel_of_client), 813 ntohl (ch->ccn.channel_of_client),
753 ch->allow_send); 814 ch->allow_send);
754 notify_window_size (ch); 815 notify_window_size (ch);
816 return;
755 } 817 }
756 else 818 if (NULL != ch->mq_cont)
757 { 819 return; /* already working on it! */
758 LOG (GNUNET_ERROR_TYPE_DEBUG, 820 LOG (GNUNET_ERROR_TYPE_DEBUG,
759 "Got an ACK on mq channel %X, sending pending message!\n", 821 "Got an ACK on mq channel %X, sending pending message!\n",
760 ntohl (ch->ccn.channel_of_client)); 822 ntohl (ch->ccn.channel_of_client));
761 GNUNET_MQ_send (h->mq, 823 ch->mq_cont
762 ch->pending_env); 824 = GNUNET_SCHEDULER_add_now (&cadet_mq_send_now,
763 ch->allow_send--; 825 ch);
764 ch->pending_env = NULL;
765 ch->mq_cont = GNUNET_SCHEDULER_add_now (&cadet_mq_send_continue,
766 ch);
767 }
768} 826}
769 827
770 828
@@ -782,7 +840,9 @@ handle_mq_error (void *cls,
782{ 840{
783 struct GNUNET_CADET_Handle *h = cls; 841 struct GNUNET_CADET_Handle *h = cls;
784 842
785 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %u\n", error); 843 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
844 "MQ ERROR: %u\n",
845 error);
786 GNUNET_MQ_destroy (h->mq); 846 GNUNET_MQ_destroy (h->mq);
787 h->mq = NULL; 847 h->mq = NULL;
788 reconnect (h); 848 reconnect (h);
@@ -790,41 +850,6 @@ handle_mq_error (void *cls,
790 850
791 851
792/** 852/**
793 * Check that message received from CADET service is well-formed.
794 *
795 * @param cls the `struct GNUNET_CADET_Handle`
796 * @param message the message we got
797 * @return #GNUNET_OK if the message is well-formed,
798 * #GNUNET_SYSERR otherwise
799 */
800static int
801check_get_peers (void *cls,
802 const struct GNUNET_CADET_LocalInfoPeer *message)
803{
804 struct GNUNET_CADET_Handle *h = cls;
805 uint16_t size;
806
807 if (NULL == h->info_cb.peers_cb)
808 {
809 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
810 " no handler for peesr monitor message!\n");
811 return GNUNET_SYSERR;
812 }
813
814 size = ntohs (message->header.size);
815 if (sizeof (struct GNUNET_CADET_LocalInfoPeer) > size)
816 {
817 h->info_cb.peers_cb (h->info_cls, NULL, -1, 0, 0);
818 h->info_cb.peers_cb = NULL;
819 h->info_cls = NULL;
820 return GNUNET_SYSERR;
821 }
822
823 return GNUNET_OK;
824}
825
826
827/**
828 * Process a local reply about info on all tunnels, pass info to the user. 853 * Process a local reply about info on all tunnels, pass info to the user.
829 * 854 *
830 * @param cls Closure (Cadet handle). 855 * @param cls Closure (Cadet handle).
@@ -835,9 +860,13 @@ handle_get_peers (void *cls,
835 const struct GNUNET_CADET_LocalInfoPeer *msg) 860 const struct GNUNET_CADET_LocalInfoPeer *msg)
836{ 861{
837 struct GNUNET_CADET_Handle *h = cls; 862 struct GNUNET_CADET_Handle *h = cls;
838 h->info_cb.peers_cb (h->info_cls, &msg->destination, 863
864 if (NULL == h->info_cb.peers_cb)
865 return;
866 h->info_cb.peers_cb (h->info_cls,
867 &msg->destination,
839 (int) ntohs (msg->tunnel), 868 (int) ntohs (msg->tunnel),
840 (unsigned int ) ntohs (msg->paths), 869 (unsigned int) ntohs (msg->paths),
841 0); 870 0);
842} 871}
843 872
@@ -854,62 +883,39 @@ static int
854check_get_peer (void *cls, 883check_get_peer (void *cls,
855 const struct GNUNET_CADET_LocalInfoPeer *message) 884 const struct GNUNET_CADET_LocalInfoPeer *message)
856{ 885{
857 struct GNUNET_CADET_Handle *h = cls; 886 size_t msize = sizeof (struct GNUNET_CADET_LocalInfoPeer);
858 const size_t msize = sizeof (struct GNUNET_CADET_LocalInfoPeer); 887 const struct GNUNET_PeerIdentity *paths_array;
859 struct GNUNET_PeerIdentity *paths_array;
860 size_t esize; 888 size_t esize;
861 unsigned int epaths; 889 unsigned int epaths;
862 unsigned int paths; 890 unsigned int paths;
863 unsigned int peers; 891 unsigned int peers;
864 892
865 if (NULL == h->info_cb.peer_cb)
866 {
867 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
868 " no handler for peer monitor message!\n");
869 goto clean_cls;
870 }
871
872 /* Verify message sanity */
873 esize = ntohs (message->header.size); 893 esize = ntohs (message->header.size);
874 if (esize < msize) 894 if (esize < msize)
875 { 895 {
876 GNUNET_break_op (0); 896 GNUNET_break (0);
877 h->info_cb.peer_cb (h->info_cls, NULL, 0, 0, 0, NULL); 897 return GNUNET_SYSERR;
878 goto clean_cls;
879 } 898 }
880 if (0 != ((esize - msize) % sizeof (struct GNUNET_PeerIdentity))) 899 if (0 != ((esize - msize) % sizeof (struct GNUNET_PeerIdentity)))
881 { 900 {
882 GNUNET_break_op (0); 901 GNUNET_break (0);
883 h->info_cb.peer_cb (h->info_cls, NULL, 0, 0, 0, NULL); 902 return GNUNET_SYSERR;
884 goto clean_cls;
885
886 } 903 }
887 peers = (esize - msize) / sizeof (struct GNUNET_PeerIdentity); 904 peers = (esize - msize) / sizeof (struct GNUNET_PeerIdentity);
888 epaths = (unsigned int) ntohs (message->paths); 905 epaths = ntohs (message->paths);
889 paths_array = (struct GNUNET_PeerIdentity *) &message[1]; 906 paths_array = (const struct GNUNET_PeerIdentity *) &message[1];
890 paths = 0; 907 paths = 0;
891 for (int i = 0; i < peers; i++) 908 for (unsigned int i = 0; i < peers; i++)
892 { 909 if (0 == memcmp (&paths_array[i],
893 if (0 == memcmp (&paths_array[i], &message->destination, 910 &message->destination,
894 sizeof (struct GNUNET_PeerIdentity))) 911 sizeof (struct GNUNET_PeerIdentity)))
895 {
896 paths++; 912 paths++;
897 }
898 }
899 if (paths != epaths) 913 if (paths != epaths)
900 { 914 {
901 GNUNET_break_op (0); 915 GNUNET_break (0);
902 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "p:%u, e: %u\n", paths, epaths); 916 return GNUNET_SYSERR;
903 h->info_cb.peer_cb (h->info_cls, NULL, 0, 0, 0, NULL);
904 goto clean_cls;
905 } 917 }
906
907 return GNUNET_OK; 918 return GNUNET_OK;
908
909clean_cls:
910 h->info_cb.peer_cb = NULL;
911 h->info_cls = NULL;
912 return GNUNET_SYSERR;
913} 919}
914 920
915 921
@@ -924,22 +930,26 @@ handle_get_peer (void *cls,
924 const struct GNUNET_CADET_LocalInfoPeer *message) 930 const struct GNUNET_CADET_LocalInfoPeer *message)
925{ 931{
926 struct GNUNET_CADET_Handle *h = cls; 932 struct GNUNET_CADET_Handle *h = cls;
927 struct GNUNET_PeerIdentity *paths_array; 933 const struct GNUNET_PeerIdentity *paths_array;
928 unsigned int paths; 934 unsigned int paths;
929 unsigned int path_length; 935 unsigned int path_length;
930 int neighbor; 936 int neighbor;
931 unsigned int peers; 937 unsigned int peers;
932 938
933 paths = (unsigned int) ntohs (message->paths); 939 if (NULL == h->info_cb.peer_cb)
934 paths_array = (struct GNUNET_PeerIdentity *) &message[1]; 940 return;
941 paths = ntohs (message->paths);
942 paths_array = (const struct GNUNET_PeerIdentity *) &message[1];
935 peers = (ntohs (message->header.size) - sizeof (*message)) 943 peers = (ntohs (message->header.size) - sizeof (*message))
936 / sizeof (struct GNUNET_PeerIdentity); 944 / sizeof (struct GNUNET_PeerIdentity);
937 path_length = 0; 945 path_length = 0;
938 neighbor = GNUNET_NO; 946 neighbor = GNUNET_NO;
939 947
940 for (int i = 0; i < peers; i++) 948 for (unsigned int i = 0; i < peers; i++)
941 { 949 {
942 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %s\n", GNUNET_i2s (&paths_array[i])); 950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
951 " %s\n",
952 GNUNET_i2s (&paths_array[i]));
943 path_length++; 953 path_length++;
944 if (0 == memcmp (&paths_array[i], &message->destination, 954 if (0 == memcmp (&paths_array[i], &message->destination,
945 sizeof (struct GNUNET_PeerIdentity))) 955 sizeof (struct GNUNET_PeerIdentity)))
@@ -951,7 +961,7 @@ handle_get_peer (void *cls,
951 } 961 }
952 962
953 /* Call Callback with tunnel info. */ 963 /* Call Callback with tunnel info. */
954 paths_array = (struct GNUNET_PeerIdentity *) &message[1]; 964 paths_array = (const struct GNUNET_PeerIdentity *) &message[1];
955 h->info_cb.peer_cb (h->info_cls, 965 h->info_cb.peer_cb (h->info_cls,
956 &message->destination, 966 &message->destination,
957 (int) ntohs (message->tunnel), 967 (int) ntohs (message->tunnel),
@@ -962,40 +972,6 @@ handle_get_peer (void *cls,
962 972
963 973
964/** 974/**
965 * Check that message received from CADET service is well-formed.
966 *
967 * @param cls the `struct GNUNET_CADET_Handle`
968 * @param msg the message we got
969 * @return #GNUNET_OK if the message is well-formed,
970 * #GNUNET_SYSERR otherwise
971 */
972static int
973check_get_tunnels (void *cls,
974 const struct GNUNET_CADET_LocalInfoTunnel *msg)
975{
976 struct GNUNET_CADET_Handle *h = cls;
977 uint16_t size;
978
979 if (NULL == h->info_cb.tunnels_cb)
980 {
981 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
982 " no handler for tunnels monitor message!\n");
983 return GNUNET_SYSERR;
984 }
985
986 size = ntohs (msg->header.size);
987 if (sizeof (struct GNUNET_CADET_LocalInfoTunnel) > size)
988 {
989 h->info_cb.tunnels_cb (h->info_cls, NULL, 0, 0, 0, 0);
990 h->info_cb.tunnels_cb = NULL;
991 h->info_cls = NULL;
992 return GNUNET_SYSERR;
993 }
994 return GNUNET_OK;
995}
996
997
998/**
999 * Process a local reply about info on all tunnels, pass info to the user. 975 * Process a local reply about info on all tunnels, pass info to the user.
1000 * 976 *
1001 * @param cls Closure (Cadet handle). 977 * @param cls Closure (Cadet handle).
@@ -1007,6 +983,8 @@ handle_get_tunnels (void *cls,
1007{ 983{
1008 struct GNUNET_CADET_Handle *h = cls; 984 struct GNUNET_CADET_Handle *h = cls;
1009 985
986 if (NULL == h->info_cb.tunnels_cb)
987 return;
1010 h->info_cb.tunnels_cb (h->info_cls, 988 h->info_cb.tunnels_cb (h->info_cls,
1011 &msg->destination, 989 &msg->destination,
1012 ntohl (msg->channels), 990 ntohl (msg->channels),
@@ -1029,28 +1007,18 @@ static int
1029check_get_tunnel (void *cls, 1007check_get_tunnel (void *cls,
1030 const struct GNUNET_CADET_LocalInfoTunnel *msg) 1008 const struct GNUNET_CADET_LocalInfoTunnel *msg)
1031{ 1009{
1032 struct GNUNET_CADET_Handle *h = cls;
1033 unsigned int ch_n; 1010 unsigned int ch_n;
1034 unsigned int c_n; 1011 unsigned int c_n;
1035 size_t esize; 1012 size_t esize;
1036 size_t msize; 1013 size_t msize;
1037 1014
1038 if (NULL == h->info_cb.tunnel_cb)
1039 {
1040 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1041 " no handler for tunnel monitor message!\n");
1042 goto clean_cls;
1043 }
1044
1045 /* Verify message sanity */ 1015 /* Verify message sanity */
1046 msize = ntohs (msg->header.size); 1016 msize = ntohs (msg->header.size);
1047 esize = sizeof (struct GNUNET_CADET_LocalInfoTunnel); 1017 esize = sizeof (struct GNUNET_CADET_LocalInfoTunnel);
1048 if (esize > msize) 1018 if (esize > msize)
1049 { 1019 {
1050 GNUNET_break_op (0); 1020 GNUNET_break (0);
1051 h->info_cb.tunnel_cb (h->info_cls, 1021 return GNUNET_SYSERR;
1052 NULL, 0, 0, NULL, NULL, 0, 0);
1053 goto clean_cls;
1054 } 1022 }
1055 ch_n = ntohl (msg->channels); 1023 ch_n = ntohl (msg->channels);
1056 c_n = ntohl (msg->connections); 1024 c_n = ntohl (msg->connections);
@@ -1065,17 +1033,9 @@ check_get_tunnel (void *cls,
1065 (unsigned int) esize, 1033 (unsigned int) esize,
1066 ch_n, 1034 ch_n,
1067 c_n); 1035 c_n);
1068 h->info_cb.tunnel_cb (h->info_cls, 1036 return GNUNET_SYSERR;
1069 NULL, 0, 0, NULL, NULL, 0, 0);
1070 goto clean_cls;
1071 } 1037 }
1072
1073 return GNUNET_OK; 1038 return GNUNET_OK;
1074
1075clean_cls:
1076 h->info_cb.tunnel_cb = NULL;
1077 h->info_cls = NULL;
1078 return GNUNET_SYSERR;
1079} 1039}
1080 1040
1081 1041
@@ -1095,6 +1055,9 @@ handle_get_tunnel (void *cls,
1095 const struct GNUNET_CADET_ConnectionTunnelIdentifier *conns; 1055 const struct GNUNET_CADET_ConnectionTunnelIdentifier *conns;
1096 const struct GNUNET_CADET_ChannelTunnelNumber *chns; 1056 const struct GNUNET_CADET_ChannelTunnelNumber *chns;
1097 1057
1058 if (NULL == h->info_cb.tunnel_cb)
1059 return;
1060
1098 ch_n = ntohl (msg->channels); 1061 ch_n = ntohl (msg->channels);
1099 c_n = ntohl (msg->connections); 1062 c_n = ntohl (msg->connections);
1100 1063
@@ -1113,28 +1076,6 @@ handle_get_tunnel (void *cls,
1113 1076
1114 1077
1115/** 1078/**
1116 * Function called during #reconnect() to destroy
1117 * all channels that are still open.
1118 *
1119 * @param cls the `struct GNUNET_CADET_Handle`
1120 * @param cid chanenl ID
1121 * @param value a `struct GNUNET_CADET_Channel` to destroy
1122 * @return #GNUNET_OK (continue to iterate)
1123 */
1124static int
1125destroy_channel_on_reconnect_cb (void *cls,
1126 uint32_t cid,
1127 void *value)
1128{
1129 /* struct GNUNET_CADET_Handle *handle = cls; */
1130 struct GNUNET_CADET_Channel *ch = value;
1131
1132 destroy_channel (ch);
1133 return GNUNET_OK;
1134}
1135
1136
1137/**
1138 * Reconnect to the service, retransmit all infomation to try to restore the 1079 * Reconnect to the service, retransmit all infomation to try to restore the
1139 * original state. 1080 * original state.
1140 * 1081 *
@@ -1160,18 +1101,18 @@ reconnect (struct GNUNET_CADET_Handle *h)
1160 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK, 1101 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK,
1161 struct GNUNET_CADET_LocalAck, 1102 struct GNUNET_CADET_LocalAck,
1162 h), 1103 h),
1163 GNUNET_MQ_hd_var_size (get_peers, 1104 GNUNET_MQ_hd_fixed_size (get_peers,
1164 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS, 1105 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS,
1165 struct GNUNET_CADET_LocalInfoPeer, 1106 struct GNUNET_CADET_LocalInfoPeer,
1166 h), 1107 h),
1167 GNUNET_MQ_hd_var_size (get_peer, 1108 GNUNET_MQ_hd_var_size (get_peer,
1168 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER, 1109 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER,
1169 struct GNUNET_CADET_LocalInfoPeer, 1110 struct GNUNET_CADET_LocalInfoPeer,
1170 h), 1111 h),
1171 GNUNET_MQ_hd_var_size (get_tunnels, 1112 GNUNET_MQ_hd_fixed_size (get_tunnels,
1172 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, 1113 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS,
1173 struct GNUNET_CADET_LocalInfoTunnel, 1114 struct GNUNET_CADET_LocalInfoTunnel,
1174 h), 1115 h),
1175 GNUNET_MQ_hd_var_size (get_tunnel, 1116 GNUNET_MQ_hd_var_size (get_tunnel,
1176 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL, 1117 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL,
1177 struct GNUNET_CADET_LocalInfoTunnel, 1118 struct GNUNET_CADET_LocalInfoTunnel,
@@ -1179,14 +1120,6 @@ reconnect (struct GNUNET_CADET_Handle *h)
1179 GNUNET_MQ_handler_end () 1120 GNUNET_MQ_handler_end ()
1180 }; 1121 };
1181 1122
1182 GNUNET_CONTAINER_multihashmap32_iterate (h->channels,
1183 &destroy_channel_on_reconnect_cb,
1184 h);
1185 if (NULL != h->mq)
1186 {
1187 GNUNET_MQ_destroy (h->mq);
1188 h->mq = NULL;
1189 }
1190 h->mq = GNUNET_CLIENT_connect (h->cfg, 1123 h->mq = GNUNET_CLIENT_connect (h->cfg,
1191 "cadet", 1124 "cadet",
1192 handlers, 1125 handlers,
@@ -1309,6 +1242,7 @@ GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p)
1309 GNUNET_CONTAINER_multihashmap_remove (p->cadet->ports, 1242 GNUNET_CONTAINER_multihashmap_remove (p->cadet->ports,
1310 &p->id, 1243 &p->id,
1311 p)); 1244 p));
1245 GNUNET_free (p->handlers);
1312 GNUNET_free (p); 1246 GNUNET_free (p);
1313} 1247}
1314 1248
@@ -1329,11 +1263,14 @@ GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel)
1329 struct GNUNET_CADET_LocalChannelDestroyMessage *msg; 1263 struct GNUNET_CADET_LocalChannelDestroyMessage *msg;
1330 struct GNUNET_MQ_Envelope *env; 1264 struct GNUNET_MQ_Envelope *env;
1331 1265
1332 env = GNUNET_MQ_msg (msg, 1266 if (NULL != h->mq)
1333 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); 1267 {
1334 msg->ccn = channel->ccn; 1268 env = GNUNET_MQ_msg (msg,
1335 GNUNET_MQ_send (h->mq, 1269 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY);
1336 env); 1270 msg->ccn = channel->ccn;
1271 GNUNET_MQ_send (h->mq,
1272 env);
1273 }
1337 destroy_channel (channel); 1274 destroy_channel (channel);
1338} 1275}
1339 1276
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c
index f9f156f58..d4286a1b0 100644
--- a/src/cadet/gnunet-cadet.c
+++ b/src/cadet/gnunet-cadet.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012 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
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -22,6 +22,7 @@
22 * @file cadet/gnunet-cadet.c 22 * @file cadet/gnunet-cadet.c
23 * @brief Print information about cadet tunnels and peers. 23 * @brief Print information about cadet tunnels and peers.
24 * @author Bartlomiej Polot 24 * @author Bartlomiej Polot
25 * @author Christian Grothoff
25 */ 26 */
26#include "platform.h" 27#include "platform.h"
27#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
@@ -30,11 +31,6 @@
30 31
31 32
32/** 33/**
33 * Option -m.
34 */
35static int monitor_mode;
36
37/**
38 * Option -P. 34 * Option -P.
39 */ 35 */
40static int request_peers; 36static int request_peers;
@@ -100,11 +96,6 @@ static char *target_id;
100static char *target_port = "default"; 96static char *target_port = "default";
101 97
102/** 98/**
103 * Data pending in netcat mode.
104 */
105static size_t data_size;
106
107/**
108 * Cadet handle. 99 * Cadet handle.
109 */ 100 */
110static struct GNUNET_CADET_Handle *mh; 101static struct GNUNET_CADET_Handle *mh;
@@ -115,11 +106,6 @@ static struct GNUNET_CADET_Handle *mh;
115static struct GNUNET_CADET_Channel *ch; 106static struct GNUNET_CADET_Channel *ch;
116 107
117/** 108/**
118 * Transmit handle.
119 */
120static struct GNUNET_CADET_TransmitHandle *th;
121
122/**
123 * HashCode of the given port string 109 * HashCode of the given port string
124 */ 110 */
125static struct GNUNET_HashCode porthash; 111static struct GNUNET_HashCode porthash;
@@ -130,11 +116,6 @@ static struct GNUNET_HashCode porthash;
130struct GNUNET_CADET_Port *lp; 116struct GNUNET_CADET_Port *lp;
131 117
132/** 118/**
133 * Shutdown task handle.
134 */
135static struct GNUNET_SCHEDULER_Task *sd;
136
137/**
138 * Task for reading from stdin. 119 * Task for reading from stdin.
139 */ 120 */
140static struct GNUNET_SCHEDULER_Task *rd_task; 121static struct GNUNET_SCHEDULER_Task *rd_task;
@@ -145,6 +126,9 @@ static struct GNUNET_SCHEDULER_Task *rd_task;
145static struct GNUNET_SCHEDULER_Task *job; 126static struct GNUNET_SCHEDULER_Task *job;
146 127
147 128
129/**
130 * Wait for input on STDIO and send it out over the #ch.
131 */
148static void 132static void
149listen_stdio (void); 133listen_stdio (void);
150 134
@@ -214,22 +198,11 @@ shutdown_task (void *cls)
214{ 198{
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
216 "Shutdown\n"); 200 "Shutdown\n");
217 if (NULL != th)
218 {
219 GNUNET_CADET_notify_transmit_ready_cancel (th);
220 th = NULL;
221 }
222 if (NULL != ch) 201 if (NULL != ch)
223 { 202 {
224 GNUNET_CADET_channel_destroy (ch); 203 GNUNET_CADET_channel_destroy (ch);
225 ch = NULL; 204 ch = NULL;
226 } 205 }
227 else if (NULL != target_id) {
228 // FIXME: would be nicer to have proper NACK support from cadet_api
229 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
230 "Connection refused to %s\n",
231 target_id);
232 }
233 if (NULL != mh) 206 if (NULL != mh)
234 { 207 {
235 GNUNET_CADET_disconnect (mh); 208 GNUNET_CADET_disconnect (mh);
@@ -254,42 +227,38 @@ shutdown_task (void *cls)
254 227
255 228
256/** 229/**
257 * Function called to notify a client about the connection 230 * Task run in stdio mode, after some data is available at stdin.
258 * begin ready to queue more data. "buf" will be
259 * NULL and "size" zero if the connection was closed for
260 * writing in the meantime.
261 *
262 * FIXME
263 * 231 *
264 * @param cls closure 232 * @param cls Closure (unused).
265 * @param size number of bytes available in buf
266 * @param buf where the callee should write the message
267 * @return number of bytes written to buf
268 */ 233 */
269static size_t 234static void
270data_ready (void *cls, size_t size, void *buf) 235read_stdio (void *cls)
271{ 236{
237 struct GNUNET_MQ_Envelope *env;
272 struct GNUNET_MessageHeader *msg; 238 struct GNUNET_MessageHeader *msg;
273 size_t total_size; 239 char buf[60000];
240 ssize_t data_size;
274 241
275 th = NULL; 242 rd_task = NULL;
276 243 data_size = read (0,
277 if (NULL == buf || 0 == size) 244 buf,
245 60000);
246 if (data_size < 1)
278 { 247 {
279 GNUNET_SCHEDULER_shutdown(); 248 GNUNET_SCHEDULER_shutdown();
280 return 0; 249 return;
281 } 250 }
282
283 total_size = data_size + sizeof (struct GNUNET_MessageHeader);
284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
285 "sending %u bytes\n", 252 "Read %u bytes from stdio\n",
286 (unsigned int) data_size); 253 (unsigned int) data_size);
287 GNUNET_assert (size >= total_size); 254 env = GNUNET_MQ_msg_extra (msg,
288 255 data_size,
289 msg = buf; 256 GNUNET_MESSAGE_TYPE_CADET_CLI);
290 msg->size = htons (total_size); 257 GNUNET_memcpy (&msg[1],
291 msg->type = htons (GNUNET_MESSAGE_TYPE_CADET_CLI); 258 buf,
292 GNUNET_memcpy (&msg[1], cls, data_size); 259 data_size);
260 GNUNET_MQ_send (GNUNET_CADET_get_mq (ch),
261 env);
293 if (GNUNET_NO == echo) 262 if (GNUNET_NO == echo)
294 { 263 {
295 listen_stdio (); 264 listen_stdio ();
@@ -298,54 +267,27 @@ data_ready (void *cls, size_t size, void *buf)
298 { 267 {
299 echo_time = GNUNET_TIME_absolute_get (); 268 echo_time = GNUNET_TIME_absolute_get ();
300 } 269 }
301
302 return total_size;
303}
304
305
306/**
307 * Task run in stdio mode, after some data is available at stdin.
308 *
309 * @param cls Closure (unused).
310 */
311static void
312read_stdio (void *cls)
313{
314 static char buf[60000];
315
316 rd_task = NULL;
317 data_size = read (0, buf, 60000);
318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
319 "stdio read %u bytes\n",
320 (unsigned int) data_size);
321 if (data_size < 1)
322 {
323 GNUNET_SCHEDULER_shutdown();
324 return;
325 }
326 GNUNET_assert (NULL == th);
327 th = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO,
328 GNUNET_TIME_UNIT_FOREVER_REL,
329 sizeof (struct GNUNET_MessageHeader)
330 + data_size,
331 &data_ready, buf);
332} 270}
333 271
334 272
335/** 273/**
336 * Start listening to stdin 274 * Wait for input on STDIO and send it out over the #ch.
337 */ 275 */
338static void 276static void
339listen_stdio (void) 277listen_stdio ()
340{ 278{
341 struct GNUNET_NETWORK_FDSet *rs; 279 struct GNUNET_NETWORK_FDSet *rs;
342 280
281 /* FIXME: why use 'rs' here, seems overly complicated... */
343 rs = GNUNET_NETWORK_fdset_create (); 282 rs = GNUNET_NETWORK_fdset_create ();
344 GNUNET_NETWORK_fdset_set_native (rs, 0); 283 GNUNET_NETWORK_fdset_set_native (rs,
284 0); /* STDIN */
345 rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 285 rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
346 GNUNET_TIME_UNIT_FOREVER_REL, 286 GNUNET_TIME_UNIT_FOREVER_REL,
347 rs, NULL, 287 rs,
348 &read_stdio, NULL); 288 NULL,
289 &read_stdio,
290 NULL);
349 GNUNET_NETWORK_fdset_destroy (rs); 291 GNUNET_NETWORK_fdset_destroy (rs);
350} 292}
351 293
@@ -356,32 +298,17 @@ listen_stdio (void)
356 * 298 *
357 * It must NOT call #GNUNET_CADET_channel_destroy on the channel. 299 * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
358 * 300 *
359 * @param cls closure (set from #GNUNET_CADET_connect) 301 * @param cls closure
360 * @param channel connection to the other end (henceforth invalid) 302 * @param channel connection to the other end (henceforth invalid)
361 * @param channel_ctx place where local state associated
362 * with the channel is stored
363 */ 303 */
364static void 304static void
365channel_ended (void *cls, 305channel_ended (void *cls,
366 const struct GNUNET_CADET_Channel *channel, 306 const struct GNUNET_CADET_Channel *channel)
367 void *channel_ctx)
368{ 307{
369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel ended!\n"); 308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
370 if (channel != ch) 309 "Channel ended!\n");
371 { 310 GNUNET_assert (channel == ch);
372 GNUNET_break (0); 311 ch = NULL;
373 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ended: %p, expected: %p\n", channel, ch);
374 }
375 else
376 {
377 ch = NULL;
378 }
379 if (NULL != th)
380 {
381 GNUNET_CADET_notify_transmit_ready_cancel (th);
382 th = NULL;
383 }
384
385 GNUNET_SCHEDULER_shutdown (); 312 GNUNET_SCHEDULER_shutdown ();
386} 313}
387 314
@@ -398,65 +325,27 @@ channel_ended (void *cls,
398 * @param cls closure 325 * @param cls closure
399 * @param channel new handle to the channel 326 * @param channel new handle to the channel
400 * @param initiator peer that started the channel 327 * @param initiator peer that started the channel
401 * @param port Port this channel is for. 328 * @return initial channel context for the channel, we use @a channel
402 * @param options CadetOption flag field, with all active option bits set to 1.
403 *
404 * @return initial channel context for the channel
405 * (can be NULL -- that's not an error)
406 */ 329 */
407static void * 330static void *
408channel_incoming (void *cls, 331channel_incoming (void *cls,
409 struct GNUNET_CADET_Channel *channel, 332 struct GNUNET_CADET_Channel *channel,
410 const struct GNUNET_PeerIdentity *initiator, 333 const struct GNUNET_PeerIdentity *initiator)
411 const struct GNUNET_HashCode *port,
412 enum GNUNET_CADET_ChannelOption options)
413{ 334{
414 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
415 "Connected from %s\n", 336 "Incomming connection from %s\n",
416 GNUNET_i2s_full (initiator)); 337 GNUNET_i2s_full (initiator));
417 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 338 GNUNET_assert (NULL == ch);
418 "Incoming channel %p on port %s\n", 339 GNUNET_assert (NULL != lp);
419 channel, GNUNET_h2s (port)); 340 GNUNET_CADET_close_port (lp);
420 if (NULL != ch) 341 lp = NULL;
421 {
422 GNUNET_break (0);
423 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
424 "A channel already exists (%p)\n", ch);
425 /*
426 * From now on multiple channels will be sending data to us
427 * making the service of this command unpredictable in its
428 * current implementation. So for now let's just bail out.
429 */
430 GNUNET_SCHEDULER_shutdown();
431 return NULL;
432 }
433 if (NULL == listen_port)
434 {
435 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not listening to channels\n");
436 return NULL;
437 }
438 // Closing the listen port currently breaks open connections.
439 // Is this an intentional departure from POSIX socket behavior?
440 //
441 if (NULL != lp) {
442 /* Now that we have our circuit up and running, let's not
443 * get confused by further incoming connect requests.
444 * You need to start another 'gnunet-cadet -o' process
445 * to receive those.
446 */
447 GNUNET_CADET_close_port (lp);
448 lp = NULL;
449 }
450 ch = channel; 342 ch = channel;
451 if (GNUNET_NO == echo) 343 if (GNUNET_NO == echo)
452 {
453 listen_stdio (); 344 listen_stdio ();
454 return NULL; 345 return channel;
455 }
456 data_size = 0;
457 return NULL;
458} 346}
459 347
348
460/** 349/**
461 * @brief Send an echo request to the remote peer. 350 * @brief Send an echo request to the remote peer.
462 * 351 *
@@ -465,14 +354,16 @@ channel_incoming (void *cls,
465static void 354static void
466send_echo (void *cls) 355send_echo (void *cls)
467{ 356{
357 struct GNUNET_MQ_Envelope *env;
358 struct GNUNET_MessageHeader *msg;
359
468 echo_task = NULL; 360 echo_task = NULL;
469 if (NULL == ch) 361 if (NULL == ch)
470 return; 362 return;
471 GNUNET_assert (NULL == th); 363 env = GNUNET_MQ_msg (msg,
472 th = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO, 364 GNUNET_MESSAGE_TYPE_CADET_CLI);
473 GNUNET_TIME_UNIT_FOREVER_REL, 365 GNUNET_MQ_send (GNUNET_CADET_get_mq (ch),
474 sizeof (struct GNUNET_MessageHeader), 366 env);
475 &data_ready, NULL);
476} 367}
477 368
478 369
@@ -485,44 +376,27 @@ static void
485request_dump (void *cls) 376request_dump (void *cls)
486{ 377{
487 GNUNET_CADET_request_dump (mh); 378 GNUNET_CADET_request_dump (mh);
488 GNUNET_SCHEDULER_cancel (sd); 379 GNUNET_SCHEDULER_shutdown ();
489 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
490 &shutdown_task, NULL);
491} 380}
492 381
493 382
494/** 383/**
495 * Call CADET's monitor API, get info of one connection. 384 * Function called whenever a message is received.
496 * 385 *
497 * @param cls Closure (unused). 386 * Each time the function must call #GNUNET_CADET_receive_done on the channel
387 * in order to receive the next message. This doesn't need to be immediate:
388 * can be delayed if some processing is done on the message.
389 *
390 * @param cls should match #ch
391 * @param message The actual message.
392 * @return #GNUNET_OK to keep the channel open,
393 * #GNUNET_SYSERR to close it (signal serious error).
498 */ 394 */
499static void 395static int
500create_channel (void *cls) 396check_data (void *cls,
397 const struct GNUNET_MessageHeader *message)
501{ 398{
502 struct GNUNET_PeerIdentity pid; 399 return GNUNET_OK; /* all is well-formed */
503 enum GNUNET_CADET_ChannelOption opt;
504
505 GNUNET_assert (NULL == ch);
506
507 if (GNUNET_OK !=
508 GNUNET_CRYPTO_eddsa_public_key_from_string (target_id,
509 strlen (target_id),
510 &pid.public_key))
511 {
512 FPRINTF (stderr,
513 _("Invalid target `%s'\n"),
514 target_id);
515 GNUNET_SCHEDULER_shutdown ();
516 return;
517 }
518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to `%s'\n", target_id);
519 opt = GNUNET_CADET_OPTION_DEFAULT | GNUNET_CADET_OPTION_RELIABLE;
520 GNUNET_CRYPTO_hash (target_port, strlen(target_port), &porthash);
521 ch = GNUNET_CADET_channel_create (mh, NULL, &pid, &porthash, opt);
522 if (GNUNET_NO == echo)
523 listen_stdio ();
524 else
525 echo_task = GNUNET_SCHEDULER_add_now (&send_echo, NULL);
526} 400}
527 401
528 402
@@ -533,42 +407,36 @@ create_channel (void *cls)
533 * in order to receive the next message. This doesn't need to be immediate: 407 * in order to receive the next message. This doesn't need to be immediate:
534 * can be delayed if some processing is done on the message. 408 * can be delayed if some processing is done on the message.
535 * 409 *
536 * @param cls Closure (set from #GNUNET_CADET_connect). 410 * @param cls NULL
537 * @param channel Connection to the other end.
538 * @param channel_ctx Place to store local state associated with the channel.
539 * @param message The actual message. 411 * @param message The actual message.
540 * @return #GNUNET_OK to keep the channel open,
541 * #GNUNET_SYSERR to close it (signal serious error).
542 */ 412 */
543static int 413static void
544data_callback (void *cls, 414handle_data (void *cls,
545 struct GNUNET_CADET_Channel *channel, 415 const struct GNUNET_MessageHeader *message)
546 void **channel_ctx,
547 const struct GNUNET_MessageHeader *message)
548{ 416{
417 size_t payload_size = ntohs (message->size) - sizeof (*message);
549 uint16_t len; 418 uint16_t len;
550 ssize_t done; 419 ssize_t done;
551 uint16_t off; 420 uint16_t off;
552 const char *buf; 421 const char *buf;
553 GNUNET_break (ch == channel);
554 GNUNET_CADET_receive_done (channel);
555 422
423 GNUNET_CADET_receive_done (ch);
556 if (GNUNET_YES == echo) 424 if (GNUNET_YES == echo)
557 { 425 {
558 if (NULL != listen_port) 426 if (NULL != listen_port)
559 { 427 {
560 /* Just listening to echo incoming messages*/ 428 struct GNUNET_MQ_Envelope *env;
561 if (NULL != th) 429 struct GNUNET_MessageHeader *msg;
562 { 430
563 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 431 env = GNUNET_MQ_msg_extra (msg,
564 "Last echo reply not yet sent, dropping current reply.\n"); 432 payload_size,
565 return GNUNET_OK; 433 GNUNET_MESSAGE_TYPE_CADET_CLI);
566 } 434 GNUNET_memcpy (&msg[1],
567 th = GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO, 435 &message[1],
568 GNUNET_TIME_UNIT_FOREVER_REL, 436 payload_size);
569 sizeof (struct GNUNET_MessageHeader), 437 GNUNET_MQ_send (GNUNET_CADET_get_mq (ch),
570 &data_ready, NULL); 438 env);
571 return GNUNET_OK; 439 return;
572 } 440 }
573 else 441 else
574 { 442 {
@@ -576,30 +444,37 @@ data_callback (void *cls,
576 444
577 latency = GNUNET_TIME_absolute_get_duration (echo_time); 445 latency = GNUNET_TIME_absolute_get_duration (echo_time);
578 echo_time = GNUNET_TIME_UNIT_FOREVER_ABS; 446 echo_time = GNUNET_TIME_UNIT_FOREVER_ABS;
579 FPRINTF (stdout, "time: %s\n", 447 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
580 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO)); 448 "time: %s\n",
449 GNUNET_STRINGS_relative_time_to_string (latency,
450 GNUNET_NO));
581 echo_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 451 echo_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
582 &send_echo, NULL); 452 &send_echo,
453 NULL);
583 } 454 }
584 } 455 }
585 456
586 len = ntohs (message->size) - sizeof (*message); 457 len = ntohs (message->size) - sizeof (*message);
587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len); 458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
459 "Got %u bytes\n",
460 len);
588 buf = (const char *) &message[1]; 461 buf = (const char *) &message[1];
589 off = 0; 462 off = 0;
590 while (off < len) 463 while (off < len)
591 { 464 {
592 done = write (1, &buf[off], len - off); 465 done = write (1,
466 &buf[off],
467 len - off);
593 if (done <= 0) 468 if (done <= 0)
594 { 469 {
595 if (-1 == done) 470 if (-1 == done)
596 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 471 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
597 "write"); 472 "write");
598 return GNUNET_SYSERR; 473 GNUNET_SCHEDULER_shutdown ();
474 return;
599 } 475 }
600 off += done; 476 off += done;
601 } 477 }
602 return GNUNET_OK;
603} 478}
604 479
605 480
@@ -625,16 +500,17 @@ peers_callback (void *cls,
625{ 500{
626 if (NULL == peer) 501 if (NULL == peer)
627 { 502 {
628 if (GNUNET_YES != monitor_mode) 503 GNUNET_SCHEDULER_shutdown();
629 {
630 GNUNET_SCHEDULER_shutdown();
631 }
632 return; 504 return;
633 } 505 }
634 FPRINTF (stdout, "%s tunnel: %c, paths: %u\n", 506 FPRINTF (stdout,
635 GNUNET_i2s_full (peer), tunnel ? 'Y' : 'N', n_paths); 507 "%s tunnel: %c, paths: %u\n",
508 GNUNET_i2s_full (peer),
509 tunnel ? 'Y' : 'N',
510 n_paths);
636} 511}
637 512
513
638/** 514/**
639 * Method called to retrieve information about a specific peer 515 * Method called to retrieve information about a specific peer
640 * known to the service. 516 * known to the service.
@@ -654,19 +530,26 @@ peer_callback (void *cls,
654 int tunnel, 530 int tunnel,
655 int neighbor, 531 int neighbor,
656 unsigned int n_paths, 532 unsigned int n_paths,
657 struct GNUNET_PeerIdentity *paths) 533 const struct GNUNET_PeerIdentity *paths)
658{ 534{
659 unsigned int i; 535 unsigned int i;
660 struct GNUNET_PeerIdentity *p; 536 const struct GNUNET_PeerIdentity *p;
661 537
662 FPRINTF (stdout, "%s [TUNNEL: %s, NEIGHBOR: %s, PATHS: %u]\n", 538 FPRINTF (stdout,
539 "%s [TUNNEL: %s, NEIGHBOR: %s, PATHS: %u]\n",
663 GNUNET_i2s_full (peer), 540 GNUNET_i2s_full (peer),
664 tunnel ? "Y" : "N", neighbor ? "Y" : "N", n_paths); 541 tunnel ? "Y" : "N",
542 neighbor ? "Y" : "N",
543 n_paths);
665 p = paths; 544 p = paths;
666 for (i = 0; i < n_paths && NULL != p;) 545 for (i = 0; i < n_paths && NULL != p;)
667 { 546 {
668 FPRINTF (stdout, "%s ", GNUNET_i2s (p)); 547 FPRINTF (stdout,
669 if (0 == memcmp (p, peer, sizeof (*p))) 548 "%s ",
549 GNUNET_i2s (p));
550 if (0 == memcmp (p,
551 peer,
552 sizeof (*p)))
670 { 553 {
671 FPRINTF (stdout, "\n"); 554 FPRINTF (stdout, "\n");
672 i++; 555 i++;
@@ -698,16 +581,16 @@ tunnels_callback (void *cls,
698{ 581{
699 if (NULL == peer) 582 if (NULL == peer)
700 { 583 {
701 if (GNUNET_YES != monitor_mode) 584 GNUNET_SCHEDULER_shutdown();
702 {
703 GNUNET_SCHEDULER_shutdown();
704 }
705 return; 585 return;
706 } 586 }
707 FPRINTF (stdout, "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n", 587 FPRINTF (stdout,
588 "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n",
708 GNUNET_i2s_full (peer), 589 GNUNET_i2s_full (peer),
709 enc_2s (estate), conn_2s (cstate), 590 enc_2s (estate),
710 channels, connections); 591 conn_2s (cstate),
592 channels,
593 connections);
711} 594}
712 595
713 596
@@ -748,11 +631,7 @@ tunnel_callback (void *cls,
748 FPRINTF (stdout, "\tencryption state: %s\n", enc_2s (estate)); 631 FPRINTF (stdout, "\tencryption state: %s\n", enc_2s (estate));
749 FPRINTF (stdout, "\tconnection state: %s\n", conn_2s (cstate)); 632 FPRINTF (stdout, "\tconnection state: %s\n", conn_2s (cstate));
750 } 633 }
751 if (GNUNET_YES != monitor_mode) 634 GNUNET_SCHEDULER_shutdown ();
752 {
753 GNUNET_SCHEDULER_shutdown ();
754 }
755 return;
756} 635}
757 636
758 637
@@ -876,18 +755,21 @@ run (void *cls,
876 const char *cfgfile, 755 const char *cfgfile,
877 const struct GNUNET_CONFIGURATION_Handle *cfg) 756 const struct GNUNET_CONFIGURATION_Handle *cfg)
878{ 757{
879 static const struct GNUNET_CADET_MessageHandler handlers[] = { 758 struct GNUNET_MQ_MessageHandler handlers[] = {
880 {&data_callback, GNUNET_MESSAGE_TYPE_CADET_CLI, 0}, 759 GNUNET_MQ_hd_var_size (data,
881 {NULL, 0, 0} /* FIXME add option to monitor msg types */ 760 GNUNET_MESSAGE_TYPE_CADET_CLI,
761 struct GNUNET_MessageHeader,
762 NULL),
763 GNUNET_MQ_handler_end ()
882 }; 764 };
883 765
884 /* FIXME add option to monitor apps */ 766 /* FIXME add option to monitor apps */
885 767
886 target_id = args[0]; 768 target_id = args[0];
887 if (target_id && args[1]) target_port = args[1]; 769 if (target_id && args[1])
770 target_port = args[1];
888 771
889 if ( (0 != (request_peers | request_tunnels) 772 if ( (0 != (request_peers | request_tunnels)
890 || 0 != monitor_mode
891 || NULL != tunnel_id 773 || NULL != tunnel_id
892 || NULL != conn_id 774 || NULL != conn_id
893 || NULL != channel_id) 775 || NULL != channel_id)
@@ -903,66 +785,128 @@ run (void *cls,
903 { 785 {
904 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
905 "requesting debug dump\n"); 787 "requesting debug dump\n");
906 GNUNET_SCHEDULER_add_now (&request_dump, NULL); 788 job = GNUNET_SCHEDULER_add_now (&request_dump,
907 } 789 NULL);
908 else if (NULL != target_id)
909 {
910 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
911 "Creating channel to %s\n",
912 target_id);
913 GNUNET_SCHEDULER_add_now (&create_channel, NULL);
914 } 790 }
915 else if (NULL != peer_id) 791 else if (NULL != peer_id)
916 { 792 {
917 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n"); 793 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
918 job = GNUNET_SCHEDULER_add_now (&show_peer, NULL); 794 "Show peer\n");
795 job = GNUNET_SCHEDULER_add_now (&show_peer,
796 NULL);
919 } 797 }
920 else if (NULL != tunnel_id) 798 else if (NULL != tunnel_id)
921 { 799 {
922 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show tunnel\n"); 800 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
923 job = GNUNET_SCHEDULER_add_now (&show_tunnel, NULL); 801 "Show tunnel\n");
802 job = GNUNET_SCHEDULER_add_now (&show_tunnel,
803 NULL);
924 } 804 }
925 else if (NULL != channel_id) 805 else if (NULL != channel_id)
926 { 806 {
927 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show channel\n"); 807 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
928 job = GNUNET_SCHEDULER_add_now (&show_channel, NULL); 808 "Show channel\n");
809 job = GNUNET_SCHEDULER_add_now (&show_channel,
810 NULL);
929 } 811 }
930 else if (NULL != conn_id) 812 else if (NULL != conn_id)
931 { 813 {
932 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n"); 814 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
933 job = GNUNET_SCHEDULER_add_now (&show_connection, NULL); 815 "Show connection\n");
816 job = GNUNET_SCHEDULER_add_now (&show_connection,
817 NULL);
934 } 818 }
935 else if (GNUNET_YES == request_peers) 819 else if (GNUNET_YES == request_peers)
936 { 820 {
937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n"); 821 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
938 job = GNUNET_SCHEDULER_add_now (&get_peers, NULL); 822 "Show all peers\n");
823 job = GNUNET_SCHEDULER_add_now (&get_peers,
824 NULL);
939 } 825 }
940 else if (GNUNET_YES == request_tunnels) 826 else if (GNUNET_YES == request_tunnels)
941 { 827 {
942 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n"); 828 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
943 job = GNUNET_SCHEDULER_add_now (&get_tunnels, NULL); 829 "Show all tunnels\n");
830 job = GNUNET_SCHEDULER_add_now (&get_tunnels,
831 NULL);
944 } 832 }
945 else if (NULL == listen_port) 833
834 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
835 "Connecting to CADET service\n");
836 mh = GNUNET_CADET_connecT (cfg);
837 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
838 NULL);
839 if (NULL == mh)
946 { 840 {
947 FPRINTF (stderr, "No action requested\n"); 841 GNUNET_SCHEDULER_shutdown ();
948 return; 842 return;
949 } 843 }
950
951 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CADET service\n");
952 mh = GNUNET_CADET_connect (cfg,
953 NULL, /* cls */
954 &channel_ended, /* cleaner */
955 handlers);
956 if (NULL == mh)
957 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
958 else
959 sd = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
960
961 if (NULL != listen_port) 844 if (NULL != listen_port)
962 { 845 {
963 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opening CADET listen port\n"); 846 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
964 GNUNET_CRYPTO_hash (listen_port, strlen(listen_port), &porthash); 847 "Opening CADET listen port\n");
965 lp = GNUNET_CADET_open_port (mh, &porthash, &channel_incoming, NULL); 848 GNUNET_CRYPTO_hash (listen_port,
849 strlen (listen_port),
850 &porthash);
851 lp = GNUNET_CADET_open_porT (mh,
852 &porthash,
853 &channel_incoming,
854 NULL,
855 NULL /* window changes */,
856 &channel_ended,
857 handlers);
858 }
859 if (NULL != target_id)
860 {
861 struct GNUNET_PeerIdentity pid;
862 enum GNUNET_CADET_ChannelOption opt;
863
864 if (GNUNET_OK !=
865 GNUNET_CRYPTO_eddsa_public_key_from_string (target_id,
866 strlen (target_id),
867 &pid.public_key))
868 {
869 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
870 _("Invalid target `%s'\n"),
871 target_id);
872 GNUNET_SCHEDULER_shutdown ();
873 return;
874 }
875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
876 "Connecting to `%s:%s'\n",
877 target_id,
878 target_port);
879 opt = GNUNET_CADET_OPTION_DEFAULT | GNUNET_CADET_OPTION_RELIABLE;
880 GNUNET_CRYPTO_hash (target_port,
881 strlen(target_port),
882 &porthash);
883 ch = GNUNET_CADET_channel_creatE (mh,
884 NULL,
885 &pid,
886 &porthash,
887 opt,
888 NULL /* window changes */,
889 &channel_ended,
890 handlers);
891 if (GNUNET_YES == echo)
892 {
893 echo_task = GNUNET_SCHEDULER_add_now (&send_echo,
894 NULL);
895 }
896 else
897 {
898 listen_stdio ();
899 }
900 }
901
902 if ( (NULL == lp) &&
903 (NULL == job) &&
904 (NULL == ch) )
905 {
906 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
907 _("No action requested\n"));
908 GNUNET_SCHEDULER_shutdown ();
909 return;
966 } 910 }
967} 911}
968 912
@@ -975,14 +919,12 @@ run (void *cls,
975 * @return 0 ok, 1 on error 919 * @return 0 ok, 1 on error
976 */ 920 */
977int 921int
978main (int argc, char *const *argv) 922main (int argc,
923 char *const *argv)
979{ 924{
980 int res; 925 int res;
981 const char helpstr[] = "Create channels and retreive info about cadets status."; 926 const char helpstr[] = "Create channels and retreive info about cadets status.";
982 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 927 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
983// {'a', "channel", "TUNNEL_ID:CHANNEL_ID",
984// gettext_noop ("provide information about a particular channel"),
985// GNUNET_YES, &GNUNET_GETOPT_set_string, &channel_id},
986 {'C', "connection", "CONNECTION_ID", 928 {'C', "connection", "CONNECTION_ID",
987 gettext_noop ("provide information about a particular connection"), 929 gettext_noop ("provide information about a particular connection"),
988 GNUNET_YES, &GNUNET_GETOPT_set_string, &conn_id}, 930 GNUNET_YES, &GNUNET_GETOPT_set_string, &conn_id},
@@ -992,10 +934,7 @@ main (int argc, char *const *argv)
992 {'d', "dump", NULL, 934 {'d', "dump", NULL,
993 gettext_noop ("dump debug information to STDERR"), 935 gettext_noop ("dump debug information to STDERR"),
994 GNUNET_NO, &GNUNET_GETOPT_set_one, &dump}, 936 GNUNET_NO, &GNUNET_GETOPT_set_one, &dump},
995// {'m', "monitor", NULL, 937 {'o', "open-port", "PORT",
996// gettext_noop ("provide information about all events (continuously)"),
997// GNUNET_NO, &GNUNET_GETOPT_set_one, &monitor_mode},
998 {'o', "open-port", NULL,
999 gettext_noop ("port to listen to"), 938 gettext_noop ("port to listen to"),
1000 GNUNET_YES, &GNUNET_GETOPT_set_string, &listen_port}, 939 GNUNET_YES, &GNUNET_GETOPT_set_string, &listen_port},
1001 {'p', "peer", "PEER_ID", 940 {'p', "peer", "PEER_ID",
@@ -1014,12 +953,13 @@ main (int argc, char *const *argv)
1014 GNUNET_GETOPT_OPTION_END 953 GNUNET_GETOPT_OPTION_END
1015 }; 954 };
1016 955
1017 monitor_mode = GNUNET_NO; 956 if (GNUNET_OK !=
1018 957 GNUNET_STRINGS_get_utf8_args (argc, argv,
1019 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 958 &argc, &argv))
1020 return 2; 959 return 2;
1021 960
1022 res = GNUNET_PROGRAM_run (argc, argv, "gnunet-cadet (OPTIONS | TARGET PORT)", 961 res = GNUNET_PROGRAM_run (argc, argv,
962 "gnunet-cadet (OPTIONS | TARGET PORT)",
1023 gettext_noop (helpstr), 963 gettext_noop (helpstr),
1024 options, &run, NULL); 964 options, &run, NULL);
1025 965
@@ -1027,8 +967,7 @@ main (int argc, char *const *argv)
1027 967
1028 if (GNUNET_OK == res) 968 if (GNUNET_OK == res)
1029 return 0; 969 return 0;
1030 else 970 return 1;
1031 return 1;
1032} 971}
1033 972
1034/* end of gnunet-cadet.c */ 973/* end of gnunet-cadet.c */