-fix
[oweals/gnunet.git] / src / include / gnunet_connection_lib.h
index 33afb0386c08d38a83b97b03d4355dfe96b9f351..3e48d32ea3b0459606584b7c8388df3e0d9c5ca0 100644 (file)
@@ -52,18 +52,39 @@ extern "C"
 struct GNUNET_CONNECTION_Handle;
 
 
+/**
+ * Credentials for UNIX domain sockets.
+ */
+struct GNUNET_CONNECTION_Credentials
+{
+  /**
+   * UID of the other end of the connection.
+   */
+  uid_t uid;
+
+  /**
+   * GID of the other end of the connection.
+   */
+  gid_t gid;
+};
+
+
 /**
  * Function to call for access control checks.
  *
  * @param cls closure
+ * @param ucred credentials, if available, otherwise NULL
  * @param addr address
  * @param addrlen length of address
  * @return GNUNET_YES to allow, GNUNET_NO to deny, GNUNET_SYSERR
  *   for unknown address family (will be denied).
  */
 typedef int (*GNUNET_CONNECTION_AccessCheck) (void *cls,
-                                           const struct sockaddr * addr,
-                                           socklen_t addrlen);
+                                              const struct
+                                              GNUNET_CONNECTION_Credentials *
+                                              ucred,
+                                              const struct sockaddr * addr,
+                                              socklen_t addrlen);
 
 
 /**
@@ -78,11 +99,10 @@ typedef int (*GNUNET_CONNECTION_AccessCheck) (void *cls,
  * @param addrlen size of addr
  * @param errCode value of errno (on errors receiving)
  */
-typedef void (*GNUNET_CONNECTION_Receiver) (void *cls,
-                                         const void *buf,
-                                         size_t available,
-                                         const struct sockaddr * addr,
-                                         socklen_t addrlen, int errCode);
+typedef void (*GNUNET_CONNECTION_Receiver) (void *cls, const void *buf,
+                                            size_t available,
+                                            const struct sockaddr * addr,
+                                            socklen_t addrlen, int errCode);
 
 /**
  * Set the persist option on this connection handle.  Indicates
@@ -92,7 +112,22 @@ typedef void (*GNUNET_CONNECTION_Receiver) (void *cls,
  * @param sock the connection to set persistent
  */
 void
-GNUNET_CONNECTION_persist_(struct GNUNET_CONNECTION_Handle *sock);
+GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *sock);
+
+/**
+ * Disable the "CORK" feature for communication with the given socket,
+ * forcing the OS to immediately flush the buffer on transmission
+ * instead of potentially buffering multiple messages.  Essentially
+ * reduces the OS send buffers to zero.
+ * Used to make sure that the last messages sent through the connection
+ * reach the other side before the process is terminated.
+ *
+ * @param sock the connection to make flushing and blocking
+ * @return GNUNET_OK on success
+ */
+int
+GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *sock);
+
 
 /**
  * Create a socket handle by boxing an existing OS socket.  The OS
@@ -102,10 +137,8 @@ GNUNET_CONNECTION_persist_(struct GNUNET_CONNECTION_Handle *sock);
  * @param osSocket existing socket to box
  * @return the boxed socket handle
  */
-struct GNUNET_CONNECTION_Handle
-  *GNUNET_CONNECTION_create_from_existing (struct
-                                                   GNUNET_NETWORK_Handle
-                                                   *osSocket);
+struct GNUNET_CONNECTION_Handle *
+GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket);
 
 
 /**
@@ -117,12 +150,10 @@ struct GNUNET_CONNECTION_Handle
  * @param lsock listen socket
  * @return the socket handle, NULL on error (for example, access refused)
  */
-struct GNUNET_CONNECTION_Handle
-  *GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck
-                                                 access, void *access_cls,
-                                                 struct
-                                                 GNUNET_NETWORK_Handle
-                                                 *lsock);
+struct GNUNET_CONNECTION_Handle *
+GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access,
+                                      void *access_cls,
+                                      struct GNUNET_NETWORK_Handle *lsock);
 
 
 /**
@@ -135,10 +166,10 @@ struct GNUNET_CONNECTION_Handle
  * @param port port to connect to
  * @return the socket handle
  */
-struct GNUNET_CONNECTION_Handle
-  *GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                                         const char *hostname,
-                                         uint16_t port);
+struct GNUNET_CONNECTION_Handle *
+GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle
+                                       *cfg, const char *hostname,
+                                       uint16_t port);
 
 
 /**
@@ -152,8 +183,8 @@ struct GNUNET_CONNECTION_Handle
  */
 struct GNUNET_CONNECTION_Handle *
 GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct
