aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-09-03 15:30:48 +0000
committerNathan S. Evans <evans@in.tum.de>2010-09-03 15:30:48 +0000
commit16b21a18ddc47de49e320a9b6a6da3cef26e3429 (patch)
tree27d9a696bc99931f13b7a061fd4b620ad78a080f /src
parent8b39eac718f4e1268a3608b6b8a2df5c1c2a6ef8 (diff)
downloadgnunet-16b21a18ddc47de49e320a9b6a6da3cef26e3429.tar.gz
gnunet-16b21a18ddc47de49e320a9b6a6da3cef26e3429.zip
allowing a single stats and/or peerinfo service per host
Diffstat (limited to 'src')
-rw-r--r--src/testing/testing.c98
-rw-r--r--src/testing/testing_group.c26
2 files changed, 116 insertions, 8 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 2e4a44b2d..72716e9f1 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -1165,6 +1165,11 @@ struct ConnectContext
1165 struct GNUNET_TESTING_Daemon *d2; 1165 struct GNUNET_TESTING_Daemon *d2;
1166 1166
1167 /** 1167 /**
1168 * Handler for the request to core to connect to this peer.
1169 */
1170 struct GNUNET_CORE_PeerRequestHandle *connect_request_handle;
1171
1172 /**
1168 * Transport handle to the second daemon. 1173 * Transport handle to the second daemon.
1169 */ 1174 */
1170 struct GNUNET_TRANSPORT_Handle *d2th; 1175 struct GNUNET_TRANSPORT_Handle *d2th;
@@ -1250,6 +1255,12 @@ notify_connect_result (void *cls,
1250 GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->hello_send_task); 1255 GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->hello_send_task);
1251 ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; 1256 ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
1252 } 1257 }
1258
1259 if (ctx->connect_request_handle != NULL)
1260 {
1261 GNUNET_CORE_peer_request_connect_cancel (ctx->connect_request_handle);
1262 ctx->connect_request_handle = NULL;
1263 }
1253 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 1264 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
1254 { 1265 {
1255 if (ctx->d2th != NULL) 1266 if (ctx->d2th != NULL)
@@ -1257,8 +1268,13 @@ notify_connect_result (void *cls,
1257 ctx->d2th = NULL; 1268 ctx->d2th = NULL;
1258 if (ctx->d1core != NULL) 1269 if (ctx->d1core != NULL)
1259 GNUNET_CORE_disconnect (ctx->d1core); 1270 GNUNET_CORE_disconnect (ctx->d1core);
1260 1271#if CONNECT_CORE2
1272 if (ctx->d2core != NULL)
1273 GNUNET_CORE_disconnect (ctx->d2core);
1274 ctx->d2core = NULL;
1275#endif
1261 ctx->d1core = NULL; 1276 ctx->d1core = NULL;
1277
1262 GNUNET_free (ctx); 1278 GNUNET_free (ctx);
1263 return; 1279 return;
1264 } 1280 }
@@ -1280,6 +1296,13 @@ notify_connect_result (void *cls,
1280 GNUNET_CORE_disconnect(ctx->d1core); 1296 GNUNET_CORE_disconnect(ctx->d1core);
1281 ctx->d1core = NULL; 1297 ctx->d1core = NULL;
1282 } 1298 }
1299#if CONNECT_CORE2
1300 if (ctx->d2core != NULL)
1301 {
1302 GNUNET_CORE_disconnect(ctx->d2core);
1303 ctx->d2core = NULL;
1304 }
1305#endif
1283 1306
1284 if (ctx->d2th != NULL) 1307 if (ctx->d2th != NULL)
1285 { 1308 {
@@ -1334,6 +1357,52 @@ connect_notify (void *cls, const struct GNUNET_PeerIdentity * peer, struct GNUNE
1334 1357
1335} 1358}
1336 1359
1360#if CONNECT_CORE2
1361/**
1362 * Success, connection is up. Signal client our success.
1363 *
1364 * @param cls our "struct ConnectContext"
1365 * @param peer identity of the peer that has connected
1366 * @param latency the round trip latency of the connection to this peer
1367 * @param distance distance the transport level distance to this peer
1368 *
1369 */
1370static void
1371connect_notify_core2 (void *cls, const struct GNUNET_PeerIdentity * peer, struct GNUNET_TIME_Relative latency,
1372 uint32_t distance)
1373{
1374 struct ConnectContext *ctx = cls;
1375
1376 if (memcmp(&ctx->d2->id, peer, sizeof(struct GNUNET_PeerIdentity)) == 0)
1377 {
1378 ctx->connected = GNUNET_YES;
1379 ctx->distance = distance;
1380 GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->timeout_task);
1381 ctx->timeout_task = GNUNET_SCHEDULER_add_now (ctx->d1->sched,
1382 &notify_connect_result,
1383 ctx);
1384 }
1385
1386}
1387#endif
1388
1389/**
1390 * Task called once a core connect request has been transmitted.
1391 *
1392 * @param cls struct ConnectContext
1393 * @param tc context information (why was this task triggered now)
1394 */
1395void core_connect_request_cont (void *cls,
1396 const struct
1397 GNUNET_SCHEDULER_TaskContext * tc)
1398{
1399 struct ConnectContext *ctx = cls;
1400
1401 if (tc->reason == GNUNET_SCHEDULER_REASON_PREREQ_DONE)
1402 ctx->connect_request_handle = NULL;
1403 return;
1404}
1405
1337static void 1406static void
1338send_hello(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1407send_hello(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1339{ 1408{
@@ -1347,6 +1416,14 @@ send_hello(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1347 hello = GNUNET_HELLO_get_header(ctx->d1->hello); 1416 hello = GNUNET_HELLO_get_header(ctx->d1->hello);
1348 GNUNET_assert(hello != NULL); 1417 GNUNET_assert(hello != NULL);
1349 GNUNET_TRANSPORT_offer_hello (ctx->d2th, hello); 1418 GNUNET_TRANSPORT_offer_hello (ctx->d2th, hello);
1419
1420 ctx->connect_request_handle = GNUNET_CORE_peer_request_connect (ctx->d1->sched,
1421 ctx->d2->cfg,
1422 GNUNET_TIME_relative_get_forever(),
1423 &ctx->d1->id,
1424 &core_connect_request_cont,
1425 ctx);
1426 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending connect request to core for peer %s\n", GNUNET_i2s(&ctx->d1->id));
1350 ctx->timeout_hello = GNUNET_TIME_relative_add(ctx->timeout_hello, 1427 ctx->timeout_hello = GNUNET_TIME_relative_add(ctx->timeout_hello,
1351 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 1428 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,
1352 500)); 1429 500));
@@ -1418,6 +1495,25 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
1418 return; 1495 return;
1419 } 1496 }
1420 1497
1498#if CONNECT_CORE2
1499 ctx->d2core = GNUNET_CORE_connect (d2->sched,
1500 d2->cfg,
1501 timeout,
1502 ctx,
1503 NULL,
1504 NULL, NULL, NULL,
1505 NULL, GNUNET_NO,
1506 NULL, GNUNET_NO, no_handlers);
1507 if (ctx->d2core == NULL)
1508 {
1509 GNUNET_free (ctx);
1510 if (NULL != cb)
1511 cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2,
1512 _("Failed to connect to core service of second peer!\n"));
1513 return;
1514 }
1515#endif
1516
1421#if DEBUG_TESTING > 2 1517#if DEBUG_TESTING > 2
1422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1423 "Asked to connect peer %s to peer %s\n", 1519 "Asked to connect peer %s to peer %s\n",
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c
index e2e91c8d7..61e8675b1 100644
--- a/src/testing/testing_group.c
+++ b/src/testing/testing_group.c
@@ -470,6 +470,7 @@ struct GNUNET_TESTING_PeerGroup
470struct UpdateContext 470struct UpdateContext
471{ 471{
472 struct GNUNET_CONFIGURATION_Handle *ret; 472 struct GNUNET_CONFIGURATION_Handle *ret;
473 const struct GNUNET_CONFIGURATION_Handle *orig;
473 const char *hostname; 474 const char *hostname;
474 unsigned int nport; 475 unsigned int nport;
475 unsigned int upnum; 476 unsigned int upnum;
@@ -688,24 +689,34 @@ update_config (void *cls,
688 unsigned int ival; 689 unsigned int ival;
689 char cval[12]; 690 char cval[12];
690 char uval[128]; 691 char uval[128];
692 char *single_variable;
691 693
692 if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival))) 694 if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival)))
693 { 695 {
694 if (ival != 0) 696 GNUNET_asprintf(&single_variable, "single_%s_per_host", section);
697 if ((ival != 0) && (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno(ctx->orig, "testing", single_variable)))
695 { 698 {
696 GNUNET_snprintf (cval, sizeof (cval), "%u", ctx->nport++); 699 GNUNET_snprintf (cval, sizeof (cval), "%u", ctx->nport++);
697 value = cval; 700 value = cval;
698 } 701 }
702
703 GNUNET_free(single_variable);
699 } 704 }
700 705
701 if (0 == strcmp (option, "UNIXPATH")) 706 if (0 == strcmp (option, "UNIXPATH"))
702 { 707 {
703 GNUNET_snprintf (uval, 708 GNUNET_asprintf(&single_variable, "single_%s_per_host", section);
704 sizeof (uval), 709 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno(ctx->orig, "testing", single_variable))
705 "/tmp/test-service-%s-%u", 710 {
706 section, 711 GNUNET_snprintf (uval,
707 ctx->upnum++); 712 sizeof (uval),
708 value = uval; 713 "/tmp/test-service-%s-%u",
714 section,
715 ctx->upnum++);
716 value = uval;
717 }
718 GNUNET_free(single_variable);
719
709 } 720 }
710 721
711 if ((0 == strcmp (option, "HOSTNAME")) && (ctx->hostname != NULL)) 722 if ((0 == strcmp (option, "HOSTNAME")) && (ctx->hostname != NULL))
@@ -747,6 +758,7 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg,
747 uc.upnum = *upnum; 758 uc.upnum = *upnum;
748 uc.ret = GNUNET_CONFIGURATION_create (); 759 uc.ret = GNUNET_CONFIGURATION_create ();
749 uc.hostname = hostname; 760 uc.hostname = hostname;
761 uc.orig = cfg;
750 762
751 GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc); 763 GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc);
752 if (uc.nport >= HIGH_PORT) 764 if (uc.nport >= HIGH_PORT)