aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_clients.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/transport/gnunet-service-transport_clients.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/transport/gnunet-service-transport_clients.c')
-rw-r--r--src/transport/gnunet-service-transport_clients.c117
1 files changed, 50 insertions, 67 deletions
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index 542e3e00b..3ad2149bb 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -205,8 +205,8 @@ transmit_to_client_callback (void *cls, size_t size, void *buf)
205 "Transmitting message of type %u to client.\n", 205 "Transmitting message of type %u to client.\n",
206 ntohs (msg->type)); 206 ntohs (msg->type));
207#endif 207#endif
208 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, 208 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, tc->message_queue_tail,
209 tc->message_queue_tail, q); 209 q);
210 tc->message_count--; 210 tc->message_count--;
211 memcpy (&cbuf[tsize], msg, msize); 211 memcpy (&cbuf[tsize], msg, msize);
212 GNUNET_free (q); 212 GNUNET_free (q);
@@ -215,11 +215,10 @@ transmit_to_client_callback (void *cls, size_t size, void *buf)
215 if (NULL != q) 215 if (NULL != q)
216 { 216 {
217 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); 217 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
218 tc->th = GNUNET_SERVER_notify_transmit_ready (tc->client, 218 tc->th =
219 msize, 219 GNUNET_SERVER_notify_transmit_ready (tc->client, msize,
220 GNUNET_TIME_UNIT_FOREVER_REL, 220 GNUNET_TIME_UNIT_FOREVER_REL,
221 &transmit_to_client_callback, 221 &transmit_to_client_callback, tc);
222 tc);
223 GNUNET_assert (tc->th != NULL); 222 GNUNET_assert (tc->th != NULL);
224 } 223 }
225 return tsize; 224 return tsize;
@@ -234,8 +233,8 @@ transmit_to_client_callback (void *cls, size_t size, void *buf)
234 * @param may_drop GNUNET_YES if the message can be dropped 233 * @param may_drop GNUNET_YES if the message can be dropped
235 */ 234 */
236static void 235static void
237unicast (struct TransportClient *tc, 236unicast (struct TransportClient *tc, const struct GNUNET_MessageHeader *msg,
238 const struct GNUNET_MessageHeader *msg, int may_drop) 237 int may_drop)
239{ 238{
240 struct ClientMessageQueueEntry *q; 239 struct ClientMessageQueueEntry *q;
241 uint16_t msize; 240 uint16_t msize;
@@ -262,11 +261,10 @@ unicast (struct TransportClient *tc,
262 tc->message_count++; 261 tc->message_count++;
263 if (tc->th != NULL) 262 if (tc->th != NULL)
264 return; 263 return;
265 tc->th = GNUNET_SERVER_notify_transmit_ready (tc->client, 264 tc->th =
266 msize, 265 GNUNET_SERVER_notify_transmit_ready (tc->client, msize,
267 GNUNET_TIME_UNIT_FOREVER_REL, 266 GNUNET_TIME_UNIT_FOREVER_REL,
268 &transmit_to_client_callback, 267 &transmit_to_client_callback, tc);
269 tc);
270 GNUNET_assert (tc->th != NULL); 268 GNUNET_assert (tc->th != NULL);
271} 269}
272 270
@@ -295,8 +293,8 @@ client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
295#endif 293#endif
296 while (NULL != (mqe = tc->message_queue_head)) 294 while (NULL != (mqe = tc->message_queue_head))
297 { 295 {
298 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, 296 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, tc->message_queue_tail,
299 tc->message_queue_tail, mqe); 297 mqe);
300 tc->message_count--; 298 tc->message_count--;
301 GNUNET_free (mqe); 299 GNUNET_free (mqe);
302 } 300 }
@@ -339,8 +337,8 @@ notify_client_about_neighbour (void *cls,
339 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 337 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
340 cim->ats_count = htonl (ats_count); 338 cim->ats_count = htonl (ats_count);
341 cim->id = *peer; 339 cim->id = *peer;
342 memcpy (&cim->ats, 340 memcpy (&cim->ats, ats,
343 ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); 341 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
344 unicast (tc, &cim->header, GNUNET_NO); 342 unicast (tc, &cim->header, GNUNET_NO);
345 GNUNET_free (cim); 343 GNUNET_free (cim);
346} 344}
@@ -356,8 +354,7 @@ notify_client_about_neighbour (void *cls,
356 * @param message the start message that was sent 354 * @param message the start message that was sent
357 */ 355 */
358static void 356static void
359clients_handle_start (void *cls, 357clients_handle_start (void *cls, struct GNUNET_SERVER_Client *client,
360 struct GNUNET_SERVER_Client *client,
361 const struct GNUNET_MessageHeader *message) 358 const struct GNUNET_MessageHeader *message)
362{ 359{
363 const struct StartMessage *start; 360 const struct StartMessage *start;
@@ -373,8 +370,9 @@ clients_handle_start (void *cls,
373 } 370 }
374 start = (const struct StartMessage *) message; 371 start = (const struct StartMessage *) message;
375 if ((GNUNET_NO != ntohl (start->do_check)) && 372 if ((GNUNET_NO != ntohl (start->do_check)) &&
376 (0 != memcmp (&start->self, 373 (0 !=
377 &GST_my_identity, sizeof (struct GNUNET_PeerIdentity)))) 374 memcmp (&start->self, &GST_my_identity,
375 sizeof (struct GNUNET_PeerIdentity))))
378 { 376 {
379 /* client thinks this is a different peer, reject */ 377 /* client thinks this is a different peer, reject */
380 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 378 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -399,8 +397,7 @@ clients_handle_start (void *cls,
399 * @param message the HELLO message 397 * @param message the HELLO message
400 */ 398 */
401static void 399static void
402clients_handle_hello (void *cls, 400clients_handle_hello (void *cls, struct GNUNET_SERVER_Client *client,
403 struct GNUNET_SERVER_Client *client,
404 const struct GNUNET_MessageHeader *message) 401 const struct GNUNET_MessageHeader *message)
405{ 402{
406 GST_validation_handle_hello (message); 403 GST_validation_handle_hello (message);
@@ -458,8 +455,7 @@ handle_send_transmit_continuation (void *cls, int success)
458 * @param message the send message that was sent 455 * @param message the send message that was sent
459 */ 456 */
460static void 457static void
461clients_handle_send (void *cls, 458clients_handle_send (void *cls, struct GNUNET_SERVER_Client *client,
462 struct GNUNET_SERVER_Client *client,
463 const struct GNUNET_MessageHeader *message) 459 const struct GNUNET_MessageHeader *message)
464{ 460{
465 const struct OutboundMessage *obm; 461 const struct OutboundMessage *obm;
@@ -509,8 +505,7 @@ clients_handle_send (void *cls,
509 stcc->target = obm->peer; 505 stcc->target = obm->peer;
510 stcc->client = client; 506 stcc->client = client;
511 GNUNET_SERVER_client_keep (client); 507 GNUNET_SERVER_client_keep (client);
512 GST_neighbours_send (&obm->peer, 508 GST_neighbours_send (&obm->peer, obmm, msize,
513 obmm, msize,
514 GNUNET_TIME_relative_ntoh (obm->timeout), 509 GNUNET_TIME_relative_ntoh (obm->timeout),
515 &handle_send_transmit_continuation, stcc); 510 &handle_send_transmit_continuation, stcc);
516} 511}
@@ -526,8 +521,8 @@ clients_handle_send (void *cls,
526 * GNUNET_NO if not 521 * GNUNET_NO if not
527 */ 522 */
528static void 523static void
529try_connect_if_allowed (void *cls, 524try_connect_if_allowed (void *cls, const struct GNUNET_PeerIdentity *peer,
530 const struct GNUNET_PeerIdentity *peer, int result) 525 int result)
531{ 526{
532 if (GNUNET_OK != result) 527 if (GNUNET_OK != result)
533 return; /* not allowed */ 528 return; /* not allowed */
@@ -543,8 +538,7 @@ try_connect_if_allowed (void *cls,
543 * @param message the actual message 538 * @param message the actual message
544 */ 539 */
545static void 540static void
546clients_handle_request_connect (void *cls, 541clients_handle_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
547 struct GNUNET_SERVER_Client *client,
548 const struct GNUNET_MessageHeader *message) 542 const struct GNUNET_MessageHeader *message)
549{ 543{
550 const struct TransportRequestConnectMessage *trcm = 544 const struct TransportRequestConnectMessage *trcm =
@@ -559,8 +553,8 @@ clients_handle_request_connect (void *cls,
559 "Received a request connect message for peer `%s'\n", 553 "Received a request connect message for peer `%s'\n",
560 GNUNET_i2s (&trcm->peer)); 554 GNUNET_i2s (&trcm->peer));
561#endif 555#endif
562 (void) GST_blacklist_test_allowed (&trcm->peer, NULL, 556 (void) GST_blacklist_test_allowed (&trcm->peer, NULL, &try_connect_if_allowed,
563 &try_connect_if_allowed, NULL); 557 NULL);
564 GNUNET_SERVER_receive_done (client, GNUNET_OK); 558 GNUNET_SERVER_receive_done (client, GNUNET_OK);
565} 559}
566 560
@@ -573,21 +567,19 @@ clients_handle_request_connect (void *cls,
573 * @param message the quota changing message 567 * @param message the quota changing message
574 */ 568 */
575static void 569static void
576clients_handle_set_quota (void *cls, 570clients_handle_set_quota (void *cls, struct GNUNET_SERVER_Client *client,
577 struct GNUNET_SERVER_Client *client,
578 const struct GNUNET_MessageHeader *message) 571 const struct GNUNET_MessageHeader *message)
579{ 572{
580 const struct QuotaSetMessage *qsm; 573 const struct QuotaSetMessage *qsm;
581 574
582 qsm = (const struct QuotaSetMessage *) message; 575 qsm = (const struct QuotaSetMessage *) message;
583 GNUNET_STATISTICS_update (GST_stats, 576 GNUNET_STATISTICS_update (GST_stats,
584 gettext_noop ("# SET QUOTA messages received"), 577 gettext_noop ("# SET QUOTA messages received"), 1,
585 1, GNUNET_NO); 578 GNUNET_NO);
586#if DEBUG_TRANSPORT 579#if DEBUG_TRANSPORT
587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
588 "Received `%s' request (new quota %u) from client for peer `%4s'\n", 581 "Received `%s' request (new quota %u) from client for peer `%4s'\n",
589 "SET_QUOTA", 582 "SET_QUOTA", (unsigned int) ntohl (qsm->quota.value__),
590 (unsigned int) ntohl (qsm->quota.value__),
591 GNUNET_i2s (&qsm->peer)); 583 GNUNET_i2s (&qsm->peer));
592#endif 584#endif
593 GST_neighbours_set_incoming_quota (&qsm->peer, qsm->quota); 585 GST_neighbours_set_incoming_quota (&qsm->peer, qsm->quota);
@@ -614,8 +606,7 @@ transmit_address_to_client (void *cls, const char *address)
614 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 606 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
615 return; 607 return;
616 } 608 }
617 GNUNET_SERVER_transmit_context_append_data (tc, 609 GNUNET_SERVER_transmit_context_append_data (tc, address, strlen (address) + 1,
618 address, strlen (address) + 1,
619 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 610 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
620} 611}
621 612
@@ -628,8 +619,7 @@ transmit_address_to_client (void *cls, const char *address)
628 * @param message the resolution request 619 * @param message the resolution request
629 */ 620 */
630static void 621static void
631clients_handle_address_lookup (void *cls, 622clients_handle_address_lookup (void *cls, struct GNUNET_SERVER_Client *client,
632 struct GNUNET_SERVER_Client *client,
633 const struct GNUNET_MessageHeader *message) 623 const struct GNUNET_MessageHeader *message)
634{ 624{
635 const struct AddressLookupMessage *alum; 625 const struct AddressLookupMessage *alum;
@@ -659,8 +649,8 @@ clients_handle_address_lookup (void *cls,
659 } 649 }
660 address = (const char *) &alum[1]; 650 address = (const char *) &alum[1];
661 plugin_name = (const char *) &address[address_len]; 651 plugin_name = (const char *) &address[address_len];
662 if (plugin_name 652 if (plugin_name[size - sizeof (struct AddressLookupMessage) - address_len - 1]
663 [size - sizeof (struct AddressLookupMessage) - address_len - 1] != '\0') 653 != '\0')
664 { 654 {
665 GNUNET_break (0); 655 GNUNET_break (0);
666 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 656 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -678,11 +668,9 @@ clients_handle_address_lookup (void *cls,
678 return; 668 return;
679 } 669 }
680 GNUNET_SERVER_disable_receive_done_warning (client); 670 GNUNET_SERVER_disable_receive_done_warning (client);
681 papi->address_pretty_printer (papi->cls, 671 papi->address_pretty_printer (papi->cls, plugin_name, address, address_len,
682 plugin_name, 672 numeric, rtimeout, &transmit_address_to_client,
683 address, address_len, 673 tc);
684 numeric,
685 rtimeout, &transmit_address_to_client, tc);
686} 674}
687 675
688 676
@@ -714,12 +702,11 @@ send_address_to_client (void *cls,
714 702
715 /* FIXME: move to a binary format!!! */ 703 /* FIXME: move to a binary format!!! */
716 GNUNET_asprintf (&addr_buf, "%s --- %s, %s", 704 GNUNET_asprintf (&addr_buf, "%s --- %s, %s",
717 GST_plugins_a2s (plugin_name, 705 GST_plugins_a2s (plugin_name, plugin_address,
718 plugin_address,
719 plugin_address_len), 706 plugin_address_len),
720 (GNUNET_YES == GST_neighbours_test_connected (target)) 707 (GNUNET_YES ==
721 ? "CONNECTED" 708 GST_neighbours_test_connected (target)) ? "CONNECTED" :
722 : "DISCONNECTED", 709 "DISCONNECTED",
723 (GNUNET_TIME_absolute_get_remaining (valid_until).rel_value > 710 (GNUNET_TIME_absolute_get_remaining (valid_until).rel_value >
724 0) ? "VALIDATED" : "UNVALIDATED"); 711 0) ? "VALIDATED" : "UNVALIDATED");
725 transmit_address_to_client (tc, addr_buf); 712 transmit_address_to_client (tc, addr_buf);
@@ -749,8 +736,7 @@ clients_handle_peer_address_lookup (void *cls,
749 tc = GNUNET_SERVER_transmit_context_create (client); 736 tc = GNUNET_SERVER_transmit_context_create (client);
750 GST_validation_get_addresses (&peer_address_lookup->peer, 737 GST_validation_get_addresses (&peer_address_lookup->peer,
751 &send_address_to_client, tc); 738 &send_address_to_client, tc);
752 GNUNET_SERVER_transmit_context_append_data (tc, 739 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
753 NULL, 0,
754 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 740 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
755 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 741 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
756} 742}
@@ -765,8 +751,7 @@ clients_handle_peer_address_lookup (void *cls,
765 * @param ats_count number of entries in ats (excluding 0-termination) 751 * @param ats_count number of entries in ats (excluding 0-termination)
766 */ 752 */
767static void 753static void
768output_addresses (void *cls, 754output_addresses (void *cls, const struct GNUNET_PeerIdentity *neighbour,
769 const struct GNUNET_PeerIdentity *neighbour,
770 const struct GNUNET_TRANSPORT_ATS_Information *ats, 755 const struct GNUNET_TRANSPORT_ATS_Information *ats,
771 uint32_t ats_count) 756 uint32_t ats_count)
772{ 757{
@@ -774,9 +759,8 @@ output_addresses (void *cls,
774 char *addr_buf; 759 char *addr_buf;
775 760
776 /* FIXME: move to a binary format!!! */ 761 /* FIXME: move to a binary format!!! */
777 GNUNET_asprintf (&addr_buf, 762 GNUNET_asprintf (&addr_buf, "%s: %s", GNUNET_i2s (neighbour),
778 "%s: %s", 763 GST_plugins_a2s ("FIXME", NULL, 0));
779 GNUNET_i2s (neighbour), GST_plugins_a2s ("FIXME", NULL, 0));
780 transmit_address_to_client (tc, addr_buf); 764 transmit_address_to_client (tc, addr_buf);
781 GNUNET_free (addr_buf); 765 GNUNET_free (addr_buf);
782} 766}
@@ -791,8 +775,7 @@ output_addresses (void *cls,
791 * @param message the peer address information request 775 * @param message the peer address information request
792 */ 776 */
793static void 777static void
794clients_handle_address_iterate (void *cls, 778clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client,
795 struct GNUNET_SERVER_Client *client,
796 const struct GNUNET_MessageHeader *message) 779 const struct GNUNET_MessageHeader *message)
797{ 780{
798 struct GNUNET_SERVER_TransmitContext *tc; 781 struct GNUNET_SERVER_TransmitContext *tc;
@@ -843,8 +826,8 @@ GST_clients_start (struct GNUNET_SERVER_Handle *server)
843 {NULL, NULL, 0, 0} 826 {NULL, NULL, 0, 0}
844 }; 827 };
845 GNUNET_SERVER_add_handlers (server, handlers); 828 GNUNET_SERVER_add_handlers (server, handlers);
846 GNUNET_SERVER_disconnect_notify (server, 829 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification,
847 &client_disconnect_notification, NULL); 830 NULL);
848} 831}
849 832
850 833