-                                                  GNUNET_CONFIGURATION_Handle *cfg,
-                                                  const char *unixpath);
+                                                   GNUNET_CONFIGURATION_Handle
+                                                   *cfg, const char *unixpath);
 
 
 
@@ -168,11 +199,10 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct
  * @param addrlen length of server address
  * @return the socket handle
  */
-struct GNUNET_CONNECTION_Handle
-  *GNUNET_CONNECTION_create_from_sockaddr (int af_family,
-                                                   const struct sockaddr
-                                                   *serv_addr,
-                                                   socklen_t addrlen);
+struct GNUNET_CONNECTION_Handle *
+GNUNET_CONNECTION_create_from_sockaddr (int af_family,
+                                        const struct sockaddr *serv_addr,
+                                        socklen_t addrlen);
 
 /**
  * Check if socket is valid (no fatal errors have happened so far).
@@ -182,8 +212,8 @@ struct GNUNET_CONNECTION_Handle
  * @param sock socket to check
  * @return GNUNET_YES if valid, GNUNET_NO otherwise
  */
-int GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle
-                                     *sock);
+int
+GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock);
 
 
 /**
@@ -194,16 +224,15 @@ int GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle
  * @param addrlen where to store the length of the address
  * @return GNUNET_OK on success
  */
-int GNUNET_CONNECTION_get_address (struct
-                                           GNUNET_CONNECTION_Handle
-                                           *sock, void **addr,
-                                           size_t * addrlen);
+int
+GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *sock,
+                               void **addr, size_t * addrlen);
 
 
 /**
  * Close the socket and free associated resources. Pending
  * transmissions may be completed or dropped depending on the
- * arguments.   If a receive call is pending and should 
+ * arguments.   If a receive call is pending and should
  * NOT be completed, 'GNUNET_CONNECTION_receive_cancel'
  * should be called explicitly first.
  *
@@ -215,7 +244,7 @@ int GNUNET_CONNECTION_get_address (struct
  */
 void
 GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock,
-                          int finish_pending_write);
+                           int finish_pending_write);
 
 
 /**
@@ -232,11 +261,10 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock,
  * @param receiver_cls closure for receiver
  */
 void
-GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle
-                                   *sock, size_t max,
-                                   struct GNUNET_TIME_Relative timeout,
-                                   GNUNET_CONNECTION_Receiver receiver,
-                                   void *receiver_cls);
+GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, size_t max,
+                           struct GNUNET_TIME_Relative timeout,
+                           GNUNET_CONNECTION_Receiver receiver,
+                           void *receiver_cls);
 
 
 /**
@@ -247,9 +275,8 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle
  * @param sock socket handle
  * @return closure of the original receiver callback closure
  */
-void *GNUNET_CONNECTION_receive_cancel (struct
-                                       GNUNET_CONNECTION_Handle
-                                       *sock);
+void *
+GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *sock);
 
 
 /**
@@ -263,8 +290,8 @@ void *GNUNET_CONNECTION_receive_cancel (struct
  * @param buf where the callee should write the message
  * @return number of bytes written to buf
  */
-typedef size_t (*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls,
-                                                        size_t size, void *buf);
+typedef size_t (*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls, size_t size,
+                                                         void *buf);
 
 
 /**
@@ -302,27 +329,24 @@ struct GNUNET_CONNECTION_TransmitHandle;
  * @return non-NULL if the notify callback was queued,
  *         NULL if we are already going to notify someone else (busy)
  */
-struct GNUNET_CONNECTION_TransmitHandle
-  *GNUNET_CONNECTION_notify_transmit_ready (struct
-                                            GNUNET_CONNECTION_Handle
-                                            *sock, size_t size,
-                                            struct
-                                            GNUNET_TIME_Relative
-                                            timeout,
-                                            GNUNET_CONNECTION_TransmitReadyNotify
-                                            notify, void *notify_cls);
+struct GNUNET_CONNECTION_TransmitHandle *
+GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *sock,
+                                         size_t size,
+                                         struct GNUNET_TIME_Relative timeout,
+                                         GNUNET_CONNECTION_TransmitReadyNotify
+                                         notify, void *notify_cls);
 
 
 /**
  * Cancel the specified transmission-ready
  * notification.
  *
- * @param h handle for notification to cancel
+ * @param th handle for notification to cancel
  */
 void
 GNUNET_CONNECTION_notify_transmit_ready_cancel (struct
-                                                        GNUNET_CONNECTION_TransmitHandle
-                                                        *h);
+                                                GNUNET_CONNECTION_TransmitHandle
+                                                *th);
 
 
 /**
@@ -333,7 +357,7 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (struct
  */
 void
 GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *sock,
-                                  int do_ignore);
+                                   int do_ignore);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */