From: Bart Polot Date: Wed, 9 Mar 2011 03:04:06 +0000 (+0000) Subject: Added first data structures for the MESH service X-Git-Tag: initial-import-from-subversion-38251~19008 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=f7c0d631f7119d27e9ddcfc0064a3cd6610ba901;p=oweals%2Fgnunet.git Added first data structures for the MESH service --- diff --git a/src/include/gnunet_mesh_service.h b/src/include/gnunet_mesh_service.h index 1ff5e3bec..36dbafb86 100644 --- a/src/include/gnunet_mesh_service.h +++ b/src/include/gnunet_mesh_service.h @@ -114,7 +114,7 @@ typedef void (GNUNET_MESH_TunnelEndHandler)(void *cls, /** - * Connect to the mesh service. + * 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) @@ -190,7 +190,7 @@ struct GNUNET_MESH_PeerRequestHandle; * * @param h mesh handle * @param timeout how long to try to establish a connection - * @param num_peers length of the peers arrray + * @param num_peers length of the peers array * @param peers list of candidates to connect to * @param connect_handler function to call on successful connect (or timeout) * @param disconnect_handler function to call on disconnect diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 60369086d..29657ff08 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -742,6 +742,57 @@ extern "C" #define GNUNET_MESSAGE_TYPE_MESH 215 +/** + * MESH message types (WiP) + */ + +/** + * Request the creation of a path + */ +#define GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE 256 + +/** + * Request the modification of an existing path + */ +#define GNUNET_MESSAGE_TYPE_MESH_PATH_CHANGE 257 + +/** + * Request the addition to a new branch to a path + */ +#define GNUNET_MESSAGE_TYPE_MESH_PATH_ADD 258 + +/** + * At some point, the route will spontaneously change + */ +#define GNUNET_MESSAGE_TYPE_MESH_PATH_CHANGED 259 + +/** + * Transport data in the mesh (origin->end) + */ +#define GNUNET_MESSAGE_TYPE_MESH_DATA_GO 260 + +/** + * Transport data back in the mesh (end->origin) + * (not sure if this is the right way, should be some other solution) + */ +#define GNUNET_MESSAGE_TYPE_MESH_DATA_BACK 261 + +/** + * We need flow control + */ +#define GNUNET_MESSAGE_TYPE_MESH_SPEED_NOTIFY 262 + +/** + * 640kb should be enough for everybody + */ +#define GNUNET_MESSAGE_TYPE_MESH_RESERVE_END 288 + +/** + * MESH message types END + */ + + + /** * Message sent from client to join a chat room. */ diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c new file mode 100644 index 000000000..bdfd1a3ac --- /dev/null +++ b/src/mesh/gnunet-service-mesh.c @@ -0,0 +1,232 @@ +/* + This file is part of GNUnet. + (C) 2001 - 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/gnunet-service-mesh.c + * @brief GNUnet MESH service + * @author Bartlomiej Polot + */ + +#include + +/** + * All the states a peer participating in a tunnel can be in. + */ +enum PeerState +{ + /** + * Request sent, not yet answered. + */ + MESH_PEER_WAITING, + + /** + * Peer connected and ready to accept data + */ + MESH_PEER_READY, + + /** + * Peer connected previosly but not responding + */ + MESH_PEER_UNAVAILABLE, + + /** + * Peer requested but not ever connected + */ + MESH_PEER_UNREACHABLE +}; + +/** + * Struct containing all information regarding a given peer + */ +struct PeerInfo +{ + /** + * ID of the peer + */ + struct GNUNET_PeerIdentity id; + + /** + * Is the peer reachable? Is the peer even connected? + */ + struct PeerState state; + + /** + * Who to send the data to + */ + uint32_t first_hop; + + /** + * Max data rate to this peer + */ + uint32_t max_speed; +}; + +/** + * Information regarding a path + */ +struct Path +{ + /** + * Id of the path, in case it's needed + */ + uint32_t id; + + /** + * Whether the path is serving traffic in a tunnel or is a backup + */ + int in_use; + + /** + * List of all the peers that form the path from origin to target + */ + PeerInfo *peers; +}; + +/** + * Struct containing all information regarding a tunnel + * For an intermediate node the improtant info used will be: + * - OID \ To identify + * - TID / the tunnel + * - paths[0] | To know where to send it next + * - metainfo: ready, speeds, accounting + * For an end node more fields will be needed (client-handling) + */ +struct MESH_tunnel +{ + /** + * Origin ID: Node that created the tunnel + */ + struct GNUNET_PeerIdentity oid; + + /** + * Tunnel number (unique for a given oid) + */ + uint32_t tid; + + /** + * Whether the tunnel is in state to transmit data + */ + int ready; + + /** + * Minimal speed for this tunnel in kb/s + */ + uint32_t speed_min; + + /** + * Maximal speed for this tunnel in kb/s + */ + uint32_t speed_max; + + /** + * Peers in the tunnel, for future optimizations + */ + struct PeerInfo *peers; + + /** + * Paths (used and backup) + */ + struct Path *paths; + + /** + * Messages ready to transmit + */ + struct GNUNET_MessageHeader *msg_out; + + /** + * Messages received and not processed + */ + struct GNUNET_MessageHeader *msg_in; + + /** + * FIXME Clients. Is anyone to be notified for traffic here? + */ +}; + +/** + * So, I'm an endpoint. Why am I receiveing traffic? + * Who is interested in this? How to communicate with them? + */ +struct Clients +{ + /** + * FIXME add structures needed to handle client connections + */ + int fixme; +}; + + + +/** + * Process mesh requests. FIXME NON FUNCTIONAL, COPIED FROM DHT!! + * + * @param cls closure + * @param server the initialized server + * @param c configuration to use + */ +static void +run (void *cls, + struct GNUNET_SERVER_Handle *server, + const struct GNUNET_CONFIGURATION_Handle *c) +{ + struct GNUNET_TIME_Relative next_send_time; + unsigned long long temp_config_num; + char *converge_modifier_buf; + + cfg = c; + datacache = GNUNET_DATACACHE_create (cfg, "dhtcache"); + GNUNET_SERVER_add_handlers (server, plugin_handlers); + GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); + coreAPI = GNUNET_CORE_connect (cfg, /* Main configuration */ + DEFAULT_CORE_QUEUE_SIZE, /* queue size */ + NULL, /* Closure passed to DHT functions */ + &core_init, /* Call core_init once connected */ + &handle_core_connect, /* Handle connects */ + &handle_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_handlers); /* Register these handlers */ + + if (coreAPI == NULL) + return; +} + +/** + * The main function for the mesh service. + * + * @param argc number of arguments from the command line + * @param argv command line arguments + * @return 0 ok, 1 on error + */ +int +main (int argc, char *const *argv) +{ + int ret; + + ret = (GNUNET_OK == + GNUNET_SERVICE_run (argc, + argv, + "mesh", + GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; + return ret; +} \ No newline at end of file diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h new file mode 100644 index 000000000..57778a352 --- /dev/null +++ b/src/mesh/mesh.h @@ -0,0 +1,126 @@ +/* + This file is part of GNUnet. + (C) 2001 - 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. +*/ + +/** + * @author Bartlomiej Polot + * @file mesh/mesh.h + */ + + +#ifndef MESH_H_ +#define MESH_H_ +#include + +/** + * Message for mesh path management + */ +struct GNUNET_MESH_ManipulatePath +{ + /** + * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_[CREATE|CHANGE|ADD] + */ + struct GNUNET_MessageHeader header; + + /** + * Id of the tunnel this path belongs to + */ + uint32_t tid; + + /** + * Information about speed requirements + */ + uint32_t speed_min; + uint32_t speed_max; + + /** + * Number of hops in the path given below + */ + uint16_t path_length; + + /** + * path_length structs defining the *whole* path + */ + struct GNUNET_PeerIdentity peers[]; +}; + +/** + * Message for mesh data traffic + */ +struct GNUNET_MESH_Data +{ + /** + * Type: GNUNET_MESSAGE_TYPE_DATA_[GO|BACK] + */ + struct GNUNET_MessageHeader header; + + /** + * OID of the tunnel + */ + struct GNUNET_PeerIdentity oid; + + /** + * TID of the tunnel + */ + uint32_t tid; + + /** + * Size of payload + * FIXME uint16 enough? + */ + uint16_t size; + + /** + * Payload + */ + uint8_t data[]; +}; + +/** + * Message for mesh flow control + */ +struct GNUNET_MESH_SpeedNotify +{ + /** + * Type: GNUNET_MESSAGE_TYPE_DATA_SPEED_NOTIFY + */ + struct GNUNET_MessageHeader header; + + /** + * OID of the tunnel + */ + struct GNUNET_PeerIdentity oid; + + /** + * TID of the tunnel + */ + uint32_t tid; + + /** + * Slowest link down the path + */ + uint32_t speed_min; + + /** + * Fastest link down the path + */ + uint32_t speed_max; +}; + +#endif \ No newline at end of file