-enable peer API to return pointer to interned peer hash code
[oweals/gnunet.git] / src / include / gnunet_network_lib.h
index ecc4adf416d074aa6c7fc33a3b663e308c4a2731..06a5ce9038021667978c95ba56ab569535317cfb 100644 (file)
@@ -68,11 +68,23 @@ struct GNUNET_NETWORK_FDSet
 };
 
 
-
 #include "gnunet_disk_lib.h"
 #include "gnunet_time_lib.h"
 
 
+/**
+ * Given a unixpath that is too long (larger than UNIX_PATH_MAX),
+ * shorten it to an acceptable length while keeping it unique
+ * and making sure it remains a valid filename (if possible).
+ *
+ * @param unixpath long path, will be freed (or same pointer returned
+ *        with moved 0-termination).
+ * @return shortened unixpath, NULL on error
+ */
+char *
+GNUNET_NETWORK_shorten_unixpath (char *unixpath);
+
+
 /**
  * Accept a new connection on a socket.  Configure it for non-blocking
  * IO and mark it as non-inheritable to child processes (set the
@@ -83,13 +95,10 @@ struct GNUNET_NETWORK_FDSet
  * @param address_len length of address
  * @return client socket
  */
-struct GNUNET_NETWORK_Handle *GNUNET_NETWORK_socket_accept (const struct
-                                                            GNUNET_NETWORK_Handle
-                                                            *desc,
-                                                            struct sockaddr
-                                                            *address,
-                                                            socklen_t *
-                                                            address_len);
+struct GNUNET_NETWORK_Handle *
+GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
+                              struct sockaddr *address,
+                              socklen_t * address_len);
 
 
 /**
@@ -98,7 +107,8 @@ struct GNUNET_NETWORK_Handle *GNUNET_NETWORK_socket_accept (const struct
  * @param fd socket to box
  * @return NULL on error (including not supported on target platform)
  */
-struct GNUNET_NETWORK_Handle *GNUNET_NETWORK_socket_box_native (int fd);
+struct GNUNET_NETWORK_Handle *
+GNUNET_NETWORK_socket_box_native (SOCKTYPE fd);
 
 
 /**
@@ -109,9 +119,10 @@ struct GNUNET_NETWORK_Handle *GNUNET_NETWORK_socket_box_native (int fd);
  * @param address_len length of address
  * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
  */
-int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
-                                const struct sockaddr *address,
-                                socklen_t address_len);
+int
+GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
+                            const struct sockaddr *address,
+                            socklen_t address_len);
 
 /**
  * Close a socket.
@@ -119,7 +130,8 @@ int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
  * @param desc socket to close
  * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
  */
-int GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc);
+int
+GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc);
 
 
 /**
@@ -130,9 +142,10 @@ int GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc);
  * @param address_len of address
  * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
  */
-int GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc,
-                                   const struct sockaddr *address,
-                                   socklen_t address_len);
+int
+GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc,
+                               const struct sockaddr *address,
+                               socklen_t address_len);
 
 
 /**
@@ -145,9 +158,10 @@ int GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc,
  * @param optlen length of optval
  * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
  */
-int GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle
-                                      *desc, int level, int optname,
-                                      void *optval, socklen_t * optlen);
+int
+GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc,
+                                  int level, int optname, void *optval,
+                                  socklen_t * optlen);
 
 
 /**
@@ -157,8 +171,9 @@ int GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle
  * @param backlog length of the listen queue
  * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
  */
-int GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc,
-                                  int backlog);
+int
+GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc,
+                              int backlog);
 
 
 /**
@@ -180,16 +195,9 @@ GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle
  * @param addrlen length of the addr
  */
 ssize_t
 GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle *desc,
                                 void *buffer, size_t length,
-                                struct sockaddr *src_addr, socklen_t * addrlen);
+                                struct sockaddr *src_addr, socklen_t *addrlen);
 
 
 /**
@@ -200,8 +208,9 @@ GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle *desc,
  * @param length length of buffer
  * @return number of bytes read
  */
-ssize_t GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle *desc,
-                                    void *buffer, size_t length);
+ssize_t
+GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle *desc,
+                            void *buffer, size_t length);
 
 
 /**
@@ -212,10 +221,11 @@ ssize_t GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle *desc,
  * @param timeout relative value when to return
  * @return number of selected sockets, GNUNET_SYSERR on error
  */
-int GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
-                                  struct GNUNET_NETWORK_FDSet *wfds,
-                                  struct GNUNET_NETWORK_FDSet *efds,
-                                  struct GNUNET_TIME_Relative timeout);
+int
+GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
+                              struct GNUNET_NETWORK_FDSet *wfds,
+                              struct GNUNET_NETWORK_FDSet *efds,
+                              struct GNUNET_TIME_Relative timeout);
 
 
 /**
@@ -226,8 +236,9 @@ int GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
  * @param length size of the buffer
  * @return number of bytes sent, GNUNET_SYSERR on error
  */
-ssize_t GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle *desc,
-                                    const void *buffer, size_t length);
+ssize_t
+GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle *desc,
+                            const void *buffer, size_t length);
 
 
 /**
@@ -241,11 +252,11 @@ ssize_t GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle *desc,
  * @param dest_len length of address
  * @return number of bytes sent, GNUNET_SYSERR on error
  */
-ssize_t GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle
-                                      *desc, const void *message,
-                                      size_t length,
-                                      const struct sockaddr *dest_addr,
-                                      socklen_t dest_len);
+ssize_t
+GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle *desc,
+                              const void *message, size_t length,
+                              const struct sockaddr *dest_addr,
+                              socklen_t dest_len);
 
 
 /**
@@ -258,10 +269,10 @@ ssize_t GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle
  * @param option_len size of option_value
  * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
  */
-int GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd,
-                                      int level, int option_name,
-                                      const void *option_value,
-                                      socklen_t option_len);
+int
+GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, int level,
+                                  int option_name, const void *option_value,
+                                  socklen_t option_len);
 
 
 /**
@@ -271,8 +282,8 @@ int GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd,
  * @param how type of shutdown
  * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
  */
-int GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc,
-                                    int how);
+int
+GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, int how);
 
 
 /**
@@ -284,7 +295,8 @@ int GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc,
  * @param desc socket
  * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
  */
-int GNUNET_NETWORK_socket_disable_corking (struct GNUNET_NETWORK_Handle *desc);
+int
+GNUNET_NETWORK_socket_disable_corking (struct GNUNET_NETWORK_Handle *desc);
 
 
 /**
@@ -297,9 +309,8 @@ int GNUNET_NETWORK_socket_disable_corking (struct GNUNET_NETWORK_Handle *desc);
  * @param protocol network protocol
  * @return new socket, NULL on error
  */
-struct GNUNET_NETWORK_Handle *GNUNET_NETWORK_socket_create (int domain,
-                                                            int type,
-                                                            int protocol);
+struct GNUNET_NETWORK_Handle *
+GNUNET_NETWORK_socket_create (int domain, int type, int protocol);
 
 
 /**
@@ -307,7 +318,8 @@ struct GNUNET_NETWORK_Handle *GNUNET_NETWORK_socket_create (int domain,
  *
  * @param fds fd set to clear
  */
-void GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds);
+void
+GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds);
 
 
 /**
@@ -315,12 +327,12 @@ void GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds);
  * @param fds fd set
  * @param desc socket to add
  */
-void GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds,
-                               const struct GNUNET_NETWORK_Handle *desc);
+void
+GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds,
+                          const struct GNUNET_NETWORK_Handle *desc);
 
 
-#ifdef __MINGW32__
-/* TODO: maybe #ifdef WINDOWS? -ndurner */
+#if WINDOWS
 /**
  * Add a W32 file handle to the fd set
  * @param fds fd set
@@ -338,8 +350,9 @@ GNUNET_NETWORK_fdset_handle_set_native_w32_handle (struct GNUNET_NETWORK_FDSet
  * @param desc socket
  * @return GNUNET_YES if the socket is in the set
  */
