aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-26 08:59:07 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-26 08:59:07 +0000
commit8a042c14d1d103a8e3b83d72a09c00e05b8eaed2 (patch)
tree3b134eb72420580eaae4c4d76d6ce92d5d3ecee7 /src/transport/gnunet-transport.c
parent9c86d92fd5c9d82de31534475821f29c29a968dd (diff)
downloadgnunet-8a042c14d1d103a8e3b83d72a09c00e05b8eaed2.tar.gz
gnunet-8a042c14d1d103a8e3b83d72a09c00e05b8eaed2.zip
start draft of gnunet-transport
Diffstat (limited to 'src/transport/gnunet-transport.c')
-rw-r--r--src/transport/gnunet-transport.c57
1 files changed, 56 insertions, 1 deletions
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 @@
32#include "gnunet_protocols.h" 32#include "gnunet_protocols.h"
33#include "gnunet_transport_service.h" 33#include "gnunet_transport_service.h"
34 34
35static char *cpid;
36
37static struct GNUNET_TRANSPORT_Handle *handle;
38
39static void
40do_disconnect (void *cls,
41 const struct GNUNET_SCHEDULER_TaskContext *tc)
42{
43 GNUNET_TRANSPORT_disconnect (handle);
44}
45
46
47/**
48 * Main function that will be run by the scheduler.
49 *
50 * @param cls closure
51 * @param args remaining command-line arguments
52 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
53 * @param cfg configuration
54 */
55static void
56run (void *cls, char *const *args, const char *cfgfile,
57 const struct GNUNET_CONFIGURATION_Handle *cfg)
58{
59 struct GNUNET_PeerIdentity pid;
60 if (NULL != cpid)
61 {
62 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL,
63 NULL, NULL, NULL);
64 if (GNUNET_OK !=
65 GNUNET_CRYPTO_hash_from_string (cpid, &pid.hashPubKey))
66 {
67 fprintf (stderr,
68 _("Failed to parse peer identity `%s'\n"),
69 cpid);
70 GNUNET_TRANSPORT_disconnect (handle);
71 return;
72 }
73 GNUNET_TRANSPORT_try_connect (handle, &pid);
74 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
75 &do_disconnect,
76 NULL);
77 }
78}
79
80
35int 81int
36main (int argc, char *const *argv) 82main (int argc, char *const *argv)
37{ 83{
38 return 0; 84 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
85 {'C', "connect", "PEER",
86 gettext_noop ("try to connect to the given peer"),
87 0, &GNUNET_GETOPT_set_string, &cpid},
88 GNUNET_GETOPT_OPTION_END
89 };
90 return (GNUNET_OK ==
91 GNUNET_PROGRAM_run (argc, argv, "gnunet-transport",
92 gettext_noop ("Direct access to transport service."),
93 options, &run, NULL)) ? 0 : 1;
39} 94}
40 95
41 96