From 83e0dcf80c9ade6c9e83c33b4add635a258bdbb4 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Thu, 7 Apr 2011 11:36:07 +0000 Subject: [PATCH] Work in progress --- src/mesh/gnunet-service-mesh.c | 134 ++++++++++++++++++++------------- src/mesh/mesh_api_new.c | 125 ++++++++++++++++++++++++++++++ 2 files changed, 205 insertions(+), 54 deletions(-) create mode 100644 src/mesh/mesh_api_new.c diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 8332100b6..e927d2737 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -23,6 +23,14 @@ * @brief GNUnet MESH service * @author Bartlomiej Polot * + * STRUCTURE: + * - MESH NETWORK MESSAGES + * - DATA STRUCTURES + * - GLOBAL VARIABLES + * - MESH NETWORK HANDLES + * - MESH LOCAL HANDLES + * - MAIN FUNCTIONS (main & run) + * * TODO: * - soft stateing (keep-alive (CHANGE?) / timeout / disconnect) -- not a message issue * - error reporting (CREATE/CHANGE/ADD/DEL?) -- new message! @@ -52,12 +60,14 @@ struct GNUNET_MESH_ManipulatePath /** * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_[CREATE|CHANGE|ADD|DEL] * - * Size: sizeof(struct GNUNET_MESH_ManipulatePath) + path_length * sizeof (struct GNUNET_PeerIdentity) + * Size: sizeof(struct GNUNET_MESH_ManipulatePath) + + * path_length * sizeof (struct GNUNET_PeerIdentity) */ struct GNUNET_MessageHeader header; /** - * (global) Id of the tunnel this path belongs to, unique in conjunction with the origin. + * Global id of the tunnel this path belongs to, + * unique in conjunction with the origin. */ uint32_t tid GNUNET_PACKED; @@ -76,7 +86,7 @@ struct GNUNET_MESH_ManipulatePath * path_length structs defining the *whole* path from the origin [0] to the * final destination [path_length-1]. */ - // struct GNUNET_PeerIdentity peers[path_length]; + /* struct GNUNET_PeerIdentity peers[path_length]; */ }; /** @@ -215,12 +225,8 @@ enum PeerState /** * Peer connected previosly but not responding */ - MESH_PEER_UNAVAILABLE, + MESH_PEER_RECONNECTING, - /** - * Peer requested but not ever connected - */ - MESH_PEER_UNREACHABLE }; /** @@ -231,7 +237,7 @@ struct PeerInfo /** * ID of the peer */ - GNUNET_PEER_Id id; + GNUNET_PEER_Id id; /** * Is the peer reachable? Is the peer even connected? @@ -241,14 +247,15 @@ struct PeerInfo /** * Who to send the data to --- what about multiple (alternate) paths? */ - GNUNET_PEER_Id first_hop; + GNUNET_PEER_Id first_hop; /** * Max data rate to this peer */ - uint32_t max_speed; + uint32_t max_speed; }; +typedef uint32_t MESH_PathID; /** * Information regarding a path */ @@ -257,19 +264,20 @@ struct Path /** * Id of the path, in case it's needed */ - uint32_t id; + MESH_PathID id; /** * Whether the path is serving traffic in a tunnel or is a backup */ - int in_use; + int in_use; /** * List of all the peers that form the path from origin to target */ - GNUNET_PEER_Id *peers; + GNUNET_PEER_Id *peers; }; +typedef uint32_t MESH_TunnelID; /** * Struct containing all information regarding a tunnel * For an intermediate node the improtant info used will be: @@ -282,34 +290,36 @@ struct Path struct MESH_tunnel { - struct MESH_tunnel *next; - - struct MESH_tunnel *prev; + /** + * Double linked list + */ + struct MESH_tunnel *next; + struct MESH_tunnel *prev; /** * Origin ID: Node that created the tunnel */ - GNUNET_PEER_Id oid; + GNUNET_PEER_Id oid; /** * Tunnel number (unique for a given oid) */ - uint32_t tid; + MESH_TunnelID tid; /** - * Whether the tunnel is in a state to transmit data + * Whether the tunnel is in a state to transmit data */ - int ready; + int ready; /** * Minimal speed for this tunnel in kb/s */ - uint32_t speed_min; + uint32_t speed_min; /** * Maximal speed for this tunnel in kb/s */ - uint32_t speed_max; + uint32_t speed_max; /** * Last time the tunnel was used @@ -319,20 +329,20 @@ struct MESH_tunnel /** * Peers in the tunnel, for future optimizations */ - struct PeerInfo *peers; + struct PeerInfo *peers; /** * Paths (used and backup) */ - struct Path *paths; + struct Path *paths; /** - * Messages ready to transmit??? -- real queues needed + * Messages ready to transmit??? -- FIXME real queues needed */ struct GNUNET_MessageHeader *msg_out; /** - * Messages received and not processed??? -- real queues needed + * Messages received and not processed??? -- FIXME real queues needed */ struct GNUNET_MessageHeader *msg_in; @@ -348,32 +358,46 @@ struct MESH_tunnel */ struct Client { + /** + * Double linked list + */ + struct Client *next; + struct Client *prev; - struct Client *next; - - struct Client *prev; - - struct MESH_tunnel *my_tunnels_head; - - struct MESH_tunnel *my_tunnels_tail; + /** + * Tunnels that belong to this client + */ + struct MESH_tunnel *my_tunnels_head; + struct MESH_tunnel *my_tunnels_tail; /** * If this tunnel was created by a local client, what's its handle? */ struct GNUNET_SERVER_Client *handle; - unsigned int messages_subscribed_counter; - - uint16_t *messages_subscribed; + /** + * Messages that this client has declared interest in + */ + uint16_t *messages_subscribed; + unsigned int messages_subscribed_counter; }; +/******************************************************************************/ +/*********************** GLOBAL VARIABLES ****************************/ +/******************************************************************************/ -// static struct MESH_tunnel *tunnel_participation_head; - -// static struct MESH_tunnel *tunnel_participation_tail; - +/** + * All the clients + */ +// static struct Client clients_head; +// static struct Client clients_tail; +/** + * All the tunnels + */ +// static struct MESH_tunnel *tunnel_participation_head; +// static struct MESH_tunnel *tunnel_participation_tail; /******************************************************************************/ @@ -549,8 +573,6 @@ handle_local_network_traffic (void *cls, */ static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { {&handle_local_new_client, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0}, - {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ANY, 0}, - {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ALL, 0}, {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD, 0}, {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL, 0}, {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE, sizeof(struct GNUNET_MESH_ConnectPeerByType)}, @@ -608,6 +630,10 @@ core_disconnect (void *cls, return; } +/******************************************************************************/ +/************************ MAIN FUNCTIONS ****************************/ +/******************************************************************************/ + /** * Process mesh requests. FIXME NON FUNCTIONAL, SKELETON * @@ -624,17 +650,17 @@ run (void *cls, GNUNET_SERVER_add_handlers (server, plugin_handlers); GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); - core = GNUNET_CORE_connect (c, /* Main configuration */ - 32, /* queue size */ - NULL, /* Closure passed to MESH functions */ - &core_init, /* Call core_init once connected */ - &core_connect, /* Handle connects */ - &core_disconnect, /* remove peers on disconnects */ - NULL, /* Do we care about "status" updates? */ - NULL, /* Don't want notified about all incoming messages */ - GNUNET_NO, /* For header only inbound notification */ - NULL, /* Don't want notified about all outbound messages */ - GNUNET_NO, /* For header only outbound notification */ + core = GNUNET_CORE_connect (c, /* Main configuration */ + 32, /* queue size */ + NULL, /* Closure passed to MESH functions */ + &core_init, /* Call core_init once connected */ + &core_connect, /* Handle connects */ + &core_disconnect, /* remove peers on disconnects */ + NULL, /* Do we care about "status" updates? */ + NULL, /* Don't notify about all incoming messages */ + GNUNET_NO, /* For header only in notification */ + NULL, /* Don't notify about all outbound messages */ + GNUNET_NO, /* For header-only out notification */ core_handlers); /* Register these handlers */ if (core == NULL) diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c new file mode 100644 index 000000000..f7b0e9034 --- /dev/null +++ b/src/mesh/mesh_api_new.c @@ -0,0 +1,125 @@ +/* + This file is part of GNUnet. + (C) 2011 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file mesh/mesh_api_new.c + * @brief mesh api: client implementation of mesh service + * @author Bartlomiej Polot + */ + +#ifdef __cplusplus + +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +#include +#include "gnunet_mesh_service.h" + +/** + * Opaque handle to the service. + */ +struct GNUNET_MESH_Handle { + struct GNUNET_MESH_Tunnel *head; + struct GNUNET_MESH_Tunnel *tail; + GNUNET_MESH_TunnelEndHandler cleaner; +}; + +/** + * Opaque handle to a tunnel. + */ +struct GNUNET_MESH_Tunnel { + GNUNET_PEER_Id owner; + GNUNET_PEER_Id destination; + GNUNET_MESH_TunnelConnectHandler connect_handler; + GNUNET_MESH_TunnelDisconnectHandler disconnect_handler; + GNUNET_PEER_Id *peers; +}; + + +/** + * Connect to the mesh service. + * + * @param cfg configuration to use + * @param cls closure for the various callbacks that follow (including handlers in the handlers array) + * @param cleaner function called when an *inbound* tunnel is destroyed + * @param handlers callbacks for messages we care about, NULL-terminated + * note that the mesh is allowed to drop notifications about inbound + * messages if the client does not process them fast enough (for this + * notification type, a bounded queue is used) + * @return handle to the mesh service + * NULL on error (in this case, init is never called) + */ +struct GNUNET_MESH_Handle * +GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + void *cls, + GNUNET_MESH_TunnelEndHandler cleaner, + const struct GNUNET_MESH_MessageHandler *handlers, + const GNUNET_MESH_ApplicationType *stypes) { + GNUNET_MESH_Handle *h; + h = GNUNET_malloc(sizeof(GNUNET_MESH_Handle)); + + h->cleaner = cleaner; + return h; +} + +/** + * Disconnect from the mesh service. + * + * @param handle connection to mesh to disconnect + */ +void GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) { + return; +} + +/** + * Create a new tunnel (we're initiator and will be allowed to add/remove peers and + * to broadcast). + * + * @param h mesh handle + * @param connect_handler function to call when peers are actually connected + * @param disconnect_handler function to call when peers are disconnected + * @param handler_cls closure for connect/disconnect handlers + */ +struct GNUNET_MESH_Tunnel * +GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, + GNUNET_MESH_TunnelConnectHandler connect_handler, + GNUNET_MESH_TunnelDisconnectHandler disconnect_handler, + void *handler_cls) { + GNUNET_MESH_Tunnel *tunnel; + tunnel = GNUNET_malloc(sizeof(GNUNET_MESH_Tunnel)); + + tunnel->connect_handler = connect_handler; + tunnel->disconnect_handler = disconnect_handler; + tunnel->peers = NULL; + + return tunnel; +} + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif \ No newline at end of file -- 2.25.1