aboutsummaryrefslogtreecommitdiff
path: root/src/rps/gnunet-rps.c
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2017-03-18 23:38:18 +0100
committerJulius Bünger <buenger@mytum.de>2017-03-18 23:38:18 +0100
commit31a93b2f7c8988dd15f654ca64381ed9c44ae50b (patch)
treef2af553301a5b4c6f7ea671a50161bb40b716b6a /src/rps/gnunet-rps.c
parent646964ac643b33c6b0fd71bb41023ca654104f4c (diff)
downloadgnunet-31a93b2f7c8988dd15f654ca64381ed9c44ae50b.tar.gz
gnunet-31a93b2f7c8988dd15f654ca64381ed9c44ae50b.zip
fix rps getopt
Diffstat (limited to 'src/rps/gnunet-rps.c')
-rw-r--r--src/rps/gnunet-rps.c67
1 files changed, 22 insertions, 45 deletions
diff --git a/src/rps/gnunet-rps.c b/src/rps/gnunet-rps.c
index 3dbb8053e..d82528182 100644
--- a/src/rps/gnunet-rps.c
+++ b/src/rps/gnunet-rps.c
@@ -41,45 +41,9 @@ static struct GNUNET_RPS_Handle *rps_handle;
41static struct GNUNET_RPS_Request_Handle *req_handle; 41static struct GNUNET_RPS_Request_Handle *req_handle;
42 42
43/** 43/**
44 * PeerID (Option --seed) 44 * PeerID in string representation (Option --seed)
45 */ 45 */
46static struct GNUNET_PeerIdentity *peer_id; 46static char *peer_id_str;
47
48
49/**
50 * Set an option of type 'struct GNUNET_PeerIdentity *' from the command line.
51 * A pointer to this function should be passed as part of the
52 * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options
53 * of this type. It should be followed by a pointer to a value of
54 * type 'struct GNUNET_PeerIdentity *', which will be allocated with the requested string.
55 *
56 * @param ctx command line processing context
57 * @param scls additional closure (will point to the 'char *',
58 * which will be allocated)
59 * @param option name of the option
60 * @param value actual value of the option (a PeerID)
61 * @return #GNUNET_OK
62 */
63static int
64GNUNET_GETOPT_set_peerid (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
65 void *scls, const char *option, const char *value)
66{
67 struct GNUNET_PeerIdentity **val = (struct GNUNET_PeerIdentity **) scls;
68
69 GNUNET_assert (NULL != value);
70 GNUNET_free_non_null (*val);
71 /* Not quite sure whether that is a sane way */
72 *val = GNUNET_new (struct GNUNET_PeerIdentity);
73 if (GNUNET_OK !=
74 GNUNET_CRYPTO_eddsa_public_key_from_string (value,
75 strlen (value),
76 &((*val)->public_key)))
77 {
78 FPRINTF (stderr, "Invalid peer ID %s\n", value);
79 return GNUNET_SYSERR;
80 }
81 return GNUNET_OK;
82}
83 47
84 48
85/** 49/**
@@ -139,10 +103,11 @@ run (void *cls,
139 const struct GNUNET_CONFIGURATION_Handle *cfg) 103 const struct GNUNET_CONFIGURATION_Handle *cfg)
140{ 104{
141 static uint64_t num_peers; 105 static uint64_t num_peers;
106 struct GNUNET_PeerIdentity peer_id;
142 107
143 rps_handle = GNUNET_RPS_connect (cfg); 108 rps_handle = GNUNET_RPS_connect (cfg);
144 109
145 if (NULL == peer_id) 110 if (NULL == peer_id_str)
146 { /* Request n PeerIDs */ 111 { /* Request n PeerIDs */
147 /* If number was specified use it, else request single peer. */ 112 /* If number was specified use it, else request single peer. */
148 num_peers = (NULL == args[0]) ? 1 : atoi (args[0]); 113 num_peers = (NULL == args[0]) ? 1 : atoi (args[0]);
@@ -153,8 +118,18 @@ run (void *cls,
153 } 118 }
154 else 119 else
155 { /* Seed PeerID */ 120 { /* Seed PeerID */
156 GNUNET_RPS_seed_ids (rps_handle, 1, peer_id); 121 if (GNUNET_OK !=
157 FPRINTF (stdout, "Seeded PeerID %s\n", GNUNET_i2s_full (peer_id)); 122 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id_str,
123 strlen (peer_id_str),
124 &peer_id.public_key))
125 {
126 FPRINTF (stderr,
127 _("Failed to parse peer identity `%s'\n"),
128 peer_id_str);
129 return;
130 }
131 GNUNET_RPS_seed_ids (rps_handle, 1, &peer_id);
132 FPRINTF (stdout, "Seeded PeerID %s\n", GNUNET_i2s_full (&peer_id));
158 ret = 0; 133 ret = 0;
159 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 134 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
160 } 135 }
@@ -172,10 +147,12 @@ main (int argc, char *const *argv)
172{ 147{
173 const char helpstr[] = 148 const char helpstr[] =
174 "Get random GNUnet peers. If none is specified a single is requested."; 149 "Get random GNUnet peers. If none is specified a single is requested.";
175 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 150 struct GNUNET_GETOPT_CommandLineOption options[] = {
176 {'s', "seed", "PEER_ID", 151 GNUNET_GETOPT_OPTION_STRING ('s',
177 gettext_noop ("Seed a PeerID"), 152 "seed",
178 GNUNET_YES, &GNUNET_GETOPT_set_peerid, &peer_id}, 153 "PEER_ID",
154 gettext_noop ("Seed a PeerID"),
155 &peer_id_str),
179 GNUNET_GETOPT_OPTION_END 156 GNUNET_GETOPT_OPTION_END
180 }; 157 };
181 return (GNUNET_OK == 158 return (GNUNET_OK ==