From 8a042c14d1d103a8e3b83d72a09c00e05b8eaed2 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 26 Oct 2011 08:59:07 +0000 Subject: [PATCH] start draft of gnunet-transport --- src/transport/gnunet-transport.c | 57 +++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index cd883fee3..419a0cdc3 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c @@ -32,10 +32,65 @@ #include "gnunet_protocols.h" #include "gnunet_transport_service.h" +static char *cpid; + +static struct GNUNET_TRANSPORT_Handle *handle; + +static void +do_disconnect (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + GNUNET_TRANSPORT_disconnect (handle); +} + + +/** + * Main function that will be run by the scheduler. + * + * @param cls closure + * @param args remaining command-line arguments + * @param cfgfile name of the configuration file used (for saving, can be NULL!) + * @param cfg configuration + */ +static void +run (void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + struct GNUNET_PeerIdentity pid; + if (NULL != cpid) + { + handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, + NULL, NULL, NULL); + if (GNUNET_OK != + GNUNET_CRYPTO_hash_from_string (cpid, &pid.hashPubKey)) + { + fprintf (stderr, + _("Failed to parse peer identity `%s'\n"), + cpid); + GNUNET_TRANSPORT_disconnect (handle); + return; + } + GNUNET_TRANSPORT_try_connect (handle, &pid); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &do_disconnect, + NULL); + } +} + + int main (int argc, char *const *argv) { - return 0; + static const struct GNUNET_GETOPT_CommandLineOption options[] = { + {'C', "connect", "PEER", + gettext_noop ("try to connect to the given peer"), + 0, &GNUNET_GETOPT_set_string, &cpid}, + GNUNET_GETOPT_OPTION_END + }; + return (GNUNET_OK == + GNUNET_PROGRAM_run (argc, argv, "gnunet-transport", + gettext_noop ("Direct access to transport service."), + options, &run, NULL)) ? 0 : 1; } -- 2.25.1