aboutsummaryrefslogtreecommitdiff
path: root/src/rps/gnunet-rps.c
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2018-03-05 18:27:45 +0100
committerJulius Bünger <buenger@mytum.de>2018-03-05 18:34:36 +0100
commit6c10bf3ecacc9701c0f189200dc66dbef00ed46d (patch)
treea9713def18d33687d610dccefcde851921c59827 /src/rps/gnunet-rps.c
parent132597e5050e591617cd4e303015608ff503d879 (diff)
downloadgnunet-6c10bf3ecacc9701c0f189200dc66dbef00ed46d.tar.gz
gnunet-6c10bf3ecacc9701c0f189200dc66dbef00ed46d.zip
rps: add debug call to get view to cli
Diffstat (limited to 'src/rps/gnunet-rps.c')
-rw-r--r--src/rps/gnunet-rps.c67
1 files changed, 64 insertions, 3 deletions
diff --git a/src/rps/gnunet-rps.c b/src/rps/gnunet-rps.c
index bbac0d634..8de588568 100644
--- a/src/rps/gnunet-rps.c
+++ b/src/rps/gnunet-rps.c
@@ -45,6 +45,16 @@ static struct GNUNET_RPS_Request_Handle *req_handle;
45 */ 45 */
46static struct GNUNET_PeerIdentity peer_id; 46static struct GNUNET_PeerIdentity peer_id;
47 47
48/**
49 * @brief Do we want to receive updates of the view? (Option --view)
50 */
51static int view_update;
52
53/**
54 * @brief Number of updates we want to receive
55 */
56static uint64_t num_view_updates;
57
48 58
49/** 59/**
50 * Task run when user presses CTRL-C to abort. 60 * Task run when user presses CTRL-C to abort.
@@ -87,6 +97,42 @@ reply_handle (void *cls,
87 GNUNET_SCHEDULER_shutdown (); 97 GNUNET_SCHEDULER_shutdown ();
88} 98}
89 99
100/**
101 * Callback called on receipt view update.
102 * Prints view.
103 *
104 * @param n number of peers
105 * @param recv_peers the received peers
106 */
107static void
108view_update_handle (void *cls,
109 uint64_t n,
110 const struct GNUNET_PeerIdentity *recv_peers)
111{
112 uint64_t i;
113
114 if (0 == n)
115 {
116 FPRINTF (stdout, "Empty view\n");
117 }
118 req_handle = NULL;
119 for (i = 0; i < n; i++)
120 {
121 FPRINTF (stdout, "%s\n",
122 GNUNET_i2s_full (&recv_peers[i]));
123 }
124
125 if (1 == num_view_updates)
126 {
127 ret = 0;
128 GNUNET_SCHEDULER_shutdown ();
129 }
130 else if (1 < num_view_updates)
131 {
132 num_view_updates--;
133 }
134}
135
90 136
91/** 137/**
92 * Main function that will be run by the scheduler. 138 * Main function that will be run by the scheduler.
@@ -107,9 +153,8 @@ run (void *cls,
107 153
108 rps_handle = GNUNET_RPS_connect (cfg); 154 rps_handle = GNUNET_RPS_connect (cfg);
109 155
110 if (0 == memcmp (&zero_pid, 156 if ((0 == memcmp (&zero_pid, &peer_id, sizeof (peer_id))) &&
111 &peer_id, 157 (!view_update))
112 sizeof (peer_id)))
113 { /* Request n PeerIDs */ 158 { /* Request n PeerIDs */
114 /* If number was specified use it, else request single peer. */ 159 /* If number was specified use it, else request single peer. */
115 num_peers = (NULL == args[0]) ? 1 : atoi (args[0]); 160 num_peers = (NULL == args[0]) ? 1 : atoi (args[0]);
@@ -117,6 +162,18 @@ run (void *cls,
117 "Requesting %" PRIu64 " PeerIDs\n", num_peers); 162 "Requesting %" PRIu64 " PeerIDs\n", num_peers);
118 req_handle = GNUNET_RPS_request_peers (rps_handle, num_peers, reply_handle, NULL); 163 req_handle = GNUNET_RPS_request_peers (rps_handle, num_peers, reply_handle, NULL);
119 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 164 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
165 } else if (view_update)
166 {
167 /* Get updates of view */
168 num_view_updates = (NULL == args[0]) ? 0 : atoi (args[0]);
169 GNUNET_RPS_view_request (rps_handle, num_view_updates, view_update_handle, NULL);
170 if (0 != num_view_updates)
171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
172 "Requesting %" PRIu64 " view updates\n", num_view_updates);
173 else
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
175 "Requesting contiuous view updates\n");
176 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
120 } 177 }
121 else 178 else
122 { /* Seed PeerID */ 179 { /* Seed PeerID */
@@ -145,6 +202,10 @@ main (int argc, char *const *argv)
145 "PEER_ID", 202 "PEER_ID",
146 gettext_noop ("Seed a PeerID"), 203 gettext_noop ("Seed a PeerID"),
147 &peer_id), 204 &peer_id),
205 GNUNET_GETOPT_option_flag ('V',
206 "view",
207 gettext_noop ("Get updates of view (0 for infinite updates)"),
208 &view_update),
148 GNUNET_GETOPT_OPTION_END 209 GNUNET_GETOPT_OPTION_END
149 }; 210 };
150 return (GNUNET_OK == 211 return (GNUNET_OK ==