extending bandwidth tracker api to support notifications
[oweals/gnunet.git] / src / include / gnunet_mesh_service.h
index 25b3809322859fa66c039ac2761dcbdad19d626e..21a51b7b22b1e4e199bb7cd5a9b0caae2a85a507 100644 (file)
@@ -59,8 +59,13 @@ struct GNUNET_MESH_Channel;
  * Channel options.
  * Second line indicates filed in the MeshChannelInfo union carrying the answer.
  */
-enum MeshOption
+enum GNUNET_MESH_ChannelOption
 {
+  /**
+   * Default options: unreliable, default buffering, not out of order.
+   */
+  GNUNET_MESH_OPTION_DEFAULT    = 0x0,
+
   /**
    * Disable buffering on intermediate nodes (for minimum latency).
    * Yes/No.
@@ -81,6 +86,7 @@ enum MeshOption
 
   /**
    * Who is the peer at the other end of the channel.
+   * Only for use in @c GNUNET_MESH_channel_get_info
    * struct GNUNET_PeerIdentity *peer
    */
   GNUNET_MESH_OPTION_PEER       = 0x8
@@ -138,14 +144,17 @@ struct GNUNET_MESH_MessageHandler
  * Method called whenever another peer has added us to a channel
  * the other peer initiated.
  * Only called (once) upon reception of data with a message type which was
- * subscribed to in #GNUNET_MESH_connect. A call to #GNUNET_MESH_channel_destroy
- * causes te channel to be ignored and no further notifications are sent about
- * the same channel.
+ * subscribed to in #GNUNET_MESH_connect.
+ *
+ * A call to #GNUNET_MESH_channel_destroy causes te channel to be ignored. In
+ * this case the handler MUST return NULL.
  *
  * @param cls closure
  * @param channel new handle to the channel
  * @param initiator peer that started the channel
  * @param port Port this channel is for.
+ * @param options MeshOption flag field, with all active option bits set to 1.
+ *
  * @return initial channel context for the channel
  *         (can be NULL -- that's not an error)
  */
@@ -156,7 +165,9 @@ typedef void *(GNUNET_MESH_InboundChannelNotificationHandler) (void *cls,
                                                                const struct
                                                                GNUNET_PeerIdentity
                                                                * initiator,
-                                                               uint32_t port);
+                                                               uint32_t port,
+                                                               enum GNUNET_MESH_ChannelOption
+                                                               options);
 
 
 /**
@@ -229,8 +240,8 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle);
  * @param channel_ctx client's channel context to associate with the channel
  * @param peer peer identity the channel should go to
  * @param port Port number.
- * @param nobuffer Flag for disabling buffering on relay nodes.
- * @param reliable Flag for end-to-end reliability.
+ * @param options MeshOption flag field, with all desired option bits set to 1.
+ *
  * @return handle to the channel
  */
 struct GNUNET_MESH_Channel *
@@ -238,8 +249,7 @@ GNUNET_MESH_channel_create (struct GNUNET_MESH_Handle *h,
                             void *channel_ctx,
                             const struct GNUNET_PeerIdentity *peer,
                             uint32_t port,
-                            int nobuffer,
-                            int reliable);
+                            enum GNUNET_MESH_ChannelOption options);
 
 
 /**
@@ -269,7 +279,7 @@ union GNUNET_MESH_ChannelInfo
   /**
    * Peer on the other side of the channel
    */
-  const struct GNUNET_PeerIdentity *peer;
+  const struct GNUNET_PeerIdentity peer;
 };
 
 
@@ -283,7 +293,7 @@ union GNUNET_MESH_ChannelInfo
  */
 const union GNUNET_MESH_ChannelInfo *
 GNUNET_MESH_channel_get_info (struct GNUNET_MESH_Channel *channel,
-                              enum MeshOption option, ...);
+                              enum GNUNET_MESH_ChannelOption option, ...);
 
 
 /**
@@ -352,87 +362,189 @@ GNUNET_MESH_receive_done (struct GNUNET_MESH_Channel *channel);
 /* normal mesh applications.                                                  */
 /******************************************************************************/
 
+
+/**
+ * Method called to retrieve information about a specific channel the mesh peer
+ * is aware of, including all transit nodes.
+ *
+ * @param cls Closure.
+ * @param root Root of the channel.
+ * @param dest Destination of the channel.
+ * @param port Destination port of the channel.
+ * @param root_channel_number Local number for root, if known.
+ * @param dest_channel_number Local number for dest, if known.
+ * @param public_channel_numbe Number for P2P, always known.
+ */
+typedef void (*GNUNET_MESH_ChannelCB) (void *cls,
+                                       const struct GNUNET_PeerIdentity *root,
+                                       const struct GNUNET_PeerIdentity *dest,
+                                       uint32_t port,
+                                       uint32_t root_channel_number,
+                                       uint32_t dest_channel_number,
+                                       uint32_t public_channel_number);
+
 /**
- * Method called to retrieve information about each channel the mesh peer
- * is aware of.
+ * Method called to retrieve information about all peers in MESH, called
+ * once per peer.
+ *
+ * After last peer has been reported, an additional call with NULL is done.
  *
  * @param cls Closure.
- * @param channel_number Channel number.
- * @param origin that started the channel (owner).
- * @param target other endpoint of the channel
+ * @param peer Peer, or NULL on "EOF".
+ * @param tunnel Do we have a tunnel towards this peer?
+ * @param n_paths Number of known paths towards this peer.
+ * @param best_path How long is the best path?
+ *                  (0 = unknown, 1 = ourselves, 2 = neighbor)
  */
