gnunet

Main GNUnet Logic
Log | Files | Refs | Submodules | README | LICENSE

commit 815f90100a95d02c1442a53ac6a2f423abffff90
parent 5f8beabc0231bd4212d3d1d988f1a435158b90cd
Author: Bart Polot <bart@net.in.tum.de>
Date:   Tue,  1 Apr 2014 00:16:26 +0000

- implement client-side peer_id info request

Diffstat:
Msrc/include/gnunet_mesh_service.h | 41+++++++++++++++++++++++++++++++++++++++++
Msrc/mesh/gnunet-mesh.c | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/mesh/mesh_api.c | 44++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 139 insertions(+), 0 deletions(-)

diff --git a/src/include/gnunet_mesh_service.h b/src/include/gnunet_mesh_service.h @@ -410,6 +410,26 @@ typedef void (*GNUNET_MESH_PeersCB) (void *cls, int tunnel, unsigned int n_paths, unsigned int best_path); +/** + * Method called to retrieve information about a specific peer + * known to the service. + * + * @param cls Closure. + * @param peer Peer ID. + * @param tunnel Do we have a tunnel towards this peer? #GNUNET_YES/#GNUNET_NO + * @param neighbor Is this a direct neighbor? #GNUNET_YES/#GNUNET_NO + * @param n_paths Number of paths known towards peer. + * @param paths Array of PEER_IDs representing all paths to reach the peer. + * Each path starts with the local peer. + * Each path ends with the destination peer (given in @c peer). + */ +typedef void (*GNUNET_MESH_PeerCB) (void *cls, + const struct GNUNET_PeerIdentity *peer, + int tunnel, + int neighbor, + unsigned int n_paths, + struct GNUNET_PeerIdentity *paths); + /** * Method called to retrieve information about all tunnels in MESH, called @@ -505,6 +525,27 @@ GNUNET_MESH_get_peers (struct GNUNET_MESH_Handle *h, void * GNUNET_MESH_get_peers_cancel (struct GNUNET_MESH_Handle *h); + +/** + * Request information about a peer known to the running mesh peer. + * The callback will be called for the tunnel once. + * Only one info request (of any kind) can be active at once. + * + * WARNING: unstable API, likely to change in the future! + * + * @param h Handle to the mesh peer. + * @param id Peer whose tunnel to examine. + * @param callback Function to call with the requested data. + * @param callback_cls Closure for @c callback. + * + * @return #GNUNET_OK / #GNUNET_SYSERR + */ +int +GNUNET_MESH_get_peer (struct GNUNET_MESH_Handle *h, + const struct GNUNET_PeerIdentity *id, + GNUNET_MESH_PeerCB callback, + void *callback_cls); + /** * Request information about tunnels of the running mesh peer. * The callback will be called for every tunnel of the service. diff --git a/src/mesh/gnunet-mesh.c b/src/mesh/gnunet-mesh.c @@ -465,6 +465,29 @@ peers_callback (void *cls, const struct GNUNET_PeerIdentity *peer, GNUNET_i2s_full (peer), tunnel ? 'Y' : 'N', n_paths); } +/** + * Method called to retrieve information about a specific peer + * known to the service. + * + * @param cls Closure. + * @param peer Peer ID. + * @param tunnel Do we have a tunnel towards this peer? #GNUNET_YES/#GNUNET_NO + * @param neighbor Is this a direct neighbor? #GNUNET_YES/#GNUNET_NO + * @param n_paths Number of paths known towards peer. + * @param paths Array of PEER_IDs representing all paths to reach the peer. + * Each path starts with the local peer. + * Each path ends with the destination peer (given in @c peer). + */ +void +peer_callback (void *cls, + const struct GNUNET_PeerIdentity *peer, + int tunnel, + int neighbor, + unsigned int n_paths, + struct GNUNET_PeerIdentity *paths) +{ +} + /** * Method called to retrieve information about all tunnels in MESH. @@ -560,6 +583,32 @@ get_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_MESH_get_peers (mh, &peers_callback, NULL); } + +/** + * Call MESH's monitor API, get info of one peer. + * + * @param cls Closure (unused). + * @param tc TaskContext + */ +static void +show_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GNUNET_PeerIdentity pid; + + if (GNUNET_OK != + GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, + strlen (peer_id), + &pid.public_key)) + { + fprintf (stderr, + _("Invalid peer ID `%s'\n"), + peer_id); + GNUNET_SCHEDULER_shutdown(); + return; + } + GNUNET_MESH_get_peer (mh, &pid, peer_callback, NULL); +} + /** * Call MESH's meta API, get all tunnels known to a peer. * @@ -682,6 +731,11 @@ run (void *cls, char *const *args, const char *cfgfile, ports = GNUNET_malloc (sizeof (uint32_t) * 2); ports[0] = listen_port; } + else if (NULL != peer_id) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n"); + GNUNET_SCHEDULER_add_now (&show_peer, NULL); + } else if (NULL != tunnel_id) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show tunnel\n"); diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c @@ -101,6 +101,11 @@ union MeshInfoCB { /** * Monitor callback */ + GNUNET_MESH_PeerCB peer_cb; + + /** + * Monitor callback + */ GNUNET_MESH_TunnelsCB tunnels_cb; /** @@ -1784,6 +1789,45 @@ GNUNET_MESH_get_peers_cancel (struct GNUNET_MESH_Handle *h) /** + * Request information about a peer known to the running mesh peer. + * The callback will be called for the tunnel once. + * Only one info request (of any kind) can be active at once. + * + * WARNING: unstable API, likely to change in the future! + * + * @param h Handle to the mesh peer. + * @param id Peer whose tunnel to examine. + * @param callback Function to call with the requested data. + * @param callback_cls Closure for @c callback. + * + * @return #GNUNET_OK / #GNUNET_SYSERR + */ +int +GNUNET_MESH_get_peer (struct GNUNET_MESH_Handle *h, + const struct GNUNET_PeerIdentity *id, + GNUNET_MESH_PeerCB callback, + void *callback_cls) +{ + struct GNUNET_MESH_LocalInfo msg; + + if (NULL != h->info_cb.peer_cb) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + + memset (&msg, 0, sizeof (msg)); + msg.header.size = htons (sizeof (msg)); + msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEER); + msg.peer = *id; + send_packet (h, &msg.header, NULL); + h->info_cb.peer_cb = callback; + h->info_cls = callback_cls; + return GNUNET_OK; +} + + +/** * Request information about tunnels of the running mesh peer. * The callback will be called for every tunnel of the service. * Only one info request (of any kind) can be active at once.