aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh_local.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2014-01-30 02:11:21 +0000
committerBart Polot <bart@net.in.tum.de>2014-01-30 02:11:21 +0000
commit38ae6e3574273e94d480d44c5428cd061c40e434 (patch)
tree6a806eacc7a46204281799491ed6ee5cca6e3982 /src/mesh/gnunet-service-mesh_local.c
parentff21154a0805872ee6dbedb82d2fd64e1a7ed1ac (diff)
downloadgnunet-38ae6e3574273e94d480d44c5428cd061c40e434.tar.gz
gnunet-38ae6e3574273e94d480d44c5428cd061c40e434.zip
- service-side implementation of peer queries
Diffstat (limited to 'src/mesh/gnunet-service-mesh_local.c')
-rw-r--r--src/mesh/gnunet-service-mesh_local.c78
1 files changed, 76 insertions, 2 deletions
diff --git a/src/mesh/gnunet-service-mesh_local.c b/src/mesh/gnunet-service-mesh_local.c
index b1f974b41..f5a3210af 100644
--- a/src/mesh/gnunet-service-mesh_local.c
+++ b/src/mesh/gnunet-service-mesh_local.c
@@ -32,6 +32,7 @@
32 32
33/* INFO DEBUG */ 33/* INFO DEBUG */
34#include "gnunet-service-mesh_tunnel.h" 34#include "gnunet-service-mesh_tunnel.h"
35#include "gnunet-service-mesh_peer.h"
35 36
36#define LOG(level, ...) GNUNET_log_from(level,"mesh-loc",__VA_ARGS__) 37#define LOG(level, ...) GNUNET_log_from(level,"mesh-loc",__VA_ARGS__)
37 38
@@ -579,6 +580,77 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client,
579} 580}
580 581
581 582
583
584/**
585 * Iterator over all peers to send a monitoring client info about each peer.
586 *
587 * @param cls Closure ().
588 * @param peer Peer ID (tunnel remote peer).
589 * @param value Peer info.
590 *
591 * @return #GNUNET_YES, to keep iterating.
592 */
593static int
594get_all_peers_iterator (void *cls,
595 const struct GNUNET_PeerIdentity * peer,
596 void *value)
597{
598 struct GNUNET_SERVER_Client *client = cls;
599 struct MeshPeer *p = value;
600 struct GNUNET_MESH_LocalInfoPeer msg;
601
602 msg.header.size = htons (sizeof (msg));
603 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEERS);
604 msg.destination = *peer;
605 msg.paths = GMP_count_paths (p);
606 msg.tunnel = NULL != GMP_get_tunnel (p);
607
608 LOG (GNUNET_ERROR_TYPE_DEBUG, "sending info about tunnel ->%s\n",
609 GNUNET_i2s (peer));
610
611 GNUNET_SERVER_notification_context_unicast (nc, client,
612 &msg.header, GNUNET_NO);
613 return GNUNET_YES;
614}
615
616
617/**
618 * Handler for client's INFO PEERS request.
619 *
620 * @param cls Closure (unused).
621 * @param client Identification of the client.
622 * @param message The actual message.
623 */
624static void
625handle_get_peers (void *cls, struct GNUNET_SERVER_Client *client,
626 const struct GNUNET_MessageHeader *message)
627{
628 struct MeshClient *c;
629 struct GNUNET_MessageHeader reply;
630
631 /* Sanity check for client registration */
632 if (NULL == (c = GML_client_get (client)))
633 {
634 GNUNET_break (0);
635 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
636 return;
637 }
638
639 LOG (GNUNET_ERROR_TYPE_DEBUG,
640 "Received get peers request from client %u (%p)\n",
641 c->id, client);
642
643 GMP_iterate_all (get_all_peers_iterator, client);
644 reply.size = htons (sizeof (reply));
645 reply.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEERS);
646 GNUNET_SERVER_notification_context_unicast (nc, client, &reply, GNUNET_NO);
647
648 LOG (GNUNET_ERROR_TYPE_DEBUG,
649 "Get peers request from client %u completed\n", c->id);
650 GNUNET_SERVER_receive_done (client, GNUNET_OK);
651}
652
653
582/** 654/**
583 * Iterator over all tunnels to send a monitoring client info about each tunnel. 655 * Iterator over all tunnels to send a monitoring client info about each tunnel.
584 * 656 *
@@ -590,8 +662,8 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client,
590 */ 662 */
591static int 663static int
592get_all_tunnels_iterator (void *cls, 664get_all_tunnels_iterator (void *cls,
593 const struct GNUNET_PeerIdentity * peer, 665 const struct GNUNET_PeerIdentity * peer,
594 void *value) 666 void *value)
595{ 667{
596 struct GNUNET_SERVER_Client *client = cls; 668 struct GNUNET_SERVER_Client *client = cls;
597 struct MeshTunnel3 *t = value; 669 struct MeshTunnel3 *t = value;
@@ -770,6 +842,8 @@ static struct GNUNET_SERVER_MessageHandler client_handlers[] = {
770 {&handle_data, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0}, 842 {&handle_data, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0},
771 {&handle_ack, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK, 843 {&handle_ack, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK,
772 sizeof (struct GNUNET_MESH_LocalAck)}, 844 sizeof (struct GNUNET_MESH_LocalAck)},
845 {&handle_get_peers, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEERS,
846 sizeof (struct GNUNET_MessageHeader)},
773 {&handle_get_tunnels, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS, 847 {&handle_get_tunnels, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS,
774 sizeof (struct GNUNET_MessageHeader)}, 848 sizeof (struct GNUNET_MessageHeader)},
775 {&handle_show_tunnel, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL, 849 {&handle_show_tunnel, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL,