diff options
-rw-r--r-- | src/core/gnunet-service-core.c | 61 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 103 | ||||
-rw-r--r-- | src/nse/gnunet-service-nse.c | 145 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport.c | 102 |
4 files changed, 130 insertions, 281 deletions
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 6e0dbc122..5665fc82a 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c | |||
@@ -54,11 +54,6 @@ struct GNUNET_STATISTICS_Handle *GSC_stats; | |||
54 | */ | 54 | */ |
55 | static struct GNUNET_SERVER_Handle *GSC_server; | 55 | static struct GNUNET_SERVER_Handle *GSC_server; |
56 | 56 | ||
57 | /** | ||
58 | * Hostkey generation context | ||
59 | */ | ||
60 | static struct GNUNET_CRYPTO_EccKeyGenerationContext *keygen; | ||
61 | |||
62 | 57 | ||
63 | /** | 58 | /** |
64 | * Last task run during shutdown. Disconnects us from | 59 | * Last task run during shutdown. Disconnects us from |
@@ -71,11 +66,6 @@ static void | |||
71 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 66 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
72 | { | 67 | { |
73 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n"); | 68 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n"); |
74 | if (NULL != keygen) | ||
75 | { | ||
76 | GNUNET_CRYPTO_ecc_key_create_stop (keygen); | ||
77 | keygen = NULL; | ||
78 | } | ||
79 | GSC_CLIENTS_done (); | 69 | GSC_CLIENTS_done (); |
80 | GSC_NEIGHBOURS_done (); | 70 | GSC_NEIGHBOURS_done (); |
81 | GSC_SESSIONS_done (); | 71 | GSC_SESSIONS_done (); |
@@ -90,42 +80,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
90 | } | 80 | } |
91 | 81 | ||
92 | 82 | ||
93 | |||
94 | /** | ||
95 | * Callback for hostkey read/generation | ||
96 | * | ||
97 | * @param cls NULL | ||
98 | * @param pk the private key | ||
99 | * @param emsg error message | ||
100 | */ | ||
101 | static void | ||
102 | key_generation_cb (void *cls, | ||
103 | struct GNUNET_CRYPTO_EccPrivateKey *pk, | ||
104 | const char *emsg) | ||
105 | { | ||
106 | keygen = NULL; | ||
107 | if (NULL == pk) | ||
108 | { | ||
109 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
110 | _("Failed to read or generate private key: %s\n"), | ||
111 | emsg); | ||
112 | GNUNET_SCHEDULER_shutdown (); | ||
113 | return; | ||
114 | } | ||
115 | if ((GNUNET_OK != GSC_KX_init (pk)) || | ||
116 | (GNUNET_OK != GSC_NEIGHBOURS_init ())) | ||
117 | { | ||
118 | GNUNET_SCHEDULER_shutdown (); | ||
119 | return; | ||
120 | } | ||
121 | GSC_SESSIONS_init (); | ||
122 | GSC_CLIENTS_init (GSC_server); | ||
123 | GNUNET_SERVER_resume (GSC_server); | ||
124 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Core service of `%4s' ready.\n"), | ||
125 | GNUNET_i2s (&GSC_my_identity)); | ||
126 | } | ||
127 | |||
128 | |||
129 | /** | 83 | /** |
130 | * Initiate core service. | 84 | * Initiate core service. |
131 | * | 85 | * |
@@ -137,6 +91,7 @@ static void | |||
137 | run (void *cls, struct GNUNET_SERVER_Handle *server, | 91 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
138 | const struct GNUNET_CONFIGURATION_Handle *c) | 92 | const struct GNUNET_CONFIGURATION_Handle *c) |
139 | { | 93 | { |
94 | struct GNUNET_CRYPTO_EccPrivateKey *pk; | ||
140 | char *keyfile; | 95 | char *keyfile; |
141 | 96 | ||
142 | GSC_cfg = c; | 97 | GSC_cfg = c; |
@@ -156,14 +111,20 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
156 | NULL); | 111 | NULL); |
157 | GNUNET_SERVER_suspend (server); | 112 | GNUNET_SERVER_suspend (server); |
158 | GSC_TYPEMAP_init (); | 113 | GSC_TYPEMAP_init (); |
159 | keygen = GNUNET_CRYPTO_ecc_key_create_start (keyfile, &key_generation_cb, NULL); | 114 | pk = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile); |
160 | GNUNET_free (keyfile); | 115 | GNUNET_free (keyfile); |
161 | if (NULL == keygen) | 116 | GNUNET_assert (NULL != pk); |
117 | if ((GNUNET_OK != GSC_KX_init (pk)) || | ||
118 | (GNUNET_OK != GSC_NEIGHBOURS_init ())) | ||
162 | { | 119 | { |
163 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
164 | _("Transport service is unable to access hostkey. Exiting.\n")); | ||
165 | GNUNET_SCHEDULER_shutdown (); | 120 | GNUNET_SCHEDULER_shutdown (); |
121 | return; | ||
166 | } | 122 | } |
123 | GSC_SESSIONS_init (); | ||
124 | GSC_CLIENTS_init (GSC_server); | ||
125 | GNUNET_SERVER_resume (GSC_server); | ||
126 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Core service of `%4s' ready.\n"), | ||
127 | GNUNET_i2s (&GSC_my_identity)); | ||
167 | } | 128 | } |
168 | 129 | ||
169 | 130 | ||
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index d05379b11..8067e6bad 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -586,11 +586,6 @@ static unsigned long long drop_percent; | |||
586 | /*************************** Static global variables **************************/ | 586 | /*************************** Static global variables **************************/ |
587 | 587 | ||
588 | /** | 588 | /** |
589 | * Hostkey generation context | ||
590 | */ | ||
591 | static struct GNUNET_CRYPTO_EccKeyGenerationContext *keygen; | ||
592 | |||
593 | /** | ||
594 | * DLL with all the clients, head. | 589 | * DLL with all the clients, head. |
595 | */ | 590 | */ |
596 | static struct MeshClient *clients_head; | 591 | static struct MeshClient *clients_head; |
@@ -5177,11 +5172,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
5177 | GNUNET_CORE_disconnect (core_handle); | 5172 | GNUNET_CORE_disconnect (core_handle); |
5178 | core_handle = NULL; | 5173 | core_handle = NULL; |
5179 | } | 5174 | } |
5180 | if (NULL != keygen) | ||
5181 | { | ||
5182 | GNUNET_CRYPTO_ecc_key_create_stop (keygen); | ||
5183 | keygen = NULL; | ||
5184 | } | ||
5185 | GNUNET_CONTAINER_multihashmap_iterate (tunnels, &shutdown_tunnel, NULL); | 5175 | GNUNET_CONTAINER_multihashmap_iterate (tunnels, &shutdown_tunnel, NULL); |
5186 | GNUNET_CONTAINER_multihashmap_iterate (peers, &shutdown_peer, NULL); | 5176 | GNUNET_CONTAINER_multihashmap_iterate (peers, &shutdown_peer, NULL); |
5187 | if (dht_handle != NULL) | 5177 | if (dht_handle != NULL) |
@@ -5204,64 +5194,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
5204 | 5194 | ||
5205 | 5195 | ||
5206 | /** | 5196 | /** |
5207 | * Callback for hostkey read/generation. | ||
5208 | * | ||
5209 | * @param cls Closure (Configuration handle). | ||
5210 | * @param pk The ECC private key. | ||
5211 | * @param emsg Error message, if any. | ||
5212 | */ | ||
5213 | static void | ||
5214 | key_generation_cb (void *cls, | ||
5215 | struct GNUNET_CRYPTO_EccPrivateKey *pk, | ||
5216 | const char *emsg) | ||
5217 | { | ||
5218 | const struct GNUNET_CONFIGURATION_Handle *c = cls; | ||
5219 | |||
5220 | keygen = NULL; | ||
5221 | if (NULL == pk) | ||
5222 | { | ||
5223 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
5224 | _("Could not access hostkey: %s. Exiting.\n"), | ||
5225 | emsg); | ||
5226 | GNUNET_SCHEDULER_shutdown (); | ||
5227 | return; | ||
5228 | } | ||
5229 | my_private_key = pk; | ||
5230 | GNUNET_CRYPTO_ecc_key_get_public (my_private_key, &my_public_key); | ||
5231 | GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), | ||
5232 | &my_full_id.hashPubKey); | ||
5233 | myid = GNUNET_PEER_intern (&my_full_id); | ||
5234 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
5235 | "Mesh for peer [%s] starting\n", | ||
5236 | GNUNET_i2s(&my_full_id)); | ||
5237 | |||
5238 | core_handle = GNUNET_CORE_connect (c, /* Main configuration */ | ||
5239 | NULL, /* Closure passed to MESH functions */ | ||
5240 | &core_init, /* Call core_init once connected */ | ||
5241 | &core_connect, /* Handle connects */ | ||
5242 | &core_disconnect, /* remove peers on disconnects */ | ||
5243 | NULL, /* Don't notify about all incoming messages */ | ||
5244 | GNUNET_NO, /* For header only in notification */ | ||
5245 | NULL, /* Don't notify about all outbound messages */ | ||
5246 | GNUNET_NO, /* For header-only out notification */ | ||
5247 | core_handlers); /* Register these handlers */ | ||
5248 | if (core_handle == NULL) | ||
5249 | { | ||
5250 | GNUNET_break (0); | ||
5251 | GNUNET_SCHEDULER_shutdown (); | ||
5252 | return; | ||
5253 | } | ||
5254 | |||
5255 | next_tid = 0; | ||
5256 | next_local_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; | ||
5257 | |||
5258 | announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls); | ||
5259 | |||
5260 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh service running\n"); | ||
5261 | } | ||
5262 | |||
5263 | |||
5264 | /** | ||
5265 | * Process mesh requests. | 5197 | * Process mesh requests. |
5266 | * | 5198 | * |
5267 | * @param cls closure | 5199 | * @param cls closure |
@@ -5273,6 +5205,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
5273 | const struct GNUNET_CONFIGURATION_Handle *c) | 5205 | const struct GNUNET_CONFIGURATION_Handle *c) |
5274 | { | 5206 | { |
5275 | char *keyfile; | 5207 | char *keyfile; |
5208 | struct GNUNET_CRYPTO_EccPrivateKey *pk; | ||
5276 | 5209 | ||
5277 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n"); | 5210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n"); |
5278 | server_handle = server; | 5211 | server_handle = server; |
@@ -5411,10 +5344,38 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
5411 | /* Scheduled the task to clean up when shutdown is called */ | 5344 | /* Scheduled the task to clean up when shutdown is called */ |
5412 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, | 5345 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
5413 | NULL); | 5346 | NULL); |
5414 | keygen = GNUNET_CRYPTO_ecc_key_create_start (keyfile, | 5347 | pk = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile); |
5415 | &key_generation_cb, | ||
5416 | (void *) c); | ||
5417 | GNUNET_free (keyfile); | 5348 | GNUNET_free (keyfile); |
5349 | GNUNET_assert (NULL != pk); | ||
5350 | my_private_key = pk; | ||
5351 | GNUNET_CRYPTO_ecc_key_get_public (my_private_key, &my_public_key); | ||
5352 | GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), | ||
5353 | &my_full_id.hashPubKey); | ||
5354 | myid = GNUNET_PEER_intern (&my_full_id); | ||
5355 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
5356 | "Mesh for peer [%s] starting\n", | ||
5357 | GNUNET_i2s(&my_full_id)); | ||
5358 | |||
5359 | core_handle = GNUNET_CORE_connect (c, /* Main configuration */ | ||
5360 | NULL, /* Closure passed to MESH functions */ | ||
5361 | &core_init, /* Call core_init once connected */ | ||
5362 | &core_connect, /* Handle connects */ | ||
5363 | &core_disconnect, /* remove peers on disconnects */ | ||
5364 | NULL, /* Don't notify about all incoming messages */ | ||
5365 | GNUNET_NO, /* For header only in notification */ | ||
5366 | NULL, /* Don't notify about all outbound messages */ | ||
5367 | GNUNET_NO, /* For header-only out notification */ | ||
5368 | core_handlers); /* Register these handlers */ | ||
5369 | if (NULL == core_handle) | ||
5370 | { | ||
5371 | GNUNET_break (0); | ||
5372 | GNUNET_SCHEDULER_shutdown (); | ||
5373 | return; | ||
5374 | } | ||
5375 | next_tid = 0; | ||
5376 | next_local_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; | ||
5377 | announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls); | ||
5378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh service running\n"); | ||
5418 | } | 5379 | } |
5419 | 5380 | ||
5420 | 5381 | ||
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index a693dcf0f..b93f7bb14 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c | |||
@@ -306,11 +306,6 @@ static uint64_t my_proof; | |||
306 | */ | 306 | */ |
307 | static struct GNUNET_SERVER_Handle *srv; | 307 | static struct GNUNET_SERVER_Handle *srv; |
308 | 308 | ||
309 | /** | ||
310 | * Hostkey generation context | ||
311 | */ | ||
312 | static struct GNUNET_CRYPTO_EccKeyGenerationContext *keygen; | ||
313 | |||
314 | 309 | ||
315 | /** | 310 | /** |
316 | * Initialize a message to clients with the current network | 311 | * Initialize a message to clients with the current network |
@@ -1303,11 +1298,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1303 | proof_task = GNUNET_SCHEDULER_NO_TASK; | 1298 | proof_task = GNUNET_SCHEDULER_NO_TASK; |
1304 | write_proof (); /* remember progress */ | 1299 | write_proof (); /* remember progress */ |
1305 | } | 1300 | } |
1306 | if (NULL != keygen) | ||
1307 | { | ||
1308 | GNUNET_CRYPTO_ecc_key_create_stop (keygen); | ||
1309 | keygen = NULL; | ||
1310 | } | ||
1311 | if (NULL != nc) | 1301 | if (NULL != nc) |
1312 | { | 1302 | { |
1313 | GNUNET_SERVER_notification_context_destroy (nc); | 1303 | GNUNET_SERVER_notification_context_destroy (nc); |
@@ -1389,16 +1379,16 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server, | |||
1389 | 1379 | ||
1390 | 1380 | ||
1391 | /** | 1381 | /** |
1392 | * Callback for hostkey read/generation | 1382 | * Handle network size estimate clients. |
1393 | * | 1383 | * |
1394 | * @param cls NULL | 1384 | * @param cls closure |
1395 | * @param pk the private key | 1385 | * @param server the initialized server |
1396 | * @param emsg error message | 1386 | * @param c configuration to use |
1397 | */ | 1387 | */ |
1398 | static void | 1388 | static void |
1399 | key_generation_cb (void *cls, | 1389 | run (void *cls, |
1400 | struct GNUNET_CRYPTO_EccPrivateKey *pk, | 1390 | struct GNUNET_SERVER_Handle *server, |
1401 | const char *emsg) | 1391 | const struct GNUNET_CONFIGURATION_Handle *c) |
1402 | { | 1392 | { |
1403 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 1393 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
1404 | {&handle_start_message, NULL, GNUNET_MESSAGE_TYPE_NSE_START, | 1394 | {&handle_start_message, NULL, GNUNET_MESSAGE_TYPE_NSE_START, |
@@ -1411,77 +1401,8 @@ key_generation_cb (void *cls, | |||
1411 | {NULL, 0, 0} | 1401 | {NULL, 0, 0} |
1412 | }; | 1402 | }; |
1413 | char *proof; | 1403 | char *proof; |
1414 | |||
1415 | keygen = NULL; | ||
1416 | if (NULL == pk) | ||
1417 | { | ||
1418 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1419 | _("Could not access hostkey: %s. Exiting.\n"), | ||
1420 | emsg); | ||
1421 | GNUNET_SCHEDULER_shutdown (); | ||
1422 | return; | ||
1423 | } | ||
1424 | my_private_key = pk; | ||
1425 | GNUNET_CRYPTO_ecc_key_get_public (my_private_key, &my_public_key); | ||
1426 | GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), | ||
1427 | &my_identity.hashPubKey); | ||
1428 | if (GNUNET_OK != | ||
1429 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) | ||
1430 | { | ||
1431 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1432 | _ | ||
1433 | ("NSE service is lacking key configuration settings. Exiting.\n")); | ||
1434 | GNUNET_CRYPTO_ecc_key_free (my_private_key); | ||
1435 | my_private_key = NULL; | ||
1436 | GNUNET_SCHEDULER_shutdown (); | ||
1437 | return; | ||
1438 | } | ||
1439 | if ((GNUNET_YES != GNUNET_DISK_file_test (proof)) || | ||
1440 | (sizeof (my_proof) != | ||
1441 | GNUNET_DISK_fn_read (proof, &my_proof, sizeof (my_proof)))) | ||
1442 | my_proof = 0; | ||
1443 | GNUNET_free (proof); | ||
1444 | proof_task = | ||
1445 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | ||
1446 | &find_proof, NULL); | ||
1447 | |||
1448 | peers = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); | ||
1449 | GNUNET_SERVER_add_handlers (srv, handlers); | ||
1450 | nc = GNUNET_SERVER_notification_context_create (srv, 1); | ||
1451 | /* Connect to core service and register core handlers */ | ||
1452 | coreAPI = GNUNET_CORE_connect (cfg, /* Main configuration */ | ||
1453 | NULL, /* Closure passed to functions */ | ||
1454 | &core_init, /* Call core_init once connected */ | ||
1455 | &handle_core_connect, /* Handle connects */ | ||
1456 | &handle_core_disconnect, /* Handle disconnects */ | ||
1457 | NULL, /* Don't want notified about all incoming messages */ | ||
1458 | GNUNET_NO, /* For header only inbound notification */ | ||
1459 | NULL, /* Don't want notified about all outbound messages */ | ||
1460 | GNUNET_NO, /* For header only outbound notification */ | ||
1461 | core_handlers); /* Register these handlers */ | ||
1462 | if (NULL == coreAPI) | ||
1463 | { | ||
1464 | GNUNET_SCHEDULER_shutdown (); | ||
1465 | return; | ||
1466 | } | ||
1467 | stats = GNUNET_STATISTICS_create ("nse", cfg); | ||
1468 | GNUNET_SERVER_resume (srv); | ||
1469 | } | ||
1470 | |||
1471 | |||
1472 | /** | ||
1473 | * Handle network size estimate clients. | ||
1474 | * | ||
1475 | * @param cls closure | ||
1476 | * @param server the initialized server | ||
1477 | * @param c configuration to use | ||
1478 | */ | ||
1479 | static void | ||
1480 | run (void *cls, | ||
1481 | struct GNUNET_SERVER_Handle *server, | ||
1482 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
1483 | { | ||
1484 | char *keyfile; | 1404 | char *keyfile; |
1405 | struct GNUNET_CRYPTO_EccPrivateKey *pk; | ||
1485 | 1406 | ||
1486 | cfg = c; | 1407 | cfg = c; |
1487 | srv = server; | 1408 | srv = server; |
@@ -1533,8 +1454,56 @@ run (void *cls, | |||
1533 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, | 1454 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
1534 | NULL); | 1455 | NULL); |
1535 | GNUNET_SERVER_suspend (srv); | 1456 | GNUNET_SERVER_suspend (srv); |
1536 | keygen = GNUNET_CRYPTO_ecc_key_create_start (keyfile, &key_generation_cb, NULL); | 1457 | |
1458 | |||
1459 | pk = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile); | ||
1537 | GNUNET_free (keyfile); | 1460 | GNUNET_free (keyfile); |
1461 | GNUNET_assert (NULL != pk); | ||
1462 | my_private_key = pk; | ||
1463 | GNUNET_CRYPTO_ecc_key_get_public (my_private_key, &my_public_key); | ||
1464 | GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), | ||
1465 | &my_identity.hashPubKey); | ||
1466 | if (GNUNET_OK != | ||
1467 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) | ||
1468 | { | ||
1469 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1470 | _ | ||
1471 | ("NSE service is lacking key configuration settings. Exiting.\n")); | ||
1472 | GNUNET_CRYPTO_ecc_key_free (my_private_key); | ||
1473 | my_private_key = NULL; | ||
1474 | GNUNET_SCHEDULER_shutdown (); | ||
1475 | return; | ||
1476 | } | ||
1477 | if ((GNUNET_YES != GNUNET_DISK_file_test (proof)) || | ||
1478 | (sizeof (my_proof) != | ||
1479 | GNUNET_DISK_fn_read (proof, &my_proof, sizeof (my_proof)))) | ||
1480 | my_proof = 0; | ||
1481 | GNUNET_free (proof); | ||
1482 | proof_task = | ||
1483 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | ||
1484 | &find_proof, NULL); | ||
1485 | |||
1486 | peers = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); | ||
1487 | GNUNET_SERVER_add_handlers (srv, handlers); | ||
1488 | nc = GNUNET_SERVER_notification_context_create (srv, 1); | ||
1489 | /* Connect to core service and register core handlers */ | ||
1490 | coreAPI = GNUNET_CORE_connect (cfg, /* Main configuration */ | ||
1491 | NULL, /* Closure passed to functions */ | ||
1492 | &core_init, /* Call core_init once connected */ | ||
1493 | &handle_core_connect, /* Handle connects */ | ||
1494 | &handle_core_disconnect, /* Handle disconnects */ | ||
1495 | NULL, /* Don't want notified about all incoming messages */ | ||
1496 | GNUNET_NO, /* For header only inbound notification */ | ||
1497 | NULL, /* Don't want notified about all outbound messages */ | ||
1498 | GNUNET_NO, /* For header only outbound notification */ | ||
1499 | core_handlers); /* Register these handlers */ | ||
1500 | if (NULL == coreAPI) | ||
1501 | { | ||
1502 | GNUNET_SCHEDULER_shutdown (); | ||
1503 | return; | ||
1504 | } | ||
1505 | stats = GNUNET_STATISTICS_create ("nse", cfg); | ||
1506 | GNUNET_SERVER_resume (srv); | ||
1538 | } | 1507 | } |
1539 | 1508 | ||
1540 | 1509 | ||
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 9971e4dca..924c7d9b3 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -63,11 +63,6 @@ struct GNUNET_PeerIdentity GST_my_identity; | |||
63 | struct GNUNET_PEERINFO_Handle *GST_peerinfo; | 63 | struct GNUNET_PEERINFO_Handle *GST_peerinfo; |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * Hostkey generation context | ||
67 | */ | ||
68 | struct GNUNET_CRYPTO_EccKeyGenerationContext *GST_keygen; | ||
69 | |||
70 | /** | ||
71 | * Handle to our service's server. | 66 | * Handle to our service's server. |
72 | */ | 67 | */ |
73 | static struct GNUNET_SERVER_Handle *GST_server; | 68 | static struct GNUNET_SERVER_Handle *GST_server; |
@@ -584,11 +579,6 @@ neighbours_address_notification (void *cls, | |||
584 | static void | 579 | static void |
585 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 580 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
586 | { | 581 | { |
587 | if (NULL != GST_keygen) | ||
588 | { | ||
589 | GNUNET_CRYPTO_ecc_key_create_stop (GST_keygen); | ||
590 | GST_keygen = NULL; | ||
591 | } | ||
592 | GST_neighbours_stop (); | 582 | GST_neighbours_stop (); |
593 | GST_validation_stop (); | 583 | GST_validation_stop (); |
594 | GST_plugins_unload (); | 584 | GST_plugins_unload (); |
@@ -620,31 +610,45 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
620 | 610 | ||
621 | 611 | ||
622 | /** | 612 | /** |
623 | * Callback for hostkey read/generation | 613 | * Initiate transport service. |
624 | * | 614 | * |
625 | * @param cls NULL | 615 | * @param cls closure |
626 | * @param pk the private key | 616 | * @param server the initialized server |
627 | * @param emsg error message | 617 | * @param c configuration to use |
628 | */ | 618 | */ |
629 | static void | 619 | static void |
630 | key_generation_cb (void *cls, | 620 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
631 | struct GNUNET_CRYPTO_EccPrivateKey *pk, | 621 | const struct GNUNET_CONFIGURATION_Handle *c) |
632 | const char *emsg) | ||
633 | { | 622 | { |
623 | char *keyfile; | ||
624 | struct GNUNET_CRYPTO_EccPrivateKey *pk; | ||
634 | long long unsigned int max_fd_cfg; | 625 | long long unsigned int max_fd_cfg; |
635 | int max_fd_rlimit; | 626 | int max_fd_rlimit; |
636 | int max_fd; | 627 | int max_fd; |
637 | int friend_only; | 628 | int friend_only; |
638 | 629 | ||
639 | GST_keygen = NULL; | 630 | /* setup globals */ |
640 | if (NULL == pk) | 631 | GST_cfg = c; |
632 | if (GNUNET_OK != | ||
633 | GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY", | ||
634 | &keyfile)) | ||
641 | { | 635 | { |
642 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 636 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
643 | _("Could not access hostkey: %s. Exiting.\n"), | 637 | _ |
644 | emsg); | 638 | ("Transport service is lacking key configuration settings. Exiting.\n")); |
645 | GNUNET_SCHEDULER_shutdown (); | 639 | GNUNET_SCHEDULER_shutdown (); |
646 | return; | 640 | return; |
647 | } | 641 | } |
642 | if (GNUNET_OK != | ||
643 | GNUNET_CONFIGURATION_get_value_time (c, "transport", "HELLO_EXPIRATION", | ||
644 | &hello_expiration)) | ||
645 | { | ||
646 | hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; | ||
647 | } | ||
648 | GST_server = server; | ||
649 | pk = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile); | ||
650 | GNUNET_free (keyfile); | ||
651 | GNUNET_assert (NULL != pk); | ||
648 | GST_my_private_key = pk; | 652 | GST_my_private_key = pk; |
649 | 653 | ||
650 | GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); | 654 | GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); |
@@ -671,10 +675,10 @@ key_generation_cb (void *cls, | |||
671 | struct rlimit r_file; | 675 | struct rlimit r_file; |
672 | if (0 == getrlimit (RLIMIT_NOFILE, &r_file)) | 676 | if (0 == getrlimit (RLIMIT_NOFILE, &r_file)) |
673 | { | 677 | { |
674 | max_fd_rlimit = r_file.rlim_cur; | 678 | max_fd_rlimit = r_file.rlim_cur; |
675 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 679 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
676 | "Maximum number of open files was: %u/%u\n", r_file.rlim_cur, | 680 | "Maximum number of open files was: %u/%u\n", r_file.rlim_cur, |
677 | r_file.rlim_max); | 681 | r_file.rlim_max); |
678 | } | 682 | } |
679 | max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */ | 683 | max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */ |
680 | #endif | 684 | #endif |
@@ -713,52 +717,6 @@ key_generation_cb (void *cls, | |||
713 | (max_fd / 3) * 2); | 717 | (max_fd / 3) * 2); |
714 | GST_clients_start (GST_server); | 718 | GST_clients_start (GST_server); |
715 | GST_validation_start ((max_fd / 3)); | 719 | GST_validation_start ((max_fd / 3)); |
716 | if (NULL != GST_server) | ||
717 | GNUNET_SERVER_resume (GST_server); | ||
718 | } | ||
719 | |||
720 | |||
721 | /** | ||
722 | * Initiate transport service. | ||
723 | * | ||
724 | * @param cls closure | ||
725 | * @param server the initialized server | ||
726 | * @param c configuration to use | ||
727 | */ | ||
728 | static void | ||
729 | run (void *cls, struct GNUNET_SERVER_Handle *server, | ||
730 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
731 | { | ||
732 | char *keyfile; | ||
733 | |||
734 | /* setup globals */ | ||
735 | GST_cfg = c; | ||
736 | if (GNUNET_OK != | ||
737 | GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY", | ||
738 | &keyfile)) | ||
739 | { | ||
740 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
741 | _ | ||
742 | ("Transport service is lacking key configuration settings. Exiting.\n")); | ||
743 | GNUNET_SCHEDULER_shutdown (); | ||
744 | return; | ||
745 | } | ||
746 | if (GNUNET_OK != | ||
747 | GNUNET_CONFIGURATION_get_value_time (c, "transport", "HELLO_EXPIRATION", | ||
748 | &hello_expiration)) | ||
749 | { | ||
750 | hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; | ||
751 | } | ||
752 | GST_server = server; | ||
753 | GNUNET_SERVER_suspend (server); | ||
754 | GST_keygen = GNUNET_CRYPTO_ecc_key_create_start (keyfile, &key_generation_cb, NULL); | ||
755 | GNUNET_free (keyfile); | ||
756 | if (NULL == GST_keygen) | ||
757 | { | ||
758 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
759 | _("Transport service is unable to access hostkey. Exiting.\n")); | ||
760 | GNUNET_SCHEDULER_shutdown (); | ||
761 | } | ||
762 | } | 720 | } |
763 | 721 | ||
764 | 722 | ||