aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_clients.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-05 09:36:02 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-05 09:36:02 +0000
commitfb567582ca24ac7450336782365e86a177d8a472 (patch)
tree053b29071811155a328bf8dec1f1c922997fe02f /src/transport/gnunet-service-transport_clients.c
parentec057166095a225d45be16e66671e0f7f74cbef2 (diff)
downloadgnunet-fb567582ca24ac7450336782365e86a177d8a472.tar.gz
gnunet-fb567582ca24ac7450336782365e86a177d8a472.zip
more refactoring
Diffstat (limited to 'src/transport/gnunet-service-transport_clients.c')
-rw-r--r--src/transport/gnunet-service-transport_clients.c121
1 files changed, 118 insertions, 3 deletions
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index 1ef28ad90..3b42c7a79 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -28,6 +28,7 @@
28#include "gnunet-service-transport_hello.h" 28#include "gnunet-service-transport_hello.h"
29#include "gnunet-service-transport_neighbours.h" 29#include "gnunet-service-transport_neighbours.h"
30#include "gnunet-service-transport_plugins.h" 30#include "gnunet-service-transport_plugins.h"
31#include "gnunet-service-transport_validation.h"
31#include "gnunet-service-transport.h" 32#include "gnunet-service-transport.h"
32#include "transport.h" 33#include "transport.h"
33 34
@@ -427,6 +428,23 @@ GST_clients_handle_start (void *cls,
427 428
428 429
429/** 430/**
431 * Client sent us a HELLO. Process the request.
432 *
433 * @param cls unused
434 * @param client the client
435 * @param message the HELLO message
436 */
437void
438GST_clients_handle_hello (void *cls,
439 struct GNUNET_SERVER_Client *client,
440 const struct GNUNET_MessageHeader *message)
441{
442 GST_validation_handle_hello (message);
443 GNUNET_SERVER_receive_done (client, GNUNET_OK);
444}
445
446
447/**
430 * Client asked for transmission to a peer. Process the request. 448 * Client asked for transmission to a peer. Process the request.
431 * 449 *
432 * @param cls unused 450 * @param cls unused
@@ -438,6 +456,8 @@ GST_clients_handle_send (void *cls,
438 struct GNUNET_SERVER_Client *client, 456 struct GNUNET_SERVER_Client *client,
439 const struct GNUNET_MessageHeader *message) 457 const struct GNUNET_MessageHeader *message)
440{ 458{
459 /* FIXME */
460 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
441} 461}
442 462
443 463
@@ -568,8 +588,52 @@ GST_clients_handle_address_lookup (void *cls,
568 588
569 589
570/** 590/**
591 * Send an address to the client.
592 *
593 * @param cls our 'struct GNUNET_SERVER_TransmitContext' (for sending)
594 * @param target peer this change is about, never NULL
595 * @param last_validated_at is FOREVER if the address has not been validated (we're currently checking)
596 * is ZERO if the address was validated a long time ago (from PEERINFO)
597 * is a time in the past if this process validated the address
598 * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO)
599 * is ZERO if the address is considered valid (no validation needed)
600 * is a time in the future if we're currently denying re-validation
601 * @param plugin_name name of the plugin
602 * @param plugin_address binary address
603 * @param plugin_address_len length of address
604 */
605static void
606send_address_to_client (void *cls,
607 const struct GNUNET_PeerIdentity *target,
608 struct GNUNET_TIME_Absolute last_validated_at,
609 struct GNUNET_TIME_Absolute validation_block,
610 const char *plugin_name,
611 const void *plugin_address,
612 size_t plugin_address_len)
613{
614 struct GNUNET_SERVER_TransmitContext *tc = cls;
615 char *addr_buf;
616
617 /* FIXME: move to a binary format!!! */
618 GNUNET_asprintf (&addr_buf, "%s --- %s, %s",
619 GST_plugins_a2s (plugin_name,
620 plugin_address,
621 plugin_address_len),
622 (GNUNET_YES == GST_neighbours_test_connected (target))
623 ? "CONNECTED"
624 : "DISCONNECTED",
625 (last_validated_at.abs_value < GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
626 ? "VALIDATED"
627 : "UNVALIDATED");
628 transmit_address_to_client (tc, addr_buf);
629 GNUNET_free (addr_buf);
630}
631
632
633/**
571 * Client asked to obtain information about a peer's addresses. 634 * Client asked to obtain information about a peer's addresses.
572 * Process the request. 635 * Process the request.
636 * FIXME: use better name!
573 * 637 *
574 * @param cls unused 638 * @param cls unused
575 * @param client the client 639 * @param client the client
@@ -580,12 +644,54 @@ GST_clients_handle_peer_address_lookup (void *cls,
580 struct GNUNET_SERVER_Client *client, 644 struct GNUNET_SERVER_Client *client,
581 const struct GNUNET_MessageHeader *message) 645 const struct GNUNET_MessageHeader *message)
582{ 646{
647 const struct PeerAddressLookupMessage *peer_address_lookup;
648 struct GNUNET_SERVER_TransmitContext *tc;
649
650 peer_address_lookup = (const struct PeerAddressLookupMessage *) message;
651 GNUNET_break (ntohl (peer_address_lookup->reserved) == 0);
652 tc = GNUNET_SERVER_transmit_context_create (client);
653 (void) GST_validation_get_addresses (&peer_address_lookup->peer,
654 GNUNET_YES,
655 &send_address_to_client,
656 tc);
657 GNUNET_SERVER_transmit_context_append_data (tc,
658 NULL, 0,
659 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
660 GNUNET_SERVER_transmit_context_run (tc,
661 GNUNET_TIME_UNIT_FOREVER_REL);
583} 662}
584 663
585 664
586/** 665/**
587 * Client asked to obtain information about all addresses. 666 * Output the active address of connected neighbours to the given client.
588 * Process the request. 667 *
668 * @param cls the 'struct GNUNET_SERVER_TransmitContext' for transmission to the client
669 * @param neighbour identity of the neighbour
670 * @param ats performance data
671 * @param ats_count number of entries in ats (excluding 0-termination)
672 */
673static void
674output_addresses (void *cls,
675 const struct GNUNET_PeerIdentity *neighbour,
676 const struct GNUNET_TRANSPORT_ATS_Information *ats,
677 uint32_t ats_count)
678{
679 struct GNUNET_SERVER_TransmitContext *tc = cls;
680 char *addr_buf;
681
682 /* FIXME: move to a binary format!!! */
683 GNUNET_asprintf (&addr_buf,
684 "%s: %s",
685 GNUNET_i2s(neighbour),
686 GST_plugins_a2s ("FIXME", NULL, 0));
687 transmit_address_to_client (tc, addr_buf);
688 GNUNET_free (addr_buf);
689}
690
691
692/**
693 * Client asked to obtain information about all actively used addresses.
694 * Process the request. FIXME: use better name!
589 * 695 *
590 * @param cls unused 696 * @param cls unused
591 * @param client the client 697 * @param client the client
@@ -595,7 +701,16 @@ void
595GST_clients_handle_address_iterate (void *cls, 701GST_clients_handle_address_iterate (void *cls,
596 struct GNUNET_SERVER_Client *client, 702 struct GNUNET_SERVER_Client *client,
597 const struct GNUNET_MessageHeader *message) 703 const struct GNUNET_MessageHeader *message)
598{ 704{
705 struct GNUNET_SERVER_TransmitContext *tc;
706
707 GNUNET_SERVER_disable_receive_done_warning (client);
708 tc = GNUNET_SERVER_transmit_context_create (client);
709 GST_neighbours_iterate (&output_addresses,
710 tc);
711 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
712 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
713 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
599} 714}
600 715
601 716