aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/peers/peers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/peers/peers.c')
-rw-r--r--src/plugins/peers/peers.c90
1 files changed, 44 insertions, 46 deletions
diff --git a/src/plugins/peers/peers.c b/src/plugins/peers/peers.c
index b0cccd88..1bfa2985 100644
--- a/src/plugins/peers/peers.c
+++ b/src/plugins/peers/peers.c
@@ -29,14 +29,12 @@
29#include <GNUnet/gnunet_directories.h> 29#include <GNUnet/gnunet_directories.h>
30#include <GNUnet/gnunet_getoption_lib.h> 30#include <GNUnet/gnunet_getoption_lib.h>
31#include <GNUnet/gnunet_identity_lib.h> 31#include <GNUnet/gnunet_identity_lib.h>
32#include <GNUnet/gnunet_util_config_impl.h> 32#include <GNUnet/gnunet_util.h>
33#include <GNUnet/gnunet_util_cron.h>
34#include <GNUnet/gnunet_util_network_client.h>
35#include <gtk/gtk.h> 33#include <gtk/gtk.h>
36 34
37#define REFRESH_RATE (15 * cronSECONDS) 35#define REFRESH_RATE (15 * GNUNET_CRON_SECONDS)
38 36
39static struct CronManager *cron; 37static struct GNUNET_CronManager *cron;
40 38
41static struct GE_Context *ectx; 39static struct GE_Context *ectx;
42 40
@@ -60,14 +58,14 @@ static struct Flags * flags;
60 58
61static int 59static int
62collector (void *data, 60collector (void *data,
63 const PeerIdentity * identity, 61 const GNUNET_PeerIdentity * identity,
64 const void *address, 62 const void *address,
65 unsigned int addr_len, 63 unsigned int addr_len,
66 cron_t last_message, unsigned int trust, unsigned int bpmFromPeer) 64 GNUNET_CronTime last_message, unsigned int trust, unsigned int bpmFromPeer)
67{ 65{
68 GtkListStore *model = data; 66 GtkListStore *model = data;
69 GtkTreeIter iter; 67 GtkTreeIter iter;
70 EncName enc; 68 GNUNET_EncName enc;
71 GdkPixbuf *ledBuf; 69 GdkPixbuf *ledBuf;
72 GdkPixbuf *flagBuf; 70 GdkPixbuf *flagBuf;
73 char *cc; 71 char *cc;
@@ -77,14 +75,14 @@ collector (void *data,
77 char *have; 75 char *have;
78 char *haddress; 76 char *haddress;
79 char *hostname; 77 char *hostname;
80 cron_t now; 78 GNUNET_CronTime now;
81 int i; 79 int i;
82 int found; 80 int found;
83 struct Flags * pos; 81 struct Flags * pos;
84 82
85 hash2enc (&identity->hashPubKey, &enc); 83 GNUNET_hash_to_enc (&identity->hashPubKey, &enc);
86 /* check if same peer is already in model! */ 84 /* check if same peer is already in model! */
87 found = NO; 85 found = GNUNET_NO;
88 if (TRUE == gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)) 86 if (TRUE == gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter))
89 { 87 {
90 do 88 do
@@ -97,29 +95,29 @@ collector (void *data,
97 { 95 {
98 if (strlen (haddress) > 0) 96 if (strlen (haddress) > 0)
99 { 97 {
100 FREE (have); 98 GNUNET_free (have);
101 FREE (haddress); 99 GNUNET_free (haddress);
102 return OK; 100 return GNUNET_OK;
103 } 101 }
104 found = YES; 102 found = GNUNET_YES;
105 } 103 }
106 FREENONNULL (haddress); 104 GNUNET_free_non_null (haddress);
107 FREE (have); 105 GNUNET_free (have);
108 } 106 }
109 } 107 }
110 while ((found == NO) && 108 while ((found == GNUNET_NO) &&
111 (TRUE == gtk_tree_model_iter_next (GTK_TREE_MODEL (model), 109 (TRUE == gtk_tree_model_iter_next (GTK_TREE_MODEL (model),
112 &iter))); 110 &iter)));
113 } 111 }
114 112
115 hostname = network_get_ip_as_string (address, addr_len, YES); 113 hostname = GNUNET_get_ip_as_string (address, addr_len, GNUNET_YES);
116 if (hostname == NULL) 114 if (hostname == NULL)
117 hostname = STRDUP ("NAT"); 115 hostname = GNUNET_strdup ("NAT");
118 /* get flag */ 116 /* get flag */
119 flagBuf = NULL; 117 flagBuf = NULL;
120 ledBuf = NULL; 118 ledBuf = NULL;
121 cc = NULL; 119 cc = NULL;
122 prefix = STRDUP (hostname); 120 prefix = GNUNET_strdup (hostname);
123 if (strstr (prefix, " ") != NULL) 121 if (strstr (prefix, " ") != NULL)
124 *strstr (prefix, " ") = '\0'; 122 *strstr (prefix, " ") = '\0';
125 cc = prefix; 123 cc = prefix;
@@ -148,11 +146,11 @@ collector (void *data,
148 pos = pos->next; 146 pos = pos->next;
149 } 147 }
150 if (pos == NULL) { 148 if (pos == NULL) {
151 cc = STRDUP (cc); 149 cc = GNUNET_strdup (cc);
152 for (i = 0; i < strlen (cc); i++) 150 for (i = 0; i < strlen (cc); i++)
153 cc[i] = tolower (cc[i]); 151 cc[i] = tolower (cc[i]);
154 dir = os_get_installation_path (IPK_DATADIR); 152 dir = GNUNET_get_installation_path (GNUNET_IPK_DATADIR);
155 fn = MALLOC (strlen (dir) + 32); 153 fn = GNUNET_malloc (strlen (dir) + 32);
156 strcpy (fn, dir); 154 strcpy (fn, dir);
157 strcat (fn, 155 strcat (fn,
158 DIR_SEPARATOR_STR ".." 156 DIR_SEPARATOR_STR ".."
@@ -160,10 +158,10 @@ collector (void *data,
160 DIR_SEPARATOR_STR "flags" DIR_SEPARATOR_STR); 158 DIR_SEPARATOR_STR "flags" DIR_SEPARATOR_STR);
161 strcat (fn, cc); 159 strcat (fn, cc);
162 strcat (fn, ".png"); 160 strcat (fn, ".png");
163 FREE (dir); 161 GNUNET_free (dir);
164 flagBuf = gdk_pixbuf_new_from_file (fn, NULL); 162 flagBuf = gdk_pixbuf_new_from_file (fn, NULL);
165 FREE (fn); 163 GNUNET_free (fn);
166 pos = MALLOC(sizeof(struct Flags)); 164 pos = GNUNET_malloc(sizeof(struct Flags));
167 pos->cc = cc; 165 pos->cc = cc;
168 pos->flag = flagBuf; 166 pos->flag = flagBuf;
169 pos->next = flags; 167 pos->next = flags;
@@ -172,10 +170,10 @@ collector (void *data,
172 } 170 }
173 171
174 /* get LED */ 172 /* get LED */
175 now = get_time (); 173 now = GNUNET_get_time ();
176 if (last_message + 150 * cronSECONDS > now) 174 if (last_message + 150 * GNUNET_CRON_SECONDS > now)
177 ledBuf = green; 175 ledBuf = green;
178 else if (last_message + 5 * cronMINUTES > now) 176 else if (last_message + 5 * GNUNET_CRON_MINUTES > now)
179 ledBuf = yellow; 177 ledBuf = yellow;
180 else if (bpmFromPeer > 0) 178 else if (bpmFromPeer > 0)
181 ledBuf = red; 179 ledBuf = red;
@@ -183,7 +181,7 @@ collector (void *data,
183 ledBuf = black; 181 ledBuf = black;
184 182
185 /* add to model */ 183 /* add to model */
186 if (found == NO) 184 if (found == GNUNET_NO)
187 gtk_list_store_append (model, &iter); 185 gtk_list_store_append (model, &iter);
188 gtk_list_store_set (model, 186 gtk_list_store_set (model,
189 &iter, 187 &iter,
@@ -192,9 +190,9 @@ collector (void *data,
192 2, bpmFromPeer, 190 2, bpmFromPeer,
193 3, (const char *) &enc, 191 3, (const char *) &enc,
194 4, ledBuf, 5, flagBuf, 6, cc, 7, last_message, -1); 192 4, ledBuf, 5, flagBuf, 6, cc, 7, last_message, -1);
195 FREE (prefix); 193 GNUNET_free (prefix);
196 FREE (hostname); 194 GNUNET_free (hostname);
197 return OK; 195 return GNUNET_OK;
198} 196}
199 197
200 198
@@ -205,7 +203,7 @@ collector (void *data,
205static GtkListStore * 203static GtkListStore *
206getPeerModel () 204getPeerModel ()
207{ 205{
208 struct ClientServerConnection *sock; 206 struct GNUNET_ClientServerConnection *sock;
209 GtkListStore *model; 207 GtkListStore *model;
210 208
211 model = gtk_list_store_new (8, G_TYPE_STRING, /* address */ 209 model = gtk_list_store_new (8, G_TYPE_STRING, /* address */
@@ -216,11 +214,11 @@ getPeerModel ()
216 GDK_TYPE_PIXBUF, /* flag */ 214 GDK_TYPE_PIXBUF, /* flag */
217 G_TYPE_STRING, /* country name */ 215 G_TYPE_STRING, /* country name */
218 G_TYPE_UINT64); /* last time seen */ 216 G_TYPE_UINT64); /* last time seen */
219 sock = client_connection_create (ectx, cfg); 217 sock = GNUNET_client_connection_create (ectx, cfg);
220 if (sock != NULL) 218 if (sock != NULL)
221 { 219 {
222 gnunet_identity_request_peer_infos (sock, &collector, model); 220 GNUNET_IDENTITY_request_peer_infos (sock, &collector, model);
223 connection_destroy (sock); 221 GNUNET_client_connection_destroy (sock);
224 } 222 }
225 return model; 223 return model;
226} 224}
@@ -353,8 +351,8 @@ init_peers (struct GE_Context *e, struct GC_Configuration *c)
353 gtk_tree_view_column_set_sort_column_id (column, 3); 351 gtk_tree_view_column_set_sort_column_id (column, 3);
354 352
355 353
356 dir = os_get_installation_path (IPK_DATADIR); 354 dir = GNUNET_get_installation_path (GNUNET_IPK_DATADIR);
357 fn = MALLOC (strlen (dir) + 32); 355 fn = GNUNET_malloc (strlen (dir) + 32);
358 strcpy (fn, dir); 356 strcpy (fn, dir);
359 strcat (fn, 357 strcat (fn,
360 DIR_SEPARATOR_STR ".." 358 DIR_SEPARATOR_STR ".."
@@ -378,13 +376,13 @@ init_peers (struct GE_Context *e, struct GC_Configuration *c)
378 DIR_SEPARATOR_STR ".." 376 DIR_SEPARATOR_STR ".."
379 DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR "black.png"); 377 DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR "black.png");
380 black = gdk_pixbuf_new_from_file (fn, NULL); 378 black = gdk_pixbuf_new_from_file (fn, NULL);
381 FREE (fn); 379 GNUNET_free (fn);
382 FREE (dir); 380 GNUNET_free (dir);
383 381
384 tab = glade_xml_get_widget (getMainXML (), "peersScrolledWindow"); 382 tab = glade_xml_get_widget (getMainXML (), "peersScrolledWindow");
385 gtk_widget_show (tab); 383 gtk_widget_show (tab);
386 cron = gnunet_gtk_get_cron (); 384 cron = gnunet_gtk_get_cron ();
387 cron_add_job (cron, &updatePeerInfo, REFRESH_RATE, REFRESH_RATE, NULL); 385 GNUNET_cron_add_job (cron, &updatePeerInfo, REFRESH_RATE, REFRESH_RATE, NULL);
388} 386}
389 387
390void 388void
@@ -393,7 +391,7 @@ done_peers ()
393 GtkWidget *w; 391 GtkWidget *w;
394 struct Flags * pos; 392 struct Flags * pos;
395 393
396 cron_del_job (cron, &updatePeerInfo, REFRESH_RATE, NULL); 394 GNUNET_cron_del_job (cron, &updatePeerInfo, REFRESH_RATE, NULL);
397 if (red != NULL) 395 if (red != NULL)
398 g_object_unref (red); 396 g_object_unref (red);
399 if (green != NULL) 397 if (green != NULL)
@@ -409,8 +407,8 @@ done_peers ()
409 pos = flags->next; 407 pos = flags->next;
410 if (flags->flag != NULL) 408 if (flags->flag != NULL)
411 g_object_unref(flags->flag); 409 g_object_unref(flags->flag);
412 FREE (flags->cc); 410 GNUNET_free (flags->cc);
413 FREE(flags); 411 GNUNET_free(flags);
414 flags = pos; 412 flags = pos;
415 } 413 }
416} 414}