aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2014-01-30 12:28:39 +0000
committerBart Polot <bart@net.in.tum.de>2014-01-30 12:28:39 +0000
commit0d83dd0910566a4b1f95227cd62a42b1521c3bc6 (patch)
treea2ba5e34e02a42b6997973300ba827729c4c6824 /src
parent7067d8df58abce4636ff94cd3621aee9de1ab594 (diff)
downloadgnunet-0d83dd0910566a4b1f95227cd62a42b1521c3bc6.tar.gz
gnunet-0d83dd0910566a4b1f95227cd62a42b1521c3bc6.zip
- use a memory-efficient, cleaner info API (limiting concurrent info requests to 1)
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_mesh_service.h119
-rw-r--r--src/mesh/mesh_api.c255
2 files changed, 160 insertions, 214 deletions
diff --git a/src/include/gnunet_mesh_service.h b/src/include/gnunet_mesh_service.h
index 40a4060db..21a51b7b2 100644
--- a/src/include/gnunet_mesh_service.h
+++ b/src/include/gnunet_mesh_service.h
@@ -362,34 +362,26 @@ GNUNET_MESH_receive_done (struct GNUNET_MESH_Channel *channel);
362/* normal mesh applications. */ 362/* normal mesh applications. */
363/******************************************************************************/ 363/******************************************************************************/
364 364
365/**
366 * Method called to retrieve information about each channel the mesh peer
367 * is aware of.
368 *
369 * @param cls Closure.
370 * @param channel_number Channel number.
371 * @param origin that started the channel (owner).
372 * @param target other endpoint of the channel
373 */
374typedef void (*GNUNET_MESH_ChannelsCB) (void *cls,
375 uint32_t root_channel_number,
376 uint32_t dest_channel_number,
377 uint32_t public_channel_number,
378 const struct GNUNET_PeerIdentity *origin,
379 const struct GNUNET_PeerIdentity *target);
380
381 365
382/** 366/**
383 * Method called to retrieve information about a specific channel the mesh peer 367 * Method called to retrieve information about a specific channel the mesh peer
384 * is aware of, including all transit nodes. 368 * is aware of, including all transit nodes.
385 * 369 *
386 * @param cls Closure. 370 * @param cls Closure.
387 * @param peer Peer in the channel's tree. 371 * @param root Root of the channel.
388 * @param parent Parent of the current peer. All 0 when peer is root. 372 * @param dest Destination of the channel.
373 * @param port Destination port of the channel.
374 * @param root_channel_number Local number for root, if known.
375 * @param dest_channel_number Local number for dest, if known.
376 * @param public_channel_numbe Number for P2P, always known.
389 */ 377 */
390typedef void (*GNUNET_MESH_ChannelCB) (void *cls, 378typedef void (*GNUNET_MESH_ChannelCB) (void *cls,
391 const struct GNUNET_PeerIdentity *peer, 379 const struct GNUNET_PeerIdentity *root,
392 const struct GNUNET_PeerIdentity *parent); 380 const struct GNUNET_PeerIdentity *dest,
381 uint32_t port,
382 uint32_t root_channel_number,
383 uint32_t dest_channel_number,
384 uint32_t public_channel_number);
393 385
394/** 386/**
395 * Method called to retrieve information about all peers in MESH, called 387 * Method called to retrieve information about all peers in MESH, called
@@ -454,28 +446,6 @@ typedef void (*GNUNET_MESH_TunnelCB) (void *cls,
454 unsigned int estate, 446 unsigned int estate,
455 unsigned int cstate); 447 unsigned int cstate);
456 448
457
458/**
459 * Request information about the running mesh peer.
460 * The callback will be called for every channel known to the service,
461 * listing all active peers that belong to the channel.
462 *
463 * If called again on the same handle, it will overwrite the previous
464 * callback and cls. To retrieve the cls, monitor_cancel must be
465 * called first.
466 *
467 * WARNING: unstable API, likely to change in the future!
468 *
469 * @param h Handle to the mesh peer.
470 * @param callback Function to call with the requested data.
471 * @param callback_cls Closure for @c callback.
472 */
473void
474GNUNET_MESH_get_channels (struct GNUNET_MESH_Handle *h,
475 GNUNET_MESH_ChannelsCB callback,
476 void *callback_cls);
477
478
479/** 449/**
480 * Request information about a specific channel of the running mesh peer. 450 * Request information about a specific channel of the running mesh peer.
481 * 451 *
@@ -496,55 +466,50 @@ GNUNET_MESH_get_channel (struct GNUNET_MESH_Handle *h,
496 466
497 467
498/** 468/**
499 * Cancel a monitor request. The monitor callback will not be called. 469 * Request information about peers known to the running mesh service.
500 *
501 * WARNING: unstable API, likely to change in the future!
502 *
503 * @param h Mesh handle.
504 *
505 * @return Closure given to GNUNET_MESH_monitor, if any.
506 */
507void *
508GNUNET_MESH_get_channels_cancel (struct GNUNET_MESH_Handle *h);
509
510
511
512/**
513 * Request information about the running mesh peer.
514 * The callback will be called for every peer known to the service. 470 * The callback will be called for every peer known to the service.
471 * Only one info request (of any kind) can be active at once.
515 * 472 *
516 * If called again on the same handle, it will overwrite the previous
517 * callback and cls. To retrieve the cls, monitor_cancel must be
518 * called first.
519 * 473 *
520 * WARNING: unstable API, likely to change in the future! 474 * WARNING: unstable API, likely to change in the future!
521 * 475 *
522 * @param h Handle to the mesh peer. 476 * @param h Handle to the mesh peer.
523 * @param callback Function to call with the requested data. 477 * @param callback Function to call with the requested data.
524 * @param callback_cls Closure for @c callback. 478 * @param callback_cls Closure for @c callback.
479 *
480 * @return #GNUNET_OK / #GNUNET_SYSERR
525 */ 481 */
526void 482int
527GNUNET_MESH_get_peers (struct GNUNET_MESH_Handle *h, 483GNUNET_MESH_get_peers (struct GNUNET_MESH_Handle *h,
528 GNUNET_MESH_PeersCB callback, 484 GNUNET_MESH_PeersCB callback,
529 void *callback_cls); 485 void *callback_cls);
530 486
531
532/** 487/**
533 * Request information about the running mesh peer. 488 * Cancel a peer info request. The callback will not be called (anymore).
534 * The callback will be called for every channel known to the service,
535 * listing all active peers that blong to the channel.
536 * 489 *
537 * If called again on the same handle, it will overwrite the previous 490 * WARNING: unstable API, likely to change in the future!
538 * callback and cls. To retrieve the cls, monitor_cancel must be 491 *
539 * called first. 492 * @param h Mesh handle.
493 *
494 * @return Closure given to GNUNET_MESH_get_peers.
495 */
496void *
497GNUNET_MESH_get_peers_cancel (struct GNUNET_MESH_Handle *h);
498
499/**
500 * Request information about tunnels of the running mesh peer.
501 * The callback will be called for every tunnel of the service.
502 * Only one info request (of any kind) can be active at once.
540 * 503 *
541 * WARNING: unstable API, likely to change in the future! 504 * WARNING: unstable API, likely to change in the future!
542 * 505 *
543 * @param h Handle to the mesh peer. 506 * @param h Handle to the mesh peer.
544 * @param callback Function to call with the requested data. 507 * @param callback Function to call with the requested data.
545 * @param callback_cls Closure for @c callback. 508 * @param callback_cls Closure for @c callback.
509 *
510 * @return #GNUNET_OK / #GNUNET_SYSERR
546 */ 511 */
547void 512int
548GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h, 513GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h,
549 GNUNET_MESH_TunnelsCB callback, 514 GNUNET_MESH_TunnelsCB callback,
550 void *callback_cls); 515 void *callback_cls);
@@ -559,22 +524,22 @@ GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h,
559void * 524void *
560GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h); 525GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h);
561 526
527
562/** 528/**
563 * Request information about the running mesh peer. 529 * Request information about a tunnel of the running mesh peer.
564 * The callback will be called for every channel known to the service, 530 * The callback will be called for the tunnel once.
565 * listing all active peers that blong to the channel. 531 * Only one info request (of any kind) can be active at once.
566 *
567 * If called again on the same handle, it will overwrite the previous
568 * callback and cls. To retrieve the cls, monitor_cancel must be
569 * called first.
570 * 532 *
571 * WARNING: unstable API, likely to change in the future! 533 * WARNING: unstable API, likely to change in the future!
572 * 534 *
573 * @param h Handle to the mesh peer. 535 * @param h Handle to the mesh peer.
536 * @param id Peer whose tunnel to examine.
574 * @param callback Function to call with the requested data. 537 * @param callback Function to call with the requested data.
575 * @param callback_cls Closure for @c callback. 538 * @param callback_cls Closure for @c callback.
539 *
540 * @return #GNUNET_OK / #GNUNET_SYSERR
576 */ 541 */
577void 542int
578GNUNET_MESH_get_tunnel (struct GNUNET_MESH_Handle *h, 543GNUNET_MESH_get_tunnel (struct GNUNET_MESH_Handle *h,
579 const struct GNUNET_PeerIdentity *id, 544 const struct GNUNET_PeerIdentity *id,
580 GNUNET_MESH_TunnelCB callback, 545 GNUNET_MESH_TunnelCB callback,
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index 19c453a5a..ec5ddcf71 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -86,6 +86,29 @@ struct GNUNET_MESH_TransmitHandle
86 size_t size; 86 size_t size;
87}; 87};
88 88
89union MeshInfoCB {
90
91 /**
92 * Channel callback.
93 */
94 GNUNET_MESH_ChannelCB channel_cb;
95
96 /**
97 * Monitor callback
98 */
99 GNUNET_MESH_PeersCB peers_cb;
100
101 /**
102 * Monitor callback
103 */
104 GNUNET_MESH_TunnelsCB tunnels_cb;
105
106 /**
107 * Tunnel callback.
108 */
109 GNUNET_MESH_TunnelCB tunnel_cb;
110};
111
89 112
90/** 113/**
91 * Opaque handle to the service. 114 * Opaque handle to the service.
@@ -185,54 +208,14 @@ struct GNUNET_MESH_Handle
185 GNUNET_SCHEDULER_TaskIdentifier reconnect_task; 208 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
186 209
187 /** 210 /**
188 * Monitor callback 211 * Callback for an info task (only one active at a time).
189 */
190 GNUNET_MESH_ChannelsCB channels_cb;
191
192 /**
193 * Monitor callback closure.
194 */ 212 */
195 void *channels_cls; 213 union MeshInfoCB info_cb;
196 214
197 /** 215 /**
198 * Channel callback. 216 * Info callback closure for @c info_cb.
199 */ 217 */
200 GNUNET_MESH_ChannelCB channel_cb; 218 void *info_cls;
201
202 /**
203 * Channel callback closure.
204 */
205 void *channel_cls;
206
207 /**
208 * Monitor callback
209 */
210 GNUNET_MESH_PeersCB peers_cb;
211
212 /**
213 * Monitor callback closure.
214 */
215 void *peers_cls;
216
217 /**
218 * Monitor callback
219 */
220 GNUNET_MESH_TunnelsCB tunnels_cb;
221
222 /**
223 * Monitor callback closure.
224 */
225 void *tunnels_cls;
226
227 /**
228 * Tunnel callback.
229 */
230 GNUNET_MESH_TunnelCB tunnel_cb;
231
232 /**
233 * Tunnel callback closure.
234 */
235 void *tunnel_cls;
236}; 219};
237 220
238 221
@@ -1048,7 +1031,7 @@ process_get_peers (struct GNUNET_MESH_Handle *h,
1048 1031
1049 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Peer messasge received\n"); 1032 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Peer messasge received\n");
1050 1033
1051 if (NULL == h->peers_cb) 1034 if (NULL == h->info_cb.peers_cb)
1052 { 1035 {
1053 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n"); 1036 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n");
1054 return; 1037 return;
@@ -1057,16 +1040,17 @@ process_get_peers (struct GNUNET_MESH_Handle *h,
1057 size = ntohs (message->size); 1040 size = ntohs (message->size);
1058 if (sizeof (struct GNUNET_MESH_LocalInfoPeer) > size) 1041 if (sizeof (struct GNUNET_MESH_LocalInfoPeer) > size)
1059 { 1042 {
1060 h->peers_cb (h->peers_cls, NULL, -1, 0, 0); 1043 h->info_cb.peers_cb (h->info_cls, NULL, -1, 0, 0);
1061 h->peers_cb = NULL; 1044 h->info_cb.peers_cb = NULL;
1062 h->peers_cls = NULL; 1045 h->info_cls = NULL;
1063 return; 1046 return;
1064 } 1047 }
1065 1048
1066 msg = (struct GNUNET_MESH_LocalInfoPeer *) message; 1049 msg = (struct GNUNET_MESH_LocalInfoPeer *) message;
1067 h->peers_cb (h->peers_cls, &msg->destination, 1050 h->info_cb.peers_cb (h->info_cls, &msg->destination,
1068 (int) ntohs (msg->tunnel), (unsigned int ) ntohs (msg->paths), 1051 (int) ntohs (msg->tunnel),
1069 0); 1052 (unsigned int ) ntohs (msg->paths),
1053 0);
1070} 1054}
1071 1055
1072 1056
@@ -1085,7 +1069,7 @@ process_get_tunnels (struct GNUNET_MESH_Handle *h,
1085 1069
1086 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Tunnels messasge received\n"); 1070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Tunnels messasge received\n");
1087 1071
1088 if (NULL == h->tunnels_cb) 1072 if (NULL == h->info_cb.tunnels_cb)
1089 { 1073 {
1090 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n"); 1074 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n");
1091 return; 1075 return;
@@ -1094,19 +1078,16 @@ process_get_tunnels (struct GNUNET_MESH_Handle *h,
1094 size = ntohs (message->size); 1078 size = ntohs (message->size);
1095 if (sizeof (struct GNUNET_MESH_LocalInfoTunnel) > size) 1079 if (sizeof (struct GNUNET_MESH_LocalInfoTunnel) > size)
1096 { 1080 {
1097 h->tunnels_cb (h->tunnel_cls, NULL, 0, 0, 0, 0); 1081 h->info_cb.tunnels_cb (h->info_cls, NULL, 0, 0, 0, 0);
1098 h->tunnels_cb = NULL; 1082 h->info_cb.tunnels_cb = NULL;
1099 h->tunnels_cls = NULL; 1083 h->info_cls = NULL;
1100 return; 1084 return;
1101 } 1085 }
1102 1086
1103 msg = (struct GNUNET_MESH_LocalInfoTunnel *) message; 1087 msg = (struct GNUNET_MESH_LocalInfoTunnel *) message;
1104 h->tunnels_cb (h->tunnel_cls, 1088 h->info_cb.tunnels_cb (h->info_cls, &msg->destination,
1105 &msg->destination, 1089 ntohl (msg->channels), ntohl (msg->connections),
1106 ntohl (msg->channels), 1090 ntohs (msg->estate), ntohs (msg->cstate));
1107 ntohl (msg->connections),
1108 ntohs (msg->estate),
1109 ntohs (msg->cstate));
1110 1091
1111} 1092}
1112 1093
@@ -1131,7 +1112,7 @@ process_get_tunnel (struct GNUNET_MESH_Handle *h,
1131 MESH_ChannelNumber *chns; 1112 MESH_ChannelNumber *chns;
1132 1113
1133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Tunnel messasge received\n"); 1114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Tunnel messasge received\n");
1134 if (NULL == h->tunnel_cb) 1115 if (NULL == h->info_cb.tunnel_cb)
1135 { 1116 {
1136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n"); 1117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n");
1137 return; 1118 return;
@@ -1144,7 +1125,7 @@ process_get_tunnel (struct GNUNET_MESH_Handle *h,
1144 if (esize > msize) 1125 if (esize > msize)
1145 { 1126 {
1146 GNUNET_break_op (0); 1127 GNUNET_break_op (0);
1147 h->tunnel_cb (h->tunnel_cls, NULL, 0, 0, NULL, NULL, 0, 0); 1128 h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0);
1148 goto clean_cls; 1129 goto clean_cls;
1149 } 1130 }
1150 ch_n = ntohl (msg->channels); 1131 ch_n = ntohl (msg->channels);
@@ -1159,20 +1140,20 @@ process_get_tunnel (struct GNUNET_MESH_Handle *h,
1159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u (%u ch, %u conn)\n", 1140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u (%u ch, %u conn)\n",
1160 sizeof (struct GNUNET_MESH_LocalInfoTunnel), 1141 sizeof (struct GNUNET_MESH_LocalInfoTunnel),
1161 sizeof (MESH_ChannelNumber), sizeof (struct GNUNET_HashCode)); 1142 sizeof (MESH_ChannelNumber), sizeof (struct GNUNET_HashCode));
1162 h->tunnel_cb (h->tunnel_cls, NULL, 0, 0, NULL, NULL, 0, 0); 1143 h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0);
1163 goto clean_cls; 1144 goto clean_cls;
1164 } 1145 }
1165 1146
1166 /* Call Callback with tunnel info. */ 1147 /* Call Callback with tunnel info. */
1167 conns = (struct GNUNET_HashCode *) &msg[1]; 1148 conns = (struct GNUNET_HashCode *) &msg[1];
1168 chns = (MESH_ChannelNumber *) &conns[c_n]; 1149 chns = (MESH_ChannelNumber *) &conns[c_n];
1169 h->tunnel_cb (h->tunnel_cls, &msg->destination, 1150 h->info_cb.tunnel_cb (h->info_cls, &msg->destination,
1170 ch_n, c_n, chns, conns, 1151 ch_n, c_n, chns, conns,
1171 ntohs (msg->estate), ntohs (msg->cstate)); 1152 ntohs (msg->estate), ntohs (msg->cstate));
1172 1153
1173clean_cls: 1154clean_cls:
1174 h->tunnel_cb = NULL; 1155 h->info_cb.tunnel_cb = NULL;
1175 h->tunnel_cls = NULL; 1156 h->info_cls = NULL;
1176} 1157}
1177 1158
1178/** 1159/**
@@ -1749,101 +1730,86 @@ send_info_request (struct GNUNET_MESH_Handle *h, uint16_t type)
1749 send_packet (h, &msg, NULL); 1730 send_packet (h, &msg, NULL);
1750} 1731}
1751 1732
1733
1752/** 1734/**
1753 * Request information about the running mesh peer. 1735 * Request information about peers known to the running mesh service.
1754 * The callback will be called for every channel known to the service, 1736 * The callback will be called for every peer known to the service.
1755 * listing all active peers that blong to the channel. 1737 * Only one info request (of any kind) can be active at once.
1756 * 1738 *
1757 * If called again on the same handle, it will overwrite the previous
1758 * callback and cls. To retrieve the cls, monitor_cancel must be
1759 * called first.
1760 * 1739 *
1761 * WARNING: unstable API, likely to change in the future! 1740 * WARNING: unstable API, likely to change in the future!
1762 * 1741 *
1763 * @param h Handle to the mesh peer. 1742 * @param h Handle to the mesh peer.
1764 * @param callback Function to call with the requested data. 1743 * @param callback Function to call with the requested data.
1765 * @param callback_cls Closure for @c callback. 1744 * @param callback_cls Closure for @c callback.
1745 *
1746 * @return #GNUNET_OK / #GNUNET_SYSERR
1766 */ 1747 */
1767void 1748int
1768GNUNET_MESH_get_channels (struct GNUNET_MESH_Handle *h, 1749GNUNET_MESH_get_peers (struct GNUNET_MESH_Handle *h,
1769 GNUNET_MESH_ChannelsCB callback, 1750 GNUNET_MESH_PeersCB callback,
1770 void *callback_cls) 1751 void *callback_cls)
1771{ 1752{
1772 send_info_request (h, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS); 1753 if (NULL != h->info_cb.peers_cb)
1773 h->channels_cb = callback; 1754 {
1774 h->channels_cls = callback_cls; 1755 GNUNET_break (0);
1756 return GNUNET_SYSERR;
1757 }
1758 send_info_request (h, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEERS);
1759 h->info_cb.peers_cb = callback;
1760 h->info_cls = callback_cls;
1761 return GNUNET_OK;
1775} 1762}
1776 1763
1777 1764
1778/** 1765/**
1779 * Cancel a monitor request. The monitor callback will not be called. 1766 * Cancel a peer info request. The callback will not be called (anymore).
1780 * 1767 *
1781 * WARNING: unstable API, likely to change in the future! 1768 * WARNING: unstable API, likely to change in the future!
1782 * 1769 *
1783 * @param h Mesh handle. 1770 * @param h Mesh handle.
1784 * 1771 *
1785 * @return Closure given to GNUNET_MESH_monitor, if any. 1772 * @return Closure given to GNUNET_MESH_get_peers.
1786 */ 1773 */
1787void * 1774void *
1788GNUNET_MESH_get_channels_cancel (struct GNUNET_MESH_Handle *h) 1775GNUNET_MESH_get_peers_cancel (struct GNUNET_MESH_Handle *h)
1789{ 1776{
1790 void *cls; 1777 void *cls;
1791 1778
1792 cls = h->channels_cls; 1779 cls = h->info_cls;
1793 h->channels_cb = NULL; 1780 h->info_cb.peers_cb = NULL;
1794 h->channels_cls = NULL; 1781 h->info_cls = NULL;
1795 return cls; 1782 return cls;
1796} 1783}
1797 1784
1798 1785
1799/** 1786/**
1800 * Request information about the running mesh peer. 1787 * Request information about tunnels of the running mesh peer.
1801 * The callback will be called for every peer known to the service. 1788 * The callback will be called for every tunnel of the service.
1802 * 1789 * Only one info request (of any kind) can be active at once.
1803 * If called again on the same handle, it will overwrite the previous
1804 * callback and cls. To retrieve the cls, monitor_cancel must be
1805 * called first.
1806 * 1790 *
1807 * WARNING: unstable API, likely to change in the future! 1791 * WARNING: unstable API, likely to change in the future!
1808 * 1792 *
1809 * @param h Handle to the mesh peer. 1793 * @param h Handle to the mesh peer.
1810 * @param callback Function to call with the requested data. 1794 * @param callback Function to call with the requested data.
1811 * @param callback_cls Closure for @c callback. 1795 * @param callback_cls Closure for @c callback.
1812 */
1813void
1814GNUNET_MESH_get_peers (struct GNUNET_MESH_Handle *h,
1815 GNUNET_MESH_PeersCB callback,
1816 void *callback_cls)
1817{
1818 send_info_request (h, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEERS);
1819 h->peers_cb = callback;
1820 h->peers_cls = callback_cls;
1821}
1822
1823
1824
1825/**
1826 * Request information about the running mesh peer.
1827 * The callback will be called for every tunnel known to the service.
1828 *
1829 * If called again on the same handle, it will overwrite the previous
1830 * callback and cls. To retrieve the cls, monitor_cancel must be
1831 * called first.
1832 * 1796 *
1833 * WARNING: unstable API, likely to change in the future! 1797 * @return #GNUNET_OK / #GNUNET_SYSERR
1834 *
1835 * @param h Handle to the mesh peer.
1836 * @param callback Function to call with the requested data.
1837 * @param callback_cls Closure for @c callback.
1838 */ 1798 */
1839void 1799int
1840GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h, 1800GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h,
1841 GNUNET_MESH_TunnelsCB callback, 1801 GNUNET_MESH_TunnelsCB callback,
1842 void *callback_cls) 1802 void *callback_cls)
1843{ 1803{
1804 if (NULL != h->info_cb.tunnels_cb)
1805 {
1806 GNUNET_break (0);
1807 return GNUNET_SYSERR;
1808 }
1844 send_info_request (h, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS); 1809 send_info_request (h, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS);
1845 h->tunnels_cb = callback; 1810 h->info_cb.tunnels_cb = callback;
1846 h->tunnels_cls = callback_cls; 1811 h->info_cls = callback_cls;
1812 return GNUNET_OK;
1847} 1813}
1848 1814
1849 1815
@@ -1852,16 +1818,16 @@ GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h,
1852 * 1818 *
1853 * @param h Mesh handle. 1819 * @param h Mesh handle.
1854 * 1820 *
1855 * @return Closure given to GNUNET_MESH_monitor, if any. 1821 * @return Closure given to GNUNET_MESH_get_tunnels.
1856 */ 1822 */
1857void * 1823void *
1858GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h) 1824GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h)
1859{ 1825{
1860 void *cls; 1826 void *cls;
1861 1827
1862 h->tunnels_cb = NULL; 1828 h->info_cb.tunnels_cb = NULL;
1863 cls = h->tunnels_cls; 1829 cls = h->info_cls;
1864 h->tunnels_cls = NULL; 1830 h->info_cls = NULL;
1865 1831
1866 return cls; 1832 return cls;
1867} 1833}
@@ -1869,21 +1835,20 @@ GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h)
1869 1835
1870 1836
1871/** 1837/**
1872 * Request information about the running mesh peer. 1838 * Request information about a tunnel of the running mesh peer.
1873 * The callback will be called for every channel known to the service, 1839 * The callback will be called for the tunnel once.
1874 * listing all active peers that blong to the channel. 1840 * Only one info request (of any kind) can be active at once.
1875 *
1876 * If called again on the same handle, it will overwrite the previous
1877 * callback and cls. To retrieve the cls, monitor_cancel must be
1878 * called first.
1879 * 1841 *
1880 * WARNING: unstable API, likely to change in the future! 1842 * WARNING: unstable API, likely to change in the future!
1881 * 1843 *
1882 * @param h Handle to the mesh peer. 1844 * @param h Handle to the mesh peer.
1845 * @param id Peer whose tunnel to examine.
1883 * @param callback Function to call with the requested data. 1846 * @param callback Function to call with the requested data.
1884 * @param callback_cls Closure for @c callback. 1847 * @param callback_cls Closure for @c callback.
1848 *
1849 * @return #GNUNET_OK / #GNUNET_SYSERR
1885 */ 1850 */
1886void 1851int
1887GNUNET_MESH_get_tunnel (struct GNUNET_MESH_Handle *h, 1852GNUNET_MESH_get_tunnel (struct GNUNET_MESH_Handle *h,
1888 const struct GNUNET_PeerIdentity *id, 1853 const struct GNUNET_PeerIdentity *id,
1889 GNUNET_MESH_TunnelCB callback, 1854 GNUNET_MESH_TunnelCB callback,
@@ -1891,13 +1856,20 @@ GNUNET_MESH_get_tunnel (struct GNUNET_MESH_Handle *h,
1891{ 1856{
1892 struct GNUNET_MESH_LocalInfo msg; 1857 struct GNUNET_MESH_LocalInfo msg;
1893 1858
1859 if (NULL != h->info_cb.tunnel_cb)
1860 {
1861 GNUNET_break (0);
1862 return GNUNET_SYSERR;
1863 }
1864
1894 memset (&msg, 0, sizeof (msg)); 1865 memset (&msg, 0, sizeof (msg));
1895 msg.header.size = htons (sizeof (msg)); 1866 msg.header.size = htons (sizeof (msg));
1896 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL); 1867 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL);
1897 msg.peer = *id; 1868 msg.peer = *id;
1898 send_packet (h, &msg.header, NULL); 1869 send_packet (h, &msg.header, NULL);
1899 h->tunnel_cb = callback; 1870 h->info_cb.tunnel_cb = callback;
1900 h->tunnel_cls = callback_cls; 1871 h->info_cls = callback_cls;
1872 return GNUNET_OK;
1901} 1873}
1902 1874
1903 1875
@@ -1912,8 +1884,10 @@ GNUNET_MESH_get_tunnel (struct GNUNET_MESH_Handle *h,
1912 * @param channel_number Channel number. 1884 * @param channel_number Channel number.
1913 * @param callback Function to call with the requested data. 1885 * @param callback Function to call with the requested data.
1914 * @param callback_cls Closure for @c callback. 1886 * @param callback_cls Closure for @c callback.
1887 *
1888 * @return #GNUNET_OK / #GNUNET_SYSERR
1915 */ 1889 */
1916void 1890int
1917GNUNET_MESH_show_channel (struct GNUNET_MESH_Handle *h, 1891GNUNET_MESH_show_channel (struct GNUNET_MESH_Handle *h,
1918 struct GNUNET_PeerIdentity *initiator, 1892 struct GNUNET_PeerIdentity *initiator,
1919 unsigned int channel_number, 1893 unsigned int channel_number,
@@ -1922,14 +1896,21 @@ GNUNET_MESH_show_channel (struct GNUNET_MESH_Handle *h,
1922{ 1896{
1923 struct GNUNET_MESH_LocalInfo msg; 1897 struct GNUNET_MESH_LocalInfo msg;
1924 1898
1899 if (NULL != h->info_cb.channel_cb)
1900 {
1901 GNUNET_break (0);
1902 return GNUNET_SYSERR;
1903 }
1904
1925 msg.header.size = htons (sizeof (msg)); 1905 msg.header.size = htons (sizeof (msg));
1926 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL); 1906 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL);
1927 msg.peer = *initiator; 1907 msg.peer = *initiator;
1928 msg.channel_id = htonl (channel_number); 1908 msg.channel_id = htonl (channel_number);
1929// msg.reserved = 0; 1909// msg.reserved = 0;
1930 send_packet (h, &msg.header, NULL); 1910 send_packet (h, &msg.header, NULL);
1931 h->channel_cb = callback; 1911 h->info_cb.channel_cb = callback;
1932 h->channel_cls = callback_cls; 1912 h->info_cls = callback_cls;
1913 return GNUNET_OK;
1933} 1914}
1934 1915
1935 1916