diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-09-17 10:45:23 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-09-17 10:45:23 +0000 |
commit | 7e065c18499688141eb68513058131a49344cac1 (patch) | |
tree | e441b44c8f0db8a4f214775e4945039cc820cf2f /src/core | |
parent | b3ad920b6e0107c3da946fe1f2f720955dbac151 (diff) | |
download | gnunet-7e065c18499688141eb68513058131a49344cac1.tar.gz gnunet-7e065c18499688141eb68513058131a49344cac1.zip |
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/gnunet-service-core.c | 86 | ||||
-rw-r--r-- | src/core/gnunet-service-core_kx.c | 23 | ||||
-rw-r--r-- | src/core/gnunet-service-core_kx.h | 3 |
3 files changed, 81 insertions, 31 deletions
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 59d938364..f5d01cd27 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c | |||
@@ -48,21 +48,39 @@ const struct GNUNET_CONFIGURATION_Handle *GSC_cfg; | |||
48 | */ | 48 | */ |
49 | struct GNUNET_STATISTICS_Handle *GSC_stats; | 49 | struct GNUNET_STATISTICS_Handle *GSC_stats; |
50 | 50 | ||
51 | /** | ||
52 | * Handle to the server of the core service. | ||
53 | */ | ||
54 | static struct GNUNET_SERVER_Handle *GSC_server; | ||
55 | |||
56 | /** | ||
57 | * Hostkey generation context | ||
58 | */ | ||
59 | struct GNUNET_CRYPTO_RsaKeyGenerationContext *GST_keygen; | ||
60 | |||
51 | 61 | ||
52 | /** | 62 | /** |
53 | * Last task run during shutdown. Disconnects us from | 63 | * Last task run during shutdown. Disconnects us from |
54 | * the transport. | 64 | * the transport. |
65 | * | ||
66 | * @param cls NULL, unused | ||
67 | * @param tc scheduler context, unused | ||
55 | */ | 68 | */ |
56 | static void | 69 | static void |
57 | cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 70 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
58 | { | 71 | { |
59 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n"); | 72 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n"); |
73 | if (NULL != GST_keygen) | ||
74 | { | ||
75 | GNUNET_CRYPTO_rsa_key_create_stop (GST_keygen); | ||
76 | GST_keygen = NULL; | ||
77 | } | ||
60 | GSC_CLIENTS_done (); | 78 | GSC_CLIENTS_done (); |
61 | GSC_NEIGHBOURS_done (); | 79 | GSC_NEIGHBOURS_done (); |
62 | GSC_SESSIONS_done (); | 80 | GSC_SESSIONS_done (); |
63 | GSC_KX_done (); | 81 | GSC_KX_done (); |
64 | GSC_TYPEMAP_done (); | 82 | GSC_TYPEMAP_done (); |
65 | if (GSC_stats != NULL) | 83 | if (NULL != GSC_stats) |
66 | { | 84 | { |
67 | GNUNET_STATISTICS_destroy (GSC_stats, GNUNET_NO); | 85 | GNUNET_STATISTICS_destroy (GSC_stats, GNUNET_NO); |
68 | GSC_stats = NULL; | 86 | GSC_stats = NULL; |
@@ -71,6 +89,42 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
71 | } | 89 | } |
72 | 90 | ||
73 | 91 | ||
92 | |||
93 | /** | ||
94 | * Callback for hostkey read/generation | ||
95 | * | ||
96 | * @param cls NULL | ||
97 | * @param pk the private key | ||
98 | * @param emsg error message | ||
99 | */ | ||
100 | static void | ||
101 | key_generation_cb (void *cls, | ||
102 | struct GNUNET_CRYPTO_RsaPrivateKey *pk, | ||
103 | const char *emsg) | ||
104 | { | ||
105 | GST_keygen = NULL; | ||
106 | if (NULL == pk) | ||
107 | { | ||
108 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
109 | _("Failed to read hostkey: %s\n"), | ||
110 | emsg); | ||
111 | GNUNET_SCHEDULER_shutdown (); | ||
112 | return; | ||
113 | } | ||
114 | if ((GNUNET_OK != GSC_KX_init (pk)) || | ||
115 | (GNUNET_OK != GSC_NEIGHBOURS_init ())) | ||
116 | { | ||
117 | GNUNET_SCHEDULER_shutdown (); | ||
118 | return; | ||
119 | } | ||
120 | GSC_SESSIONS_init (); | ||
121 | GSC_CLIENTS_init (GSC_server); | ||
122 | GNUNET_SERVER_resume (GSC_server); | ||
123 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Core service of `%4s' ready.\n"), | ||
124 | GNUNET_i2s (&GSC_my_identity)); | ||
125 | } | ||
126 | |||
127 | |||
74 | /** | 128 | /** |
75 | * Initiate core service. | 129 | * Initiate core service. |
76 | * | 130 | * |
@@ -82,24 +136,36 @@ static void | |||
82 | run (void *cls, struct GNUNET_SERVER_Handle *server, | 136 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
83 | const struct GNUNET_CONFIGURATION_Handle *c) | 137 | const struct GNUNET_CONFIGURATION_Handle *c) |
84 | { | 138 | { |
139 | char *keyfile; | ||
140 | |||
85 | GSC_cfg = c; | 141 | GSC_cfg = c; |
142 | GSC_server = server; | ||
143 | if (GNUNET_OK != | ||
144 | GNUNET_CONFIGURATION_get_value_filename (GSC_cfg, "GNUNETD", "HOSTKEY", | ||
145 | &keyfile)) | ||
146 | { | ||
147 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
148 | _ | ||
149 | ("Core service is lacking HOSTKEY configuration setting. Exiting.\n")); | ||
150 | GNUNET_SCHEDULER_shutdown (); | ||
151 | return; | ||
152 | } | ||
86 | GSC_stats = GNUNET_STATISTICS_create ("core", GSC_cfg); | 153 | GSC_stats = GNUNET_STATISTICS_create ("core", GSC_cfg); |
87 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task, | 154 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
88 | NULL); | 155 | NULL); |
156 | GNUNET_SERVER_suspend (server); | ||
89 | GSC_TYPEMAP_init (); | 157 | GSC_TYPEMAP_init (); |
90 | if ((GNUNET_OK != GSC_KX_init ()) || (GNUNET_OK != GSC_NEIGHBOURS_init ())) | 158 | GST_keygen = GNUNET_CRYPTO_rsa_key_create_start (keyfile, &key_generation_cb, NULL); |
159 | GNUNET_free (keyfile); | ||
160 | if (NULL == GST_keygen) | ||
91 | { | 161 | { |
162 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
163 | _("Transport service is unable to access hostkey. Exiting.\n")); | ||
92 | GNUNET_SCHEDULER_shutdown (); | 164 | GNUNET_SCHEDULER_shutdown (); |
93 | return; | ||
94 | } | 165 | } |
95 | GSC_SESSIONS_init (); | ||
96 | GSC_CLIENTS_init (server); | ||
97 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Core service of `%4s' ready.\n"), | ||
98 | GNUNET_i2s (&GSC_my_identity)); | ||
99 | } | 166 | } |
100 | 167 | ||
101 | 168 | ||
102 | |||
103 | /** | 169 | /** |
104 | * The main function for the transport service. | 170 | * The main function for the transport service. |
105 | * | 171 | * |
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c index f5bea09e5..755d0c34c 100644 --- a/src/core/gnunet-service-core_kx.c +++ b/src/core/gnunet-service-core_kx.c | |||
@@ -1686,30 +1686,13 @@ deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m) | |||
1686 | /** | 1686 | /** |
1687 | * Initialize KX subsystem. | 1687 | * Initialize KX subsystem. |
1688 | * | 1688 | * |
1689 | * @param pk private key to use for the peer | ||
1689 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | 1690 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure |
1690 | */ | 1691 | */ |
1691 | int | 1692 | int |
1692 | GSC_KX_init () | 1693 | GSC_KX_init (struct GNUNET_CRYPTO_RsaPrivateKey *pk) |
1693 | { | 1694 | { |
1694 | char *keyfile; | 1695 | my_private_key = pk; |
1695 | |||
1696 | if (GNUNET_OK != | ||
1697 | GNUNET_CONFIGURATION_get_value_filename (GSC_cfg, "GNUNETD", "HOSTKEY", | ||
1698 | &keyfile)) | ||
1699 | { | ||
1700 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1701 | _ | ||
1702 | ("Core service is lacking HOSTKEY configuration setting. Exiting.\n")); | ||
1703 | return GNUNET_SYSERR; | ||
1704 | } | ||
1705 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | ||
1706 | GNUNET_free (keyfile); | ||
1707 | if (NULL == my_private_key) | ||
1708 | { | ||
1709 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1710 | _("Core service could not access hostkey. Exiting.\n")); | ||
1711 | return GNUNET_SYSERR; | ||
1712 | } | ||
1713 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); | 1696 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); |
1714 | GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), | 1697 | GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), |
1715 | &GSC_my_identity.hashPubKey); | 1698 | &GSC_my_identity.hashPubKey); |
diff --git a/src/core/gnunet-service-core_kx.h b/src/core/gnunet-service-core_kx.h index 5ecd2c17f..fcb561e01 100644 --- a/src/core/gnunet-service-core_kx.h +++ b/src/core/gnunet-service-core_kx.h | |||
@@ -121,10 +121,11 @@ GSC_KX_stop (struct GSC_KeyExchangeInfo *kx); | |||
121 | /** | 121 | /** |
122 | * Initialize KX subsystem. | 122 | * Initialize KX subsystem. |
123 | * | 123 | * |
124 | * @param pk private key to use for the peer | ||
124 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | 125 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure |
125 | */ | 126 | */ |
126 | int | 127 | int |
127 | GSC_KX_init (void); | 128 | GSC_KX_init (struct GNUNET_CRYPTO_RsaPrivateKey *pk); |
128 | 129 | ||
129 | 130 | ||
130 | /** | 131 | /** |