HKDF (does not work yet)
[oweals/gnunet.git] / src / include / gnunet_server_lib.h
index 7af133b89fbeea15dad1c5d4086a15a7cac089c6..fb6713b84eb6b1ac6ddd192e3dcfd88294a7ed83 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2009 Christian Grothoff (and other contributing authors)
+     (C) 2009, 2010 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
@@ -108,6 +108,29 @@ struct GNUNET_SERVER_MessageHandler
 };
 
 
+/**
+ * Create a new server.
+ *
+ * @param sched scheduler to use
+ * @param access function for access control
+ * @param access_cls closure for access
+ * @param lsocks NULL-terminated array of listen sockets
+ * @param maxbuf maximum write buffer size for accepted sockets
+ * @param idle_timeout after how long should we timeout idle connections?
+ * @param require_found if YES, connections sending messages of unknown type
+ *        will be closed
+ * @return handle for the new server, NULL on error
+ *         (typically, "port" already in use)
+ */
+struct GNUNET_SERVER_Handle *
+GNUNET_SERVER_create_with_sockets (struct GNUNET_SCHEDULER_Handle *sched,
+                                  GNUNET_CONNECTION_AccessCheck access, void *access_cls,
+                                  struct GNUNET_NETWORK_Handle **lsocks,
+                                  size_t maxbuf,
+                                  struct GNUNET_TIME_Relative
+                                  idle_timeout,
+                                  int require_found);
+
 /**
  * Create a new server.
  *
@@ -252,120 +275,6 @@ struct GNUNET_SERVER_Client *GNUNET_SERVER_connect_socket (struct
                                                            *connection);
 
 
-/**
- * Receive data from the given connection.  This function should call
- * "receiver" asynchronously using the scheduler.  It must return
- * "immediately".
- *
- * @param cls closure
- * @param sched scheduler to use
- * @param max maximum number of bytes to read
- * @param timeout maximum amount of time to wait (use -1 for "forever")
- * @param receiver function to call with received data
- * @param receiver_cls closure for receiver
- */
-typedef void
-  (*GNUNET_SERVER_ReceiveCallback) (void *cls,
-                                    size_t max,
-                                    struct GNUNET_TIME_Relative timeout,
-                                    GNUNET_CONNECTION_Receiver
-                                    receiver, void *receiver_cls);
-
-
-/**
- * Cancel receive request.
- *
- * @param cls closure
- */
-typedef void (*GNUNET_SERVER_ReceiveCancelCallback) (void *cls);
-
-
-/**
- * Notify us when the connection is ready to transmit size bytes.
- *
- * @param cls closure
- * @param size number of bytes to be ready for sending
- * @param timeout after how long should we give up (and call
- *        notify with buf NULL and size 0)?
- * @param notify function to call
- * @param notify_cls closure for notify
- * @return a handle that can be used to cancel
- *         the transmission request or NULL if
- *         queueing a transmission request failed
- */
-typedef void *(*GNUNET_SERVER_TransmitReadyCallback) (void *cls,
-                                                      size_t size,
-                                                      struct
-                                                      GNUNET_TIME_Relative
-                                                      timeout,
-                                                      GNUNET_CONNECTION_TransmitReadyNotify
-                                                      notify,
-                                                      void *notify_cls);
-
-
-/**
- * Cancel an earlier transmit notification request.
- *
- * @param cls closure
- * @param ctx handle that was returned by the TransmitReadyCallback
- */
-typedef void (*GNUNET_SERVER_TransmitReadyCancelCallback) (void *cls,
-                                                           void *ctx);
-
-
-/**
- * Check if connection is still valid (no fatal errors have happened so far).
- *
- * @param cls closure
- * @return GNUNET_YES if valid, GNUNET_NO otherwise
- */
-typedef int (*GNUNET_SERVER_CheckCallback) (void *cls);
-
-
-/**
- * Destroy this connection (free resources).
- *
- * @param cls closure
- * @param persist when connection is closed, "leak" socket
- */
-typedef void (*GNUNET_SERVER_DestroyCallback) (void *cls, int persist);
-
-
-/**
- * Add an arbitrary connection to the set of handles managed by this
- * server.  This can be used if a sending and receiving does not
- * really go over the network (internal transmission) or for servers
- * using UDP.
- *
- * @param server the server to use
- * @param chandle opaque handle for the connection
- * @param creceive receive function for the connection
- * @param ccancel cancel receive function for the connection
- * @param cnotify transmit notification function for the connection
- * @param cnotify_cancel transmit notification cancellation function for the connection
- * @param ccheck function to test if the connection is still up
- * @param cdestroy function to close and free the connection
- * @return the client handle (client should call
- *         "client_drop" on the return value eventually)
- */
-struct GNUNET_SERVER_Client *GNUNET_SERVER_connect_callback (struct
-                                                             GNUNET_SERVER_Handle
-                                                             *server,
-                                                             void *chandle,
-                                                             GNUNET_SERVER_ReceiveCallback
-                                                             creceive,
-                                                             GNUNET_SERVER_ReceiveCancelCallback
-                                                             ccancel,
-                                                             GNUNET_SERVER_TransmitReadyCallback
-                                                             cnotify,
-                                                             GNUNET_SERVER_TransmitReadyCancelCallback
-                                                             cnotify_cancel,
-                                                             GNUNET_SERVER_CheckCallback
-                                                             ccheck,
-                                                             GNUNET_SERVER_DestroyCallback
-                                                             cdestroy);
-
-
 /**
  * Notify the server that the given client handle should
  * be kept (keeps the connection up if possible, increments
@@ -635,15 +544,12 @@ typedef void (*GNUNET_SERVER_MessageTokenizerCallback) (void *cls,
  *
  * @param maxbuf maximum message size to support (typically
  *    GNUNET_SERVER_MAX_MESSAGE_SIZE)
- * @param client_identity ID of client for which this is a buffer,
- *        can be NULL (will be passed back to 'cb')
  * @param cb function to call on completed messages
  * @param cb_cls closure for cb
  * @return handle to tokenizer
  */
 struct GNUNET_SERVER_MessageStreamTokenizer *
 GNUNET_SERVER_mst_create (size_t maxbuf,
-                         void *client_identity,
                          GNUNET_SERVER_MessageTokenizerCallback cb,
                          void *cb_cls);
 
@@ -653,18 +559,25 @@ GNUNET_SERVER_mst_create (size_t maxbuf,
  * callback for all complete messages.
  *
  * @param mst tokenizer to use
+ * @param client_identity ID of client for which this is a buffer,
+ *        can be NULL (will be passed back to 'cb')
  * @param buf input data to add
  * @param size number of bytes in buf
  * @param purge should any excess bytes in the buffer be discarded 
  *       (i.e. for packet-based services like UDP)
- * @return GNUNET_NO if the data stream is corrupt 
- *         GNUNET_SYSERR if the data stream is corrupt beyond repair
+ * @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
  */
 int
 GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
+                          void *client_identity,
                           const char *buf,
                           size_t size,
-                          int purge);
+                          int purge,
+                          int one_shot);
+
 
 /**
  * Destroys a tokenizer.