aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport-new.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-transport-new.c')
-rw-r--r--src/transport/gnunet-service-transport-new.c324
1 files changed, 150 insertions, 174 deletions
diff --git a/src/transport/gnunet-service-transport-new.c b/src/transport/gnunet-service-transport-new.c
index 3cc1191fd..8ceffd86c 100644
--- a/src/transport/gnunet-service-transport-new.c
+++ b/src/transport/gnunet-service-transport-new.c
@@ -86,17 +86,16 @@ struct GNUNET_ATS_Handle *GST_ats;
86 */ 86 */
87static void 87static void
88transmit_our_hello (void *cls, 88transmit_our_hello (void *cls,
89 const struct GNUNET_PeerIdentity *target, 89 const struct GNUNET_PeerIdentity *target,
90 const struct GNUNET_TRANSPORT_ATS_Information *ats, 90 const struct GNUNET_TRANSPORT_ATS_Information *ats,
91 uint32_t ats_count) 91 uint32_t ats_count)
92{ 92{
93 const struct GNUNET_MessageHeader *hello = cls; 93 const struct GNUNET_MessageHeader *hello = cls;
94 94
95 GST_neighbours_send (target, 95 GST_neighbours_send (target,
96 (const char*) hello, 96 (const char *) hello,
97 ntohs (hello->size), 97 ntohs (hello->size),
98 GST_HELLO_ADDRESS_EXPIRATION, 98 GST_HELLO_ADDRESS_EXPIRATION, NULL, NULL);
99 NULL, NULL);
100} 99}
101 100
102 101
@@ -107,12 +106,10 @@ transmit_our_hello (void *cls,
107 * @param hello new HELLO 106 * @param hello new HELLO
108 */ 107 */
109static void 108static void
110process_hello_update (void *cls, 109process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello)
111 const struct GNUNET_MessageHeader *hello)
112{ 110{
113 GST_clients_broadcast (hello, GNUNET_NO); 111 GST_clients_broadcast (hello, GNUNET_NO);
114 GST_neighbours_iterate (&transmit_our_hello, 112 GST_neighbours_iterate (&transmit_our_hello, (void *) hello);
115 (void*) hello);
116} 113}
117 114
118 115
@@ -127,11 +124,10 @@ process_hello_update (void *cls,
127 */ 124 */
128static void 125static void
129try_connect_if_allowed (void *cls, 126try_connect_if_allowed (void *cls,
130 const struct GNUNET_PeerIdentity *peer, 127 const struct GNUNET_PeerIdentity *peer, int result)
131 int result)
132{ 128{
133 if (GNUNET_OK != result) 129 if (GNUNET_OK != result)
134 return; /* not allowed */ 130 return; /* not allowed */
135 GST_neighbours_try_connect (peer); 131 GST_neighbours_try_connect (peer);
136} 132}
137 133
@@ -159,14 +155,14 @@ try_connect_if_allowed (void *cls,
159 * @return how long the plugin should wait until receiving more data 155 * @return how long the plugin should wait until receiving more data
160 * (plugins that do not support this, can ignore the return value) 156 * (plugins that do not support this, can ignore the return value)
161 */ 157 */
162static struct GNUNET_TIME_Relative 158static struct GNUNET_TIME_Relative
163plugin_env_receive_callback (void *cls, 159plugin_env_receive_callback (void *cls,
164 const struct GNUNET_PeerIdentity *peer, 160 const struct GNUNET_PeerIdentity *peer,
165 const struct GNUNET_MessageHeader *message, 161 const struct GNUNET_MessageHeader *message,
166 const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count, 162 const struct GNUNET_TRANSPORT_ATS_Information *ats,
167 struct Session *session, 163 uint32_t ats_count, struct Session *session,
168 const char *sender_address, 164 const char *sender_address,
169 uint16_t sender_address_len) 165 uint16_t sender_address_len)
170{ 166{
171 const char *plugin_name = cls; 167 const char *plugin_name = cls;
172 int do_forward; 168 int do_forward;
@@ -176,80 +172,72 @@ plugin_env_receive_callback (void *cls,
176 172
177 ret = GNUNET_TIME_UNIT_ZERO; 173 ret = GNUNET_TIME_UNIT_ZERO;
178 if (NULL != message) 174 if (NULL != message)
175 {
176 type = ntohs (message->type);
177 switch (type)
179 { 178 {
180 type = ntohs (message->type); 179 case GNUNET_MESSAGE_TYPE_HELLO:
181 switch (type) 180 GST_validation_handle_hello (message);
182 { 181 break;
183 case GNUNET_MESSAGE_TYPE_HELLO: 182 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
184 GST_validation_handle_hello (message);
185 break;
186 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
187#if DEBUG_TRANSPORT 183#if DEBUG_TRANSPORT
188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
189 "Processing `%s' from `%s'\n", 185 "Processing `%s' from `%s'\n",
190 "PING", 186 "PING",
191 (sender_address != NULL) 187 (sender_address != NULL)
192 ? GST_plugins_a2s (plugin_name, 188 ? GST_plugins_a2s (plugin_name,
193 sender_address, 189 sender_address,
194 sender_address_len) 190 sender_address_len) : "<inbound>");
195 : "<inbound>");
196#endif 191#endif
197 GST_validation_handle_ping (peer, 192 GST_validation_handle_ping (peer,
198 message, 193 message,
199 plugin_name, 194 plugin_name,
200 session, 195 session, sender_address, sender_address_len);
201 sender_address, sender_address_len); 196 break;
202 break; 197 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
203 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
204#if DEBUG_TRANSPORT 198#if DEBUG_TRANSPORT
205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
206 "Processing `%s' from `%s'\n", 200 "Processing `%s' from `%s'\n",
207 "PONG", 201 "PONG",
208 (sender_address != NULL) 202 (sender_address != NULL)
209 ? GST_plugins_a2s (plugin_name, 203 ? GST_plugins_a2s (plugin_name,
210 sender_address, 204 sender_address,
211 sender_address_len) 205 sender_address_len) : "<inbound>");
212 : "<inbound>");
213#endif 206#endif
214 GST_validation_handle_pong (peer, 207 GST_validation_handle_pong (peer, message);
215 message); 208 break;
216 break; 209 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT:
217 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: 210 (void) GST_blacklist_test_allowed (peer,
218 (void) GST_blacklist_test_allowed (peer, 211 NULL, &try_connect_if_allowed, NULL);
219 NULL, 212 /* TODO: if 'session != NULL', maybe notify ATS that this is now the preferred
220 &try_connect_if_allowed, NULL); 213 * way to communicate with this peer (other peer switched transport) */
221 /* TODO: if 'session != NULL', maybe notify ATS that this is now the preferred 214 break;
222 way to communicate with this peer (other peer switched transport) */ 215 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
223 break; 216 /* TODO: do some validation to prevent an attacker from sending
224 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: 217 * a fake disconnect message... */
225 /* TODO: do some validation to prevent an attacker from sending 218 GST_neighbours_force_disconnect (peer);
226 a fake disconnect message... */ 219 break;
227 GST_neighbours_force_disconnect (peer); 220 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
228 break; 221 GST_neighbours_keepalive (peer);
229 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE: 222 break;
230 GST_neighbours_keepalive (peer); 223 default:
231 break; 224 /* should be payload */
232 default: 225 do_forward = GNUNET_SYSERR;
233 /* should be payload */ 226 ret = GST_neighbours_calculate_receive_delay (peer,
234 do_forward = GNUNET_SYSERR; 227 (message == NULL)
235 ret = GST_neighbours_calculate_receive_delay (peer, 228 ? 0
236 (message == NULL) 229 : ntohs (message->size),
237 ? 0 230 &do_forward);
238 : ntohs (message->size), 231 if (do_forward == GNUNET_YES)
239 &do_forward); 232 GST_clients_broadcast (message, GNUNET_YES);
240 if (do_forward == GNUNET_YES) 233 break;
241 GST_clients_broadcast (message, GNUNET_YES);
242 break;
243 }
244 } 234 }
245 GNUNET_ATS_address_update (GST_ats, 235 }
246 peer, 236 GNUNET_ATS_address_update (GST_ats, peer, GNUNET_TIME_absolute_get (), /* valid at least until right now... */
247 GNUNET_TIME_absolute_get (), /* valid at least until right now... */ 237 plugin_name,
248 plugin_name, 238 session,
249 session, 239 sender_address,
250 sender_address, 240 sender_address_len, ats, ats_count);
251 sender_address_len,
252 ats, ats_count);
253 241
254 return ret; 242 return ret;
255} 243}
@@ -266,18 +254,14 @@ plugin_env_receive_callback (void *cls,
266 * the specific address format depends on the transport 254 * the specific address format depends on the transport
267 * @param addrlen length of the address 255 * @param addrlen length of the address
268 */ 256 */
269static void 257static void
270plugin_env_address_change_notification (void *cls, 258plugin_env_address_change_notification (void *cls,
271 int add_remove, 259 int add_remove,
272 const void *addr, 260 const void *addr, size_t addrlen)
273 size_t addrlen)
274{ 261{
275 const char *plugin_name = cls; 262 const char *plugin_name = cls;
276 263
277 GST_hello_modify_addresses (add_remove, 264 GST_hello_modify_addresses (add_remove, plugin_name, addr, addrlen);
278 plugin_name,
279 addr,
280 addrlen);
281} 265}
282 266
283 267
@@ -296,11 +280,10 @@ plugin_env_address_change_notification (void *cls,
296 */ 280 */
297static void 281static void
298plugin_env_session_end (void *cls, 282plugin_env_session_end (void *cls,
299 const struct GNUNET_PeerIdentity *peer, 283 const struct GNUNET_PeerIdentity *peer,
300 struct Session *session) 284 struct Session *session)
301{ 285{
302 GST_neighbours_session_terminated (peer, 286 GST_neighbours_session_terminated (peer, session);
303 session);
304} 287}
305 288
306 289
@@ -319,23 +302,20 @@ plugin_env_session_end (void *cls,
319 * @param plugin_addr_len number of bytes in addr 302 * @param plugin_addr_len number of bytes in addr
320 * @param bandwidth assigned outbound bandwidth for the connection 303 * @param bandwidth assigned outbound bandwidth for the connection
321 */ 304 */
322static void 305static void
323ats_request_address_change (void *cls, 306ats_request_address_change (void *cls,
324 const struct GNUNET_PeerIdentity *peer, 307 const struct GNUNET_PeerIdentity *peer,
325 const char *plugin_name, 308 const char *plugin_name,
326 struct Session *session, 309 struct Session *session,
327 const void *plugin_addr, 310 const void *plugin_addr,
328 size_t plugin_addr_len, 311 size_t plugin_addr_len,
329 struct GNUNET_BANDWIDTH_Value32NBO bandwidth) 312 struct GNUNET_BANDWIDTH_Value32NBO bandwidth)
330{ 313{
331 GST_neighbours_switch_to_address (peer, 314 GST_neighbours_switch_to_address (peer,
332 plugin_name, 315 plugin_name,
333 plugin_addr, 316 plugin_addr,
334 plugin_addr_len, 317 plugin_addr_len, session, NULL, 0);
335 session, 318 GST_neighbours_set_incoming_quota (peer, bandwidth);
336 NULL, 0);
337 GST_neighbours_set_incoming_quota (peer,
338 bandwidth);
339} 319}
340 320
341 321
@@ -350,23 +330,24 @@ ats_request_address_change (void *cls,
350 */ 330 */
351static void 331static void
352neighbours_connect_notification (void *cls, 332neighbours_connect_notification (void *cls,
353 const struct GNUNET_PeerIdentity * peer, 333 const struct GNUNET_PeerIdentity *peer,
354 const struct GNUNET_TRANSPORT_ATS_Information *ats, 334 const struct GNUNET_TRANSPORT_ATS_Information
355 uint32_t ats_count) 335 *ats, uint32_t ats_count)
356{ 336{
357 char buf[sizeof(struct ConnectInfoMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)]; 337 char buf[sizeof (struct ConnectInfoMessage) +
358 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage*) buf; 338 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)];
339 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf;
359 struct GNUNET_TRANSPORT_ATS_Information *atsm = &connect_msg->ats; 340 struct GNUNET_TRANSPORT_ATS_Information *atsm = &connect_msg->ats;
360 341
361 connect_msg->header.size = htons (sizeof (buf)); 342 connect_msg->header.size = htons (sizeof (buf));
362 connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 343 connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
363 connect_msg->ats_count = htonl (ats_count); 344 connect_msg->ats_count = htonl (ats_count);
364 connect_msg->id = *peer; 345 connect_msg->id = *peer;
365 memcpy (&connect_msg->ats, ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); 346 memcpy (&connect_msg->ats, ats,
347 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
366 atsm[ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 348 atsm[ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
367 atsm[ats_count].value = htonl (0); 349 atsm[ats_count].value = htonl (0);
368 GST_clients_broadcast (&connect_msg->header, 350 GST_clients_broadcast (&connect_msg->header, GNUNET_NO);
369 GNUNET_NO);
370} 351}
371 352
372 353
@@ -379,7 +360,7 @@ neighbours_connect_notification (void *cls,
379 */ 360 */
380static void 361static void
381neighbours_disconnect_notification (void *cls, 362neighbours_disconnect_notification (void *cls,
382 const struct GNUNET_PeerIdentity *peer) 363 const struct GNUNET_PeerIdentity *peer)
383{ 364{
384 struct DisconnectInfoMessage disconnect_msg; 365 struct DisconnectInfoMessage disconnect_msg;
385 366
@@ -387,8 +368,7 @@ neighbours_disconnect_notification (void *cls,
387 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); 368 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
388 disconnect_msg.reserved = htonl (0); 369 disconnect_msg.reserved = htonl (0);
389 disconnect_msg.peer = *peer; 370 disconnect_msg.peer = *peer;
390 GST_clients_broadcast (&disconnect_msg.header, 371 GST_clients_broadcast (&disconnect_msg.header, GNUNET_NO);
391 GNUNET_NO);
392} 372}
393 373
394 374
@@ -400,32 +380,32 @@ neighbours_disconnect_notification (void *cls,
400 * @param tc task context (unused) 380 * @param tc task context (unused)
401 */ 381 */
402static void 382static void
403shutdown_task (void *cls, 383shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
404 const struct GNUNET_SCHEDULER_TaskContext *tc) 384{
405{
406 GST_validation_stop (); 385 GST_validation_stop ();
407 GST_neighbours_stop (); 386 GST_neighbours_stop ();
408 GNUNET_ATS_shutdown (GST_ats); GST_ats = NULL; 387 GNUNET_ATS_shutdown (GST_ats);
388 GST_ats = NULL;
409 GST_clients_stop (); 389 GST_clients_stop ();
410 GST_blacklist_stop (); 390 GST_blacklist_stop ();
411 GST_plugins_unload (); 391 GST_plugins_unload ();
412 GST_hello_stop (); 392 GST_hello_stop ();
413 393
414 if (GST_peerinfo != NULL) 394 if (GST_peerinfo != NULL)
415 { 395 {
416 GNUNET_PEERINFO_disconnect (GST_peerinfo); 396 GNUNET_PEERINFO_disconnect (GST_peerinfo);
417 GST_peerinfo = NULL; 397 GST_peerinfo = NULL;
418 } 398 }
419 if (GST_stats != NULL) 399 if (GST_stats != NULL)
420 { 400 {
421 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO); 401 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
422 GST_stats = NULL; 402 GST_stats = NULL;
423 } 403 }
424 if (GST_my_private_key != NULL) 404 if (GST_my_private_key != NULL)
425 { 405 {
426 GNUNET_CRYPTO_rsa_key_free (GST_my_private_key); 406 GNUNET_CRYPTO_rsa_key_free (GST_my_private_key);
427 GST_my_private_key = NULL; 407 GST_my_private_key = NULL;
428 } 408 }
429} 409}
430 410
431 411
@@ -447,24 +427,23 @@ run (void *cls,
447 GST_cfg = c; 427 GST_cfg = c;
448 if (GNUNET_OK != 428 if (GNUNET_OK !=
449 GNUNET_CONFIGURATION_get_value_filename (c, 429 GNUNET_CONFIGURATION_get_value_filename (c,
450 "GNUNETD", 430 "GNUNETD", "HOSTKEY", &keyfile))
451 "HOSTKEY", &keyfile)) 431 {
452 { 432 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
453 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 433 _
454 _ 434 ("Transport service is lacking key configuration settings. Exiting.\n"));
455 ("Transport service is lacking key configuration settings. Exiting.\n")); 435 GNUNET_SCHEDULER_shutdown ();
456 GNUNET_SCHEDULER_shutdown (); 436 return;
457 return; 437 }
458 }
459 GST_my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); 438 GST_my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
460 GNUNET_free (keyfile); 439 GNUNET_free (keyfile);
461 if (GST_my_private_key == NULL) 440 if (GST_my_private_key == NULL)
462 { 441 {
463 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 442 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
464 _("Transport service could not access hostkey. Exiting.\n")); 443 _("Transport service could not access hostkey. Exiting.\n"));
465 GNUNET_SCHEDULER_shutdown (); 444 GNUNET_SCHEDULER_shutdown ();
466 return; 445 return;
467 } 446 }
468 GST_stats = GNUNET_STATISTICS_create ("transport", c); 447 GST_stats = GNUNET_STATISTICS_create ("transport", c);
469 GST_peerinfo = GNUNET_PEERINFO_connect (c); 448 GST_peerinfo = GNUNET_PEERINFO_connect (c);
470 GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key); 449 GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key);
@@ -473,25 +452,23 @@ run (void *cls,
473 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 452 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
474 &shutdown_task, NULL); 453 &shutdown_task, NULL);
475 if (GST_peerinfo == NULL) 454 if (GST_peerinfo == NULL)
476 { 455 {
477 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 456 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
478 _("Could not access PEERINFO service. Exiting.\n")); 457 _("Could not access PEERINFO service. Exiting.\n"));
479 GNUNET_SCHEDULER_shutdown (); 458 GNUNET_SCHEDULER_shutdown ();
480 return; 459 return;
481 } 460 }
482 461
483 /* start subsystems */ 462 /* start subsystems */
484 GST_hello_start (&process_hello_update, NULL); 463 GST_hello_start (&process_hello_update, NULL);
485 GST_blacklist_start (server); 464 GST_blacklist_start (server);
486 GST_plugins_load (&plugin_env_receive_callback, 465 GST_plugins_load (&plugin_env_receive_callback,
487 &plugin_env_address_change_notification, 466 &plugin_env_address_change_notification,
488 &plugin_env_session_end); 467 &plugin_env_session_end);
489 GST_ats = GNUNET_ATS_init (GST_cfg, 468 GST_ats = GNUNET_ATS_init (GST_cfg, &ats_request_address_change, NULL);
490 &ats_request_address_change,
491 NULL);
492 GST_neighbours_start (NULL, 469 GST_neighbours_start (NULL,
493 &neighbours_connect_notification, 470 &neighbours_connect_notification,
494 &neighbours_disconnect_notification); 471 &neighbours_disconnect_notification);
495 GST_clients_start (server); 472 GST_clients_start (server);
496 GST_validation_start (); 473 GST_validation_start ();
497} 474}
@@ -511,8 +488,7 @@ main (int argc, char *const *argv)
511 GNUNET_SERVICE_run (argc, 488 GNUNET_SERVICE_run (argc,
512 argv, 489 argv,
513 "transport", 490 "transport",
514 GNUNET_SERVICE_OPTION_NONE, 491 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
515 &run, NULL)) ? 0 : 1;
516} 492}
517 493
518/* end of file gnunet-service-transport-new.c */ 494/* end of file gnunet-service-transport-new.c */