aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-06-15 09:56:48 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-06-15 09:56:48 +0000
commite0c30daf391bdcbaf873d845a7c7d9347217f884 (patch)
tree0eb7153f03b39f5fe6a8b07c396016bde119337b /src/ats
parent6c147cc9bfa5ac134269593d6e4dbcd0be66ac91 (diff)
downloadgnunet-e0c30daf391bdcbaf873d845a7c7d9347217f884.tar.gz
gnunet-e0c30daf391bdcbaf873d845a7c7d9347217f884.zip
- gnunet-ats cmd line tool basics
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/Makefile.am10
-rw-r--r--src/ats/gnunet-ats.c116
2 files changed, 125 insertions, 1 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index 87a7fc05a..f547f9ec8 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -37,7 +37,8 @@ libgnunetats_la_LDFLAGS = \
37 37
38 38
39bin_PROGRAMS = \ 39bin_PROGRAMS = \
40 gnunet-service-ats 40 gnunet-service-ats \
41 gnunet-ats
41 42
42gnunet_service_ats_SOURCES = \ 43gnunet_service_ats_SOURCES = \
43 gnunet-service-ats.c gnunet-service-ats.h\ 44 gnunet-service-ats.c gnunet-service-ats.h\
@@ -51,6 +52,13 @@ gnunet_service_ats_LDADD = \
51 $(top_builddir)/src/util/libgnunetutil.la \ 52 $(top_builddir)/src/util/libgnunetutil.la \
52 $(GN_LIBGLPK) \ 53 $(GN_LIBGLPK) \
53 $(GN_LIBINTL) 54 $(GN_LIBINTL)
55
56gnunet_ats_SOURCES = \
57 gnunet-ats.c gnunet-service-ats.h
58gnunet_ats_LDADD = \
59 $(top_builddir)/src/util/libgnunetutil.la \
60 $(top_builddir)/src/ats/libgnunetats.la \
61 $(GN_LIBINTL)
54 62
55 63
56check_PROGRAMS = \ 64check_PROGRAMS = \
diff --git a/src/ats/gnunet-ats.c b/src/ats/gnunet-ats.c
new file mode 100644
index 000000000..a6af3abcb
--- /dev/null
+++ b/src/ats/gnunet-ats.c
@@ -0,0 +1,116 @@
1/*
2 This file is part of GNUnet.
3 (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
4
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
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file ats/gnunet-ats.c
23 * @brief ATS command line tool
24 * @author Matthias Wachs
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_ats_service.h"
29
30/**
31 * Final status code.
32 */
33static int ret;
34
35static char * peer_str;
36
37static int all_peers;
38
39/**
40 * Main function that will be run by the scheduler.
41 *
42 * @param cls closure
43 * @param args remaining command-line arguments
44 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
45 * @param cfg configuration
46 */
47static void
48run (void *cls, char *const *args, const char *cfgfile,
49 const struct GNUNET_CONFIGURATION_Handle *cfg)
50{
51 if (GNUNET_YES == all_peers)
52 {
53 /* list information for all peers */
54 printf ("To be implemented!\n");
55
56 /* TODO: get all peers */
57
58 /* TODO: get addresses for each peer */
59 }
60 else if (NULL != peer_str)
61 {
62 /* list information for a specific peer */
63 printf ("To be implemented!\n");
64 struct GNUNET_PeerIdentity id;
65 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string2(peer_str, strlen (peer_str), &id.hashPubKey))
66 {
67 printf ("`%s' is not a valid peer identity\n", peer_str);
68 GNUNET_free (peer_str);
69 return;
70 }
71
72 printf ("Peer `%s':\n", GNUNET_i2s_full (&id));
73
74 /* TODO: get addresses for each peer */
75 GNUNET_free (peer_str);
76 }
77}
78
79
80/**
81 * The main function.
82 *
83 * @param argc number of arguments from the command line
84 * @param argv command line arguments
85 * @return 0 ok, 1 on error
86 */
87int
88main (int argc, char *const *argv)
89{
90 int res;
91 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
92 {'P', "peer", "PEER",
93 gettext_noop ("list information for the given peer"),
94 1, &GNUNET_GETOPT_set_string, &peer_str},
95 {'A', "all", NULL,
96 gettext_noop ("list information for all peers"),
97 0, &GNUNET_GETOPT_set_one, &all_peers},
98 GNUNET_GETOPT_OPTION_END
99 };
100
101 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
102 return 2;
103
104 res = GNUNET_PROGRAM_run (argc, argv, "gnunet-ats",
105 gettext_noop ("Print information about ATS state"), options, &run,
106 NULL);
107 GNUNET_free ((void *) argv);
108
109 if (GNUNET_OK == res)
110 return ret;
111 else
112 return 1;
113
114}
115
116/* end of gnunet-ats.c */