diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-07-17 10:42:37 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-07-17 10:42:37 +0000 |
commit | bc2398b056ea557c86173c2bb2823fbdf788c067 (patch) | |
tree | c9a29a4a8a98d60f91c50796c4c7735c20405955 /src/transport/test_plugin_transport.c | |
parent | 7bf136782e1fb5bf89780c86596692de625e26a3 (diff) | |
download | gnunet-bc2398b056ea557c86173c2bb2823fbdf788c067.tar.gz gnunet-bc2398b056ea557c86173c2bb2823fbdf788c067.zip |
importing Sailor's code
Diffstat (limited to 'src/transport/test_plugin_transport.c')
-rw-r--r-- | src/transport/test_plugin_transport.c | 273 |
1 files changed, 273 insertions, 0 deletions
diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c new file mode 100644 index 000000000..180e7c073 --- /dev/null +++ b/src/transport/test_plugin_transport.c | |||
@@ -0,0 +1,273 @@ | |||
1 | |||
2 | This file is part of GNUnet. | ||
3 | (C) 2009 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file transport/test_transport_api.c | ||
22 | * @brief testcase for transport_api.c | ||
23 | * @author Sailor Siraj | ||
24 | */ | ||
25 | |||
26 | #include "platform.h" | ||
27 | #include "gnunet_constants.h" | ||
28 | #include "gnunet_getopt_lib.h" | ||
29 | #include "gnunet_hello_lib.h" | ||
30 | #include "gnunet_os_lib.h" | ||
31 | #include "gnunet_peerinfo_service.h" | ||
32 | #include "gnunet_plugin_lib.h" | ||
33 | #include "gnunet_protocols.h" | ||
34 | #include "gnunet_service_lib.h" | ||
35 | #include "gnunet_signatures.h" | ||
36 | #include "plugin_transport.h" | ||
37 | #include "transport.h" | ||
38 | |||
39 | /** | ||
40 | * Our public key. | ||
41 | */ | ||
42 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *my_public_key; | ||
43 | |||
44 | /** | ||
45 | * Our identity. | ||
46 | */ | ||
47 | static struct GNUNET_PeerIdentity my_identity; | ||
48 | |||
49 | /** | ||
50 | * Our private key. | ||
51 | */ | ||
52 | static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key; | ||
53 | |||
54 | /** | ||
55 | * Our scheduler. | ||
56 | */ | ||
57 | struct GNUNET_SCHEDULER_Handle *sched; | ||
58 | |||
59 | /** | ||
60 | * Our configuration. | ||
61 | */ | ||
62 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
63 | |||
64 | |||
65 | |||
66 | /** | ||
67 | * All loaded plugins. | ||
68 | */ | ||
69 | static struct TransportPlugin *plugins; | ||
70 | |||
71 | /** | ||
72 | * Our server. | ||
73 | */ | ||
74 | static struct GNUNET_SERVER_Handle *server; | ||
75 | |||
76 | |||
77 | |||
78 | /** | ||
79 | * Number of neighbours we'd like to have. | ||
80 | */ | ||
81 | static uint32_t max_connect_per_transport; | ||
82 | |||
83 | /** | ||
84 | * Environment for this plugin. | ||
85 | */ | ||
86 | struct GNUNET_TRANSPORT_PluginEnvironment env; | ||
87 | |||
88 | /** | ||
89 | *handle for the api provided by this plugin | ||
90 | */ | ||
91 | struct GNUNET_TRANSPORT_PluginFunctions *api; | ||
92 | |||
93 | /** | ||
94 | * Initialize Environment for this plugin | ||
95 | * | ||
96 | * | ||
97 | */ | ||
98 | |||
99 | struct ReadyList * receive(void *cls,void *plugin_context, | ||
100 | struct ReadyList * | ||
101 | service_context, | ||
102 | struct GNUNET_TIME_Relative | ||
103 | latency, | ||
104 | const struct GNUNET_PeerIdentity | ||
105 | * peer, | ||
106 | const struct GNUNET_MessageHeader | ||
107 | * message){ | ||
108 | |||
109 | return NULL; | ||
110 | } | ||
111 | |||
112 | void notify_address(void *cls, | ||
113 | const char *name, | ||
114 | const void *addr, | ||
115 | size_t addrlen, | ||
116 | struct | ||
117 | GNUNET_TIME_Relative | ||
118 | expires) | ||
119 | { | ||
120 | |||
121 | |||
122 | |||
123 | } | ||
124 | |||
125 | void lookup (void *cls, | ||
126 | struct GNUNET_TIME_Relative | ||
127 | timeout, | ||
128 | const struct | ||
129 | GNUNET_PeerIdentity * target, | ||
130 | GNUNET_TRANSPORT_AddressCallback | ||
131 | iter, void *iter_cls){ | ||
132 | |||
133 | |||
134 | } | ||
135 | |||
136 | |||
137 | static void setup_plugin_environment() | ||
138 | { | ||
139 | |||
140 | |||
141 | env.cfg = cfg; | ||
142 | env.sched = sched; | ||
143 | env.my_public_key = my_public_key; | ||
144 | env.cls=&env; | ||
145 | env.receive=&receive; | ||
146 | env.lookup=&lookup; | ||
147 | env.notify_address=¬ify_address; | ||
148 | env.max_connections = max_connect_per_transport; | ||
149 | |||
150 | } | ||
151 | /** | ||
152 | * Initiate transport service. | ||
153 | * | ||
154 | * @param cls closure | ||
155 | * @param s scheduler to use | ||
156 | * @param serv the initialized server | ||
157 | * @param c configuration to use | ||
158 | */ | ||
159 | static void | ||
160 | run (void *cls, | ||
161 | struct GNUNET_SCHEDULER_Handle *s, | ||
162 | struct GNUNET_SERVER_Handle *serv, struct GNUNET_CONFIGURATION_Handle *c) | ||
163 | { | ||
164 | |||
165 | |||
166 | unsigned long long tneigh; | ||
167 | char *keyfile; | ||
168 | |||
169 | sched = s; | ||
170 | cfg = c; | ||
171 | server = serv; | ||
172 | /* parse configuration */ | ||
173 | if ((GNUNET_OK != | ||
174 | GNUNET_CONFIGURATION_get_value_number (c, | ||
175 | "TRANSPORT", | ||
176 | "NEIGHBOUR_LIMIT", | ||
177 | &tneigh)) || | ||
178 | (GNUNET_OK != | ||
179 | GNUNET_CONFIGURATION_get_value_filename (c, | ||
180 | "GNUNETD", | ||
181 | "HOSTKEY", &keyfile))) | ||
182 | { | ||
183 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
184 | _ | ||
185 | ("Transport service is lacking key configuration settings. Exiting.\n")); | ||
186 | GNUNET_SCHEDULER_shutdown (s); | ||
187 | return; | ||
188 | } | ||
189 | max_connect_per_transport = (uint32_t) tneigh; | ||
190 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | ||
191 | GNUNET_free (keyfile); | ||
192 | if (my_private_key == NULL) | ||
193 | { | ||
194 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
195 | _ | ||
196 | ("Transport service could not access hostkey. Exiting.\n")); | ||
197 | GNUNET_SCHEDULER_shutdown (s); | ||
198 | return; | ||
199 | } | ||
200 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); | ||
201 | GNUNET_CRYPTO_hash (&my_public_key, | ||
202 | sizeof (my_public_key), &my_identity.hashPubKey); | ||
203 | |||
204 | |||
205 | |||
206 | /* load plugins... */ | ||
207 | |||
208 | |||
209 | |||
210 | setup_plugin_environment(); | ||
211 | char *libname; | ||
212 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
213 | _("Loading tcp transport plugin\n")); | ||
214 | GNUNET_asprintf (&libname, "libgnunet_plugin_transport_tcp"); | ||
215 | |||
216 | api = GNUNET_PLUGIN_load(libname,&env); | ||
217 | |||
218 | if (api == NULL) | ||
219 | { | ||
220 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
221 | _("Failed to load transport plugin for tcp\n")); | ||
222 | } | ||
223 | |||
224 | |||
225 | } | ||
226 | |||
227 | |||
228 | /** | ||
229 | * Function called when the service shuts | ||
230 | * down. Unloads our plugins. | ||
231 | * | ||
232 | * @param cls closure | ||
233 | * @param cfg configuration to use | ||
234 | */ | ||
235 | static void | ||
236 | unload_plugins (void *cls, struct GNUNET_CONFIGURATION_Handle *cfg) | ||
237 | { | ||
238 | |||
239 | GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_tcp",api)); | ||
240 | if (my_private_key != NULL) | ||
241 | GNUNET_CRYPTO_rsa_key_free (my_private_key); | ||
242 | |||
243 | } | ||
244 | |||
245 | |||
246 | /** | ||
247 | * The main function for the transport service. | ||
248 | * | ||
249 | * @param argc number of arguments from the command line | ||
250 | * @param argv command line arguments | ||
251 | * @return 0 ok, 1 on error | ||
252 | */ | ||
253 | int | ||
254 | main (int argc, char *const *argv) | ||
255 | { | ||
256 | GNUNET_log_setup ("test-puglin-transport", | ||
257 | #if VERBOSE | ||
258 | "DEBUG", | ||
259 | #else | ||
260 | "WARNING", | ||
261 | #endif | ||
262 | NULL); | ||
263 | |||
264 | |||
265 | |||
266 | return (GNUNET_OK == | ||
267 | GNUNET_SERVICE_run (argc, | ||
268 | argv, | ||
269 | "transport", | ||
270 | &run, NULL, &unload_plugins, NULL)) ? 0 : 1; | ||
271 | } | ||
272 | |||
273 | /* end of test_plugin_transport.c */ | ||