-typedef void (*GNUNET_MESH_ChannelsCB) (void *cls,
-                                        uint32_t channel_number,
-                                        const struct GNUNET_PeerIdentity *origin,
-                                        const struct GNUNET_PeerIdentity *target);
+typedef void (*GNUNET_MESH_PeersCB) (void *cls,
+                                     const struct GNUNET_PeerIdentity *peer,
+                                     int tunnel, unsigned int n_paths,
+                                     unsigned int best_path);
 
 
 /**
- * Method called to retrieve information about a specific channel the mesh peer
- * is aware of, including all transit nodes.
+ * Method called to retrieve information about all tunnels in MESH, called
+ * once per tunnel.
+ *
+ * After last tunnel has been reported, an additional call with NULL is done.
  *
  * @param cls Closure.
- * @param peer Peer in the channel's tree.
- * @param parent Parent of the current peer. All 0 when peer is root.
+ * @param peer Destination peer, or NULL on "EOF".
+ * @param channels Number of channels.
+ * @param connections Number of connections.
+ * @param estate Encryption state.
+ * @param cstate Connectivity state.
  */
-typedef void (*GNUNET_MESH_ChannelCB) (void *cls,
-                                      const struct GNUNET_PeerIdentity *peer,
-                                      const struct GNUNET_PeerIdentity *parent);
+typedef void (*GNUNET_MESH_TunnelsCB) (void *cls,
+                                       const struct GNUNET_PeerIdentity *peer,
+                                       unsigned int channels,
+                                       unsigned int connections,
+                                       uint16_t estate,
+                                       uint16_t cstate);
+
 
 
 /**
- * Request information about the running mesh peer.
- * The callback will be called for every channel known to the service,
- * listing all active peers that belong to the channel.
+ * Method called to retrieve information about a specific tunnel the mesh peer
+ * has established, o`r is trying to establish.
  *
- * If called again on the same handle, it will overwrite the previous
- * callback and cls. To retrieve the cls, monitor_cancel must be
- * called first.
+ * @param cls Closure.
+ * @param peer Peer towards whom the tunnel is directed.
+ * @param n_channels Number of channels.
+ * @param n_connections Number of connections.
+ * @param channels Channels.
+ * @param connections Connections.
+ * @param estate Encryption state.
+ * @param cstate Connectivity state.
+ */
+typedef void (*GNUNET_MESH_TunnelCB) (void *cls,
+                                      const struct GNUNET_PeerIdentity *peer,
+                                      unsigned int n_channels,
+                                      unsigned int n_connections,
+                                      uint32_t *channels,
+                                      struct GNUNET_HashCode *connections,
+                                      unsigned int estate,
+                                      unsigned int cstate);
+
+/**
+ * Request information about a specific channel of the running mesh peer.
  *
  * WARNING: unstable API, likely to change in the future!
  *
  * @param h Handle to the mesh peer.
+ * @param peer ID of the other end of the channel.
+ * @param channel_number Channel number.
  * @param callback Function to call with the requested data.
  * @param callback_cls Closure for @c callback.
  */
 void
-GNUNET_MESH_get_channels (struct GNUNET_MESH_Handle *h,
-                         GNUNET_MESH_ChannelsCB callback,
+GNUNET_MESH_get_channel (struct GNUNET_MESH_Handle *h,
+                         struct GNUNET_PeerIdentity *peer,
+                         uint32_t channel_number,
+                         GNUNET_MESH_ChannelCB callback,
                          void *callback_cls);
 
 
 /**
- * Request information about a specific channel of the running mesh peer.
+ * Request information about peers known to the running mesh service.
+ * The callback will be called for every peer known to the service.
+ * 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 initiator ID of the owner of the channel.
- * @param channel_number Channel number.
  * @param callback Function to call with the requested data.
  * @param callback_cls Closure for @c callback.
+ *
+ * @return #GNUNET_OK / #GNUNET_SYSERR
  */
-void
-GNUNET_MESH_show_channel (struct GNUNET_MESH_Handle *h,
-                         struct GNUNET_PeerIdentity *initiator,
-                         uint32_t channel_number,
-                         GNUNET_MESH_ChannelCB callback,
-                         void *callback_cls);
+int
+GNUNET_MESH_get_peers (struct GNUNET_MESH_Handle *h,
+                       GNUNET_MESH_PeersCB callback,
+                       void *callback_cls);
 
+/**
+ * Cancel a peer info request. The callback will not be called (anymore).
+ *
+ * WARNING: unstable API, likely to change in the future!
+ *
+ * @param h Mesh handle.
+ *
+ * @return Closure given to GNUNET_MESH_get_peers.
+ */
+void *
+GNUNET_MESH_get_peers_cancel (struct GNUNET_MESH_Handle *h);
 
 /**
- * Cancel a monitor request. The monitor callback will not be called.
+ * 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.
  *
  * WARNING: unstable API, likely to change in the future!
  *
+ * @param h Handle to the mesh peer.
+ * @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_tunnels (struct GNUNET_MESH_Handle *h,
+                         GNUNET_MESH_TunnelsCB callback,
+                         void *callback_cls);
+
+/**
+ * Cancel a monitor request. The monitor callback will not be called.
+ *
  * @param h Mesh handle.
  *
  * @return Closure given to GNUNET_MESH_monitor, if any.
  */
 void *
-GNUNET_MESH_get_channels_cancel (struct GNUNET_MESH_Handle *h);
+GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h);
 
 
+/**
+ * Request information about a tunnel of 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_tunnel (struct GNUNET_MESH_Handle *h,
+                        const struct GNUNET_PeerIdentity *id,
+                        GNUNET_MESH_TunnelCB callback,
+                        void *callback_cls);
+
 /**
  * Create a message queue for a mesh channel.
  * The message queue can only be used to transmit messages,