diff options
-rw-r--r-- | src/testbed/gnunet-daemon-testbed-underlay.c | 118 |
1 files changed, 35 insertions, 83 deletions
diff --git a/src/testbed/gnunet-daemon-testbed-underlay.c b/src/testbed/gnunet-daemon-testbed-underlay.c index 9b77ba0d1..8cdfe4440 100644 --- a/src/testbed/gnunet-daemon-testbed-underlay.c +++ b/src/testbed/gnunet-daemon-testbed-underlay.c | |||
@@ -77,11 +77,6 @@ static struct GNUNET_CONTAINER_MultiPeerMap *blacklist_map; | |||
77 | static struct sqlite3 *db; | 77 | static struct sqlite3 *db; |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * The array of peer identities we read from whitelist/blacklist | ||
81 | */ | ||
82 | static struct GNUNET_PeerIdentity *ilist; | ||
83 | |||
84 | /** | ||
85 | * The blacklist handle we obtain from transport when we register ourselves for | 80 | * The blacklist handle we obtain from transport when we register ourselves for |
86 | * access control | 81 | * access control |
87 | */ | 82 | */ |
@@ -95,7 +90,7 @@ static struct GNUNET_DISK_MapHandle *idmap; | |||
95 | /** | 90 | /** |
96 | * The hostkeys data | 91 | * The hostkeys data |
97 | */ | 92 | */ |
98 | static struct GNUNET_PeerIdentity *hostkeys; | 93 | static char *hostkeys_data; |
99 | 94 | ||
100 | /** | 95 | /** |
101 | * Handle to the transport service. This is used for setting link metrics | 96 | * Handle to the transport service. This is used for setting link metrics |
@@ -192,48 +187,18 @@ check_access (void *cls, const struct GNUNET_PeerIdentity * pid) | |||
192 | } | 187 | } |
193 | 188 | ||
194 | 189 | ||
195 | /** | 190 | static int |
196 | * Setup the access control by reading the given file containing peer identities | 191 | get_identity (unsigned int offset, struct GNUNET_PeerIdentity *id) |
197 | * and then establishing blacklist handler with the peer's transport service | ||
198 | * | ||
199 | * @param fname the filename to read the list of peer identities | ||
200 | * @param cfg the configuration for connecting to the peer's transport service | ||
201 | */ | ||
202 | static void | ||
203 | setup_ac (const char *fname, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
204 | { | 192 | { |
205 | uint64_t fsize; | 193 | struct GNUNET_CRYPTO_EddsaPrivateKey private_key; |
206 | unsigned int npeers; | ||
207 | unsigned int cnt; | ||
208 | 194 | ||
209 | GNUNET_assert (GNUNET_OK != GNUNET_DISK_file_size (fname, &fsize, GNUNET_NO, | 195 | if (offset >= num_hostkeys) |
210 | GNUNET_YES)); | 196 | return GNUNET_SYSERR; |
211 | if (0 != (fsize % sizeof (struct GNUNET_PeerIdentity))) | 197 | (void) memcpy (&private_key, |
212 | { | 198 | hostkeys_data + (offset * GNUNET_TESTING_HOSTKEYFILESIZE), |
213 | GNUNET_break (0); | 199 | GNUNET_TESTING_HOSTKEYFILESIZE); |
214 | return; | 200 | GNUNET_CRYPTO_eddsa_key_get_public (&private_key, &id->public_key); |
215 | } | 201 | return GNUNET_OK; |
216 | npeers = fsize / sizeof (struct GNUNET_PeerIdentity); | ||
217 | if (0 != npeers) | ||
218 | { | ||
219 | map = GNUNET_CONTAINER_multipeermap_create (npeers, GNUNET_YES); | ||
220 | ilist = GNUNET_malloc_large (fsize); | ||
221 | GNUNET_assert (fsize == GNUNET_DISK_fn_read (fname, ilist, fsize)); | ||
222 | } | ||
223 | for (cnt = 0; cnt < npeers; cnt++) | ||
224 | { | ||
225 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put (map, &ilist[cnt], | ||
226 | &ilist[cnt], | ||
227 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
228 | { | ||
229 | cleanup_map (); | ||
230 | GNUNET_free (ilist); | ||
231 | return; | ||
232 | } | ||
233 | } | ||
234 | shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
235 | &do_shutdown, NULL); | ||
236 | bh = GNUNET_TRANSPORT_blacklist (cfg, &check_access, NULL); | ||
237 | } | 202 | } |
238 | 203 | ||
239 | 204 | ||
@@ -245,11 +210,10 @@ setup_ac (const char *fname, const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
245 | static void | 210 | static void |
246 | blacklist_peer (unsigned int offset) | 211 | blacklist_peer (unsigned int offset) |
247 | { | 212 | { |
248 | struct GNUNET_CRYPTO_EddsaPrivateKey private_key; | ||
249 | struct GNUNET_PeerIdentity id; | 213 | struct GNUNET_PeerIdentity id; |
250 | 214 | ||
251 | (void) memcpy (&private_key, &hostkeys[offset], sizeof (private_key)); | 215 | GNUNET_assert (offset < num_hostkeys); |
252 | GNUNET_CRYPTO_eddsa_key_get_public (&private_key, &id.public_key); | 216 | GNUNET_assert (GNUNET_OK == get_identity (offset, &id)); |
253 | GNUNET_break (GNUNET_OK == | 217 | GNUNET_break (GNUNET_OK == |
254 | GNUNET_CONTAINER_multipeermap_put (map, &id, &id, | 218 | GNUNET_CONTAINER_multipeermap_put (map, &id, &id, |
255 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 219 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
@@ -306,35 +270,6 @@ struct WhiteListRow | |||
306 | 270 | ||
307 | 271 | ||
308 | /** | 272 | /** |
309 | * Add peers in the blacklist to the blacklist map | ||
310 | */ | ||
311 | static int | ||
312 | map_populate (struct BlackListRow *head, | ||
313 | struct GNUNET_CONTAINER_MultiPeerMap *map, | ||
314 | const struct GNUNET_PeerIdentity *hostkeys) | ||
315 | { | ||
316 | struct BlackListRow *row; | ||
317 | int ret; | ||
318 | |||
319 | while (NULL != (row = head)) | ||
320 | { | ||
321 | if (head->id >= num_hostkeys) | ||
322 | { | ||
323 | LOG (GNUNET_ERROR_TYPE_WARNING, "Hostkey index %u out of max range %u\n", | ||
324 | row->id, num_hostkeys); | ||
325 | } | ||
326 | head = row->next; | ||
327 | ret = GNUNET_CONTAINER_multipeermap_put (blacklist_map, &hostkeys[row->id], | ||
328 | (void *) &hostkeys[row->id], | ||
329 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
330 | if (GNUNET_OK != ret) | ||
331 | return GNUNET_SYSERR; | ||
332 | } | ||
333 | return GNUNET_OK; | ||
334 | } | ||
335 | |||
336 | |||
337 | /** | ||
338 | * Function to load keys | 273 | * Function to load keys |
339 | */ | 274 | */ |
340 | static int | 275 | static int |
@@ -376,9 +311,11 @@ load_keys (const struct GNUNET_CONFIGURATION_Handle *c) | |||
376 | } | 311 | } |
377 | GNUNET_free (idfile); | 312 | GNUNET_free (idfile); |
378 | idfile = NULL; | 313 | idfile = NULL; |
379 | hostkeys = (struct GNUNET_PeerIdentity *) | 314 | hostkeys_data = GNUNET_DISK_file_map (fd, |
380 | GNUNET_DISK_file_map (fd, &idmap, GNUNET_DISK_MAP_TYPE_READ, fsize); | 315 | &idmap, |
381 | if (NULL == hostkeys) | 316 | GNUNET_DISK_MAP_TYPE_READ, |
317 | fsize); | ||
318 | if (NULL != hostkeys_data) | ||
382 | num_hostkeys = fsize / GNUNET_TESTING_HOSTKEYFILESIZE; | 319 | num_hostkeys = fsize / GNUNET_TESTING_HOSTKEYFILESIZE; |
383 | return GNUNET_OK; | 320 | return GNUNET_OK; |
384 | } | 321 | } |
@@ -497,6 +434,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
497 | struct BlackListRow *bl_entry; | 434 | struct BlackListRow *bl_entry; |
498 | struct WhiteListRow *wl_head; | 435 | struct WhiteListRow *wl_head; |
499 | struct WhiteListRow *wl_entry; | 436 | struct WhiteListRow *wl_entry; |
437 | struct GNUNET_PeerIdentity identity; | ||
500 | struct GNUNET_ATS_Information triplet[3]; | 438 | struct GNUNET_ATS_Information triplet[3]; |
501 | unsigned long long pid; | 439 | unsigned long long pid; |
502 | unsigned int nrows; | 440 | unsigned int nrows; |
@@ -541,7 +479,19 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
541 | if (GNUNET_OK != load_keys (c)) | 479 | if (GNUNET_OK != load_keys (c)) |
542 | goto close_db; | 480 | goto close_db; |
543 | } | 481 | } |
544 | /* process whitelist */ | 482 | while (NULL != (bl_entry = bl_head)) |
483 | { | ||
484 | bl_head = bl_entry->next; | ||
485 | blacklist_peer (bl_entry->id); | ||
486 | GNUNET_free (bl_entry); | ||
487 | } | ||
488 | if (NULL != blacklist_map) | ||
489 | { | ||
490 | bh = GNUNET_TRANSPORT_blacklist (c, &check_access, NULL); | ||
491 | shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
492 | &do_shutdown, NULL); | ||
493 | } | ||
494 | /* read and process whitelist */ | ||
545 | nrows = 0; | 495 | nrows = 0; |
546 | wl_head = NULL; | 496 | wl_head = NULL; |
547 | nrows = db_read_whitelist (db, pid, &wl_head); | 497 | nrows = db_read_whitelist (db, pid, &wl_head); |
@@ -556,11 +506,13 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
556 | triplet[0].value = wl_entry->bandwidth; //FIXME: bandwidth != throughput !! | 506 | triplet[0].value = wl_entry->bandwidth; //FIXME: bandwidth != throughput !! |
557 | triplet[1].value = wl_entry->latency; | 507 | triplet[1].value = wl_entry->latency; |
558 | triplet[2].value = wl_entry->loss; | 508 | triplet[2].value = wl_entry->loss; |
509 | GNUNET_assert (GNUNET_OK == get_identity (wl_entry->id, &identity)); | ||
559 | GNUNET_TRANSPORT_set_traffic_metric (transport, | 510 | GNUNET_TRANSPORT_set_traffic_metric (transport, |
560 | &hostkeys[wl_entry->id], | 511 | &identity, |
561 | GNUNET_YES, | 512 | GNUNET_YES, |
562 | GNUNET_YES, /* FIXME: Separate inbound, outboud metrics */ | 513 | GNUNET_YES, /* FIXME: Separate inbound, outboud metrics */ |
563 | triplet, 3); | 514 | triplet, 3); |
515 | GNUNET_free (wl_entry); | ||
564 | } | 516 | } |
565 | 517 | ||
566 | close_db: | 518 | close_db: |