aboutsummaryrefslogtreecommitdiff
path: root/src/rps/gnunet-rps.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rps/gnunet-rps.c')
-rw-r--r--src/rps/gnunet-rps.c57
1 files changed, 13 insertions, 44 deletions
diff --git a/src/rps/gnunet-rps.c b/src/rps/gnunet-rps.c
index 3dbb8053e..e36e547fa 100644
--- a/src/rps/gnunet-rps.c
+++ b/src/rps/gnunet-rps.c
@@ -43,43 +43,7 @@ static struct GNUNET_RPS_Request_Handle *req_handle;
43/** 43/**
44 * PeerID (Option --seed) 44 * PeerID (Option --seed)
45 */ 45 */
46static struct GNUNET_PeerIdentity *peer_id; 46static struct GNUNET_PeerIdentity peer_id;
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,13 @@ 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 static struct GNUNET_PeerIdentity zero_pid;
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 (0 == memcmp (&zero_pid,
111 &peer_id,
112 sizeof (peer_id)))
146 { /* Request n PeerIDs */ 113 { /* Request n PeerIDs */
147 /* If number was specified use it, else request single peer. */ 114 /* If number was specified use it, else request single peer. */
148 num_peers = (NULL == args[0]) ? 1 : atoi (args[0]); 115 num_peers = (NULL == args[0]) ? 1 : atoi (args[0]);
@@ -153,8 +120,8 @@ run (void *cls,
153 } 120 }
154 else 121 else
155 { /* Seed PeerID */ 122 { /* Seed PeerID */
156 GNUNET_RPS_seed_ids (rps_handle, 1, peer_id); 123 GNUNET_RPS_seed_ids (rps_handle, 1, &peer_id);
157 FPRINTF (stdout, "Seeded PeerID %s\n", GNUNET_i2s_full (peer_id)); 124 FPRINTF (stdout, "Seeded PeerID %s\n", GNUNET_i2s_full (&peer_id));
158 ret = 0; 125 ret = 0;
159 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 126 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
160 } 127 }
@@ -172,10 +139,12 @@ main (int argc, char *const *argv)
172{ 139{
173 const char helpstr[] = 140 const char helpstr[] =
174 "Get random GNUnet peers. If none is specified a single is requested."; 141 "Get random GNUnet peers. If none is specified a single is requested.";
175 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 142 struct GNUNET_GETOPT_CommandLineOption options[] = {
176 {'s', "seed", "PEER_ID", 143 GNUNET_GETOPT_OPTION_SET_BASE32_AUTO ('s',
177 gettext_noop ("Seed a PeerID"), 144 "seed",
178 GNUNET_YES, &GNUNET_GETOPT_set_peerid, &peer_id}, 145 "PEER_ID",
146 gettext_noop ("Seed a PeerID"),
147 &peer_id),
179 GNUNET_GETOPT_OPTION_END 148 GNUNET_GETOPT_OPTION_END
180 }; 149 };
181 return (GNUNET_OK == 150 return (GNUNET_OK ==