gnunetutil: add 2d and 3d allocation including tests
[oweals/gnunet.git] / src / include / gnunet_server_lib.h
index 0195a2898016d6a24d0100e4ca0a39a7b8eef1fb..5da31bcd782b20e800425efb75bf47dd94f33a0e 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2009-2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2009-2013 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
 
      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.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 
 /**
- * @file include/gnunet_server_lib.h
- * @brief library for building GNUnet network servers
  * @author Christian Grothoff
- * @defgroup server functions for a server that communicates with clients
+ *
+ * @file
+ * Library for building GNUnet network servers
+
+ * @defgroup server  Server library
+ * Library for building GNUnet network servers
+ *
+ * Provides functions for a server that communicates with clients.
+ *
+ * @see [Documentation](https://gnunet.org/ipc)
+ *
  * @{
  */
 
@@ -78,10 +86,10 @@ struct GNUNET_SERVER_TransmitHandle;
  * @param client identification of the client
  * @param message the actual message
  */
-typedef void (*GNUNET_SERVER_MessageCallback) (void *cls,
-                                               struct GNUNET_SERVER_Client *client,
-                                               const struct GNUNET_MessageHeader
-                                               *message);
+typedef void
+(*GNUNET_SERVER_MessageCallback) (void *cls,
+                                  struct GNUNET_SERVER_Client *client,
+                                  const struct GNUNET_MessageHeader *message);
 
 
 /**
@@ -96,7 +104,7 @@ struct GNUNET_SERVER_MessageHandler
   GNUNET_SERVER_MessageCallback callback;
 
   /**
-   * Closure argument for "callback".
+   * Closure argument for @e callback.
    */
   void *callback_cls;
 
@@ -119,8 +127,8 @@ struct GNUNET_SERVER_MessageHandler
 /**
  * Create a new server.
  *
- * @param access function for access control
- * @param access_cls closure for @a access
+ * @param access_cb function for access control
+ * @param access_cb_cls closure for @a access_cb
  * @param lsocks NULL-terminated array of listen sockets
  * @param idle_timeout after how long should we timeout idle connections?
  * @param require_found if #GNUNET_YES, connections sending messages of unknown type
@@ -129,8 +137,8 @@ struct GNUNET_SERVER_MessageHandler
  *         (typically, "port" already in use)
  */
 struct GNUNET_SERVER_Handle *
-GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access,
-                                   void *access_cls,
+GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access_cb,
+                                   void *access_cb_cls,
                                    struct GNUNET_NETWORK_Handle **lsocks,
                                    struct GNUNET_TIME_Relative idle_timeout,
                                    int require_found);
@@ -138,10 +146,10 @@ GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access,
 /**
  * Create a new server.
  *
- * @param access function for access control
- * @param access_cls closure for @a access
- * @param serverAddr address toes listen on (including port), NULL terminated array
- * @param socklen lengths of respective @a serverAddr
+ * @param access_cb function for access control
+ * @param access_cb_cls closure for @a access_cb
+ * @param server_addr address toes listen on (including port), NULL terminated array
+ * @param socklen lengths of respective @a server_addr
  * @param idle_timeout after how long should we timeout idle connections?
  * @param require_found if #GNUNET_YES, connections sending messages of unknown type
  *        will be closed
@@ -149,9 +157,10 @@ GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access,
  *         (typically, "port" already in use)
  */
 struct GNUNET_SERVER_Handle *
-GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, void *access_cls,
-                      struct sockaddr *const *serverAddr,
-                      const socklen_t * socklen,
+GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access_cb,
+                     void *access_cb_cls,
+                      struct sockaddr *const *server_addr,
+                      const socklen_t *socklen,
                       struct GNUNET_TIME_Relative idle_timeout,
                       int require_found);
 
@@ -210,8 +219,7 @@ GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server);
  */
 void
 GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server,
-                            const struct GNUNET_SERVER_MessageHandler
-                            *handlers);
+                            const struct GNUNET_SERVER_MessageHandler *handlers);
 
 
 /**
@@ -233,8 +241,8 @@ struct GNUNET_SERVER_TransmitHandle *
 GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client,
                                      size_t size,
                                      struct GNUNET_TIME_Relative timeout,
-                                     GNUNET_CONNECTION_TransmitReadyNotify
-                                     callback, void *callback_cls);
+                                     GNUNET_CONNECTION_TransmitReadyNotify callback,
+                                     void *callback_cls);
 
 
 /**
@@ -288,7 +296,7 @@ GNUNET_SERVER_client_persist_ (struct GNUNET_SERVER_Client *client);
  *                          serious error)
  */
 void
-GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client, 
+GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client,
                            int success);
 
 
