diff options
Diffstat (limited to 'src/peerinfo/gnunet-peerinfo-gtk.c')
-rw-r--r-- | src/peerinfo/gnunet-peerinfo-gtk.c | 240 |
1 files changed, 104 insertions, 136 deletions
diff --git a/src/peerinfo/gnunet-peerinfo-gtk.c b/src/peerinfo/gnunet-peerinfo-gtk.c index 42e44317..7f1d3442 100644 --- a/src/peerinfo/gnunet-peerinfo-gtk.c +++ b/src/peerinfo/gnunet-peerinfo-gtk.c | |||
@@ -54,7 +54,7 @@ struct PeerInfo | |||
54 | * Total number of addresses found. | 54 | * Total number of addresses found. |
55 | */ | 55 | */ |
56 | guint palc_counter; | 56 | guint palc_counter; |
57 | 57 | ||
58 | }; | 58 | }; |
59 | 59 | ||
60 | 60 | ||
@@ -108,7 +108,7 @@ get_object (const char *name) | |||
108 | 108 | ||
109 | 109 | ||
110 | /** | 110 | /** |
111 | * Function called on each entry in the 'peer2info' map | 111 | * Function called on each entry in the 'peer2info' map |
112 | * to free the associated path. | 112 | * to free the associated path. |
113 | * | 113 | * |
114 | * @param cls unused | 114 | * @param cls unused |
@@ -117,19 +117,17 @@ get_object (const char *name) | |||
117 | * @return GNUNET_OK (continue to iterate) | 117 | * @return GNUNET_OK (continue to iterate) |
118 | */ | 118 | */ |
119 | static int | 119 | static int |
120 | free_paths (void *cls, | 120 | free_paths (void *cls, const GNUNET_HashCode * key, void *value) |
121 | const GNUNET_HashCode *key, | ||
122 | void *value) | ||
123 | { | 121 | { |
124 | struct PeerInfo *info = value; | 122 | struct PeerInfo *info = value; |
125 | 123 | ||
126 | if (NULL != info->palc) | 124 | if (NULL != info->palc) |
127 | { | 125 | { |
128 | GNUNET_TRANSPORT_peer_address_lookup_cancel (info->palc); | 126 | GNUNET_TRANSPORT_peer_address_lookup_cancel (info->palc); |
129 | info->palc = NULL; | 127 | info->palc = NULL; |
130 | GNUNET_free (info->palc_accumulator); | 128 | GNUNET_free (info->palc_accumulator); |
131 | info->palc_accumulator = NULL; | 129 | info->palc_accumulator = NULL; |
132 | } | 130 | } |
133 | gtk_tree_row_reference_free (info->rr); | 131 | gtk_tree_row_reference_free (info->rr); |
134 | GNUNET_free (info); | 132 | GNUNET_free (info); |
135 | return GNUNET_OK; | 133 | return GNUNET_OK; |
@@ -143,8 +141,7 @@ free_paths (void *cls, | |||
143 | * @param tc scheduler context, unused | 141 | * @param tc scheduler context, unused |
144 | */ | 142 | */ |
145 | static void | 143 | static void |
146 | shutdown_task (void *cls, | 144 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
147 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
148 | { | 145 | { |
149 | GNUNET_PEERINFO_notify_cancel (pnc); | 146 | GNUNET_PEERINFO_notify_cancel (pnc); |
150 | pnc = NULL; | 147 | pnc = NULL; |
@@ -153,9 +150,7 @@ shutdown_task (void *cls, | |||
153 | GNUNET_CORE_disconnect (core); | 150 | GNUNET_CORE_disconnect (core); |
154 | core = NULL; | 151 | core = NULL; |
155 | } | 152 | } |
156 | GNUNET_CONTAINER_multihashmap_iterate (peer2info, | 153 | GNUNET_CONTAINER_multihashmap_iterate (peer2info, &free_paths, NULL); |
157 | &free_paths, | ||
158 | NULL); | ||
159 | GNUNET_CONTAINER_multihashmap_destroy (peer2info); | 154 | GNUNET_CONTAINER_multihashmap_destroy (peer2info); |
160 | peer2info = NULL; | 155 | peer2info = NULL; |
161 | GNUNET_PEERINFO_GTK_flags_shutdown (); | 156 | GNUNET_PEERINFO_GTK_flags_shutdown (); |
@@ -169,8 +164,7 @@ shutdown_task (void *cls, | |||
169 | * @param address NULL on error, otherwise 0-terminated printable UTF-8 string | 164 | * @param address NULL on error, otherwise 0-terminated printable UTF-8 string |
170 | */ | 165 | */ |
171 | static void | 166 | static void |
172 | peer_address_cb (void *cls, | 167 | peer_address_cb (void *cls, const char *address) |
173 | const char *address) | ||
174 | { | 168 | { |
175 | struct PeerInfo *info = cls; | 169 | struct PeerInfo *info = cls; |
176 | char *tmp; | 170 | char *tmp; |
@@ -183,41 +177,34 @@ peer_address_cb (void *cls, | |||
183 | char *country; | 177 | char *country; |
184 | 178 | ||
185 | if (NULL == address) | 179 | if (NULL == address) |
180 | { | ||
181 | /* last address, store information in model */ | ||
182 | country = NULL; | ||
183 | colon = strstr (info->palc_accumulator, ":"); | ||
184 | if (NULL != colon) | ||
186 | { | 185 | { |
187 | /* last address, store information in model */ | 186 | for (dot = colon - 1; dot != info->palc_accumulator; dot--) |
188 | country = NULL; | 187 | if ('.' == *dot) |
189 | colon = strstr (info->palc_accumulator, ":"); | 188 | break; |
190 | if (NULL != colon) | 189 | if ('.' == *dot) |
191 | { | 190 | country = GNUNET_strndup (&dot[1], (colon - dot) - 1); |
192 | for (dot = colon - 1; dot != info->palc_accumulator; dot--) | ||
193 | if ('.' == *dot) | ||
194 | break; | ||
195 | if ('.' == *dot) | ||
196 | country = GNUNET_strndup (&dot[1], (colon - dot) - 1); | ||
197 | } | ||
198 | ls = GTK_LIST_STORE (get_object ("GNUNET_PEERINFO_GTK_list_store")); | ||
199 | tm = GTK_TREE_MODEL (ls); | ||
200 | path = gtk_tree_row_reference_get_path (info->rr); | ||
201 | GNUNET_assert (NULL != path); | ||
202 | GNUNET_assert (TRUE == | ||
203 | gtk_tree_model_get_iter (tm, &iter, path)); | ||
204 | gtk_tree_path_free (path); | ||
205 | gtk_list_store_set (ls, &iter, | ||
206 | 1, info->palc_counter, | ||
207 | 2, country, | ||
208 | 3, GNUNET_PEERINFO_GTK_get_flag (country), | ||
209 | 6, &info->palc_accumulator[1], | ||
210 | -1); | ||
211 | GNUNET_free_non_null (country); | ||
212 | info->palc = NULL; | ||
213 | GNUNET_free (info->palc_accumulator); | ||
214 | info->palc_accumulator = NULL; | ||
215 | return; | ||
216 | } | 191 | } |
217 | GNUNET_asprintf (&tmp, | 192 | ls = GTK_LIST_STORE (get_object ("GNUNET_PEERINFO_GTK_list_store")); |
218 | "%s|%s", | 193 | tm = GTK_TREE_MODEL (ls); |
219 | info->palc_accumulator, | 194 | path = gtk_tree_row_reference_get_path (info->rr); |
220 | address); | 195 | GNUNET_assert (NULL != path); |
196 | GNUNET_assert (TRUE == gtk_tree_model_get_iter (tm, &iter, path)); | ||
197 | gtk_tree_path_free (path); | ||
198 | gtk_list_store_set (ls, &iter, 1, info->palc_counter, 2, country, 3, | ||
199 | GNUNET_PEERINFO_GTK_get_flag (country), 6, | ||
200 | &info->palc_accumulator[1], -1); | ||
201 | GNUNET_free_non_null (country); | ||
202 | info->palc = NULL; | ||
203 | GNUNET_free (info->palc_accumulator); | ||
204 | info->palc_accumulator = NULL; | ||
205 | return; | ||
206 | } | ||
207 | GNUNET_asprintf (&tmp, "%s|%s", info->palc_accumulator, address); | ||
221 | GNUNET_free (info->palc_accumulator); | 208 | GNUNET_free (info->palc_accumulator); |
222 | info->palc_accumulator = tmp; | 209 | info->palc_accumulator = tmp; |
223 | info->palc_counter++; | 210 | info->palc_counter++; |
@@ -233,10 +220,9 @@ peer_address_cb (void *cls, | |||
233 | * @param err_msg NULL if successful, otherwise contains error message | 220 | * @param err_msg NULL if successful, otherwise contains error message |
234 | */ | 221 | */ |
235 | static void | 222 | static void |
236 | peerinfo_processor (void *cls, | 223 | peerinfo_processor (void *cls, const struct GNUNET_PeerIdentity *peer, |
237 | const struct GNUNET_PeerIdentity *peer, | 224 | const struct GNUNET_HELLO_Message *hello, |
238 | const struct GNUNET_HELLO_Message *hello, | 225 | const char *err_msg) |
239 | const char *err_msg) | ||
240 | { | 226 | { |
241 | GtkListStore *ls; | 227 | GtkListStore *ls; |
242 | GtkTreeModel *tm; | 228 | GtkTreeModel *tm; |
@@ -248,48 +234,43 @@ peerinfo_processor (void *cls, | |||
248 | 234 | ||
249 | ls = GTK_LIST_STORE (get_object ("GNUNET_PEERINFO_GTK_list_store")); | 235 | ls = GTK_LIST_STORE (get_object ("GNUNET_PEERINFO_GTK_list_store")); |
250 | if (NULL == ls) | 236 | if (NULL == ls) |
251 | { | 237 | { |
252 | GNUNET_break (0); | 238 | GNUNET_break (0); |
253 | return; | 239 | return; |
254 | } | 240 | } |
255 | tm = GTK_TREE_MODEL (ls); | 241 | tm = GTK_TREE_MODEL (ls); |
256 | info = GNUNET_CONTAINER_multihashmap_get (peer2info, | 242 | info = GNUNET_CONTAINER_multihashmap_get (peer2info, &peer->hashPubKey); |
257 | &peer->hashPubKey); | ||
258 | if (NULL == info) | 243 | if (NULL == info) |
259 | { | 244 | { |
260 | GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &enc); | 245 | GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &enc); |
261 | npid = (char *) &enc; | 246 | npid = (char *) &enc; |
262 | npid[4] = '\0'; | 247 | npid[4] = '\0'; |
263 | gtk_list_store_append (ls, &iter); | 248 | gtk_list_store_append (ls, &iter); |
264 | gtk_list_store_set (ls, &iter, | 249 | gtk_list_store_set (ls, &iter, 0, npid, 1, |
265 | 0, npid, | 250 | 0 /* number of known addresses */ , |
266 | 1, 0 /* number of known addresses */ , | 251 | 2, "" /* country name */ , |
267 | 2, "" /* country name */ , | 252 | 3, NULL /* country flag */ , |
268 | 3, NULL /* country flag */ , | 253 | 4, (guint64) 0 /* bandwidth-in */ , |
269 | 4, (guint64) 0 /* bandwidth-in */ , | 254 | 5, (guint64) 0 /* bandwidth-out */ , |
270 | 5, (guint64) 0 /* bandwidth-out */ , | 255 | 6, "" /* addresses as strings */ , |
271 | 6, "" /* addresses as strings */, | 256 | -1); |
272 | -1); | 257 | path = gtk_tree_model_get_path (tm, &iter); |
273 | path = gtk_tree_model_get_path (tm, &iter); | 258 | info = GNUNET_malloc (sizeof (struct PeerInfo)); |
274 | info = GNUNET_malloc (sizeof (struct PeerInfo)); | 259 | info->rr = gtk_tree_row_reference_new (tm, path); |
275 | info->rr = gtk_tree_row_reference_new (tm, path); | 260 | GNUNET_assert (NULL != info->rr); |
276 | GNUNET_assert (NULL != info->rr); | 261 | gtk_tree_path_free (path); |
277 | gtk_tree_path_free (path); | 262 | GNUNET_CONTAINER_multihashmap_put (peer2info, &peer->hashPubKey, info, |
278 | GNUNET_CONTAINER_multihashmap_put (peer2info, | 263 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
279 | &peer->hashPubKey, | 264 | } |
280 | info, | ||
281 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
282 | } | ||
283 | if (NULL == info->palc) | 265 | if (NULL == info->palc) |
284 | { | 266 | { |
285 | info->palc_accumulator = GNUNET_strdup ("|"); | 267 | info->palc_accumulator = GNUNET_strdup ("|"); |
286 | info->palc_counter = 0; | 268 | info->palc_counter = 0; |
287 | info->palc = GNUNET_TRANSPORT_peer_address_lookup (get_configuration(), | 269 | info->palc = |
288 | peer, | 270 | GNUNET_TRANSPORT_peer_address_lookup (get_configuration (), peer, |
289 | GNUNET_TIME_UNIT_MINUTES, | 271 | GNUNET_TIME_UNIT_MINUTES, |
290 | &peer_address_cb, | 272 | &peer_address_cb, info); |
291 | info); | 273 | } |
292 | } | ||
293 | 274 | ||
294 | } | 275 | } |
295 | 276 | ||
@@ -306,17 +287,13 @@ peerinfo_processor (void *cls, | |||
306 | * @param my_identity ID of this peer, NULL if we failed | 287 | * @param my_identity ID of this peer, NULL if we failed |
307 | * @param publicKey public key of this peer, NULL if we failed | 288 | * @param publicKey public key of this peer, NULL if we failed |
308 | */ | 289 | */ |
309 | static void | 290 | static void |
310 | init_cb (void *cls, | 291 | init_cb (void *cls, struct GNUNET_CORE_Handle *server, |
311 | struct GNUNET_CORE_Handle * server, | 292 | const struct GNUNET_PeerIdentity *my_identity, |
312 | const struct GNUNET_PeerIdentity * | 293 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) |
313 | my_identity, | ||
314 | const struct | ||
315 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | ||
316 | * publicKey) | ||
317 | { | 294 | { |
318 | /* FIXME: should probably do something to my 'own' entry | 295 | /* FIXME: should probably do something to my 'own' entry |
319 | in the peerinfo list to make it stand out */ | 296 | * in the peerinfo list to make it stand out */ |
320 | } | 297 | } |
321 | 298 | ||
322 | 299 | ||
@@ -331,35 +308,30 @@ init_cb (void *cls, | |||
331 | * @param bandwidth_out available amount of outbound bandwidth | 308 | * @param bandwidth_out available amount of outbound bandwidth |
332 | * @param atsi performance data for the connection | 309 | * @param atsi performance data for the connection |
333 | */ | 310 | */ |
334 | static void | 311 | static void |
335 | status_cb (void *cls, | 312 | status_cb (void *cls, const struct GNUNET_PeerIdentity *peer, |
336 | const struct GNUNET_PeerIdentity * peer, | 313 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
337 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 314 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
338 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 315 | struct GNUNET_TIME_Absolute timeout, |
339 | struct GNUNET_TIME_Absolute timeout, | 316 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
340 | const struct GNUNET_TRANSPORT_ATS_Information* atsi) | ||
341 | { | 317 | { |
342 | struct PeerInfo *info; | 318 | struct PeerInfo *info; |
343 | GtkListStore *ls; | 319 | GtkListStore *ls; |
344 | GtkTreeModel *tm; | 320 | GtkTreeModel *tm; |
345 | GtkTreeIter iter; | 321 | GtkTreeIter iter; |
346 | GtkTreePath *path; | 322 | GtkTreePath *path; |
347 | 323 | ||
348 | info = GNUNET_CONTAINER_multihashmap_get (peer2info, | 324 | info = GNUNET_CONTAINER_multihashmap_get (peer2info, &peer->hashPubKey); |
349 | &peer->hashPubKey); | ||
350 | if (NULL == info) | 325 | if (NULL == info) |
351 | return; /* should rarely happen... */ | 326 | return; /* should rarely happen... */ |
352 | ls = GTK_LIST_STORE (get_object ("GNUNET_PEERINFO_GTK_list_store")); | 327 | ls = GTK_LIST_STORE (get_object ("GNUNET_PEERINFO_GTK_list_store")); |
353 | tm = GTK_TREE_MODEL (ls); | 328 | tm = GTK_TREE_MODEL (ls); |
354 | path = gtk_tree_row_reference_get_path (info->rr); | 329 | path = gtk_tree_row_reference_get_path (info->rr); |
355 | GNUNET_assert (NULL != path); | 330 | GNUNET_assert (NULL != path); |
356 | GNUNET_assert (TRUE == | 331 | GNUNET_assert (TRUE == gtk_tree_model_get_iter (tm, &iter, path)); |
357 | gtk_tree_model_get_iter (tm, &iter, path)); | ||
358 | gtk_tree_path_free (path); | 332 | gtk_tree_path_free (path); |
359 | gtk_list_store_set (ls, &iter, | 333 | gtk_list_store_set (ls, &iter, 4, (guint64) ntohl (bandwidth_in.value__), 5, |
360 | 4, (guint64) ntohl (bandwidth_in.value__), | 334 | (guint64) ntohl (bandwidth_out.value__), -1); |
361 | 5, (guint64) ntohl (bandwidth_out.value__), | ||
362 | -1); | ||
363 | } | 335 | } |
364 | 336 | ||
365 | 337 | ||
@@ -383,30 +355,26 @@ static void | |||
383 | run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 355 | run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
384 | { | 356 | { |
385 | GtkWidget *main_window; | 357 | GtkWidget *main_window; |
358 | |||
386 | ml = cls; | 359 | ml = cls; |
387 | 360 | ||
388 | GNUNET_GTK_set_icon_search_path (); | 361 | GNUNET_GTK_set_icon_search_path (); |
389 | GNUNET_GTK_setup_nls (); | 362 | GNUNET_GTK_setup_nls (); |
390 | peer2info = GNUNET_CONTAINER_multihashmap_create (256); | 363 | peer2info = GNUNET_CONTAINER_multihashmap_create (256); |
391 | pnc = GNUNET_PEERINFO_notify (get_configuration(), | 364 | pnc = |
392 | &peerinfo_processor, NULL); | 365 | GNUNET_PEERINFO_notify (get_configuration (), &peerinfo_processor, NULL); |
393 | if (pnc == NULL) | 366 | if (pnc == NULL) |
394 | { | 367 | { |
395 | fprintf (stderr, _("Failed to initialize communication with peerinfo service!\n")); | 368 | fprintf (stderr, |
369 | _("Failed to initialize communication with peerinfo service!\n")); | ||
396 | exit (1); | 370 | exit (1); |
397 | } | 371 | } |
398 | core = GNUNET_CORE_connect (get_configuration(), | 372 | core = |
399 | 1, NULL, | 373 | GNUNET_CORE_connect (get_configuration (), 1, NULL, &init_cb, NULL, NULL, |
400 | &init_cb, | 374 | &status_cb, NULL, GNUNET_NO, NULL, GNUNET_NO, NULL); |
401 | NULL, NULL, | ||
402 | &status_cb, | ||
403 | NULL, GNUNET_NO, | ||
404 | NULL, GNUNET_NO, | ||
405 | NULL); | ||
406 | 375 | ||
407 | /* setup main window */ | 376 | /* setup main window */ |
408 | main_window = | 377 | main_window = GTK_WIDGET (get_object ("GNUNET_PEERINFO_GTK_main_window")); |
409 | GTK_WIDGET (get_object ("GNUNET_PEERINFO_GTK_main_window")); | ||
410 | gtk_window_maximize (GTK_WINDOW (main_window)); | 378 | gtk_window_maximize (GTK_WINDOW (main_window)); |
411 | GNUNET_GTK_tray_icon_create (GTK_WINDOW (main_window), | 379 | GNUNET_GTK_tray_icon_create (GTK_WINDOW (main_window), |
412 | "gnunet-gtk" /* FIXME: different icon? */ , | 380 | "gnunet-gtk" /* FIXME: different icon? */ , |
@@ -433,10 +401,10 @@ main (int argc, char *const *argv) | |||
433 | 401 | ||
434 | if (GNUNET_OK != | 402 | if (GNUNET_OK != |
435 | GNUNET_GTK_main_loop_start ("gnunet-peerinfo-gtk", | 403 | GNUNET_GTK_main_loop_start ("gnunet-peerinfo-gtk", |
436 | "GTK GUI for inspecting GNUnet Peers", | 404 | "GTK GUI for inspecting GNUnet Peers", argc, |
437 | argc, | ||
438 | argv, options, | 405 | argv, options, |
439 | "gnunet_peerinfo_gtk_main_window.glade", &run)) | 406 | "gnunet_peerinfo_gtk_main_window.glade", |
407 | &run)) | ||
440 | return 1; | 408 | return 1; |
441 | return 0; | 409 | return 0; |
442 | } | 410 | } |