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);
/**
* @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
* @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
* socket should henceforth be no longer used directly.
* GNUNET_socket_destroy will close it.
*
- * @param sched scheduler to use
* @param osSocket existing socket to box
- * @param maxbuf maximum write buffer size for the socket (use
- * 0 for sockets that need no write buffers, such as listen sockets)
* @return the boxed socket handle
*/
-struct GNUNET_CONNECTION_Handle
- *GNUNET_CONNECTION_create_from_existing (struct
- GNUNET_SCHEDULER_Handle
- *sched,
- struct
- GNUNET_NETWORK_Handle
- *osSocket, size_t maxbuf);
+struct GNUNET_CONNECTION_Handle *
+GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket);
/**
* Create a socket handle by accepting on a listen socket. This
* function may block if the listen socket has no connection ready.
*
- * @param sched scheduler to use
* @param access function to use to check if access is allowed
* @param access_cls closure for access
* @param lsock listen socket
- * @param maxbuf maximum write buffer size for the socket (use
- * 0 for sockets that need no write buffers, such as listen sockets)
* @return the socket handle, NULL on error (for example, access refused)
*/
-struct GNUNET_CONNECTION_Handle
- *GNUNET_CONNECTION_create_from_accept (struct
- GNUNET_SCHEDULER_Handle
- *sched,
- GNUNET_CONNECTION_AccessCheck
- access, void *access_cls,
- struct
- GNUNET_NETWORK_Handle
- *lsock, size_t maxbuf);
+struct GNUNET_CONNECTION_Handle *
+GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access,
+ void *access_cls,
+ struct GNUNET_NETWORK_Handle *lsock);
/**
* This function returns immediately, even if the connection has not
* yet been established. This function only creates TCP connections.
*
- * @param sched scheduler to use
* @param cfg configuration to use
* @param hostname name of the host to connect to
* @param port port to connect to
- * @param maxbuf maximum write buffer size for the socket (use
- * 0 for sockets that need no write buffers, such as listen sockets)
* @return the socket handle
*/
-struct GNUNET_CONNECTION_Handle
- *GNUNET_CONNECTION_create_from_connect (struct GNUNET_SCHEDULER_Handle *sched,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *hostname,
- uint16_t port,
- size_t maxbuf);
+struct GNUNET_CONNECTION_Handle *
+GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle
+ *cfg, const char *hostname,
+ uint16_t port);
/**
* This function returns immediately, even if the connection has not
* yet been established. This function only creates UNIX connections.
*
- * @param sched scheduler to use
* @param cfg configuration to use
- * @param unixpath path to connect to
- * @param maxbuf maximum write buffer size for the socket (use
- * 0 for sockets that need no write buffers, such as listen sockets)
+ * @param unixpath path to connect to)
* @return the socket handle, NULL on systems without UNIX support
*/
struct GNUNET_CONNECTION_Handle *
-GNUNET_CONNECTION_create_from_connect_to_unixpath (struct GNUNET_SCHEDULER_Handle *sched,
- const struct
- GNUNET_CONFIGURATION_Handle *cfg,
- const char *unixpath,
- size_t maxbuf);
+GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct
+ GNUNET_CONFIGURATION_Handle
+ *cfg, const char *unixpath);
* This function returns immediately, even if the connection has not
* yet been established. This function only creates TCP connections.
*
- * @param sched scheduler to use
* @param af_family address family to use
* @param serv_addr server address
* @param addrlen length of server address
- * @param maxbuf maximum write buffer size for the socket (use
- * 0 for sockets that need no write buffers, such as listen sockets)
* @return the socket handle
*/
-struct GNUNET_CONNECTION_Handle
- *GNUNET_CONNECTION_create_from_sockaddr (struct
- GNUNET_SCHEDULER_Handle
- *sched, int af_family,
- const struct sockaddr
- *serv_addr,
- socklen_t addrlen,
- size_t maxbuf);
+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).
* @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);
/**
* @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.
*
*/
void
GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock,
- int finish_pending_write);
+ int finish_pending_write);
/**
* @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);
/**
* @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);
/**
* @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);
/**
* are free in the transmission buffer. May call the notify
* method immediately if enough space is available. Note that
* this function will abort if "size" is greater than
- * "maxbuf" (as specified when the socket handle was created).
+ * GNUNET_SERVER_MAX_MESSAGE_SIZE.
*
* Note that "notify" will be called either when enough
* buffer space is available OR when the socket is destroyed.
* @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);
/**
*/
void
GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *sock,
- int do_ignore);
+ int do_ignore);
#if 0 /* keep Emacsens' auto-indent happy */