Work in progress (handle_new_client)
authorBart Polot <bart@net.in.tum.de>
Fri, 8 Apr 2011 11:10:07 +0000 (11:10 +0000)
committerBart Polot <bart@net.in.tum.de>
Fri, 8 Apr 2011 11:10:07 +0000 (11:10 +0000)
src/mesh/gnunet-service-mesh.c
src/mesh/mesh.h

index f6be64457d3705168729286bc2ec6a1cb61ef430..ea9de3211a6fce9d91fd35e96bb227c5f5c5fbfa 100644 (file)
@@ -242,10 +242,10 @@ struct PeerInfo
     /**
      * Is the peer reachable? Is the peer even connected?
      */
-    enum PeerState state;
+    enum PeerState              state;
 
     /**
-     * Who to send the data to --- what about multiple (alternate) paths?
+     * Who to send the data to --- FIXME what about multiple (alternate) paths?
      */
     GNUNET_PEER_Id              first_hop;
 
@@ -262,6 +262,11 @@ typedef uint32_t MESH_PathID;
  */
 struct Path
 {
+    /**
+     * Double linked list
+     */
+    struct Path                 *next;
+    struct Path                 *prev;
     /**
      * Id of the path, in case it's needed
      */
@@ -308,11 +313,6 @@ struct MESH_tunnel
      */
     MESH_TunnelID               tid;
 
-    /**
-     * Whether the tunnel is in a state to transmit data
-     */
-    int                         ready;
-
     /**
      * Minimal speed for this tunnel in kb/s
      */
@@ -331,12 +331,24 @@ struct MESH_tunnel
     /**
      * Peers in the tunnel, for future optimizations
      */
-    struct PeerInfo             *peers;
+    struct PeerInfo             *peers_head;
+    struct PeerInfo             *peers_tail;
+
+    /**
+     * Number of peers that are connected and potentially ready to receive data
+     */
+    unsigned int                peers_ready;
+
+    /**
+     * Number of peers that have been added to the tunnel
+     */
+    unsigned int                peers_total;
 
     /**
      * Paths (used and backup)
      */
-    struct Path                 *paths;
+    struct Path                 *paths_head;
+    struct Path                 *paths_tail;
 
     /**
      * If this tunnel was created by a local client, what's its handle?
@@ -356,8 +368,7 @@ struct MESH_tunnel
 };
 
 /**
- * So, I'm an endpoint. Why am I receiveing traffic?
- * Who is interested in this? How to communicate with them?
+ * Struct containing information about a client of the service
  */
 struct Client
 {
@@ -368,21 +379,21 @@ struct Client
     struct Client               *prev;
 
     /**
-     * Tunnels that belong to this client
+     * Tunnels that belong to this client, for convenience on disconnect
      */
-    struct MESH_tunnel          *my_tunnels_head;
-    struct MESH_tunnel          *my_tunnels_tail;
+    struct MESH_tunnel          *tunnels_head;
+    struct MESH_tunnel          *tunnels_tail;
 
     /**
-     * If this tunnel was created by a local client, what's its handle?
+     * Handle to communicate with the client
      */
     struct GNUNET_SERVER_Client *handle;
 
     /**
      * Messages that this client has declared interest in
      */
-    uint16_t                    *messages_subscribed;
-    unsigned int                messages_subscribed_counter;
+    GNUNET_MESH_ApplicationType *messages_subscribed;
+    unsigned int                subscription_counter;
 
 };
 
@@ -393,8 +404,8 @@ struct Client
 /**
  * All the clients
  */
-//static struct Client            clients_head;
-//static struct Client            clients_tail;
+static struct Client            clients_head;
+static struct Client            clients_tail;
 
 /**
  * All the tunnels
@@ -402,6 +413,11 @@ struct Client
 // static struct MESH_tunnel       *tunnel_participation_head;
 // static struct MESH_tunnel       *tunnel_participation_tail;
 
+/**
+ * All the paths (for future path optimization)
+ */
+// static struct Path             *paths_head;
+// static struct Path             *paths_tail;
 
 /******************************************************************************/
 /********************      MESH NETWORK HANDLERS     **************************/
@@ -524,20 +540,35 @@ handle_local_new_client (void *cls,
                          struct GNUNET_SERVER_Client *client,
                          const struct GNUNET_MessageHeader *message)
 {
-    struct Client *c;
+    struct Client               *c;
+    unsigned int                payload_size;
+//     struct GNUNET_MESH_Connect  *connect_msg;
+// 
+//     connect_msg = (struct GNUNET_MESH_Connect *) message;
+
+    /* FIXME: check if already exists? NO (optimization) */
+
+    /* FIXME: is this way correct? NO */
+    GNUNET_assert(0 == payload_size % sizeof(GNUNET_MESH_ApplicationType));
+    /* GNUNET_break */
+    /* notify done with syserr */
+    /* return */
+    /* Create new client structure */
+
     c = GNUNET_malloc(sizeof(struct Client));
     c->handle = client;
-    //c->messages_subscribed = message->;
-    
-      /*client *c;
-  tunnel *t;
+    c->tunnels_head = NULL;
+    c->tunnels_tail = NULL;
+    payload_size = message->size - sizeof(GNUNET_MessageHeader);
 
-  t = new;
-  GNUNET_CONTAINER_DLL_insert (c->my_tunnels_head,
-                               c->my_tunnels_tail,
-                               t);*/
+    c->messages_subscribed = GNUNET_malloc(payload_size);
+    memcpy(c->messages_subscribed, &message[1], payload_size);
+    c->subscription_counter = payload_size / sizeof(GNUNET_MESH_ApplicationType);
 
+    /* Insert new client in DLL */
+    GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
 
+    /* FIXME: notify done */
 }
 
 /**
index 551694c272efefbfb1bd8739c099bd70fc4c7297..609d35ec7c8ca2b2c9c4ccbc7d6fc5645f41e26b 100644 (file)
@@ -84,7 +84,7 @@ struct GNUNET_MESH_Connect {
      */
     struct GNUNET_MessageHeader header;
 
-    /* uint16_t messages_subscribed[] */
+    /* GNUNET_MESH_ApplicationType messages_subscribed[] */
 };