aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-12-09 14:29:39 +0000
committerChristian Grothoff <christian@grothoff.org>2013-12-09 14:29:39 +0000
commit8efe79dfadceb61f752a08e2fc8c09f9fbe2ad4e (patch)
tree0c8b1bcd6af51d933dce452e1c1a082def2852b0 /src/transport/gnunet-service-transport.c
parenta3f96148ee0ac38d3a94a136f05285bbfe98db31 (diff)
downloadgnunet-8efe79dfadceb61f752a08e2fc8c09f9fbe2ad4e.tar.gz
gnunet-8efe79dfadceb61f752a08e2fc8c09f9fbe2ad4e.zip
-doxygen, indentation fixes
Diffstat (limited to 'src/transport/gnunet-service-transport.c')
-rw-r--r--src/transport/gnunet-service-transport.c149
1 files changed, 83 insertions, 66 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index dc86a69e6..6a3c2a17c 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -151,23 +151,24 @@ process_payload (const struct GNUNET_PeerIdentity *peer,
151 do_forward = GNUNET_SYSERR; 151 do_forward = GNUNET_SYSERR;
152 ret = GST_neighbours_calculate_receive_delay (peer, msg_size, &do_forward); 152 ret = GST_neighbours_calculate_receive_delay (peer, msg_size, &do_forward);
153 153
154 if (!GST_neighbours_test_connected (peer)) 154 if (! GST_neighbours_test_connected (peer))
155 { 155 {
156 156
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
158 "Discarded %u bytes type %u payload from peer `%s'\n", msg_size, 158 "Discarded %u bytes type %u payload from peer `%s'\n",
159 msg_size,
159 ntohs (message->type), GNUNET_i2s (peer)); 160 ntohs (message->type), GNUNET_i2s (peer));
160 161
161 GNUNET_STATISTICS_update (GST_stats, 162 GNUNET_STATISTICS_update (GST_stats,
162 gettext_noop 163 gettext_noop
163 ("# bytes payload discarded due to not connected peer "), 164 ("# bytes payload discarded due to not connected peer"),
164 msg_size, GNUNET_NO); 165 msg_size, GNUNET_NO);
165 return ret; 166 return ret;
166 } 167 }
167 168
168 GST_ats_add_address ((struct GNUNET_HELLO_Address *) address, session); 169 GST_ats_add_address ((struct GNUNET_HELLO_Address *) address, session);
169 170
170 if (do_forward != GNUNET_YES) 171 if (GNUNET_YES != do_forward)
171 return ret; 172 return ret;
172 im = (struct InboundMessage *) buf; 173 im = (struct InboundMessage *) buf;
173 im->header.size = htons (size); 174 im->header.size = htons (size);
@@ -203,11 +204,12 @@ process_payload (const struct GNUNET_PeerIdentity *peer,
203 * (plugins that do not support this, can ignore the return value) 204 * (plugins that do not support this, can ignore the return value)
204 */ 205 */
205struct GNUNET_TIME_Relative 206struct GNUNET_TIME_Relative
206GST_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, 207GST_receive_callback (void *cls,
207 const struct GNUNET_MessageHeader *message, 208 const struct GNUNET_PeerIdentity *peer,
208 struct Session *session, 209 const struct GNUNET_MessageHeader *message,
209 const char *sender_address, 210 struct Session *session,
210 uint16_t sender_address_len) 211 const char *sender_address,
212 uint16_t sender_address_len)
211{ 213{
212 const char *plugin_name = cls; 214 const char *plugin_name = cls;
213 struct GNUNET_TIME_Relative ret; 215 struct GNUNET_TIME_Relative ret;
@@ -222,11 +224,14 @@ GST_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
222 if (NULL == message) 224 if (NULL == message)
223 goto end; 225 goto end;
224 type = ntohs (message->type); 226 type = ntohs (message->type);
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received Message with type %u from peer `%s'\n", type, GNUNET_i2s (peer)); 227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
228 "Received Message with type %u from peer `%s'\n",
229 type,
230 GNUNET_i2s (peer));
226 231
227 GNUNET_STATISTICS_update (GST_stats, 232 GNUNET_STATISTICS_update (GST_stats,
228 gettext_noop 233 gettext_noop
229 ("# bytes total received"), 234 ("# bytes total received"),
230 ntohs (message->size), GNUNET_NO); 235 ntohs (message->size), GNUNET_NO);
231 GST_neighbours_notify_data_recv (peer, &address, session, message); 236 GST_neighbours_notify_data_recv (peer, &address, session, message);
232 237
@@ -298,7 +303,7 @@ end:
298 * set of valid addresses? 303 * set of valid addresses?
299 * @param addr one of the addresses of the host 304 * @param addr one of the addresses of the host
300 * the specific address format depends on the transport 305 * the specific address format depends on the transport
301 * @param addrlen length of the address 306 * @param addrlen length of the @a addr
302 * @param dest_plugin destination plugin to use this address with 307 * @param dest_plugin destination plugin to use this address with
303 */ 308 */
304static void 309static void
@@ -400,46 +405,46 @@ plugin_env_address_to_type (void *cls,
400 */ 405 */
401void 406void
402GST_ats_add_address (const struct GNUNET_HELLO_Address *address, 407GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
403 struct Session *session) 408 struct Session *session)
404{ 409{
405 struct GNUNET_TRANSPORT_PluginFunctions *papi; 410 struct GNUNET_TRANSPORT_PluginFunctions *papi;
406 struct GNUNET_ATS_Information ats; 411 struct GNUNET_ATS_Information ats;
407 uint32_t net; 412 uint32_t net;
408 413
409 /* valid new address, let ATS know! */ 414 /* valid new address, let ATS know! */
410 if (NULL == address->transport_name) 415 if (NULL == address->transport_name)
411 { 416 {
412 GNUNET_break (0); 417 GNUNET_break (0);
413 return; 418 return;
414 } 419 }
415 if (NULL == (papi = GST_plugins_find (address->transport_name))) 420 if (NULL == (papi = GST_plugins_find (address->transport_name)))
416 { 421 {
417 /* we don't have the plugin for this address */ 422 /* we don't have the plugin for this address */
418 GNUNET_break (0); 423 GNUNET_break (0);
419 return; 424 return;
420 } 425 }
421 426
422 if (GNUNET_YES == GNUNET_ATS_session_known (GST_ats, address, session)) 427 if (GNUNET_YES == GNUNET_ATS_session_known (GST_ats, address, session))
423 return; 428 return;
424 429
425 net = papi->get_network (NULL, (void *) session); 430 net = papi->get_network (NULL, (void *) session);
426 if (GNUNET_ATS_NET_UNSPECIFIED == net) 431 if (GNUNET_ATS_NET_UNSPECIFIED == net)
427 { 432 {
428 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 433 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
429 _("Could not obtain a valid network for `%s' %s\n"), 434 _("Could not obtain a valid network for `%s' %s\n"),
430 GNUNET_i2s (&address->peer), GST_plugins_a2s (address)); 435 GNUNET_i2s (&address->peer), GST_plugins_a2s (address));
431 GNUNET_break (0); 436 GNUNET_break (0);
432 } 437 }
433 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); 438 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
434 ats.value = htonl(net); 439 ats.value = htonl(net);
435 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
436 "Notifying ATS about peer `%s''s new address `%s' session %p in network %s\n", 441 "Notifying ATS about peer `%s''s new address `%s' session %p in network %s\n",
437 GNUNET_i2s (&address->peer), 442 GNUNET_i2s (&address->peer),
438 (0 == address->address_length) ? "<inbound>" : GST_plugins_a2s (address), 443 (0 == address->address_length) ? "<inbound>" : GST_plugins_a2s (address),
439 session, 444 session,
440 GNUNET_ATS_print_network_type(net)); 445 GNUNET_ATS_print_network_type(net));
441 GNUNET_ATS_address_add (GST_ats, 446 GNUNET_ATS_address_add (GST_ats,
442 address, session, &ats, 1); 447 address, session, &ats, 1);
443} 448}
444 449
445 450
@@ -450,7 +455,7 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
450 * @param address the address 455 * @param address the address
451 * @param session the session 456 * @param session the session
452 * @param ats performance information 457 * @param ats performance information
453 * @param ats_count number of elements in ats 458 * @param ats_count number of elements in @a ats
454 */ 459 */
455void 460void
456GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer, 461GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer,
@@ -459,14 +464,14 @@ GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer,
459 const struct GNUNET_ATS_Information *ats, 464 const struct GNUNET_ATS_Information *ats,
460 uint32_t ats_count) 465 uint32_t ats_count)
461{ 466{
462 struct GNUNET_ATS_Information *ats_new; 467 struct GNUNET_ATS_Information *ats_new;
463 468
464 if (GNUNET_NO == GNUNET_ATS_session_known (GST_ats, address, session)) 469 if (GNUNET_NO == GNUNET_ATS_session_known (GST_ats, address, session))
465 return; 470 return;
466 471
467 /* Call to manipulation to manipulate ATS information */ 472 /* Call to manipulation to manipulate ATS information */
468 ats_new = GST_manipulation_manipulate_metrics (peer, address, session, ats, 473 ats_new = GST_manipulation_manipulate_metrics (peer, address, session, ats,
469 ats_count); 474 ats_count);
470 if (NULL == ats_new) 475 if (NULL == ats_new)
471 { 476 {
472 GNUNET_break(0); 477 GNUNET_break(0);
@@ -475,12 +480,14 @@ GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer,
475 if (GNUNET_NO == GNUNET_ATS_address_update (GST_ats, 480 if (GNUNET_NO == GNUNET_ATS_address_update (GST_ats,
476 address, session, ats_new, ats_count)) 481 address, session, ats_new, ats_count))
477 { 482 {
478 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 483 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
479 _("Address or session unknown: failed to update properties for peer `%s' plugin `%s' address `%s' session %p\n"), 484 _("Address or session unknown: failed to update properties for peer `%s' plugin `%s' address `%s' session %p\n"),
480 GNUNET_i2s (peer), address->transport_name, GST_plugins_a2s (address), 485 GNUNET_i2s (peer),
481 session); 486 address->transport_name,
487 GST_plugins_a2s (address),
488 session);
482 } 489 }
483 GNUNET_free(ats_new); 490 GNUNET_free (ats_new);
484} 491}
485 492
486 493
@@ -491,10 +498,10 @@ GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer,
491 * @param cls closure 498 * @param cls closure
492 * @param peer the peer 499 * @param peer the peer
493 * @param address binary address 500 * @param address binary address
494 * @param address_len length of the address 501 * @param address_len length of the @a address
495 * @param session the session 502 * @param session the session
496 * @param ats the ats information to update 503 * @param ats the ats information to update
497 * @param ats_count the number of ats elements 504 * @param ats_count the number of @a ats elements
498 */ 505 */
499static void 506static void
500plugin_env_update_metrics (void *cls, 507plugin_env_update_metrics (void *cls,
@@ -505,24 +512,27 @@ plugin_env_update_metrics (void *cls,
505 const struct GNUNET_ATS_Information *ats, 512 const struct GNUNET_ATS_Information *ats,
506 uint32_t ats_count) 513 uint32_t ats_count)
507{ 514{
508 struct GNUNET_HELLO_Address haddress;
509 const char *plugin_name = cls; 515 const char *plugin_name = cls;
516 struct GNUNET_HELLO_Address haddress;
510 517
511 if ((NULL == ats) || (0 == ats_count)) 518 if ((NULL == ats) || (0 == ats_count))
512 return; 519 return;
513 GNUNET_assert (NULL != GST_ats); 520 GNUNET_assert (NULL != GST_ats);
514
515 521
516 haddress.peer = *peer; 522 haddress.peer = *peer;
517 haddress.address = address; 523 haddress.address = address;
518 haddress.address_length = address_len; 524 haddress.address_length = address_len;
519 haddress.transport_name = plugin_name; 525 haddress.transport_name = plugin_name;
520 526
521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating metrics for peer `%s' address %s session %p\n", 527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
522 GNUNET_i2s (peer), GST_plugins_a2s(&haddress), session); 528 "Updating metrics for peer `%s' address %s session %p\n",
529 GNUNET_i2s (peer),
530 GST_plugins_a2s (&haddress),
531 session);
523 GST_ats_update_metrics (peer, &haddress, session, ats, ats_count); 532 GST_ats_update_metrics (peer, &haddress, session, ats, ats_count);
524} 533}
525 534
535
526/** 536/**
527 * Plugin tells transport service about a new (inbound) session 537 * Plugin tells transport service about a new (inbound) session
528 * 538 *
@@ -530,19 +540,22 @@ plugin_env_update_metrics (void *cls,
530 * @param peer the peer 540 * @param peer the peer
531 * @param plugin plugin name 541 * @param plugin plugin name
532 * @param address address 542 * @param address address
533 * @param address_len address length 543 * @param address_len @a address length
534 * @param session the new session 544 * @param session the new session
535 * @param ats ats information 545 * @param ats ats information
536 * @param ats_count number of ats information 546 * @param ats_count number of @a ats information
537 */ 547 */
538
539static void 548static void
540plugin_env_session_start (void *cls, const struct GNUNET_PeerIdentity *peer, 549plugin_env_session_start (void *cls,
541 const char *plugin, const void *address, uint16_t address_len, 550 const struct GNUNET_PeerIdentity *peer,
542 struct Session *session, const struct GNUNET_ATS_Information *ats, 551 const char *plugin,
543 uint32_t ats_count) 552 const void *address, uint16_t address_len,
553 struct Session *session,
554 const struct GNUNET_ATS_Information *ats,
555 uint32_t ats_count)
544{ 556{
545 struct GNUNET_HELLO_Address *addr; 557 struct GNUNET_HELLO_Address *addr;
558
546 if (NULL == peer) 559 if (NULL == peer)
547 { 560 {
548 GNUNET_break(0); 561 GNUNET_break(0);
@@ -561,8 +574,11 @@ plugin_env_session_start (void *cls, const struct GNUNET_PeerIdentity *peer,
561 574
562 addr = GNUNET_HELLO_address_allocate (peer, plugin, address, address_len); 575 addr = GNUNET_HELLO_address_allocate (peer, plugin, address, address_len);
563 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 576 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
564 "Notification from plugin `%s' about new session %p from peer `%s' address `%s'\n", 577 "Notification from plugin `%s' about new session %p from peer `%s' address `%s'\n",
565 plugin, session, GNUNET_i2s (peer), GST_plugins_a2s (addr)); 578 plugin,
579 session,
580 GNUNET_i2s (peer),
581 GST_plugins_a2s (addr));
566 GST_ats_add_address (addr, session); 582 GST_ats_add_address (addr, session);
567 583
568 if (0 < ats_count) 584 if (0 < ats_count)
@@ -570,6 +586,7 @@ plugin_env_session_start (void *cls, const struct GNUNET_PeerIdentity *peer,
570 GNUNET_free(addr); 586 GNUNET_free(addr);
571} 587}
572 588
589
573/** 590/**
574 * Function called by ATS to notify the callee that the 591 * Function called by ATS to notify the callee that the
575 * assigned bandwidth or address for a given peer was changed. If the 592 * assigned bandwidth or address for a given peer was changed. If the
@@ -585,7 +602,7 @@ plugin_env_session_start (void *cls, const struct GNUNET_PeerIdentity *peer,
585 * @param bandwidth_in assigned inbound bandwidth for the connection in NBO, 602 * @param bandwidth_in assigned inbound bandwidth for the connection in NBO,
586 * 0 to disconnect from peer 603 * 0 to disconnect from peer
587 * @param ats ATS information 604 * @param ats ATS information
588 * @param ats_count number of ATS elements 605 * @param ats_count number of @a ats elements
589 */ 606 */
590static void 607static void
591ats_request_address_change (void *cls, 608ats_request_address_change (void *cls,
@@ -756,8 +773,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
756 &keyfile)) 773 &keyfile))
757 { 774 {
758 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 775 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
759 _ 776 _("Transport service is lacking key configuration settings. Exiting.\n"));
760 ("Transport service is lacking key configuration settings. Exiting.\n"));
761 GNUNET_SCHEDULER_shutdown (); 777 GNUNET_SCHEDULER_shutdown ();
762 return; 778 return;
763 } 779 }
@@ -800,7 +816,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
800 { 816 {
801 max_fd_rlimit = r_file.rlim_cur; 817 max_fd_rlimit = r_file.rlim_cur;
802 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
803 "Maximum number of open files was: %u/%u\n", r_file.rlim_cur, 819 "Maximum number of open files was: %u/%u\n",
820 r_file.rlim_cur,
804 r_file.rlim_max); 821 r_file.rlim_max);
805 } 822 }
806 max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */ 823 max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */