X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fmesh%2Fgnunet-service-mesh_tunnel.h;h=369713e660a86d5856c94d6403ede42e4cf60f97;hb=1ef7f26b7579ae2a6256751a3f5ebfbf60afbb2f;hp=afa0ee169cf3313e8ec98b0bb6001a9f1d2a3d7d;hpb=50f061e6ca2df0c9473b87f79beb5225b1400f03;p=oweals%2Fgnunet.git diff --git a/src/mesh/gnunet-service-mesh_tunnel.h b/src/mesh/gnunet-service-mesh_tunnel.h index afa0ee169..369713e66 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.h +++ b/src/mesh/gnunet-service-mesh_tunnel.h @@ -40,38 +40,35 @@ extern "C" #include "platform.h" #include "gnunet_util_lib.h" -#include "gnunet-service-mesh_channel.h" -#include "gnunet-service-mesh_connection.h" - /** * All the states a tunnel can be in. */ -enum MeshTunnelState +enum MeshTunnel3State { /** * Uninitialized status, should never appear in operation. */ - MESH_TUNNEL_NEW, + MESH_TUNNEL3_NEW, /** * Path to the peer not known yet */ - MESH_TUNNEL_SEARCHING, + MESH_TUNNEL3_SEARCHING, /** * Request sent, not yet answered. */ - MESH_TUNNEL_WAITING, + MESH_TUNNEL3_WAITING, /** * Peer connected and ready to accept data */ - MESH_TUNNEL_READY, + MESH_TUNNEL3_READY, /** * Peer connected previosly but not responding */ - MESH_TUNNEL_RECONNECTING + MESH_TUNNEL3_RECONNECTING }; /** @@ -79,6 +76,12 @@ enum MeshTunnelState */ struct MeshTunnel3; + +#include "gnunet-service-mesh_channel.h" +#include "gnunet-service-mesh_connection.h" +#include "gnunet-service-mesh_peer.h" + + /******************************************************************************/ /******************************** API ***********************************/ /******************************************************************************/ @@ -87,13 +90,11 @@ struct MeshTunnel3; * Initialize tunnel subsystem. * * @param c Configuration handle. - * @param id Peer identity. * @param key ECC private key, to derive all other keys and do crypto. */ void GMT_init (const struct GNUNET_CONFIGURATION_Handle *c, - const struct GNUNET_PeerIdentity *id, - const struct GNUNET_CRYPTO_EccPrivateKey *key); + const struct GNUNET_CRYPTO_EddsaPrivateKey *key); /** * Shut down the tunnel subsystem. @@ -101,6 +102,14 @@ GMT_init (const struct GNUNET_CONFIGURATION_Handle *c, void GMT_shutdown (void); +/** + * Create a tunnel. + * + * @param destination Peer this tunnel is towards. + */ +struct MeshTunnel3 * +GMT_new (struct MeshPeer *destination); + /** * Tunnel is empty: destroy it. * @@ -140,7 +149,7 @@ GMT_destroy (struct MeshTunnel3 *t); * @param state New state. */ void -GMT_change_state (struct MeshTunnel3* t, enum MeshTunnelState state); +GMT_change_state (struct MeshTunnel3* t, enum MeshTunnel3State state); /** * Add a connection to a tunnel. @@ -151,7 +160,6 @@ GMT_change_state (struct MeshTunnel3* t, enum MeshTunnelState state); void GMT_add_connection (struct MeshTunnel3 *t, struct MeshConnection *c); - /** * Remove a connection from a tunnel. * @@ -161,6 +169,49 @@ GMT_add_connection (struct MeshTunnel3 *t, struct MeshConnection *c); void GMT_remove_connection (struct MeshTunnel3 *t, struct MeshConnection *c); +/** + * Add a channel to a tunnel. + * + * @param t Tunnel. + * @param ch Channel. + */ +void +GMT_add_channel (struct MeshTunnel3 *t, struct MeshChannel *ch); + +/** + * Remove a channel from a tunnel. + * + * @param t Tunnel. + * @param ch Channel. + */ +void +GMT_remove_channel (struct MeshTunnel3 *t, struct MeshChannel *ch); + +/** + * Search for a channel by global ID. + * + * @param t Tunnel containing the channel. + * @param chid Public channel number. + * + * @return channel handler, NULL if doesn't exist + */ +struct MeshChannel * +GMT_get_channel (struct MeshTunnel3 *t, MESH_ChannelNumber chid); + +/** + * Decrypt and demultiplex by message type. Call appropriate handler + * for a message + * towards a channel of a local tunnel. + * + * @param t Tunnel this message came on. + * @param msg Message header. + * @param fwd Is this message fwd? + */ +void +GMT_handle_encrypted (struct MeshTunnel3 *t, + const struct GNUNET_MESH_Encrypted *msg, + int fwd); + /** * Cache a message to be sent once tunnel is online. * @@ -175,6 +226,28 @@ GMT_queue_data (struct MeshTunnel3 *t, struct GNUNET_MessageHeader *msg, int fwd); +/** + * Send all cached messages that we can, tunnel is online. + * + * @param t Tunnel that holds the messages. + * @param fwd Is this fwd? + */ +void +GMT_send_queued_data (struct MeshTunnel3 *t, int fwd); + +/** + * @brief Use the given path for the tunnel. + * Update the next and prev hops (and RCs). + * (Re)start the path refresh in case the tunnel is locally owned. + * + * @param t Tunnel to update. + * @param p Path to use. + * + * @return Connection created. + */ +struct MeshConnection * +GMT_use_path (struct MeshTunnel3 *t, struct MeshPeerPath *p); + /** * Count established (ready) connections of a tunnel. * @@ -195,8 +268,20 @@ GMT_count_connections (struct MeshTunnel3 *t); unsigned int GMT_count_channels (struct MeshTunnel3 *t); +/** + * Get the state of a tunnel. + * + * @param t Tunnel. + * + * @return Tunnel's state. + */ +enum MeshTunnel3State +GMT_get_state (struct MeshTunnel3 *t); + /** * Get the total buffer space for a tunnel. + * + * FIXME get a ch parameter in case of loopback tunnels * * @param t Tunnel. * @param fwd Is this for FWD traffic? @@ -206,6 +291,104 @@ GMT_count_channels (struct MeshTunnel3 *t); unsigned int GMT_get_buffer (struct MeshTunnel3 *t, int fwd); +/** + * Get the tunnel's destination. + * + * @param t Tunnel. + * + * @return ID of the destination peer. + */ +const struct GNUNET_PeerIdentity * +GMT_get_destination (struct MeshTunnel3 *t); + +/** + * Get the tunnel's next free Channel ID. + * + * @param t Tunnel. + * + * @return ID of a channel free to use. + */ +MESH_ChannelNumber +GMT_get_next_chid (struct MeshTunnel3 *t); + +/** + * Send ACK on one or more channels due to buffer in connections.. + * + * @param t Channel which has some free buffer space. + * @param fwd Is this for FWD traffic? (ACK goes to root) + */ +void +GMT_unchoke_channels (struct MeshTunnel3 *t, int fwd); + +/** + * Send ACK on one or more connections due to buffer space to the client. + * + * Iterates all connections of the tunnel and sends ACKs appropriately. + * + * @param ch Channel which has some free buffer space. + * @param fwd Is this in for FWD traffic? (ACK goes dest->root) + */ +void +GMT_send_acks (struct MeshTunnel3 *t, int fwd); + +/** + * Sends an already built message on a tunnel, encrypting it and + * choosing the best connection. + * + * @param message Message to send. Function modifies it. + * @param t Tunnel on which this message is transmitted. + * @param ch Channel on which this message is transmitted. + * @param fwd Is this a fwd message? + */ +void +GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message, + struct MeshTunnel3 *t, + struct MeshChannel *ch, + int fwd); + +/** + * Is the tunnel directed towards the local peer? + * + * @param t Tunnel. + * + * @return GNUNET_YES if it is loopback. + */ +int +GMT_is_loopback (const struct MeshTunnel3 *t); + +/** + * Is the tunnel using this path already? + * + * @param t Tunnel. + * @param p Path. + * + * @return GNUNET_YES a connection uses this path. + */ +int +GMT_is_path_used (const struct MeshTunnel3 *t, const struct MeshPeerPath *p); + +/** + * Get a cost of a path for a tunnel considering existing connections. + * + * @param t Tunnel. + * @param path Candidate path. + * + * @return Cost of the path (path length + number of overlapping nodes) + */ +unsigned int +GMT_get_path_cost (const struct MeshTunnel3 *t, + const struct MeshPeerPath *path); + +/** + * Get the static string for the peer this tunnel is directed. + * + * @param t Tunnel. + * + * @return Static string the destination peer's ID. + */ +const char * +GMT_2s (const struct MeshTunnel3 *t); + #if 0 /* keep Emacsens' auto-indent happy */ { #endif @@ -215,4 +398,4 @@ GMT_get_buffer (struct MeshTunnel3 *t, int fwd); /* ifndef GNUNET_MESH_SERVICE_TUNNEL_H */ #endif -/* end of gnunet-mesh-service_tunnel.h */ \ No newline at end of file +/* end of gnunet-mesh-service_tunnel.h */