@@ -326,7 +334,7 @@ GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client,
  * @param ptr pointer to user context
  * @param size number of bytes in user context struct (for verification only)
  */
-void 
+void
 GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
                                        void *ptr,
                                        size_t size);
@@ -339,7 +347,8 @@ GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
  * @param type expected return type (i.e. 'struct Foo')
  * @return pointer to user context of type 'type *'.
  */
-#define GNUNET_SERVER_client_get_user_context(client,type) (type *) GNUNET_SERVER_client_get_user_context_ (client, sizeof (type))
+#define GNUNET_SERVER_client_get_user_context(client,type)              \
+  (type *) GNUNET_SERVER_client_get_user_context_ (client, sizeof (type))
 
 /**
  * Set user context to be associated with the given client.
@@ -347,7 +356,8 @@ GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
  * @param client client to query
  * @param value pointer to user context
  */
-#define GNUNET_SERVER_client_set_user_context(client,value) GNUNET_SERVER_client_set_user_context_ (client, value, sizeof (*value))
+#define GNUNET_SERVER_client_set_user_context(client,value)             \
+  GNUNET_SERVER_client_set_user_context_ (client, value, sizeof (*value))
 
 
 /**
@@ -392,8 +402,7 @@ GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server,
  * @param server the server to use
  * @param connection the connection to manage (client must
  *        stop using this connection from now on)
- * @return the client handle (client should call
- *         #GNUNET_SERVER_client_drop on the return value eventually)
+ * @return the client handle
  */
 struct GNUNET_SERVER_Client *
 GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server,
@@ -444,8 +453,9 @@ GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client,
  * @param client identification of the client; NULL
  *        for the last call when the server is destroyed
  */
-typedef void (*GNUNET_SERVER_DisconnectCallback) (void *cls,
-                                                  struct GNUNET_SERVER_Client *client);
+typedef void
+(*GNUNET_SERVER_DisconnectCallback) (void *cls,
+                                     struct GNUNET_SERVER_Client *client);
 
 
 /**
@@ -455,8 +465,9 @@ typedef void (*GNUNET_SERVER_DisconnectCallback) (void *cls,
  * @param cls closure
  * @param client identification of the client
  */
-typedef void (*GNUNET_SERVER_ConnectCallback) (void *cls,
-                                              struct GNUNET_SERVER_Client *client);
+typedef void
+(*GNUNET_SERVER_ConnectCallback) (void *cls,
+                                  struct GNUNET_SERVER_Client *client);
 
 
 /**
@@ -500,7 +511,7 @@ GNUNET_SERVER_connect_notify (struct GNUNET_SERVER_Handle *server,
 
 /**
  * Ask the server to stop notifying us whenever a client disconnects.
- * Arguments must match exactly those given to 
+ * Arguments must match exactly those given to
  * #GNUNET_SERVER_disconnect_notify.  It is not necessary to call this
  * function during shutdown of the server; in fact, most applications
  * will never use this function.
@@ -511,13 +522,13 @@ GNUNET_SERVER_connect_notify (struct GNUNET_SERVER_Handle *server,
  */
 void
 GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server,
-                                        GNUNET_SERVER_DisconnectCallback
-                                        callback, void *callback_cls);
+                                        GNUNET_SERVER_DisconnectCallback callback,
+                                        void *callback_cls);
 
 
 /**
  * Ask the server to stop notifying us whenever a client connects.
- * Arguments must match exactly those given to 
+ * Arguments must match exactly those given to
  * #GNUNET_SERVER_connect_notify.  It is not necessary to call this
  * function during shutdown of the server; in fact, most applications
  * will never use this function.
@@ -585,8 +596,8 @@ GNUNET_SERVER_transmit_context_create (struct GNUNET_SERVER_Client *client);
  * @param type type of the message
  */
 void
-GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext
-                                            *tc, const void *data,
+GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext *tc,
+                                            const void *data,
                                             size_t length, uint16_t type);
 
 
@@ -599,11 +610,8 @@ GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext
  * @param msg message to append
  */
 void
-GNUNET_SERVER_transmit_context_append_message (struct
-                                               GNUNET_SERVER_TransmitContext
-                                               *tc,
-                                               const struct GNUNET_MessageHeader
-                                               *msg);
+GNUNET_SERVER_transmit_context_append_message (struct GNUNET_SERVER_TransmitContext *tc,
+                                               const struct GNUNET_MessageHeader *msg);
 
 
 /**
@@ -632,8 +640,8 @@ GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc,
  *                          serious error)
  */
 void
-GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext
-                                        *tc, int success);
+GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext *tc,
+                                        int success);
 
 
 /**
@@ -693,7 +701,7 @@ GNUNET_SERVER_notification_context_add (struct GNUNET_SERVER_NotificationContext
 void
 GNUNET_SERVER_notification_context_unicast (struct GNUNET_SERVER_NotificationContext *nc,
                                             struct GNUNET_SERVER_Client *client,
-                                            const struct GNUNET_MessageHeader *msg, 
+                                            const struct GNUNET_MessageHeader *msg,
                                             int can_drop);
 
 
@@ -706,10 +714,30 @@ GNUNET_SERVER_notification_context_unicast (struct GNUNET_SERVER_NotificationCon
  */
 void
 GNUNET_SERVER_notification_context_broadcast (struct GNUNET_SERVER_NotificationContext *nc,
-                                              const struct GNUNET_MessageHeader *msg, 
+                                              const struct GNUNET_MessageHeader *msg,
                                               int can_drop);
 
 
+/**
+ * Return active number of subscribers in this context.
+ *
+ * @param nc context to query
+ * @return number of current subscribers
+ */
+unsigned int
+GNUNET_SERVER_notification_context_get_size (struct GNUNET_SERVER_NotificationContext *nc);
+
+
+/**
+ * Create a message queue for a server's client.
+ *
+ * @param client the client
+ * @return the message queue
+ */
+struct GNUNET_MQ_Handle *
+GNUNET_MQ_queue_for_server_client (struct GNUNET_SERVER_Client *client);
+
+
 /**
  * Handle to a message stream tokenizer.
  */
@@ -728,10 +756,10 @@ struct GNUNET_SERVER_MessageStreamTokenizer;
  * @param message the actual message
  * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
  */
-typedef int (*GNUNET_SERVER_MessageTokenizerCallback) (void *cls, void *client,
-                                                        const struct
-                                                        GNUNET_MessageHeader *
-                                                        message);
+typedef int
+(*GNUNET_SERVER_MessageTokenizerCallback) (void *cls,
+                                           void *client,
+                                           const struct GNUNET_MessageHeader *message);
 
 
 /**
@@ -764,7 +792,8 @@ GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb,
  */
 int
 GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
-                           void *client_identity, const char *buf, size_t size,
+                           void *client_identity,
+                           const char *buf, size_t size,
                            int purge, int one_shot);
 
 
@@ -780,21 +809,24 @@ GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst);
 /**
  * Signature of a function to create a custom tokenizer.
  *
- * @param cls closure from 'GNUNET_SERVER_set_callbacks'
+ * @param cls closure from #GNUNET_SERVER_set_callbacks
  * @param client handle to client the tokenzier will be used for
  * @return handle to custom tokenizer ('mst')
  */
-typedef void* (*GNUNET_SERVER_MstCreateCallback) (void *cls,
-                                                  struct GNUNET_SERVER_Client *client);
+typedef void*
+(*GNUNET_SERVER_MstCreateCallback) (void *cls,
+                                    struct GNUNET_SERVER_Client *client);
 
 
 /**
  * Signature of a function to destroy a custom tokenizer.
  *
- * @param cls closure from 'GNUNET_SERVER_set_callbacks'
+ * @param cls closure from #GNUNET_SERVER_set_callbacks
  * @param mst custom tokenizer handle
  */
-typedef void (*GNUNET_SERVER_MstDestroyCallback) (void *cls, void *mst);
+typedef void
+(*GNUNET_SERVER_MstDestroyCallback) (void *cls,
+                                     void *mst);
 
 
 /**
@@ -811,12 +843,15 @@ typedef void (*GNUNET_SERVER_MstDestroyCallback) (void *cls, void *mst);
  * @param one_shot only call callback once, keep rest of message in buffer
  * @return #GNUNET_OK if we are done processing (need more data)
  *         #GNUNET_NO if one_shot was set and we have another message ready
- *         #GNUNET_SYSERR if the data stream is corrupt 
+ *         #GNUNET_SYSERR if the data stream is corrupt
  */
-typedef int (*GNUNET_SERVER_MstReceiveCallback) (void *cls, void *mst,
-                                                 struct GNUNET_SERVER_Client *client,
-                                                 const char *buf, size_t size,
-                                                 int purge, int one_shot);
+typedef int
+(*GNUNET_SERVER_MstReceiveCallback) (void *cls, void *mst,
+                                     struct GNUNET_SERVER_Client *client,
+                                     const char *buf,
+                                     size_t size,
+                                     int purge,
+                                     int one_shot);
 
 
 /**
@@ -844,8 +879,9 @@ GNUNET_SERVER_set_callbacks (struct GNUNET_SERVER_Handle *server,
 }
 #endif
 
-/** @} */ /* end of group server */
-
 /* ifndef GNUNET_SERVER_LIB_H */
 #endif
+
+/** @} */  /* end of group server */
+
 /* end of gnunet_server_lib.h */