changes to server lib
authorMatthias Wachs <wachs@net.in.tum.de>
Fri, 26 Aug 2011 11:42:39 +0000 (11:42 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Fri, 26 Aug 2011 11:42:39 +0000 (11:42 +0000)
Added a unique ID to struct GNUNET_SERVER_Client to be able to distinguish between different clients

src/include/gnunet_server_lib.h
src/util/server.c

index 3d8130c605bafe9bee2d1272cf33d334eaf68f6b..45da3efa28858a6280171f4562ba123a5fdb33c3 100644 (file)
@@ -325,6 +325,16 @@ GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client,
                                   void **addr, size_t * addrlen);
 
 
+/**
+ * Retrieve the unique id from the opaque defined GNUNET_SERVER_Client
+ *
+ * @param client the client
+ * @return the unique id
+ */
+uint64_t
+GNUNET_SERVER_client_get_id (struct GNUNET_SERVER_Client *client);
+
+
 /**
  * Functions with this signature are called whenever a client
  * is disconnected on the network level.
index 31d298e3a259a4b4644339dfe6530ab6ef32c78a..ddbae441098a577cc4becde995a5e56bc8c14f32 100644 (file)
@@ -247,6 +247,11 @@ struct GNUNET_SERVER_Client
    * Type of last message processed (for warn_no_receive_done).
    */
   uint16_t warn_type;
+
+  /**
+   * unique identifier to distinguish between clients
+   */
+  uint64_t id;
 };
 
 
@@ -932,6 +937,18 @@ client_message_tokenizer_callback (void *cls, void *client,
 }
 
 
+/**
+ * Get a unique identifier for each GNUNET_SERVER_Client
+ */
+static uint64_t
+get_client_id (void)
+{
+  static uint64_t id;
+
+  GNUNET_assert (id < ULONG_LONG_MAX);
+  return (id++);
+}
+
 /**
  * Add a TCP socket-based connection to the set of handles managed by
  * this server.  Use this function for outgoing (P2P) connections that
@@ -963,6 +980,7 @@ GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server,
   client->receive_pending = GNUNET_YES;
   client->callback = NULL;
   client->callback_cls = NULL;
+  client->id = get_client_id ();
   GNUNET_CONNECTION_receive (client->connection,
                              GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
                              client->idle_timeout, &process_incoming, client);
@@ -1274,6 +1292,18 @@ GNUNET_SERVER_client_persist_ (struct GNUNET_SERVER_Client *client)
 }
 
 
+/**
+ * Retrieve the unique id from the opaque defined GNUNET_SERVER_Client
+ *
+ * @param client the client
+ * @return the unique id
+ */
+uint64_t
+GNUNET_SERVER_client_get_id (struct GNUNET_SERVER_Client *client)
+{
+  return client->id;
+}
+
 /**
  * Resume receiving from this client, we are done processing the
  * current request.  This function must be called from within each