-int GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds,
-                                const struct GNUNET_NETWORK_Handle *desc);
+int
+GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds,
+                            const struct GNUNET_NETWORK_Handle *desc);
 
 
 /**
@@ -347,8 +360,9 @@ int GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds,
  * @param dst the fd set to add to
  * @param src the fd set to add from
  */
-void GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
-                               const struct GNUNET_NETWORK_FDSet *src);
+void
+GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
+                          const struct GNUNET_NETWORK_FDSet *src);
 
 
 /**
@@ -356,8 +370,9 @@ void GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
  * @param to destination
  * @param from source
  */
-void GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to,
-                                const struct GNUNET_NETWORK_FDSet *from);
+void
+GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to,
+                           const struct GNUNET_NETWORK_FDSet *from);
 
 
 /**
@@ -366,7 +381,28 @@ void GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to,
  * @param desc wrapper to process
  * @return POSIX file descriptor
  */
-int GNUNET_NETWORK_get_fd (struct GNUNET_NETWORK_Handle *desc);
+int
+GNUNET_NETWORK_get_fd (struct GNUNET_NETWORK_Handle *desc);
+
+
+/**
+ * Return the sockaddr for this network handle
+ *
+ * @param desc wrapper to process
+ * @return POSIX file descriptor
+ */
+struct sockaddr*
+GNUNET_NETWORK_get_addr (struct GNUNET_NETWORK_Handle *desc);
+
+
+/**
+ * Return sockaddr length for this network handle
+ *
+ * @param desc wrapper to process
+ * @return socklen_t for sockaddr
+ */
+socklen_t
+GNUNET_NETWORK_get_addrlen (struct GNUNET_NETWORK_Handle *desc);
 
 
 /**
@@ -375,8 +411,9 @@ int GNUNET_NETWORK_get_fd (struct GNUNET_NETWORK_Handle *desc);
  * @param from native source set
  * @param nfds the biggest socket number in from + 1
  */
-void GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to,
-                                       const fd_set * from, int nfds);
+void
+GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to,
+                                  const fd_set * from, int nfds);
 
 
 /**
@@ -385,7 +422,8 @@ void GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to,
  * @param to destination
  * @param nfd native FD to set
  */
-void GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to, int nfd);
+void
+GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to, int nfd);
 
 
 /**
@@ -405,8 +443,9 @@ GNUNET_NETWORK_fdset_test_native (const struct GNUNET_NETWORK_FDSet *to,
  * @param fds fd set
  * @param h the file handle to add
  */
-void GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
-                                      const struct GNUNET_DISK_FileHandle *h);
+void
+GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
+                                 const struct GNUNET_DISK_FileHandle *h);
 
 
 /**
@@ -415,8 +454,9 @@ void GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
  * @param h file handle
  * @return GNUNET_YES if the file handle is part of the set
  */
-int GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
-                                       const struct GNUNET_DISK_FileHandle *h);
+int
+GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
+                                   const struct GNUNET_DISK_FileHandle *h);
 
 
 /**
@@ -425,22 +465,25 @@ int GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
  * @param fds2 second fd set
  * @return GNUNET_YES if they do overlap, GNUNET_NO otherwise
  */
-int GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
-                                  const struct GNUNET_NETWORK_FDSet *fds2);
+int
+GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
+                              const struct GNUNET_NETWORK_FDSet *fds2);
 
 
 /**
  * Creates an fd set
  * @return a new fd set
  */
-struct GNUNET_NETWORK_FDSet *GNUNET_NETWORK_fdset_create (void);
+struct GNUNET_NETWORK_FDSet *
+GNUNET_NETWORK_fdset_create (void);
 
 
 /**
  * Releases the associated memory of an fd set
  * @param fds fd set
  */
-void GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds);
+void
+GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */