diff options
Diffstat (limited to 'src/rps/gnunet-rps.c')
-rw-r--r-- | src/rps/gnunet-rps.c | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/src/rps/gnunet-rps.c b/src/rps/gnunet-rps.c index 03b2c8ab7..d2c497fd4 100644 --- a/src/rps/gnunet-rps.c +++ b/src/rps/gnunet-rps.c | |||
@@ -49,10 +49,20 @@ static struct GNUNET_PeerIdentity peer_id; | |||
49 | static int view_update; | 49 | static int view_update; |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * @brief Do we want to receive updates of the view? (Option --view) | ||
53 | */ | ||
54 | static int stream_input; | ||
55 | |||
56 | /** | ||
52 | * @brief Number of updates we want to receive | 57 | * @brief Number of updates we want to receive |
53 | */ | 58 | */ |
54 | static uint64_t num_view_updates; | 59 | static uint64_t num_view_updates; |
55 | 60 | ||
61 | /** | ||
62 | * @brief Number of updates we want to receive | ||
63 | */ | ||
64 | static uint64_t num_stream_peers; | ||
65 | |||
56 | 66 | ||
57 | /** | 67 | /** |
58 | * Task run when user presses CTRL-C to abort. | 68 | * Task run when user presses CTRL-C to abort. |
@@ -137,6 +147,22 @@ view_update_handle (void *cls, | |||
137 | 147 | ||
138 | 148 | ||
139 | /** | 149 | /** |
150 | * Callback called on receipt of peer from biased stream | ||
151 | * | ||
152 | * @param n number of peers | ||
153 | * @param recv_peers the received peers | ||
154 | */ | ||
155 | static void | ||
156 | stream_input_handle (void *cls, | ||
157 | const struct GNUNET_PeerIdentity *recv_peer) | ||
158 | { | ||
159 | // TODO when source of peer is sent, also print source | ||
160 | FPRINTF (stdout, "%s\n", | ||
161 | GNUNET_i2s_full (recv_peer)); | ||
162 | } | ||
163 | |||
164 | |||
165 | /** | ||
140 | * Main function that will be run by the scheduler. | 166 | * Main function that will be run by the scheduler. |
141 | * | 167 | * |
142 | * @param cls closure | 168 | * @param cls closure |
@@ -163,7 +189,8 @@ run (void *cls, | |||
163 | } | 189 | } |
164 | 190 | ||
165 | if ((0 == memcmp (&zero_pid, &peer_id, sizeof (peer_id))) && | 191 | if ((0 == memcmp (&zero_pid, &peer_id, sizeof (peer_id))) && |
166 | (!view_update)) | 192 | (!view_update) && |
193 | (!stream_input)) | ||
167 | { /* Request n PeerIDs */ | 194 | { /* Request n PeerIDs */ |
168 | /* If number was specified use it, else request single peer. */ | 195 | /* If number was specified use it, else request single peer. */ |
169 | if (NULL == args[0] || | 196 | if (NULL == args[0] || |
@@ -189,7 +216,23 @@ run (void *cls, | |||
189 | "Requesting %" PRIu64 " view updates\n", num_view_updates); | 216 | "Requesting %" PRIu64 " view updates\n", num_view_updates); |
190 | else | 217 | else |
191 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
192 | "Requesting contiuous view updates\n"); | 219 | "Requesting continuous view updates\n"); |
220 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | ||
221 | } else if (stream_input) | ||
222 | { | ||
223 | /* Get updates of view */ | ||
224 | if (NULL == args[0] || | ||
225 | 0 == sscanf (args[0], "%lu", &num_stream_peers)) | ||
226 | { | ||
227 | num_stream_peers = 0; | ||
228 | } | ||
229 | GNUNET_RPS_stream_request (rps_handle, num_stream_peers, stream_input_handle, NULL); | ||
230 | if (0 != num_stream_peers) | ||
231 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
232 | "Requesting %" PRIu64 " peers from biased stream\n", num_stream_peers); | ||
233 | else | ||
234 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
235 | "Requesting continuous peers from biased stream\n"); | ||
193 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 236 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
194 | } | 237 | } |
195 | else | 238 | else |
@@ -223,6 +266,10 @@ main (int argc, char *const *argv) | |||
223 | "view", | 266 | "view", |
224 | gettext_noop ("Get updates of view (0 for infinite updates)"), | 267 | gettext_noop ("Get updates of view (0 for infinite updates)"), |
225 | &view_update), | 268 | &view_update), |
269 | GNUNET_GETOPT_option_flag ('S', | ||
270 | "stream", | ||
271 | gettext_noop ("Get peers from biased stream"), | ||
272 | &stream_input), | ||
226 | GNUNET_GETOPT_OPTION_END | 273 | GNUNET_GETOPT_OPTION_END |
227 | }; | 274 | }; |
228 | return (GNUNET_OK == | 275 | return (GNUNET_OK == |