aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_mesh_service.h41
-rw-r--r--src/mesh/gnunet-mesh.c54
-rw-r--r--src/mesh/mesh_api.c44
3 files changed, 139 insertions, 0 deletions
diff --git a/src/include/gnunet_mesh_service.h b/src/include/gnunet_mesh_service.h
index 7f108683f..241a3d54e 100644
--- 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,
410 int tunnel, unsigned int n_paths, 410 int tunnel, unsigned int n_paths,
411 unsigned int best_path); 411 unsigned int best_path);
412 412
413/**
414 * Method called to retrieve information about a specific peer
415 * known to the service.
416 *
417 * @param cls Closure.
418 * @param peer Peer ID.
419 * @param tunnel Do we have a tunnel towards this peer? #GNUNET_YES/#GNUNET_NO
420 * @param neighbor Is this a direct neighbor? #GNUNET_YES/#GNUNET_NO
421 * @param n_paths Number of paths known towards peer.
422 * @param paths Array of PEER_IDs representing all paths to reach the peer.
423 * Each path starts with the local peer.
424 * Each path ends with the destination peer (given in @c peer).
425 */
426typedef void (*GNUNET_MESH_PeerCB) (void *cls,
427 const struct GNUNET_PeerIdentity *peer,
428 int tunnel,
429 int neighbor,
430 unsigned int n_paths,
431 struct GNUNET_PeerIdentity *paths);
432
413 433
414/** 434/**
415 * Method called to retrieve information about all tunnels in MESH, called 435 * Method called to retrieve information about all tunnels in MESH, called
@@ -505,6 +525,27 @@ GNUNET_MESH_get_peers (struct GNUNET_MESH_Handle *h,
505void * 525void *
506GNUNET_MESH_get_peers_cancel (struct GNUNET_MESH_Handle *h); 526GNUNET_MESH_get_peers_cancel (struct GNUNET_MESH_Handle *h);
507 527
528
529/**
530 * Request information about a peer known to the running mesh peer.
531 * The callback will be called for the tunnel once.
532 * Only one info request (of any kind) can be active at once.
533 *
534 * WARNING: unstable API, likely to change in the future!
535 *
536 * @param h Handle to the mesh peer.
537 * @param id Peer whose tunnel to examine.
538 * @param callback Function to call with the requested data.
539 * @param callback_cls Closure for @c callback.
540 *
541 * @return #GNUNET_OK / #GNUNET_SYSERR
542 */
543int
544GNUNET_MESH_get_peer (struct GNUNET_MESH_Handle *h,
545 const struct GNUNET_PeerIdentity *id,
546 GNUNET_MESH_PeerCB callback,
547 void *callback_cls);
548
508/** 549/**
509 * Request information about tunnels of the running mesh peer. 550 * Request information about tunnels of the running mesh peer.
510 * The callback will be called for every tunnel of the service. 551 * 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
index d4b56fc74..3f751d8f8 100644
--- 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,
465 GNUNET_i2s_full (peer), tunnel ? 'Y' : 'N', n_paths); 465 GNUNET_i2s_full (peer), tunnel ? 'Y' : 'N', n_paths);
466} 466}
467 467
468/**
469 * Method called to retrieve information about a specific peer
470 * known to the service.
471 *
472 * @param cls Closure.
473 * @param peer Peer ID.
474 * @param tunnel Do we have a tunnel towards this peer? #GNUNET_YES/#GNUNET_NO
475 * @param neighbor Is this a direct neighbor? #GNUNET_YES/#GNUNET_NO
476 * @param n_paths Number of paths known towards peer.
477 * @param paths Array of PEER_IDs representing all paths to reach the peer.
478 * Each path starts with the local peer.
479 * Each path ends with the destination peer (given in @c peer).
480 */
481void
482peer_callback (void *cls,
483 const struct GNUNET_PeerIdentity *peer,
484 int tunnel,
485 int neighbor,
486 unsigned int n_paths,
487 struct GNUNET_PeerIdentity *paths)
488{
489}
490
468 491
469/** 492/**
470 * Method called to retrieve information about all tunnels in MESH. 493 * Method called to retrieve information about all tunnels in MESH.
@@ -560,6 +583,32 @@ get_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
560 GNUNET_MESH_get_peers (mh, &peers_callback, NULL); 583 GNUNET_MESH_get_peers (mh, &peers_callback, NULL);
561} 584}
562 585
586
587/**
588 * Call MESH's monitor API, get info of one peer.
589 *
590 * @param cls Closure (unused).
591 * @param tc TaskContext
592 */
593static void
594show_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
595{
596 struct GNUNET_PeerIdentity pid;
597
598 if (GNUNET_OK !=
599 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
600 strlen (peer_id),
601 &pid.public_key))
602 {
603 fprintf (stderr,
604 _("Invalid peer ID `%s'\n"),
605 peer_id);
606 GNUNET_SCHEDULER_shutdown();
607 return;
608 }
609 GNUNET_MESH_get_peer (mh, &pid, peer_callback, NULL);
610}
611
563/** 612/**
564 * Call MESH's meta API, get all tunnels known to a peer. 613 * Call MESH's meta API, get all tunnels known to a peer.
565 * 614 *
@@ -682,6 +731,11 @@ run (void *cls, char *const *args, const char *cfgfile,
682 ports = GNUNET_malloc (sizeof (uint32_t) * 2); 731 ports = GNUNET_malloc (sizeof (uint32_t) * 2);
683 ports[0] = listen_port; 732 ports[0] = listen_port;
684 } 733 }
734 else if (NULL != peer_id)
735 {
736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n");
737 GNUNET_SCHEDULER_add_now (&show_peer, NULL);
738 }
685 else if (NULL != tunnel_id) 739 else if (NULL != tunnel_id)
686 { 740 {
687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show tunnel\n"); 741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show tunnel\n");
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index ff755c1ac..8a16f9583 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -101,6 +101,11 @@ union MeshInfoCB {
101 /** 101 /**
102 * Monitor callback 102 * Monitor callback
103 */ 103 */
104 GNUNET_MESH_PeerCB peer_cb;
105
106 /**
107 * Monitor callback
108 */
104 GNUNET_MESH_TunnelsCB tunnels_cb; 109 GNUNET_MESH_TunnelsCB tunnels_cb;
105 110
106 /** 111 /**
@@ -1784,6 +1789,45 @@ GNUNET_MESH_get_peers_cancel (struct GNUNET_MESH_Handle *h)
1784 1789
1785 1790
1786/** 1791/**
1792 * Request information about a peer known to the running mesh peer.
1793 * The callback will be called for the tunnel once.
1794 * Only one info request (of any kind) can be active at once.
1795 *
1796 * WARNING: unstable API, likely to change in the future!
1797 *
1798 * @param h Handle to the mesh peer.
1799 * @param id Peer whose tunnel to examine.
1800 * @param callback Function to call with the requested data.
1801 * @param callback_cls Closure for @c callback.
1802 *
1803 * @return #GNUNET_OK / #GNUNET_SYSERR
1804 */
1805int
1806GNUNET_MESH_get_peer (struct GNUNET_MESH_Handle *h,
1807 const struct GNUNET_PeerIdentity *id,
1808 GNUNET_MESH_PeerCB callback,
1809 void *callback_cls)
1810{
1811 struct GNUNET_MESH_LocalInfo msg;
1812
1813 if (NULL != h->info_cb.peer_cb)
1814 {
1815 GNUNET_break (0);
1816 return GNUNET_SYSERR;
1817 }
1818
1819 memset (&msg, 0, sizeof (msg));
1820 msg.header.size = htons (sizeof (msg));
1821 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEER);
1822 msg.peer = *id;
1823 send_packet (h, &msg.header, NULL);
1824 h->info_cb.peer_cb = callback;
1825 h->info_cls = callback_cls;
1826 return GNUNET_OK;
1827}
1828
1829
1830/**
1787 * Request information about tunnels of the running mesh peer. 1831 * Request information about tunnels of the running mesh peer.
1788 * The callback will be called for every tunnel of the service. 1832 * The callback will be called for every tunnel of the service.
1789 * Only one info request (of any kind) can be active at once. 1833 * Only one info request (of any kind) can be active at once.