aboutsummaryrefslogtreecommitdiff
path: root/src
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
parentff21154a0805872ee6dbedb82d2fd64e1a7ed1ac (diff)
downloadgnunet-38ae6e3574273e94d480d44c5428cd061c40e434.tar.gz
gnunet-38ae6e3574273e94d480d44c5428cd061c40e434.zip
- service-side implementation of peer queries
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-service-mesh_local.c78
-rw-r--r--src/mesh/gnunet-service-mesh_peer.c33
-rw-r--r--src/mesh/gnunet-service-mesh_peer.h19
-rw-r--r--src/mesh/mesh.h32
4 files changed, 159 insertions, 3 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,
diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c
index f801a9e4e..3e4c2acab 100644
--- a/src/mesh/gnunet-service-mesh_peer.c
+++ b/src/mesh/gnunet-service-mesh_peer.c
@@ -1792,6 +1792,39 @@ GMP_get_tunnel (const struct MeshPeer *peer)
1792 1792
1793 1793
1794/** 1794/**
1795 * Count the number of known paths toward the peer.
1796 *
1797 * @param peer Peer to get path info.
1798 *
1799 * @return Number of known paths.
1800 */
1801unsigned int
1802GMP_count_paths (const struct MeshPeer *peer)
1803{
1804 struct MeshPeerPath *iter;
1805 unsigned int i;
1806
1807 for (iter = peer->path_head, i = 0; NULL != iter; iter = iter->next)
1808 i++;
1809
1810 return i;
1811}
1812
1813
1814/**
1815 * Iterate all known peers.
1816 *
1817 * @param iter Iterator.
1818 * @param cls Closure for @c iter.
1819 */
1820void
1821GMP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter, void *cls)
1822{
1823 GNUNET_CONTAINER_multipeermap_iterate (peers, iter, cls);
1824}
1825
1826
1827/**
1795 * Get the static string for a peer ID. 1828 * Get the static string for a peer ID.
1796 * 1829 *
1797 * @param peer Peer. 1830 * @param peer Peer.
diff --git a/src/mesh/gnunet-service-mesh_peer.h b/src/mesh/gnunet-service-mesh_peer.h
index 5468d0181..0a6237c6a 100644
--- a/src/mesh/gnunet-service-mesh_peer.h
+++ b/src/mesh/gnunet-service-mesh_peer.h
@@ -319,6 +319,25 @@ struct MeshTunnel3 *
319GMP_get_tunnel (const struct MeshPeer *peer); 319GMP_get_tunnel (const struct MeshPeer *peer);
320 320
321/** 321/**
322 * Count the number of known paths toward the peer.
323 *
324 * @param peer Peer to get path info.
325 *
326 * @return Number of known paths.
327 */
328unsigned int
329GMP_count_paths (const struct MeshPeer *peer);
330
331/**
332 * Iterate all known peers.
333 *
334 * @param iter Iterator.
335 * @param cls Closure for @c iter.
336 */
337void
338GMP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter, void *cls);
339
340/**
322 * Get the static string for a peer ID. 341 * Get the static string for a peer ID.
323 * 342 *
324 * @param peer Peer. 343 * @param peer Peer.
diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h
index 7011bd51a..a12c0ccb9 100644
--- a/src/mesh/mesh.h
+++ b/src/mesh/mesh.h
@@ -169,7 +169,7 @@ struct GNUNET_MESH_LocalAck
169struct GNUNET_MESH_LocalInfo 169struct GNUNET_MESH_LocalInfo
170{ 170{
171 /** 171 /**
172 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO[_TUNNEL] 172 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO[_TUNNEL,_PEER]
173 */ 173 */
174 struct GNUNET_MessageHeader header; 174 struct GNUNET_MessageHeader header;
175 175
@@ -189,6 +189,36 @@ struct GNUNET_MESH_LocalInfo
189 struct GNUNET_PeerIdentity peer; 189 struct GNUNET_PeerIdentity peer;
190}; 190};
191 191
192
193/**
194 * Message to inform the client about one of the peers in the service.
195 */
196struct GNUNET_MESH_LocalInfoPeer
197{
198 /**
199 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEER[S]
200 */
201 struct GNUNET_MessageHeader header;
202
203 /**
204 * Number of paths.
205 */
206 uint16_t paths GNUNET_PACKED;
207
208 /**
209 * Do we have a tunnel toward this peer?
210 */
211 uint16_t tunnel GNUNET_PACKED;
212
213 /**
214 * ID of the destination of the tunnel (can be local peer).
215 */
216 struct GNUNET_PeerIdentity destination;
217
218 /* If type == PEER (no 'S'): GNUNET_PeerIdentity paths[]
219 * (each path ends in destination) */
220};
221
192/** 222/**
193 * Message to inform the client about one of the tunnels in the service. 223 * Message to inform the client about one of the tunnels in the service.
194 */ 224 */