diff options
author | Bertrand Marc <beberking@gmail.com> | 2012-06-06 20:47:48 +0200 |
---|---|---|
committer | Bertrand Marc <beberking@gmail.com> | 2012-06-06 20:47:48 +0200 |
commit | 740b30688bd745a527f96f9116c19acb3480971a (patch) | |
tree | 2709a3f4dba11c174aa9e1ba3612e30c578e76a9 /src/include | |
parent | 2b81464a43485fcc8ce079fafdee7b7a171835f4 (diff) |
Imported Upstream version 0.9.3upstream/0.9.3
Diffstat (limited to 'src/include')
48 files changed, 3611 insertions, 361 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am index afe4ecb..34a879f 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -51,7 +51,9 @@ gnunetinclude_HEADERS = \ gnunet_hello_lib.h \ gnunet_helper_lib.h \ gnunet_load_lib.h \ + gnunet_lockmanager_service.h \ gnunet_mesh_service.h \ + gnunet_mysql_lib.h \ gnunet_namestore_plugin.h \ gnunet_namestore_service.h \ gnunet_nat_lib.h \ @@ -61,10 +63,12 @@ gnunetinclude_HEADERS = \ gnunet_peer_lib.h \ gnunet_peerinfo_service.h \ gnunet_plugin_lib.h \ + gnunet_postgres_lib.h \ gnunet_program_lib.h \ gnunet_protocols.h \ gnunet_pseudonym_lib.h \ gnunet_resolver_service.h \ + gnunet_regex_lib.h \ gnunet_scheduler_lib.h \ gnunet_server_lib.h \ gnunet_service_lib.h \ @@ -73,7 +77,9 @@ gnunetinclude_HEADERS = \ gnunet_statistics_service.h \ gnunet_stream_lib.h \ gnunet_strings_lib.h \ + gnunet_testbed_service.h \ gnunet_testing_lib.h \ + gnunet_testing_lib-new.h \ gnunet_time_lib.h \ gnunet_transport_service.h \ gnunet_transport_plugin.h \ diff --git a/src/include/Makefile.in b/src/include/Makefile.in index ce91bd7..ac6b874 100644 --- a/src/include/Makefile.in +++ b/src/include/Makefile.in @@ -87,18 +87,22 @@ am__gnunetinclude_HEADERS_DIST = gauger.h gettext.h platform.h plibc.h \ gnunet_dv_service.h gnunet_fragmentation_lib.h \ gnunet_fs_service.h gnunet_getopt_lib.h gnunet_gns_service.h \ gnunet_hello_lib.h gnunet_helper_lib.h gnunet_load_lib.h \ - gnunet_mesh_service.h gnunet_namestore_plugin.h \ + gnunet_lockmanager_service.h gnunet_mesh_service.h \ + gnunet_mysql_lib.h gnunet_namestore_plugin.h \ gnunet_namestore_service.h gnunet_nat_lib.h \ gnunet_network_lib.h gnunet_nse_service.h gnunet_os_lib.h \ gnunet_peer_lib.h gnunet_peerinfo_service.h \ - gnunet_plugin_lib.h gnunet_program_lib.h gnunet_protocols.h \ - gnunet_pseudonym_lib.h gnunet_resolver_service.h \ + gnunet_plugin_lib.h gnunet_postgres_lib.h gnunet_program_lib.h \ + gnunet_protocols.h gnunet_pseudonym_lib.h \ + gnunet_resolver_service.h gnunet_regex_lib.h \ gnunet_scheduler_lib.h gnunet_server_lib.h \ gnunet_service_lib.h gnunet_signal_lib.h gnunet_signatures.h \ gnunet_statistics_service.h gnunet_stream_lib.h \ - gnunet_strings_lib.h gnunet_testing_lib.h gnunet_time_lib.h \ - gnunet_transport_service.h gnunet_transport_plugin.h \ - gnunet_tun_lib.h gnunet_util_lib.h gnunet_vpn_service.h + gnunet_strings_lib.h gnunet_testbed_service.h \ + gnunet_testing_lib.h gnunet_testing_lib-new.h \ + gnunet_time_lib.h gnunet_transport_service.h \ + gnunet_transport_plugin.h gnunet_tun_lib.h gnunet_util_lib.h \ + gnunet_vpn_service.h am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ @@ -212,6 +216,7 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ INTLLIBS = @INTLLIBS@ INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ +JAVAPORT = @JAVAPORT@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBADD_DL = @LIBADD_DL@ @@ -245,6 +250,7 @@ LT_DLLOADERS = @LT_DLLOADERS@ LT_DLPREOPEN = @LT_DLPREOPEN@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ +MONKEYPREFIX = @MONKEYPREFIX@ MSGFMT = @MSGFMT@ MSGFMT_015 = @MSGFMT_015@ MSGMERGE = @MSGMERGE@ @@ -409,7 +415,9 @@ gnunetinclude_HEADERS = \ gnunet_hello_lib.h \ gnunet_helper_lib.h \ gnunet_load_lib.h \ + gnunet_lockmanager_service.h \ gnunet_mesh_service.h \ + gnunet_mysql_lib.h \ gnunet_namestore_plugin.h \ gnunet_namestore_service.h \ gnunet_nat_lib.h \ @@ -419,10 +427,12 @@ gnunetinclude_HEADERS = \ gnunet_peer_lib.h \ gnunet_peerinfo_service.h \ gnunet_plugin_lib.h \ + gnunet_postgres_lib.h \ gnunet_program_lib.h \ gnunet_protocols.h \ gnunet_pseudonym_lib.h \ gnunet_resolver_service.h \ + gnunet_regex_lib.h \ gnunet_scheduler_lib.h \ gnunet_server_lib.h \ gnunet_service_lib.h \ @@ -431,7 +441,9 @@ gnunetinclude_HEADERS = \ gnunet_statistics_service.h \ gnunet_stream_lib.h \ gnunet_strings_lib.h \ + gnunet_testbed_service.h \ gnunet_testing_lib.h \ + gnunet_testing_lib-new.h \ gnunet_time_lib.h \ gnunet_transport_service.h \ gnunet_transport_plugin.h \ diff --git a/src/include/block_dns.h b/src/include/block_dns.h index 4c2f1a3..e047779 100644 --- a/src/include/block_dns.h +++ b/src/include/block_dns.h @@ -64,7 +64,7 @@ struct GNUNET_DNS_Record * The descriptor for the service * (a peer may provide more than one service) */ - GNUNET_HashCode service_descriptor GNUNET_PACKED; + GNUNET_HashCode service_descriptor; /** * When does this record expire? diff --git a/src/include/block_gns.h b/src/include/block_gns.h index 4514acf..ffdb294 100644 --- a/src/include/block_gns.h +++ b/src/include/block_gns.h @@ -65,19 +65,14 @@ struct GNSNameRecordBlock { /** - * GNUNET_RSA_Signature using RSA-key generated from the records. - */ - struct GNUNET_CRYPTO_RsaSignature signature; - - /** - * What is being signed and why? + * The public key of the authority */ - struct GNUNET_CRYPTO_RsaSignaturePurpose purpose; + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; /** - * The public key of the authority + * GNUNET_RSA_Signature using RSA-key generated from the records. */ - struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; + struct GNUNET_CRYPTO_RsaSignature signature; /* number of records that follow */ uint32_t rd_count GNUNET_PACKED; @@ -86,7 +81,6 @@ struct GNSNameRecordBlock /* variable-size GNSRecordBlocks follows here */ - }; GNUNET_NETWORK_STRUCT_END diff --git a/src/include/gnunet_arm_service.h b/src/include/gnunet_arm_service.h index af1c8cd..116bfc5 100644 --- a/src/include/gnunet_arm_service.h +++ b/src/include/gnunet_arm_service.h @@ -111,6 +111,19 @@ enum GNUNET_ARM_ProcessStatus typedef void (*GNUNET_ARM_Callback) (void *cls, enum GNUNET_ARM_ProcessStatus result); +/** + * Callback function invoked when list operation is complete. + * + * @param cls closure + * @param result outcome of the operation (GNUNET_YES if successful) + * @param count number of strings in the list + * @param list list of running services + */ +typedef void (*GNUNET_ARM_List_Callback) (void *cls, + int result, + unsigned int count, + const char *const *list); + /** * Handle for interacting with ARM. @@ -183,6 +196,18 @@ GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h, const char *service_name, GNUNET_ARM_Callback cb, void *cb_cls); +/** + * List all running services. + * + * @param h handle to ARM + * @param timeout how long to wait before failing for good + * @param cb callback to invoke when service is ready + * @param cb_cls closure for callback + */ +void +GNUNET_ARM_list_running_services (struct GNUNET_ARM_Handle *h, + struct GNUNET_TIME_Relative timeout, + GNUNET_ARM_List_Callback cb, void *cb_cls); #if 0 /* keep Emacsens' auto-indent happy */ { diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h index 858ae1d..aa7a089 100644 --- a/src/include/gnunet_ats_service.h +++ b/src/include/gnunet_ats_service.h @@ -523,6 +523,17 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh); /** + * We would like to reset the address suggestion block time for this + * peer + * + * @param sh handle + * @param peer identity of the peer we want to reset + */ +void +GNUNET_ATS_reset_backoff (struct GNUNET_ATS_SchedulingHandle *sh, + const struct GNUNET_PeerIdentity *peer); + +/** * We would like to establish a new connection with a peer. ATS * should suggest a good address to begin with. * @@ -552,7 +563,7 @@ GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SchedulingHandle *sh, * @param addrlen address length * @return location as GNUNET_ATS_Information */ -const struct GNUNET_ATS_Information +struct GNUNET_ATS_Information GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle *sh, const struct sockaddr * addr, socklen_t addrlen); @@ -594,6 +605,7 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, const struct GNUNET_HELLO_Address *address, struct Session *session, int in_use); + /** * A session got destroyed, stop including it as a valid address. * diff --git a/src/include/gnunet_client_lib.h b/src/include/gnunet_client_lib.h index 60fa938..51da46d 100644 --- a/src/include/gnunet_client_lib.h +++ b/src/include/gnunet_client_lib.h @@ -69,13 +69,10 @@ GNUNET_CLIENT_connect (const char *service_name, * destroyed (unless, of course, there is an error with the server in * which case the message may still be lost). * - * @param sock handle to the service connection - * @param finish_pending_write should a transmission already passed to the - * handle be completed? + * @param client handle to the service connection */ void -GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock, - int finish_pending_write); +GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *client); /** @@ -106,13 +103,13 @@ typedef void (*GNUNET_CLIENT_ShutdownTask) (void *cls, int reason); /** * Read from the service. * - * @param sock the service + * @param client connection to the service * @param handler function to call with the message * @param handler_cls closure for handler * @param timeout how long to wait until timing out */ void -GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock, +GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *client, GNUNET_CLIENT_MessageHandler handler, void *handler_cls, struct GNUNET_TIME_Relative timeout); @@ -128,7 +125,7 @@ struct GNUNET_CLIENT_TransmitHandle; * are free in the transmission buffer. May call the notify * method immediately if enough space is available. * - * @param sock connection to the service + * @param client connection to the service * @param size number of bytes to send * @param timeout after how long should we give up (and call * notify with buf NULL and size 0)? @@ -144,7 +141,7 @@ struct GNUNET_CLIENT_TransmitHandle; * using GNUNET_CONNECTION_notify_transmit_ready_cancel) */ struct GNUNET_CLIENT_TransmitHandle * -GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock, +GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *client, size_t size, struct GNUNET_TIME_Relative timeout, int auto_retry, @@ -169,7 +166,7 @@ GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle * will be called with a "NULL" response (in which * case the connection should probably be destroyed). * - * @param sock connection to use + * @param client connection to use * @param hdr message to transmit * @param timeout when to give up (for both transmission * and for waiting for a response) @@ -184,7 +181,7 @@ GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle * is already pending */ int -GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection *sock, +GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection *client, const struct GNUNET_MessageHeader *hdr, struct GNUNET_TIME_Relative timeout, int auto_retry, diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index a1ef4ee..9f77658 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h @@ -141,6 +141,26 @@ #define GNUNET_PACKED __attribute__((packed)) /** + * gcc-ism to get gcc bitfield layout when compiling with -mms-bitfields + */ +#if MINGW +#define GNUNET_GCC_STRUCT_LAYOUT __attribute__((gcc_struct)) +#else +#define GNUNET_GCC_STRUCT_LAYOUT +#endif + +/** + * gcc-ism to force alignment; we use this to align char-arrays + * that may then be cast to 'struct's. See also gcc + * bug #33594. + */ +#ifdef __BIGGEST_ALIGNMENT__ +#define GNUNET_ALIGN __attribute__((aligned (__BIGGEST_ALIGNMENT__))) +#else +#define GNUNET_ALIGN __attribute__((aligned (8))) +#endif + +/** * gcc-ism to document unused arguments */ #define GNUNET_UNUSED __attribute__((unused)) @@ -199,27 +219,25 @@ struct GNUNET_MessageHeader uint16_t type GNUNET_PACKED; }; -GNUNET_NETWORK_STRUCT_END + /** * @brief 512-bit hashcode */ -typedef struct +typedef struct GNUNET_HashCode { uint32_t bits[512 / 8 / sizeof (uint32_t)]; /* = 16 */ } GNUNET_HashCode; -GNUNET_NETWORK_STRUCT_BEGIN - /** * The identity of the host (basically the SHA-512 hashcode of * it's public key). */ struct GNUNET_PeerIdentity { - GNUNET_HashCode hashPubKey GNUNET_PACKED; + GNUNET_HashCode hashPubKey; }; GNUNET_NETWORK_STRUCT_END diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h index f8f302a..0fcb4e0 100644 --- a/src/include/gnunet_configuration_lib.h +++ b/src/include/gnunet_configuration_lib.h @@ -87,6 +87,19 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, /** + * Load default configuration. This function will parse the + * defaults from the given defaults_d directory. + * + * @param cfg configuration to update + * @param defaults_d directory with the defaults + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *defaults_d); + + +/** * Parse a configuration file, add all of the options in the * file to the configuration environment. * diff --git a/src/include/gnunet_connection_lib.h b/src/include/gnunet_connection_lib.h index 3e48d32..5ee4635 100644 --- a/src/include/gnunet_connection_lib.h +++ b/src/include/gnunet_connection_lib.h @@ -109,10 +109,10 @@ typedef void (*GNUNET_CONNECTION_Receiver) (void *cls, const void *buf, * that the underlying socket or fd should never really be closed. * Used for indicating process death. * - * @param sock the connection to set persistent + * @param connection the connection to set persistent */ void -GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *sock); +GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *connection); /** * Disable the "CORK" feature for communication with the given socket, @@ -122,17 +122,17 @@ GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *sock); * 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 + * @param connection the connection to make flushing and blocking * @return GNUNET_OK on success */ int -GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *sock); +GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *connection); /** - * Create a socket handle by boxing an existing OS socket. The OS + * Create a connection handle by boxing an existing OS socket. The OS * socket should henceforth be no longer used directly. - * GNUNET_socket_destroy will close it. + * GNUNET_CONNECTION_destroy will close it. * * @param osSocket existing socket to box * @return the boxed socket handle @@ -142,13 +142,13 @@ GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket); /** - * Create a socket handle by accepting on a listen socket. This + * Create a connection handle by accepting on a listen socket. This * function may block if the listen socket has no connection ready. * * @param access function to use to check if access is allowed * @param access_cls closure for access * @param lsock listen socket - * @return the socket handle, NULL on error (for example, access refused) + * @return the connection handle, NULL on error (for example, access refused) */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access, @@ -157,14 +157,14 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access, /** - * Create a socket handle by (asynchronously) connecting to a host. + * Create a connection handle by (asynchronously) connecting to a host. * This function returns immediately, even if the connection has not * yet been established. This function only creates TCP connections. * * @param cfg configuration to use * @param hostname name of the host to connect to * @param port port to connect to - * @return the socket handle + * @return the connection handle */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle @@ -173,13 +173,13 @@ GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle /** - * Create a socket handle by connecting to a UNIX domain service. + * Create a connection handle by connecting to a UNIX domain service. * This function returns immediately, even if the connection has not * yet been established. This function only creates UNIX connections. * * @param cfg configuration to use * @param unixpath path to connect to) - * @return the socket handle, NULL on systems without UNIX support + * @return the connection handle, NULL on systems without UNIX support */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct @@ -190,14 +190,14 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct /** - * Create a socket handle by (asynchronously) connecting to a host. + * Create a connection handle by (asynchronously) connecting to a host. * This function returns immediately, even if the connection has not * yet been established. This function only creates TCP connections. * * @param af_family address family to use * @param serv_addr server address * @param addrlen length of server address - * @return the socket handle + * @return the connection handle */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_sockaddr (int af_family, @@ -205,84 +205,77 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family, socklen_t addrlen); /** - * Check if socket is valid (no fatal errors have happened so far). - * Note that a socket that is still trying to connect is considered + * Check if connection is valid (no fatal errors have happened so far). + * Note that a connection that is still trying to connect is considered * valid. * - * @param sock socket to check + * @param connection handle to check * @return GNUNET_YES if valid, GNUNET_NO otherwise */ int -GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock); +GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection); /** * Obtain the network address of the other party. * - * @param sock the client to get the address for + * @param connection the client to get the address for * @param addr where to store the address * @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, +GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *connection, 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 - * NOT be completed, 'GNUNET_CONNECTION_receive_cancel' - * should be called explicitly first. + * Close the connection and free associated resources. There must + * not be any pending requests for reading or writing to the + * connection at this time. * - * @param sock socket to destroy - * @param finish_pending_write should pending writes be completed or aborted? - * (this applies to transmissions where the data has already been - * read from the application; all other transmissions should be - * aborted using 'GNUNET_CONNECTION_notify_transmit_ready_cancel'). + * @param connection connection to destroy */ void -GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock, - int finish_pending_write); +GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection); /** - * Receive data from the given socket. Note that this function will + * Receive data from the given connection. Note that this function will * call "receiver" asynchronously using the scheduler. It will * "immediately" return. Note that there MUST only be one active - * receive call per socket at any given point in time (so do not + * receive call per connection at any given point in time (so do not * call receive again until the receiver callback has been invoked). * - * @param sock socket handle + * @param connection connection handle * @param max maximum number of bytes to read * @param timeout maximum amount of time to wait * @param receiver function to call with received data * @param receiver_cls closure for receiver */ void -GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, size_t max, +GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, size_t max, struct GNUNET_TIME_Relative timeout, GNUNET_CONNECTION_Receiver receiver, void *receiver_cls); /** - * Cancel receive job on the given socket. Note that the + * Cancel receive job on the given connection. Note that the * receiver callback must not have been called yet in order * for the cancellation to be valid. * - * @param sock socket handle + * @param connection connection handle * @return closure of the original receiver callback closure */ void * -GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *sock); +GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *connection); /** - * Function called to notify a client about the socket + * Function called to notify a client about the connection * begin ready to queue more data. "buf" will be - * NULL and "size" zero if the socket was closed for + * NULL and "size" zero if the connection was closed for * writing in the meantime. * * @param cls closure @@ -301,17 +294,17 @@ typedef size_t (*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls, size_t size, struct GNUNET_CONNECTION_TransmitHandle; /** - * Ask the socket to call us once the specified number of bytes + * Ask the connection to call us once the specified number of bytes * 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 * GNUNET_SERVER_MAX_MESSAGE_SIZE. * * Note that "notify" will be called either when enough - * buffer space is available OR when the socket is destroyed. + * buffer space is available OR when the connection is destroyed. * The size parameter given to notify is guaranteed to be * larger or equal to size if the buffer is ready, or zero - * if the socket was destroyed (or at least closed for + * if the connection was destroyed (or at least closed for * writing). Finally, any time before 'notify' is called, a * client may call "notify_transmit_ready_cancel" to cancel * the transmission request. @@ -320,7 +313,7 @@ struct GNUNET_CONNECTION_TransmitHandle; * time. Notify will be run with the same scheduler priority * as that of the caller. * - * @param sock socket + * @param connection connection * @param size number of bytes to send * @param timeout after how long should we give up (and call * notify with buf NULL and size 0)? @@ -330,7 +323,7 @@ struct GNUNET_CONNECTION_TransmitHandle; * 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, +GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connection, size_t size, struct GNUNET_TIME_Relative timeout, GNUNET_CONNECTION_TransmitReadyNotify @@ -349,16 +342,6 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (struct *th); -/** - * Configure this connection to ignore shutdown signals. - * - * @param sock socket handle - * @param do_ignore GNUNET_YES to ignore, GNUNET_NO to restore default - */ -void -GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *sock, - int do_ignore); - #if 0 /* keep Emacsens' auto-indent happy */ { diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h index 75443b6..a78d8cc 100644 --- a/src/include/gnunet_container_lib.h +++ b/src/include/gnunet_container_lib.h @@ -70,7 +70,8 @@ typedef int (*GNUNET_HashCodeIterator) (void *cls, GNUNET_HashCode * next); * * @param filename the name of the file (or the prefix) * @param size the size of the bloom-filter (number of - * bytes of storage space to use) + * bytes of storage space to use); will be rounded up + * to next power of 2 * @param k the number of GNUNET_CRYPTO_hash-functions to apply per * element (number of bits set per element in the set) * @return the bloomfilter @@ -1152,12 +1153,28 @@ GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l); * @param l list * @param buf payload buffer to find * @param len length of the payload (number of bytes in buf) + * + * @return GNUNET_YES if found, GNUNET_NO otherwise */ int GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l, const void *buf, size_t len); - +/** + * Check if a list contains a certain element using 'compare' function + * + * @param l list + * @param buf payload buffer to find + * @param len length of the payload (number of bytes in buf) + * @param compare comparison function + * + * @return NULL if the 'buf' could not be found, pointer to the + * list element, if found + */ +void * +GNUNET_CONTAINER_slist_contains2 (const struct GNUNET_CONTAINER_SList *l, + const void *buf, size_t len, + int (*compare)(const void *, const size_t, const void *, const size_t)); /** * Count the elements of a list * @param l list diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h index 1f6c0f3..cb48f41 100644 --- a/src/include/gnunet_core_service.h +++ b/src/include/gnunet_core_service.h @@ -157,8 +157,8 @@ typedef void (*GNUNET_CORE_StartupCallback) (void *cls, * @param cfg configuration to use * @param queue_size size of the per-peer message queue * @param cls closure for the various callbacks that follow (including handlers in the handlers array) - * @param init callback to call on timeout or once we have successfully - * connected to the core service; note that timeout is only meaningful if init is not NULL + * @param init callback to call once we have successfully + * connected to the core service * @param connects function to call on peer connect, can be NULL * @param disconnects function to call on peer disconnect / timeout, can be NULL * @param inbound_notify function to call for all inbound messages, can be NULL @@ -229,8 +229,7 @@ struct GNUNET_CORE_TransmitHandle; * @param cork is corking allowed for this transmission? * @param priority how important is the message? * @param maxdelay how long can the message wait? - * @param target who should receive the message, - * use NULL for this peer (loopback) + * @param target who should receive the message, never NULL (can be this peer's identity for loopback) * @param notify_size how many bytes of buffer space does notify want? * @param notify function to call when buffer space is available; * will be called with NULL on timeout or if the overall queue @@ -293,6 +292,12 @@ GNUNET_CORE_iterate_peers (const struct GNUNET_CONFIGURATION_Handle *cfg, /** + * Handle to cancel 'is_peer_connected' test. + */ +struct GNUNET_CORE_ConnectTestHandle; + + +/** * Check if the given peer is currently connected and return information * about the session if so. This function is for special cirumstances * (GNUNET_TESTING uses it), normal users of the CORE API are @@ -300,22 +305,28 @@ GNUNET_CORE_iterate_peers (const struct GNUNET_CONFIGURATION_Handle *cfg, * connect/disconnect callbacks from GNUNET_CORE_connect. This * function is NOT part of the 'versioned', 'official' API. * - * FIXME: we should probably make it possible to 'cancel' the - * operation... - * * @param cfg configuration to use * @param peer the specific peer to check for * @param peer_cb function to call with the peer information * @param cb_cls closure for peer_cb - * @return GNUNET_OK if iterating, GNUNET_SYSERR on error + * @return handle to cancel the operation */ -int +struct GNUNET_CORE_ConnectTestHandle * GNUNET_CORE_is_peer_connected (const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_PeerIdentity *peer, + const struct GNUNET_PeerIdentity *peer, GNUNET_CORE_ConnectEventHandler peer_cb, void *cb_cls); +/** + * Abort 'is_connected' test operation. + * + * @param cth handle for operation to cancel + */ +void +GNUNET_CORE_is_peer_connected_cancel (struct GNUNET_CORE_ConnectTestHandle *cth); + + #if 0 /* keep Emacsens' auto-indent happy */ { #endif diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 6e37266..777ddd9 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and other contributing authors) + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2012 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 @@ -86,7 +86,7 @@ enum GNUNET_CRYPTO_Quality /** - * Length of an RSA KEY (d,e,len), 2048 bit (=256 octests) key d, 2 byte e + * Length of an RSA KEY (n,e,len), 2048 bit (=256 octests) key n, 2 byte e */ #define GNUNET_CRYPTO_RSA_KEY_LENGTH 258 @@ -101,6 +101,32 @@ enum GNUNET_CRYPTO_Quality */ struct GNUNET_CRYPTO_RsaPrivateKey; +GNUNET_NETWORK_STRUCT_BEGIN + +/** + * GNUnet mandates a certain format for the encoding + * of private RSA key information that is provided + * by the RSA implementations. This format is used + * to serialize a private RSA key (typically when + * writing it to disk). + */ +struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded +{ + /** + * Total size of the structure, in bytes, in big-endian! + */ + uint16_t len GNUNET_PACKED; + uint16_t sizen GNUNET_PACKED; /* in big-endian! */ + uint16_t sizee GNUNET_PACKED; /* in big-endian! */ + uint16_t sized GNUNET_PACKED; /* in big-endian! */ + uint16_t sizep GNUNET_PACKED; /* in big-endian! */ + uint16_t sizeq GNUNET_PACKED; /* in big-endian! */ + uint16_t sizedmp1 GNUNET_PACKED; /* in big-endian! */ + uint16_t sizedmq1 GNUNET_PACKED; /* in big-endian! */ + /* followed by the actual values */ +}; +GNUNET_NETWORK_STRUCT_END + /** * @brief 0-terminated ASCII encoding of a GNUNET_HashCode. @@ -112,6 +138,26 @@ struct GNUNET_CRYPTO_HashAsciiEncoded + +/** + * @brief 256-bit hashcode + */ +struct GNUNET_CRYPTO_ShortHashCode +{ + uint32_t bits[256 / 8 / sizeof (uint32_t)]; /* = 8 */ +}; + + +/** + * @brief 0-terminated ASCII encoding of a 'struct GNUNET_ShortHashCode'. + */ +struct GNUNET_CRYPTO_ShortHashAsciiEncoded +{ + unsigned char short_encoding[53]; +}; + + + /** * @brief an RSA signature */ @@ -320,6 +366,7 @@ GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n); void GNUNET_CRYPTO_aes_create_session_key (struct GNUNET_CRYPTO_AesSessionKey *key); + /** * Check that a new session key is well-formed. * @@ -406,7 +453,19 @@ GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block, /** - * Convert ASCII encoding back to GNUNET_CRYPTO_hash + * Convert short hash to ASCII encoding. + * + * @param block the hash code + * @param result where to store the encoding (struct GNUNET_CRYPTO_ShortHashAsciiEncoded can be + * safely cast to char*, a '\\0' termination is set). + */ +void +GNUNET_CRYPTO_short_hash_to_enc (const struct GNUNET_CRYPTO_ShortHashCode * block, + struct GNUNET_CRYPTO_ShortHashAsciiEncoded *result); + + +/** + * Convert ASCII encoding back to a 'GNUNET_HashCode' * * @param enc the encoding * @param enclen number of characters in 'enc' (without 0-terminator, which can be missing) @@ -419,16 +478,53 @@ GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen, /** - * Convert ASCII encoding back to GNUNET_CRYPTO_hash + * Convert ASCII encoding back to a 'struct GNUNET_CRYPTO_ShortHash' + * * @param enc the encoding + * @param enclen number of characters in 'enc' (without 0-terminator, which can be missing) * @param result where to store the GNUNET_CRYPTO_hash code * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding */ +int +GNUNET_CRYPTO_short_hash_from_string2 (const char *enc, size_t enclen, + struct GNUNET_CRYPTO_ShortHashCode * result); + + +/** + * Convert ASCII encoding back to GNUNET_HashCode + * + * @param enc the encoding + * @param result where to store the hash code + * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding + */ #define GNUNET_CRYPTO_hash_from_string(enc, result) \ GNUNET_CRYPTO_hash_from_string2 (enc, strlen(enc), result) /** + * Convert ASCII encoding back to a 'struct GNUNET_CRYPTO_ShortHash' + * + * @param enc the encoding + * @param result where to store the GNUNET_CRYPTO_ShortHash + * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding + */ +#define GNUNET_CRYPTO_short_hash_from_string(enc, result) \ + GNUNET_CRYPTO_short_hash_from_string2 (enc, strlen(enc), result) + + +/** + * Compare function for ShortHashCodes, producing a total ordering + * of all hashcodes. + * + * @param h1 some hash code + * @param h2 some hash code + * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. + */ +int +GNUNET_CRYPTO_short_hash_cmp (const struct GNUNET_CRYPTO_ShortHashCode * h1, + const struct GNUNET_CRYPTO_ShortHashCode * h2); + +/** * Compute the distance between 2 hashcodes. * The computation must be fast, not involve * a.a or a.e (they're used elsewhere), and @@ -456,6 +552,42 @@ GNUNET_CRYPTO_hash (const void *block, size_t size, GNUNET_HashCode * ret); /** + * Compute short (256-bit) hash of a given block. + * + * @param block the data to hash + * @param size size of the block + * @param ret pointer to where to write the hashcode + */ +void +GNUNET_CRYPTO_short_hash (const void *block, size_t size, + struct GNUNET_CRYPTO_ShortHashCode * ret); + + +/** + * Double short (256-bit) hash to create a long hash. + * + * @param sh short hash to double + * @param dh where to store the (doubled) long hash (not really a hash) + */ +void +GNUNET_CRYPTO_short_hash_double (const struct GNUNET_CRYPTO_ShortHashCode *sh, + struct GNUNET_HashCode *dh); + + +/** + * Truncate doubled short hash back to a short hash. + * + * @param dh doubled short hash to reduce again + * @param sh where to store the short hash + * @return GNUNET_OK on success, GNUNET_SYSERR if this was not a + * doubled short hash + */ +int +GNUNET_CRYPTO_short_hash_from_truncation (const struct GNUNET_HashCode *dh, + struct GNUNET_CRYPTO_ShortHashCode *sh); + + +/** * Calculate HMAC of a message (RFC 2104) * * @param key secret key @@ -735,6 +867,40 @@ GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts, struct GNUNET_CRYPTO_RsaPrivateKey * GNUNET_CRYPTO_rsa_key_create (void); + +/** + * Convert a public key to a string. + * + * @param pub key to convert + * @return string representing 'pub' + */ +char * +GNUNET_CRYPTO_rsa_public_key_to_string (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub); + + +/** + * Convert a string representing a public key to a public key. + * + * @param enc encoded public key + * @param enclen number of bytes in enc (without 0-terminator) + * @param pub where to store the public key + * @return GNUNET_OK on success + */ +int +GNUNET_CRYPTO_rsa_public_key_from_string (const char *enc, + size_t enclen, + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub); + + +/** + * Encode the private key in a format suitable for + * storing it into a file. + * @returns encoding of the private key. + * The first 4 bytes give the size of the array, as usual. + */ +struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded * +GNUNET_CRYPTO_rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey); + /** * Decode the private key from the data-format back * to the "normal", internal format. @@ -764,6 +930,18 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename); /** + * Setup a hostkey file for a peer given the name of the + * configuration file (!). This function is used so that + * at a later point code can be certain that reading a + * hostkey is fast (for example in time-dependent testcases). + * + * @param cfg_name name of the configuration file to use + */ +void +GNUNET_CRYPTO_setup_hostkey (const char *cfg_name); + + +/** * Deterministically (!) create a private key using only the * given HashCode as input to the PRNG. * @@ -869,6 +1047,7 @@ GNUNET_CRYPTO_rsa_verify (uint32_t purpose, void GNUNET_CRYPTO_random_disable_entropy_gathering (void); + #if 0 /* keep Emacsens' auto-indent happy */ { #endif diff --git a/src/include/gnunet_datastore_service.h b/src/include/gnunet_datastore_service.h index b4af0e6..2950832 100644 --- a/src/include/gnunet_datastore_service.h +++ b/src/include/gnunet_datastore_service.h @@ -292,8 +292,8 @@ typedef void (*GNUNET_DATASTORE_DatumProcessor) (void *cls, * @param max_queue_size at what queue size should this request be dropped * (if other requests of higher priority are in the queue) * @param timeout how long to wait at most for a response - * @param proc function to call on each matching value; - * will be called once with a NULL value at the end + * @param proc function to call on a matching value; + * or with a NULL value if no datum matches * @param proc_cls closure for proc * @return NULL if the entry was not queued, otherwise a handle that can be used to * cancel diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h index e533ef2..6606acb 100644 --- a/src/include/gnunet_dht_service.h +++ b/src/include/gnunet_dht_service.h @@ -121,6 +121,28 @@ GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle); /* *************** Standard API: get and put ******************* */ + +/** + * Opaque handle to cancel a PUT operation. + */ +struct GNUNET_DHT_PutHandle; + + +/** + * Type of a PUT continuation. You must not call + * "GNUNET_DHT_disconnect" in this continuation. + * + * @param cls closure + * @param success GNUNET_OK if the PUT was transmitted, + * GNUNET_NO on timeout, + * GNUNET_SYSERR on disconnect from service + * after the PUT message was transmitted + * (so we don't know if it was received or not) + */ +typedef void (*GNUNET_DHT_PutContinuation)(void *cls, + int success); + + /** * Perform a PUT operation storing data in the DHT. * @@ -135,19 +157,38 @@ GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle); * @param exp desired expiration time for the value * @param timeout how long to wait for transmission of this request * @param cont continuation to call when done (transmitting request to service) + * You must not call "GNUNET_DHT_disconnect" in this continuation * @param cont_cls closure for cont + * @return handle to cancel the "PUT" operation, NULL on error + * (size too big) */ -void +struct GNUNET_DHT_PutHandle * GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, const GNUNET_HashCode * key, uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, size_t size, const char *data, struct GNUNET_TIME_Absolute exp, - struct GNUNET_TIME_Relative timeout, GNUNET_SCHEDULER_Task cont, + struct GNUNET_TIME_Relative timeout, + GNUNET_DHT_PutContinuation cont, void *cont_cls); /** + * Cancels a DHT PUT operation. Note that the PUT request may still + * go out over the network (we can't stop that); However, if the PUT + * has not yet been sent to the service, cancelling the PUT will stop + * this from happening (but there is no way for the user of this API + * to tell if that is the case). The only use for this API is to + * prevent a later call to 'cont' from "GNUNET_DHT_put" (i.e. because + * the system is shutting down). + * + * @param ph put operation to cancel ('cont' will no longer be called) + */ +void +GNUNET_DHT_put_cancel (struct GNUNET_DHT_PutHandle *ph); + + +/** * Iterator called on each result obtained for a DHT * operation that expects a reply * @@ -179,7 +220,6 @@ typedef void (*GNUNET_DHT_GetIterator) (void *cls, * also "GNUNET_BLOCK_evaluate". * * @param handle handle to the DHT service - * @param timeout how long to wait for transmission of this request to the service * @param type expected type of the response object * @param key the key to look up * @param desired_replication_level estimate of how many @@ -194,7 +234,6 @@ typedef void (*GNUNET_DHT_GetIterator) (void *cls, */ struct GNUNET_DHT_GetHandle * GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, - struct GNUNET_TIME_Relative timeout, enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key, uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, const void *xquery, @@ -216,37 +255,85 @@ GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle); /* *************** Extended API: monitor ******************* */ +/** + * Handle to monitor requests + */ struct GNUNET_DHT_MonitorHandle; /** - * Callback called on each request going through the DHT. + * Callback called on each GET request going through the DHT. + * + * @param cls Closure. + * @param options Options, for instance RecordRoute, DemultiplexEverywhere. + * @param type The type of data in the request. + * @param hop_count Hop count so far. + * @param path_length number of entries in path (or 0 if not recorded). + * @param path peers on the GET path (or NULL if not recorded). + * @param desired_replication_level Desired replication level. + * @param key Key of the requested data. + */ +typedef void (*GNUNET_DHT_MonitorGetCB) (void *cls, + enum GNUNET_DHT_RouteOption options, + enum GNUNET_BLOCK_Type type, + uint32_t hop_count, + uint32_t desired_replication_level, + unsigned int path_length, + const struct GNUNET_PeerIdentity *path, + const GNUNET_HashCode * key); + +/** + * Callback called on each GET reply going through the DHT. * * @param cls Closure. - * @param mtype Type of the DHT message monitored. - * @param exp When will this value expire. - * @param key Key of the result/request. - * @param get_path Peers on reply path (or NULL if not recorded). + * @param type The type of data in the result. + * @param get_path Peers on GET path (or NULL if not recorded). * @param get_path_length number of entries in get_path. * @param put_path peers on the PUT path (or NULL if not recorded). * @param put_path_length number of entries in get_path. - * @param desired_replication_level Desired replication level. - * @param type Type of the result/request. + * @param exp Expiration time of the data. + * @param key Key of the data. * @param data Pointer to the result data. * @param size Number of bytes in data. */ -typedef void (*GNUNET_DHT_MonitorCB) (void *cls, - uint16_t mtype, - struct GNUNET_TIME_Absolute exp, - const GNUNET_HashCode * key, - const struct GNUNET_PeerIdentity * - get_path, unsigned int get_path_length, - const struct GNUNET_PeerIdentity * - put_path, unsigned int put_path_length, - uint32_t desired_replication_level, - enum GNUNET_DHT_RouteOption options, - enum GNUNET_BLOCK_Type type, - const void *data, - size_t size); +typedef void (*GNUNET_DHT_MonitorGetRespCB) (void *cls, + enum GNUNET_BLOCK_Type type, + const struct GNUNET_PeerIdentity + *get_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity + * put_path, + unsigned int put_path_length, + struct GNUNET_TIME_Absolute exp, + const GNUNET_HashCode * key, + const void *data, + size_t size); + +/** + * Callback called on each PUT request going through the DHT. + * + * @param cls Closure. + * @param options Options, for instance RecordRoute, DemultiplexEverywhere. + * @param type The type of data in the request. + * @param hop_count Hop count so far. + * @param path_length number of entries in path (or 0 if not recorded). + * @param path peers on the PUT path (or NULL if not recorded). + * @param desired_replication_level Desired replication level. + * @param exp Expiration time of the data. + * @param key Key under which data is to be stored. + * @param data Pointer to the data carried. + * @param size Number of bytes in data. + */ +typedef void (*GNUNET_DHT_MonitorPutCB) (void *cls, + enum GNUNET_DHT_RouteOption options, + enum GNUNET_BLOCK_Type type, + uint32_t hop_count, + uint32_t desired_replication_level, + unsigned int path_length, + const struct GNUNET_PeerIdentity *path, + struct GNUNET_TIME_Absolute exp, + const GNUNET_HashCode * key, + const void *data, + size_t size); /** * Start monitoring the local DHT service. @@ -254,7 +341,9 @@ typedef void (*GNUNET_DHT_MonitorCB) (void *cls, * @param handle Handle to the DHT service. * @param type Type of blocks that are of interest. * @param key Key of data of interest, NULL for all. - * @param cb Callback to process all monitored data. + * @param get_cb Callback to process monitored get messages. + * @param get_resp_cb Callback to process monitored get response messages. + * @param put_cb Callback to process monitored put messages. * @param cb_cls Closure for cb. * * @return Handle to stop monitoring. @@ -263,7 +352,9 @@ struct GNUNET_DHT_MonitorHandle * GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle, enum GNUNET_BLOCK_Type type, const GNUNET_HashCode *key, - GNUNET_DHT_MonitorCB cb, + GNUNET_DHT_MonitorGetCB get_cb, + GNUNET_DHT_MonitorGetRespCB get_resp_cb, + GNUNET_DHT_MonitorPutCB put_cb, void *cb_cls); diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h index 18f5535..d6ec0fe 100644 --- a/src/include/gnunet_disk_lib.h +++ b/src/include/gnunet_disk_lib.h @@ -302,8 +302,8 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, OFF_T offset, /** - * Get the size of the file (or directory) - * of the given file (in bytes). + * Get the size of the file (or directory) of the given file (in + * bytes). * * @param filename name of the file or directory * @param size set to the size of the file (or, @@ -311,11 +311,13 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, OFF_T offset, * of all sizes of files in the directory) * @param includeSymLinks should symbolic links be * included? - * @return GNUNET_OK on success, GNUNET_SYSERR on error + * @param singleFileMode GNUNET_YES to only get size of one file + * and return GNUNET_SYSERR for directories. + * @return GNUNET_SYSERR on error, GNUNET_OK on success */ int GNUNET_DISK_file_size (const char *filename, uint64_t * size, - int includeSymLinks); + int includeSymLinks, int singleFileMode); /** diff --git a/src/include/gnunet_dnsparser_lib.h b/src/include/gnunet_dnsparser_lib.h index 0c310ba..28cc4c0 100644 --- a/src/include/gnunet_dnsparser_lib.h +++ b/src/include/gnunet_dnsparser_lib.h @@ -128,7 +128,7 @@ struct GNUNET_DNSPARSER_Flags */ unsigned int recursion_available : 1 GNUNET_PACKED; -}; +} GNUNET_GCC_STRUCT_LAYOUT; /** diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index 3eb5892..1f1e60f 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h @@ -1820,7 +1820,11 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h, * @param cls closure * @param offset offset to read from; it is possible * that the caller might need to go backwards - * a bit at times + * a bit at times; set to UINT64_MAX to tell + * the reader that we won't be reading for a while + * (used to close the file descriptor but NOT fully + * clean up the reader's state); in this case, + * a value of '0' for max should be ignored * @param max maximum number of bytes that should be * copied to buf; readers are not allowed * to provide less data unless there is an error; diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h index 2422178..4e040f7 100644 --- a/src/include/gnunet_gns_service.h +++ b/src/include/gnunet_gns_service.h @@ -34,6 +34,7 @@ #define GNUNET_GNS_SERVICE_H #include "gnunet_util_lib.h" +#include "gnunet_dnsparser_lib.h" #include "gnunet_namestore_service.h" #ifdef __cplusplus @@ -56,36 +57,40 @@ struct GNUNET_GNS_Handle; struct GNUNET_GNS_LookupHandle; /** + * Handle to control a shorten operation + */ + +/** * Record types * Based on GNUNET_DNSPARSER_TYPEs (standard DNS) */ enum GNUNET_GNS_RecordType { /* Standard DNS */ - GNUNET_GNS_RECORD_TYPE_A = 1, - GNUNET_GNS_RECORD_TYPE_NS = 2, - GNUNET_GNS_RECORD_TYPE_CNAME = 5, - GNUNET_GNS_RECORD_TYPE_SOA = 6, - GNUNET_GNS_RECORD_TYPE_PTR = 12, - GNUNET_GNS_RECORD_MX = 15, - GNUNET_GNS_RECORD_TXT = 16, - GNUNET_GNS_RECORD_AAAA = 28, + GNUNET_GNS_RECORD_TYPE_A = GNUNET_DNSPARSER_TYPE_A, + GNUNET_GNS_RECORD_TYPE_NS = GNUNET_DNSPARSER_TYPE_NS, + GNUNET_GNS_RECORD_TYPE_CNAME = GNUNET_DNSPARSER_TYPE_CNAME, + GNUNET_GNS_RECORD_TYPE_SOA = GNUNET_DNSPARSER_TYPE_SOA, + GNUNET_GNS_RECORD_TYPE_PTR = GNUNET_DNSPARSER_TYPE_PTR, + GNUNET_GNS_RECORD_MX = GNUNET_DNSPARSER_TYPE_MX, + GNUNET_GNS_RECORD_TXT = GNUNET_DNSPARSER_TYPE_TXT, + GNUNET_GNS_RECORD_AAAA = GNUNET_DNSPARSER_TYPE_AAAA, /* GNS specific */ - GNUNET_GNS_RECORD_PKEY = 256 + GNUNET_GNS_RECORD_PKEY = GNUNET_NAMESTORE_TYPE_PKEY, + GNUNET_GNS_RECORD_PSEU = GNUNET_NAMESTORE_TYPE_PSEU, + GNUNET_GNS_RECORD_ANY = GNUNET_NAMESTORE_TYPE_ANY }; /** * Initialize the connection with the GNS service. - * FIXME: Do we need the ht_len? * * @param cfg configuration to use - * @param ht_len size of the internal hash table to use for parallel lookups - * @return NULL on error + * + * @return handle to the GNS service, or NULL on error */ struct GNUNET_GNS_Handle * -GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, - unsigned int ht_len); +GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); /** @@ -100,56 +105,135 @@ GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle); /* *************** Standard API: lookup ******************* */ /** - * Iterator called on each result obtained for a GNS + * Iterator called on obtained result for a GNS * lookup * * @param cls closure * @param name "name" of the original lookup - * @param record the records in reply - * @param num_records the number of records in reply + * @param rd_count number of records + * @param rd the records in reply */ -typedef void (*GNUNET_GNS_LookupIterator) (void *cls, - const char * name, - const struct GNUNET_NAMESTORE_RecordData *record, - unsigned int num_records); +typedef void (*GNUNET_GNS_LookupResultProcessor) (void *cls, + uint32_t rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd); /** - * Perform an asynchronous lookup operation on the GNS. + * Perform an asynchronous lookup operation on the GNS + * in the default zone. * * @param handle handle to the GNS service - * @param timeout how long to wait for transmission of this request to the service - * // FIXME: what happens afterwards? + * @param name the name to look up + * @param type the GNUNET_GNS_RecordType to look for + * @param proc function to call on result + * @param proc_cls closure for processor + * + * @return handle to the queued request + */ +struct GNUNET_GNS_QueueEntry * +GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, + const char * name, + enum GNUNET_GNS_RecordType type, + GNUNET_GNS_LookupResultProcessor proc, + void *proc_cls); + +/** + * Perform an asynchronous lookup operation on the GNS + * in the zone specified by 'zone'. + * * @param handle handle to the GNS service - * @param timeout timeout of request * @param name the name to look up + * @param zone the zone to start the resolution in * @param type the GNUNET_GNS_RecordType to look for - * @param iter function to call on each result - * @param iter_cls closure for iter + * @param proc function to call on result + * @param proc_cls closure for processor * - * @return handle to stop the async lookup + * @return handle to the queued request */ -struct GNUNET_GNS_LookupHandle * -GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle, - struct GNUNET_TIME_Relative timeout, +struct GNUNET_GNS_QueueEntry * +GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle, const char * name, + struct GNUNET_CRYPTO_ShortHashCode *zone, enum GNUNET_GNS_RecordType type, - GNUNET_GNS_LookupIterator iter, - void *iter_cls); + GNUNET_GNS_LookupResultProcessor proc, + void *proc_cls); + +/* *************** Standard API: shorten ******************* */ /** - * Stop async GNS lookup. Frees associated resources. + * Processor called on for a name shortening result + * called only once * - * @param lookup_handle lookup operation to stop. + * @param cls closure + * @param short_name the shortened name or NULL if no result + */ +typedef void (*GNUNET_GNS_ShortenResultProcessor) (void *cls, + const char* short_name); + + +/** + * Perform a name shortening operation on the GNS. * - * On return lookup_handle will no longer be valid, caller - * must not use again!!! + * @param handle handle to the GNS service + * @param name the name to look up + * @param proc function to call on result + * @param proc_cls closure for processor + * @return handle to the operation */ -void -GNUNET_GNS_lookup_stop (struct GNUNET_GNS_LookupHandle *lookup_handle); +struct GNUNET_GNS_QueueEntry * +GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle, + const char * name, + GNUNET_GNS_ShortenResultProcessor proc, + void *proc_cls); + + +/** + * Perform a name shortening operation on the GNS. + * + * @param handle handle to the GNS service + * @param name the name to look up + * @param zone the zone to start the resolution in + * @param proc function to call on result + * @param proc_cls closure for processor + * @return handle to the operation + */ +struct GNUNET_GNS_QueueEntry * +GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle, + const char * name, + struct GNUNET_CRYPTO_ShortHashCode *zone, + GNUNET_GNS_ShortenResultProcessor proc, + void *proc_cls); + +/* *************** Standard API: get authority ******************* */ + +/** + * Processor called on for a name shortening result + * called only once + * + * @param cls closure + * @param auth_name the name of the auhtority or NULL + */ +typedef void (*GNUNET_GNS_GetAuthResultProcessor) (void *cls, + const char* short_name); + + +/** + * Perform an authority lookup for a given name. + * + * @param handle handle to the GNS service + * @param name the name to look up authority for + * @param proc function to call on result + * @param proc_cls closure for processor + * @return handle to the operation + */ +struct GNUNET_GNS_QueueEntry * +GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle, + const char * name, + GNUNET_GNS_GetAuthResultProcessor proc, + void *proc_cls); #if 0 /* keep Emacsens' auto-indent happy */ { diff --git a/src/include/gnunet_helper_lib.h b/src/include/gnunet_helper_lib.h index 7115748..9c1bc21 100644 --- a/src/include/gnunet_helper_lib.h +++ b/src/include/gnunet_helper_lib.h @@ -75,6 +75,12 @@ typedef void (*GNUNET_HELPER_Continuation)(void *cls, /** + * Handle to cancel 'send' + */ +struct GNUNET_HELPER_SendHandle; + + +/** * Send an message to the helper. * * @param h helper to send message to @@ -82,10 +88,11 @@ typedef void (*GNUNET_HELPER_Continuation)(void *cls, * @param can_drop can the message be dropped if there is already one in the queue? * @param cont continuation to run once the message is out * @param cont_cls closure for 'cont' - * @return GNUNET_YES if the message will be sent - * GNUNET_NO if the message was dropped + * @return NULL if the message was dropped, + * otherwise handle to cancel *cont* (actual transmission may + * not be abortable) */ -int +struct GNUNET_HELPER_SendHandle * GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h, const struct GNUNET_MessageHeader *msg, int can_drop, @@ -93,4 +100,14 @@ GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h, void *cont_cls); +/** + * Cancel a 'send' operation. If possible, transmitting the + * message is also aborted, but at least 'cont' won't be + * called. + * + * @param sh operation to cancel + */ +void +GNUNET_HELPER_send_cancel (struct GNUNET_HELPER_SendHandle *sh); + #endif /* end of include guard: GNUNET_HELPER_LIB_H */ diff --git a/src/include/gnunet_lockmanager_service.h b/src/include/gnunet_lockmanager_service.h new file mode 100644 index 0000000..570cce5 --- /dev/null +++ b/src/include/gnunet_lockmanager_service.h @@ -0,0 +1,165 @@ +/* + This file is part of GNUnet. + (C) 2012 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 + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + 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. +*/ + +/** + * @file include/gnunet_lockmanager_service.h + * @brief API for the lockmanger service + * @author Sree Harsha Totakura + */ + +#ifndef GNUNET_LOCKMANAGER_SERVICE_H +#define GNUNET_LOCKMANAGER_SERVICE_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_configuration_lib.h" + +/** + * Opaque handle for the lockmanager service + */ +struct GNUNET_LOCKMANAGER_Handle; + + +/** + * Connect to the lockmanager service + * + * @param cfg the configuration to use + * + * @return upon success the handle to the service; NULL upon error + */ +struct GNUNET_LOCKMANAGER_Handle * +GNUNET_LOCKMANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); + + +/** + * Disconnect from the lockmanager service + * + * @param handle the handle to the lockmanager service + */ +void +GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle); + + +/** + * Enumeration for status + */ +enum GNUNET_LOCKMANAGER_Status + { + /** + * Signifies a successful operation + */ + GNUNET_LOCKMANAGER_SUCCESS = 1, + + /** + * Used to signal that a lock is no longer valid. It must then be released + */ + GNUNET_LOCKMANAGER_RELEASE + }; + + +/** + * This callback will be called when a lock has been successfully acquired or + * when an acquired lock has been lost (happens when the lockmanager service + * crashes/restarts). + * + * @param cls the closure from GNUNET_LOCKMANAGER_lock call + * + * @param domain_name the locking domain of the lock + * + * @param lock the lock for which this status is relevant + * + * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully + * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost + */ +typedef void +(*GNUNET_LOCKMANAGER_StatusCallback) (void *cls, + const char *domain_name, + uint32_t lock, + enum GNUNET_LOCKMANAGER_Status + status); + + +/** + * Opaque handle to locking request + */ +struct GNUNET_LOCKMANAGER_LockingRequest; + + +/** + * Tries to acquire the given lock(even if the lock has been lost) until the + * request is called. If the lock is available the status_cb will be + * called. If the lock is busy then the request is queued and status_cb + * will be called when the lock has been made available and acquired by us. + * + * @param handle the handle to the lockmanager service + * + * @param domain_name name of the locking domain. Clients who want to share + * locks must use the same name for the locking domain. Also the + * domain_name should be selected with the prefix + * "GNUNET_<PROGRAM_NAME>_" to avoid domain name collisions. + * + * + * @param lock which lock to lock + * + * @param status_cb the callback for signalling when the lock is acquired and + * when it is lost + * + * @param status_cb_cls the closure to the above callback + * + * @return the locking request handle for this request + */ +struct GNUNET_LOCKMANAGER_LockingRequest * +GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle, + const char *domain_name, + uint32_t lock, + GNUNET_LOCKMANAGER_StatusCallback + status_cb, + void *status_cb_cls); + + +/** + * Function to cancel the locking request generated by + * GNUNET_LOCKMANAGER_acquire_lock. If the lock is acquired us then the lock is + * released. GNUNET_LOCKMANAGER_StatusCallback will not be called upon any + * status changes resulting due to this call. + * + * @param request the LockingRequest to cancel + */ +void +GNUNET_LOCKMANAGER_cancel_request (struct GNUNET_LOCKMANAGER_LockingRequest + *request); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_LOCKMANAGER_SERVICE_H */ +#endif +/* end of gnunet_lockmanager_service.h */ diff --git a/src/include/gnunet_mysql_lib.h b/src/include/gnunet_mysql_lib.h new file mode 100644 index 0000000..c61bdca --- /dev/null +++ b/src/include/gnunet_mysql_lib.h @@ -0,0 +1,214 @@ +/* + This file is part of GNUnet + (C) 2012 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 + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + 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. +*/ +/** + * @file include/gnunet_mysql_lib.h + * @brief library to help with access to a MySQL database + * @author Christian Grothoff + */ +#ifndef GNUNET_MYSQL_LIB_H +#define GNUNET_MYSQL_LIB_H + +#include "gnunet_util_lib.h" +#include <mysql/mysql.h> + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +/** + * Mysql context. + */ +struct GNUNET_MYSQL_Context; + + +/** + * Handle for a prepared statement. + */ +struct GNUNET_MYSQL_StatementHandle; + + +/** + * Type of a callback that will be called for each + * data set returned from MySQL. + * + * @param cls user-defined argument + * @param num_values number of elements in values + * @param values values returned by MySQL + * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort + */ +typedef int (*GNUNET_MYSQL_DataProcessor) (void *cls, unsigned int num_values, + MYSQL_BIND * values); + + +/** + * Create a mysql context. + * + * @param cfg configuration + * @param section configuration section to use to get MySQL configuration options + * @return the mysql context + */ +struct GNUNET_MYSQL_Context * +GNUNET_MYSQL_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section); + + +/** + * Destroy a mysql context. Also frees all associated prepared statements. + * + * @param mc context to destroy + */ +void +GNUNET_MYSQL_context_destroy (struct GNUNET_MYSQL_Context *mc); + + +/** + * Close database connection and all prepared statements (we got a DB + * error). The connection will automatically be re-opened and + * statements will be re-prepared if they are needed again later. + * + * @param mc mysql context + */ +void +GNUNET_MYSQL_statements_invalidate (struct GNUNET_MYSQL_Context *mc); + + +/** + * Get internal handle for a prepared statement. This function should rarely + * be used, and if, with caution! On failures during the interaction with + * the handle, you must call 'GNUNET_MYSQL_statements_invalidate'! + * + * @param mc mysql context + * @param sh prepared statement to introspect + * @return MySQL statement handle, NULL on error + */ +MYSQL_STMT * +GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_Context *mc, + struct GNUNET_MYSQL_StatementHandle *sh); + + +/** + * Prepare a statement. Prepared statements are automatically discarded + * when the MySQL context is destroyed. + * + * @param mc mysql context + * @param query query text + * @return prepared statement, NULL on error + */ +struct GNUNET_MYSQL_StatementHandle * +GNUNET_MYSQL_statement_prepare (struct GNUNET_MYSQL_Context *mc, + const char *query); + + +/** + * Run a SQL statement. + * + * @param mc mysql context + * @param sql SQL statement to run + * @return GNUNET_OK on success + * GNUNET_SYSERR if there was a problem + */ +int +GNUNET_MYSQL_statement_run (struct GNUNET_MYSQL_Context *mc, + const char *sql); + + +/** + * Run a prepared SELECT statement. + * + * @param mc mysql context + * @param sh handle to SELECT statment + * @param result_size number of elements in results array + * @param results pointer to already initialized MYSQL_BIND + * array (of sufficient size) for passing results + * @param processor function to call on each result + * @param processor_cls extra argument to processor + * @param ... pairs and triplets of "MYSQL_TYPE_XXX" keys and their respective + * values (size + buffer-reference for pointers); terminated + * with "-1" + * @return GNUNET_SYSERR on error, otherwise + * the number of successfully affected (or queried) rows + */ +int +GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_Context *mc, + struct GNUNET_MYSQL_StatementHandle *sh, + unsigned int result_size, MYSQL_BIND * results, + GNUNET_MYSQL_DataProcessor processor, + void *processor_cls, ...); + + +/** + * Run a prepared SELECT statement. + * + * @param mc mysql context + * @param s statement to run + * @param result_size number of elements in results array + * @param results pointer to already initialized MYSQL_BIND + * array (of sufficient size) for passing results + * @param processor function to call on each result + * @param processor_cls extra argument to processor + * @param ap pairs and triplets of "MYSQL_TYPE_XXX" keys and their respective + * values (size + buffer-reference for pointers); terminated + * with "-1" + * @return GNUNET_SYSERR on error, otherwise + * the number of successfully affected (or queried) rows + */ +int +GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc, + struct GNUNET_MYSQL_StatementHandle *s, + unsigned int result_size, + MYSQL_BIND * results, + GNUNET_MYSQL_DataProcessor processor, + void *processor_cls, + va_list ap); + + +/** + * Run a prepared statement that does NOT produce results. + * + * @param mc mysql context + * @param sh handle to statment + * @param insert_id NULL or address where to store the row ID of whatever + * was inserted (only for INSERT statements!) + * @param ... pairs and triplets of "MYSQL_TYPE_XXX" keys and their respective + * values (size + buffer-reference for pointers); terminated + * with "-1" + * @return GNUNET_SYSERR on error, otherwise + * the number of successfully affected rows + */ +int +GNUNET_MYSQL_statement_run_prepared (struct GNUNET_MYSQL_Context *mc, + struct GNUNET_MYSQL_StatementHandle *sh, + unsigned long long *insert_id, ...); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* end of gnunet_mysql_lib.h */ +#endif diff --git a/src/include/gnunet_namestore_plugin.h b/src/include/gnunet_namestore_plugin.h index 5468513..b27867f 100644 --- a/src/include/gnunet_namestore_plugin.h +++ b/src/include/gnunet_namestore_plugin.h @@ -56,7 +56,7 @@ typedef void (*GNUNET_NAMESTORE_RecordIterator) (void *cls, const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, struct GNUNET_TIME_Absolute expire, const char *name, - unsigned int rd_count, + unsigned int rd_len, const struct GNUNET_NAMESTORE_RecordData *rd, const struct GNUNET_CRYPTO_RsaSignature *signature); @@ -85,13 +85,13 @@ struct GNUNET_NAMESTORE_PluginFunctions * @param rd array of records with data to store * @param signature signature of the record block, NULL if signature is unavailable (i.e. * because the user queried for a particular record type only) - * @return GNUNET_OK on success + * @return GNUNET_OK on success, else GNUNET_SYSERR */ int (*put_records) (void *cls, const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, struct GNUNET_TIME_Absolute expire, const char *name, - unsigned int rd_count, + unsigned int rd_len, const struct GNUNET_NAMESTORE_RecordData *rd, const struct GNUNET_CRYPTO_RsaSignature *signature); @@ -105,7 +105,7 @@ struct GNUNET_NAMESTORE_PluginFunctions * @return GNUNET_OK on success */ int (*remove_records) (void *cls, - const GNUNET_HashCode *zone, + const struct GNUNET_CRYPTO_ShortHashCode *zone, const char *name); @@ -115,27 +115,44 @@ struct GNUNET_NAMESTORE_PluginFunctions * * @param cls closure (internal context for the plugin) * @param zone hash of public key of the zone, NULL to iterate over all zones - * @param name_hash hash of name, NULL to iterate over all records of the zone + * @param name name as '\0' terminated string, NULL to iterate over all records of the zone * @param offset offset in the list of all matching records * @param iter function to call with the result * @param iter_cls closure for iter * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error */ int (*iterate_records) (void *cls, - const GNUNET_HashCode *zone, - const GNUNET_HashCode *name_hash, + const struct GNUNET_CRYPTO_ShortHashCode *zone, + const char *name, uint64_t offset, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls); /** + * Look for an existing PKEY delegation record for a given public key. + * Returns at most one result to the iterator. + * + * @param cls closure (internal context for the plugin) + * @param zone hash of public key of the zone to look up in, never NULL + * @param value_zone hash of the public key of the target zone (value), never NULL + * @param iter function to call with the result + * @param iter_cls closure for iter + * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error + */ + int (*zone_to_name) (void *cls, + const struct GNUNET_CRYPTO_ShortHashCode *zone, + const struct GNUNET_CRYPTO_ShortHashCode *value_zone, + GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls); + + + /** * Delete an entire zone (all records). Not used in normal operation. * * @param cls closure (internal context for the plugin) * @param zone zone to delete */ void (*delete_zone) (void *cls, - const GNUNET_HashCode *zone); + const struct GNUNET_CRYPTO_ShortHashCode *zone); }; diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index 8ab2ce8..a484601 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h @@ -44,6 +44,26 @@ extern "C" #endif /** + * Record type indicating any record/'*' + */ +#define GNUNET_NAMESTORE_TYPE_ANY 0 + +/** + * Record type for GNS zone transfer ("PKEY"). + */ +#define GNUNET_NAMESTORE_TYPE_PKEY 65536 + +/** + * Record type for GNS zone transfer ("PSEU"). + */ +#define GNUNET_NAMESTORE_TYPE_PSEU 65537 + +/** + * Record type for GNS legacy hostnames ("LEHO"). + */ +#define GNUNET_NAMESTORE_TYPE_LEHO 65538 + +/** * Entry in the queue. */ struct GNUNET_NAMESTORE_QueueEntry; @@ -63,6 +83,8 @@ struct GNUNET_NAMESTORE_ZoneIterator; */ #define GNUNET_NAMESTORE_MAX_VALUE_SIZE (63 * 1024) + + /** * Connect to the namestore service. * @@ -90,7 +112,7 @@ GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h, int drop); * * @param cls closure * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) - * GNUNET_NO if content was already there + * GNUNET_NO if content was already there or not found * GNUNET_YES (or other positive value) on success * @param emsg NULL on success, otherwise an error message */ @@ -121,7 +143,13 @@ enum GNUNET_NAMESTORE_RecordFlags * This is a private record of this peer and it should * thus not be handed out to other peers. */ - GNUNET_NAMESTORE_RF_PRIVATE = 2 + GNUNET_NAMESTORE_RF_PRIVATE = 2, + + /** + * This record was added by the system + * and is pending user confimation + */ + GNUNET_NAMESTORE_RF_PENDING = 4 }; @@ -168,7 +196,7 @@ struct GNUNET_NAMESTORE_RecordData * @param h handle to the namestore * @param zone_key public key of the zone * @param name name that is being mapped (at most 255 characters long) - * @param expire when does the corresponding block in the DHT expire (until + * @param freshness when does the corresponding block in the DHT expire (until * when should we never do a DHT lookup for the same name again)? * @param rd_count number of entries in 'rd' array * @param rd array of records with data to store @@ -181,7 +209,7 @@ struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, const char *name, - struct GNUNET_TIME_Absolute expire, + struct GNUNET_TIME_Absolute freshness, unsigned int rd_count, const struct GNUNET_NAMESTORE_RecordData *rd, const struct GNUNET_CRYPTO_RsaSignature *signature, @@ -194,6 +222,7 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, * to validate signatures received from the network. * * @param public_key public key of the zone + * @param expire block expiration * @param name name that is being mapped (at most 255 characters long) * @param rd_count number of entries in 'rd' array * @param rd array of records with data to store @@ -202,10 +231,11 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, */ int GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, - const char *name, - unsigned int rd_count, - const struct GNUNET_NAMESTORE_RecordData *rd, - const struct GNUNET_CRYPTO_RsaSignature *signature); + const struct GNUNET_TIME_Absolute freshness, + const char *name, + unsigned int rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd, + const struct GNUNET_CRYPTO_RsaSignature *signature); /** @@ -223,11 +253,11 @@ GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinary */ struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h, - const struct GNUNET_CRYPTO_RsaPrivateKey *pkey, - const char *name, - const struct GNUNET_NAMESTORE_RecordData *rd, - GNUNET_NAMESTORE_ContinuationWithStatus cont, - void *cont_cls); + const struct GNUNET_CRYPTO_RsaPrivateKey *pkey, + const char *name, + const struct GNUNET_NAMESTORE_RecordData *rd, + GNUNET_NAMESTORE_ContinuationWithStatus cont, + void *cont_cls); /** @@ -240,7 +270,7 @@ GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h, * @param h handle to the namestore * @param pkey private key of the zone * @param name name that is being mapped (at most 255 characters long) - * @param rd record data + * @param rd record data, remove specific record, NULL to remove the name and all records * @param cont continuation to call when done * @param cont_cls closure for cont * @return handle to abort the request @@ -272,9 +302,9 @@ GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h, */ typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls, const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, - struct GNUNET_TIME_Absolute expire, + struct GNUNET_TIME_Absolute freshness, const char *name, - unsigned int rd_count, + unsigned int rd_len, const struct GNUNET_NAMESTORE_RecordData *rd, const struct GNUNET_CRYPTO_RsaSignature *signature); @@ -295,17 +325,36 @@ typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls, */ struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, - const GNUNET_HashCode *zone, + const struct GNUNET_CRYPTO_ShortHashCode *zone, const char *name, uint32_t record_type, GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls); /** + * Look for an existing PKEY delegation record for a given public key. + * Returns at most one result to the processor. + * + * @param h handle to the namestore + * @param zone hash of public key of the zone to look up in, never NULL + * @param value_zone hash of the public key of the target zone (value), never NULL + * @param proc function to call on the matching records, or with + * NULL (rd_count == 0) if there are no matching records + * @param proc_cls closure for proc + * @return a handle that can be used to + * cancel + */ +struct GNUNET_NAMESTORE_QueueEntry * +GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, + const struct GNUNET_CRYPTO_ShortHashCode *zone, + const struct GNUNET_CRYPTO_ShortHashCode *value_zone, + GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls); + + + +/** * Starts a new zone iteration (used to periodically PUT all of our - * records into our DHT). This MUST lock the GNUNET_NAMESTORE_Handle - * for any other calls than GNUNET_NAMESTORE_zone_iterator_next and - * GNUNET_NAMESTORE_zone_iteration_stop. "proc" will be called once + * records into our DHT). "proc" will be called once * immediately, and then again after * "GNUNET_NAMESTORE_zone_iterator_next" is invoked. * @@ -321,7 +370,7 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, */ struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h, - const GNUNET_HashCode *zone, + const struct GNUNET_CRYPTO_ShortHashCode *zone, enum GNUNET_NAMESTORE_RecordFlags must_have_flags, enum GNUNET_NAMESTORE_RecordFlags must_not_have_flags, GNUNET_NAMESTORE_RecordProcessor proc, @@ -357,6 +406,117 @@ void GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe); + +/* convenience APIs for serializing / deserializing GNS records */ + +/** + * Calculate how many bytes we will need to serialize the given + * records. + * + * @param rd_count number of records in the rd array + * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements + * + * @return the required size to serialize + * + */ +size_t +GNUNET_NAMESTORE_records_get_size (unsigned int rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd); + +/** + * Serialize the given records to the given destination buffer. + * + * @param rd_count number of records in the rd array + * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements + * @param dest_size size of the destination array + * @param dest where to write the result + * + * @return the size of serialized records + */ +ssize_t +GNUNET_NAMESTORE_records_serialize (unsigned int rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd, + size_t dest_size, + char *dest); + + +/** + * Deserialize the given records to the given destination. + * + * @param len size of the serialized record data + * @param src the serialized record data + * @param rd_count number of records in the rd array + * @param dest where to put the data + * + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_NAMESTORE_records_deserialize (size_t len, + const char *src, + unsigned int rd_count, + struct GNUNET_NAMESTORE_RecordData *dest); + + +/** + * Checks if a name is wellformed + * + * @param name the name to check + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_NAMESTORE_check_name (const char * name); + +/** + * Convert the 'value' of a record to a string. + * + * @param type type of the record + * @param data value in binary encoding + * @param data_size number of bytes in data + * @return NULL on error, otherwise human-readable representation of the value + */ +char * +GNUNET_NAMESTORE_value_to_string (uint32_t type, + const void *data, + size_t data_size); + + +/** + * Convert human-readable version of a 'value' of a record to the binary + * representation. + * + * @param type type of the record + * @param s human-readable string + * @param data set to value in binary encoding (will be allocated) + * @param data_size set to number of bytes in data + * @return GNUNET_OK on success + */ +int +GNUNET_NAMESTORE_string_to_value (uint32_t type, + const char *s, + void **data, + size_t *data_size); + + +/** + * Convert a type name (i.e. "AAAA") to the corresponding number. + * + * @param typename name to convert + * @return corresponding number, UINT32_MAX on error + */ +uint32_t +GNUNET_NAMESTORE_typename_to_number (const char *typename); + + +/** + * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A") + * + * @param type number of a type to convert + * @return corresponding typestring, NULL on error + */ +const char * +GNUNET_NAMESTORE_number_to_typename (uint32_t type); + + #if 0 /* keep Emacsens' auto-indent happy */ { #endif diff --git a/src/include/gnunet_nat_lib.h b/src/include/gnunet_nat_lib.h index 6c1db80..3a1e9a6 100644 --- a/src/include/gnunet_nat_lib.h +++ b/src/include/gnunet_nat_lib.h @@ -117,8 +117,11 @@ GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h, const void *addr, * * @param h handle (used for configuration) * @param sa the address of the peer (IPv4-only) + * + * @return GNUNET_SYSERR on error, GNUNET_NO if nat client is disabled, + * GNUNET_OK otherwise */ -void +int GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h, const struct sockaddr_in *sa); diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h index a14d5f0..085845a 100644 --- a/src/include/gnunet_network_lib.h +++ b/src/include/gnunet_network_lib.h @@ -374,6 +374,26 @@ 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); + + +/** * Copy a native fd set * @param to destination * @param from native source set diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h index e9e484f..67b6cce 100644 --- a/src/include/gnunet_os_lib.h +++ b/src/include/gnunet_os_lib.h @@ -227,7 +227,7 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig); * @param proc pointer to process structure */ void -GNUNET_OS_process_close (struct GNUNET_OS_Process *proc); +GNUNET_OS_process_destroy (struct GNUNET_OS_Process *proc); /** @@ -364,7 +364,8 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls, /** - * Retrieve the status of a process. Nonblocking version. + * Retrieve the status of a process, waiting on him if dead. + * Nonblocking version. * * @param proc pointer to process structure * @param type status type diff --git a/src/include/gnunet_peerinfo_service.h b/src/include/gnunet_peerinfo_service.h index 12264fb..49ba916 100644 --- a/src/include/gnunet_peerinfo_service.h +++ b/src/include/gnunet_peerinfo_service.h @@ -58,7 +58,6 @@ struct GNUNET_PEERINFO_Handle * GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); - /** * Disconnect from the peerinfo service. Note that all iterators must * have completed or have been cancelled by the time this function is @@ -73,6 +72,22 @@ GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h); /** + * Continuation called with a status result. + * + * @param cls closure + * @param emsg error message, NULL on success + */ +typedef void (*GNUNET_PEERINFO_Continuation)(void *cls, + const char *emsg); + + +/** + * Opaque handle to cancel 'add' operation. + */ +struct GNUNET_PEERINFO_AddContext; + + +/** * Add a host to the persistent list. This method operates in * semi-reliable mode: if the transmission is not completed by * the time 'GNUNET_PEERINFO_disconnect' is called, it will be @@ -82,10 +97,29 @@ GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h); * * @param h handle to the peerinfo service * @param hello the verified (!) HELLO message + * @param cont continuation to call when done, NULL is allowed + * @param cont_cls closure for 'cont' + * @return handle to cancel add operation; all pending + * 'add' operations will be cancelled automatically + * on disconnect, so it is not necessary to keep this + * handle (unless 'cont' is NULL and at some point + * calling 'cont' must be prevented) */ -void +struct GNUNET_PEERINFO_AddContext * GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h, - const struct GNUNET_HELLO_Message *hello); + const struct GNUNET_HELLO_Message *hello, + GNUNET_PEERINFO_Continuation cont, + void *cont_cls); + + +/** + * Cancel pending 'add' operation. Must only be called before + * either 'cont' or 'GNUNET_PEERINFO_disconnect' are invoked. + * + * @param ac handle for the add operation to cancel + */ +void +GNUNET_PEERINFO_add_peer_cancel (struct GNUNET_PEERINFO_AddContext *ac); /** diff --git a/src/include/gnunet_postgres_lib.h b/src/include/gnunet_postgres_lib.h new file mode 100644 index 0000000..559793d --- /dev/null +++ b/src/include/gnunet_postgres_lib.h @@ -0,0 +1,163 @@ +/* + This file is part of GNUnet + (C) 2012 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 + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + 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. +*/ +/** + * @file include/gnunet_postgres_lib.h + * @brief library to help with access to a Postgres database + * @author Christian Grothoff + */ +#ifndef GNUNET_POSTGRES_LIB_H +#define GNUNET_POSTGRES_LIB_H + +#include "gnunet_util_lib.h" +#include <postgresql/libpq-fe.h> + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +/** + * Check if the result obtained from Postgres has + * the desired status code. If not, log an error, clear the + * result and return GNUNET_SYSERR. + * + * @param dbh database handle + * @param ret return value from database operation to check + * @param expected_status desired status + * @param command description of the command that was run + * @param args arguments given to the command + * @param filename name of the source file where the command was run + * @param line line number in the source file + * @return GNUNET_OK if the result is acceptable + */ +int +GNUNET_POSTGRES_check_result_ (PGconn *dbh, PGresult * ret, int expected_status, + const char *command, const char *args, + const char *filename, int line); + + +/** + * Check if the result obtained from Postgres has + * the desired status code. If not, log an error, clear the + * result and return GNUNET_SYSERR. + * + * @param dbh database handle + * @param ret return value from database operation to check + * @param expected_status desired status + * @param command description of the command that was run + * @param args arguments given to the command + * @return GNUNET_OK if the result is acceptable + */ +#define GNUNET_POSTGRES_check_result(dbh,ret,expected_status,command,args) GNUNET_POSTGRES_check_result_(dbh,ret,expected_status,command,args,__FILE__,__LINE__) + + +/** + * Run simple SQL statement (without results). + * + * @param dbh database handle + * @param sql statement to run + * @param filename filename for error reporting + * @param line code line for error reporting + * @return GNUNET_OK on success + */ +int +GNUNET_POSTGRES_exec_ (PGconn *dbh, const char *sql, const char *filename, int line); + + +/** + * Run simple SQL statement (without results). + * + * @param dbh database handle + * @param sql statement to run + * @return GNUNET_OK on success + */ +#define GNUNET_POSTGRES_exec(dbh,sql) GNUNET_POSTGRES_exec_(dbh,sql,__FILE__,__LINE__) + + +/** + * Prepare SQL statement. + * + * @param dbh database handle + * @param name name for the prepared SQL statement + * @param sql SQL code to prepare + * @param nparms number of parameters in sql + * @param filename filename for error reporting + * @param line code line for error reporting + * @return GNUNET_OK on success + */ +int +GNUNET_POSTGRES_prepare_ (PGconn *dbh, const char *name, const char *sql, + int nparms, + const char *filename, int line); + + +/** + * Prepare SQL statement. + * + * @param dbh database handle + * @param name name for the prepared SQL statement + * @param sql SQL code to prepare + * @param nparams number of parameters in sql + * @return GNUNET_OK on success + */ +#define GNUNET_POSTGRES_prepare(dbh,name,sql,nparams) GNUNET_POSTGRES_prepare_(dbh,name,sql,nparams,__FILE__,__LINE__) + + +/** + * Connect to a postgres database + * + * @param cfg configuration + * @param section configuration section to use to get Postgres configuration options + * @return the postgres handle + */ +PGconn * +GNUNET_POSTGRES_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section); + + +/** + * Delete the row identified by the given rowid (qid + * in postgres). + * + * @param dbh database handle + * @param stmt name of the prepared statement + * @param rowid which row to delete + * @return GNUNET_OK on success + */ +int +GNUNET_POSTGRES_delete_by_rowid (PGconn *dbh, + const char *stmt, + uint32_t rowid); + + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* end of gnunet_postgres_lib.h */ +#endif diff --git a/src/include/gnunet_program_lib.h b/src/include/gnunet_program_lib.h index 48d5280..fa96ecf 100644 --- a/src/include/gnunet_program_lib.h +++ b/src/include/gnunet_program_lib.h @@ -60,6 +60,28 @@ typedef void (*GNUNET_PROGRAM_Main) (void *cls, char *const *args, * @param argc number of command line arguments * @param argv command line arguments * @param binaryName our expected name + * @param binaryHelp help text for the program + * @param options command line options + * @param task main function to run + * @param task_cls closure for task + * @param run_without_scheduler GNUNET_NO start the scheduler, GNUNET_YES do not + * start the scheduler just run the main task + * @return GNUNET_SYSERR on error, GNUNET_OK on success + */ +int +GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, + const char *binaryHelp, + const struct GNUNET_GETOPT_CommandLineOption *options, + GNUNET_PROGRAM_Main task, void *task_cls, + int run_without_scheduler); + +/** + * Run a standard GNUnet command startup sequence (initialize loggers + * and configuration, parse options). + * + * @param argc number of command line arguments + * @param argv command line arguments + * @param binaryName our expected name * @param binaryHelp helptext for "-h" option (about the app) * @param options command line options * @param task main function to run diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index dd7c7fe..b655f08 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -87,6 +87,15 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_ARM_RESULT 11 +/** + * Request to ARM to list all currently running services + */ +#define GNUNET_MESSAGE_TYPE_ARM_LIST 12 + +/** + * Response from ARM for listing currently running services + */ +#define GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT 13 /******************************************************************************* * HELLO message types @@ -119,15 +128,18 @@ extern "C" ******************************************************************************/ /** - * Type of messages between the gnunet-wlan-helper and the daemon - * + * Type of data messages from the plugin to the gnunet-wlan-helper */ -#define GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA 40 +#define GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER 39 /** - * Control messages between the gnunet-wlan-helper and the daemon + * Type of data messages from the gnunet-wlan-helper to the plugin */ +#define GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER 40 +/** + * Control message between the gnunet-wlan-helper and the daemon (with the MAC). + */ #define GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL 41 /** @@ -243,12 +255,6 @@ extern "C" #define GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY 65 /** - * Notify clients about new peer-to-peer connections (before - * key exchange and authentication). - */ -#define GNUNET_MESSAGE_TYPE_CORE_NOTIFY_PRE_CONNECT 66 - -/** * Notify clients about new peer-to-peer connections (triggered * after key exchange). */ @@ -518,25 +524,40 @@ extern "C" #define GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT 148 /** - * Request / receive information about transiting GETs + * Receive information about transiting GETs */ #define GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET 149 /** - * Request / receive information about transiting GET responses + * Receive information about transiting GET responses */ #define GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP 150 /** - * Request / receive information about transiting PUTs + * Receive information about transiting PUTs */ #define GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT 151 /** - * Request / receive information about transiting PUT responses (TODO) + * Receive information about transiting PUT responses (TODO) */ #define GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT_RESP 152 +/** + * Request information about transiting messages + */ +#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_START 153 + +/** + * Stop information about transiting messages + */ +#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP 154 + +/** + * Acknowledge receiving PUT request + */ +#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT_OK 155 + /******************************************************************************* * HOSTLIST message types @@ -1007,7 +1028,11 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE 351 - +/** + * Type of the 'struct AddressUseMessage' sent by ATS to client + * to confirm that an address is used or not used anymore + */ +#define GNUNET_MESSAGE_TYPE_ATS_RESET_BACKOFF 352 /******************************************************************************* @@ -1260,8 +1285,27 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_NAMESTORE_START 430 +/******************************************************************************* + * LOCKMANAGER message types + ******************************************************************************/ + +/** + * Message to acquire Lock + */ +#define GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE 440 + +/** + * Message to release lock + */ +#define GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE 441 + +/** + * SUCESS reply from lockmanager + */ +#define GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS 442 + /** - * Next available: 440 + * Next available: 450 */ /******************************************************************************* diff --git a/src/include/gnunet_pseudonym_lib.h b/src/include/gnunet_pseudonym_lib.h index bde98ef..8fd938d 100644 --- a/src/include/gnunet_pseudonym_lib.h +++ b/src/include/gnunet_pseudonym_lib.h @@ -44,12 +44,16 @@ extern "C" * * @param cls closure * @param pseudonym hash code of public key of pseudonym + * @param name name of the pseudonym (might be NULL) + * @param unique_name unique name of the pseudonym (might be NULL) * @param md meta data known about the pseudonym * @param rating the local rating of the pseudonym * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort */ typedef int (*GNUNET_PSEUDONYM_Iterator) (void *cls, const GNUNET_HashCode * pseudonym, + const char *name, + const char *unique_name, const struct GNUNET_CONTAINER_MetaData * md, int rating); @@ -110,22 +114,76 @@ GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator iterator, void *closure); /** - * Return the unique, human readable name for the given pseudonym. + * Return unique variant of the namespace name. + * Use after GNUNET_PSEUDONYM_id_to_name() to make sure + * that name is unique. * - * @return NULL on failure (should never happen) + * @param cfg configuration + * @param nsid cryptographic ID of the namespace + * @param name name to uniquify + * @param suffix if not NULL, filled with the suffix value + * @return NULL on failure (should never happen), name on success. + * Free the name with GNUNET_free(). */ char * -GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg, - const GNUNET_HashCode * pseudo); +GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg, + const GNUNET_HashCode * nsid, const char *name, unsigned int *suffix); /** - * Get the pseudonym ID belonging to the given human readable name. + * Get namespace name, metadata and rank + * This is a wrapper around internal read_info() call, and ensures that + * returned data is not invalid (not NULL). + * Writing back information returned by this function will give + * a name "no-name" to pseudonyms that have no name. This side-effect is + * unavoidable, but hardly harmful. * - * @return GNUNET_OK on success + * @param cfg configuration + * @param nsid cryptographic ID of the namespace + * @param ret_meta a location to store metadata pointer. NULL, if metadata + * is not needed. Destroy with GNUNET_CONTAINER_meta_data_destroy(). + * @param ret_rank a location to store rank. NULL, if rank not needed. + * @param ret_name a location to store human-readable name. Name is not unique. + * NULL, if name is not needed. Free with GNUNET_free(). + * @param name_is_a_dup is set to GNUNET_YES, if ret_name was filled with + * a duplicate of a "no-name" placeholder + * @return GNUNET_OK on success. GNUENT_SYSERR if the data was + * unobtainable (in that case ret_* are filled with placeholders - + * empty metadata container, rank -1 and a "no-name" name). + */ +int +GNUNET_PSEUDONYM_get_info (const struct GNUNET_CONFIGURATION_Handle *cfg, + const GNUNET_HashCode * nsid, struct GNUNET_CONTAINER_MetaData **ret_meta, + int32_t *ret_rank, char **ret_name, int *name_is_a_dup); + + +/** + * Get the namespace ID belonging to the given namespace name. + * + * @param cfg configuration to use + * @param ns_uname unique (!) human-readable name for the namespace + * @param nsid set to namespace ID based on 'ns_uname' + * @return GNUNET_OK on success, GNUNET_SYSERR on failure */ int GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *hname, GNUNET_HashCode * psid); + const char *ns_uname, GNUNET_HashCode * nsid); + +/** + * Set the pseudonym metadata, rank and name. + * + * @param cfg overall configuration + * @param nsid id of the pseudonym + * @param name name to set. Must be the non-unique version of it. + * May be NULL, in which case it erases pseudonym's name! + * @param md metadata to set + * May be NULL, in which case it erases pseudonym's metadata! + * @param rank rank to assign + * @return GNUNET_OK on success, GNUNET_SYSERR on failure + */ +int +GNUNET_PSEUDONYM_set_info (const struct GNUNET_CONFIGURATION_Handle *cfg, + const GNUNET_HashCode * nsid, const char *name, + const struct GNUNET_CONTAINER_MetaData *md, int rank); #if 0 /* keep Emacsens' auto-indent happy */ diff --git a/src/include/gnunet_regex_lib.h b/src/include/gnunet_regex_lib.h new file mode 100644 index 0000000..aec37c1 --- /dev/null +++ b/src/include/gnunet_regex_lib.h @@ -0,0 +1,180 @@ +/* + This file is part of GNUnet + (C) 2012 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 + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + 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. +*/ +/** + * @file include/gnunet_regex_lib.h + * @brief library to parse regular expressions into dfa + * @author Maximilian Szengel + * + */ + +#ifndef GNUNET_REGEX_LIB_H +#define GNUNET_REGEX_LIB_H + +#include "gnunet_util_lib.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +/** + * Automaton (NFA/DFA) representation. + */ +struct GNUNET_REGEX_Automaton; + +/** + * Edge representation. + */ +struct GNUNET_REGEX_Edge +{ + /** + * Label of the edge. + */ + const char *label; + + /** + * Destionation of the edge. + */ + GNUNET_HashCode destination; +}; + +/** + * Construct an NFA by parsing the regex string of length 'len'. + * + * @param regex regular expression string. + * @param len length of the string. + * + * @return NFA, needs to be freed using GNUNET_REGEX_destroy_automaton. + */ +struct GNUNET_REGEX_Automaton * +GNUNET_REGEX_construct_nfa (const char *regex, const size_t len); + +/** + * Construct DFA for the given 'regex' of length 'len'. + * + * @param regex regular expression string. + * @param len length of the regular expression. + * + * @return DFA, needs to be freed using GNUNET_REGEX_destroy_automaton. + */ +struct GNUNET_REGEX_Automaton * +GNUNET_REGEX_construct_dfa (const char *regex, const size_t len); + +/** + * Free the memory allocated by constructing the GNUNET_REGEX_Automaton. + * data structure. + * + * @param a automaton to be destroyed. + */ +void +GNUNET_REGEX_automaton_destroy (struct GNUNET_REGEX_Automaton *a); + +/** + * Save the given automaton as a GraphViz dot file. + * + * @param a the automaton to be saved. + * @param filename where to save the file. + */ +void +GNUNET_REGEX_automaton_save_graph (struct GNUNET_REGEX_Automaton *a, + const char *filename); + +/** + * Evaluates the given 'string' against the given compiled regex. + * + * @param a automaton. + * @param string string to check. + * + * @return 0 if string matches, non 0 otherwise. + */ +int +GNUNET_REGEX_eval (struct GNUNET_REGEX_Automaton *a, + const char *string); + +/** + * Get the first key for the given 'input_string'. This hashes + * the first x bits of the 'input_strings'. + * + * @param input_string string. + * @param string_len length of the 'input_string'. + * @param key pointer to where to write the hash code. + * + * @return number of bits of 'input_string' that have been consumed + * to construct the key + */ +unsigned int +GNUNET_REGEX_get_first_key (const char *input_string, unsigned int string_len, + GNUNET_HashCode * key); + +/** + * Check if the given 'proof' matches the given 'key'. + * + * @param proof partial regex + * @param key hash + * + * @return GNUNET_OK if the proof is valid for the given key + */ +int +GNUNET_REGEX_check_proof (const char *proof, + const GNUNET_HashCode *key); + +/** + * Iterator callback function. + * + * @param cls closure. + * @param key hash for current state. + * @param proof proof for current state. + * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not. + * @param num_edges number of edges leaving current state. + * @param edges edges leaving current state. + */ +typedef void (*GNUNET_REGEX_KeyIterator)(void *cls, + const GNUNET_HashCode *key, + const char *proof, + int accepting, + unsigned int num_edges, + const struct GNUNET_REGEX_Edge *edges); + +/** + * Iterate over all edges starting from start state of automaton 'a'. Calling + * iterator for each edge. + * + * @param a automaton. + * @param iterator iterator called for each edge. + * @param iterator_cls closure. + */ +void +GNUNET_REGEX_iterate_all_edges (struct GNUNET_REGEX_Automaton *a, + GNUNET_REGEX_KeyIterator iterator, + void *iterator_cls); + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* end of gnunet_regex_lib.h */ +#endif + diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h index e16ccc5..4727534 100644 --- a/src/include/gnunet_scheduler_lib.h +++ b/src/include/gnunet_scheduler_lib.h @@ -238,7 +238,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls); * scheduled AFTER this call may still be delayed arbitrarily. */ void -GNUNET_SCHEDULER_shutdown (); +GNUNET_SCHEDULER_shutdown (void); /** @@ -309,26 +309,6 @@ GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_Task task, voi /** - * Schedule a new task to be run after the specified prerequisite task - * has completed. It will be run with DEFAULT priority. - * - * * @param prerequisite_task run this task after the task with the given - * task identifier completes (and any of our other - * conditions, such as delay, read or write-readiness - * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency - * on completion of other tasks (this will cause the task to run as - * soon as possible). - * @param task main function of the task - * @param task_cls closure of task - * @return unique task identifier for the job - * only valid until "task" is started! - */ -GNUNET_SCHEDULER_TaskIdentifier -GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, - GNUNET_SCHEDULER_Task task, void *task_cls); - - -/** * Schedule a new task to be run with a specified priority. * * * @param prio how important is the new task? @@ -432,6 +412,30 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, /** + * Schedule a new task to be run with a specified priority and to be + * run after the specified delay or when the specified file descriptor + * is ready for reading. The delay can be used as a timeout on the + * socket being ready. The task will be scheduled for execution once + * either the delay has expired or the socket operation is ready. It + * will be run with the DEFAULT priority. + * + * @param delay when should this operation time out? Use + * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" + * @param priority priority to use for the task + * @param rfd read file-descriptor + * @param task main function of the task + * @param task_cls closure of task + * @return unique task identifier for the job + * only valid until "task" is started! + */ +GNUNET_SCHEDULER_TaskIdentifier +GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay, + enum GNUNET_SCHEDULER_Priority priority, + struct GNUNET_NETWORK_Handle *rfd, + GNUNET_SCHEDULER_Task task, void *task_cls); + + +/** * Schedule a new task to be run with a specified delay or when the * specified file descriptor is ready for writing. The delay can be * used as a timeout on the socket being ready. The task will be @@ -511,12 +515,7 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, * || shutdown-active) * </code> * - * * @param prio how important is this task? - * @param prerequisite_task run this task after the task with the given - * task identifier completes (and any of our other - * conditions, such as delay, read or write-readiness - * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency - * on completion of other tasks. + * @param prio how important is this task? * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever", * which means that the task will only be run after we receive SIGTERM * @param rs set of file descriptors we want to read (can be NULL) @@ -527,8 +526,7 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, * only valid until "task" is started! */ GNUNET_SCHEDULER_TaskIdentifier -GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, - GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, +GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws, diff --git a/src/include/gnunet_server_lib.h b/src/include/gnunet_server_lib.h index 7fb8ae7..73fe800 100644 --- a/src/include/gnunet_server_lib.h +++ b/src/include/gnunet_server_lib.h @@ -55,12 +55,16 @@ extern "C" */ struct GNUNET_SERVER_Handle; - /** * @brief opaque handle for a client of the server */ struct GNUNET_SERVER_Client; +/** + * @brief opaque handle server returns for aborting transmission to a client. + */ +struct GNUNET_SERVER_TransmitHandle; + /** * Functions with this signature are called whenever a message is @@ -151,12 +155,22 @@ GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, void *access_cls, /** + * Stop the listen socket and get ready to shutdown the server + * once only 'monitor' clients are left. + * + * @param server server to stop listening on + */ +void +GNUNET_SERVER_stop_listening (struct GNUNET_SERVER_Handle *server); + + +/** * Free resources held by this server. * - * @param s server to destroy + * @param server server to destroy */ void -GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *s); +GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server); /** @@ -190,10 +204,10 @@ GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server, * @param callback_cls closure for callback * @return non-NULL if the notify callback was queued; can be used * to cancel the request using - * GNUNET_CONNECTION_notify_transmit_ready_cancel. + * GNUNET_SERVER_notify_transmit_ready_cancel. * NULL if we are already going to notify someone else (busy) */ -struct GNUNET_CONNECTION_TransmitHandle * +struct GNUNET_SERVER_TransmitHandle * GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, size_t size, struct GNUNET_TIME_Relative timeout, @@ -202,6 +216,31 @@ GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, /** + * Abort transmission request. + * + * @param th request to abort + */ +void +GNUNET_SERVER_notify_transmit_ready_cancel (struct GNUNET_SERVER_TransmitHandle *th); + + +/** + * Set the 'monitor' flag on this client. Clients which have been + * marked as 'monitors' won't prevent the server from shutting down + * once 'GNUNET_SERVER_stop_listening' has been invoked. The idea is + * that for "normal" clients we likely want to allow them to process + * their requests; however, monitor-clients are likely to 'never' + * disconnect during shutdown and thus will not be considered when + * determining if the server should continue to exist after + * 'GNUNET_SERVER_destroy' has been called. + * + * @param client the client to set the 'monitor' flag on + */ +void +GNUNET_SERVER_client_mark_monitor (struct GNUNET_SERVER_Client *client); + + +/** * Set the persistent flag on this client, used to setup client connection * to only be killed when the service it's connected to is actually dead. * @@ -210,6 +249,7 @@ GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, void GNUNET_SERVER_client_persist_ (struct GNUNET_SERVER_Client *client); + /** * Resume receiving from this client, we are done processing the * current request. This function must be called from within each @@ -240,14 +280,6 @@ GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client, /** - * Set if a client should finish a pending write when disconnecting. - */ -void -GNUNET_SERVER_client_set_finish_pending_write (struct GNUNET_SERVER_Client *client, - int finish); - - -/** * Disable the warning the server issues if a message is not acknowledged * in a timely fashion. Use this call if a client is intentionally delayed * for a while. Only applies to the current message. @@ -392,22 +424,6 @@ GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client); /** - * Configure this server's connections to continue handling client - * requests as usual even after we get a shutdown signal. The change - * only applies to clients that connect to the server from the outside - * using TCP after this call. Clients managed previously or those - * added using GNUNET_SERVER_connect_socket and - * GNUNET_SERVER_connect_callback are not affected by this option. - * - * @param h server handle - * @param do_ignore GNUNET_YES to ignore, GNUNET_NO to restore default - */ -void -GNUNET_SERVER_ignore_shutdown (struct GNUNET_SERVER_Handle *h, int do_ignore); - - - -/** * Disable the "CORK" feature for communication with the given client, * forcing the OS to immediately flush the buffer on transmission * instead of potentially buffering multiple messages. @@ -591,11 +607,15 @@ struct GNUNET_SERVER_MessageStreamTokenizer; * Functions with this signature are called whenever a * complete message is received by the tokenizer. * + * Do not call GNUNET_SERVER_mst_destroy in callback + * * @param cls closure * @param client identification of the client * @param message the actual message + * + * @return GNUNET_OK on success, GNUNET_SYSERR to stop further processing */ -typedef void (*GNUNET_SERVER_MessageTokenizerCallback) (void *cls, void *client, +typedef int (*GNUNET_SERVER_MessageTokenizerCallback) (void *cls, void *client, const struct GNUNET_MessageHeader * message); diff --git a/src/include/gnunet_service_lib.h b/src/include/gnunet_service_lib.h index 1641e0f..39e6a80 100644 --- a/src/include/gnunet_service_lib.h +++ b/src/include/gnunet_service_lib.h @@ -43,7 +43,7 @@ extern "C" * Get the list of addresses that a server for the given service * should bind to. * - * @param serviceName name of the service + * @param service_name name of the service * @param cfg configuration (which specifies the addresses) * @param addrs set (call by reference) to an array of pointers to the * addresses the server should bind to and listen on; the @@ -60,7 +60,7 @@ extern "C" * set to NULL). */ int -GNUNET_SERVICE_get_server_addresses (const char *serviceName, +GNUNET_SERVICE_get_server_addresses (const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg, struct sockaddr ***addrs, socklen_t ** addr_lens); @@ -85,16 +85,22 @@ typedef void (*GNUNET_SERVICE_Main) (void *cls, */ enum GNUNET_SERVICE_Options { - /** - * Use defaults. - */ + /** + * Use defaults. + */ GNUNET_SERVICE_OPTION_NONE = 0, - /** - * Do not trigger server shutdown on signals, allow for the user - * to terminate the server explicitly when needed. - */ - GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN = 1 + /** + * Do not trigger server shutdown on signals, allow for the user + * to terminate the server explicitly when needed. + */ + GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN = 1, + + /** + * Trigger a SOFT server shutdown on signals, allowing active + * non-monitor clients to complete their transactions. + */ + GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN = 2 }; @@ -104,32 +110,37 @@ enum GNUNET_SERVICE_Options * * @param argc number of command line arguments * @param argv command line arguments - * @param serviceName our service name - * @param opt service options + * @param service_name our service name + * @param options service options * @param task main task of the service * @param task_cls closure for task * @return GNUNET_SYSERR on error, GNUNET_OK * if we shutdown nicely */ int -GNUNET_SERVICE_run (int argc, char *const *argv, const char *serviceName, - enum GNUNET_SERVICE_Options opt, GNUNET_SERVICE_Main task, +GNUNET_SERVICE_run (int argc, char *const *argv, const char *service_name, + enum GNUNET_SERVICE_Options options, GNUNET_SERVICE_Main task, void *task_cls); +/** + * Opaque handle for a service. + */ struct GNUNET_SERVICE_Context; /** * Run a service startup sequence within an existing * initialized system. * - * @param serviceName our service name + * @param service_name our service name * @param cfg configuration to use + * @param options service options * @return NULL on error, service handle */ struct GNUNET_SERVICE_Context * -GNUNET_SERVICE_start (const char *serviceName, - const struct GNUNET_CONFIGURATION_Handle *cfg); +GNUNET_SERVICE_start (const char *service_name, + const struct GNUNET_CONFIGURATION_Handle *cfg, + enum GNUNET_SERVICE_Options options); /** diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h index 580282d..ee105c6 100644 --- a/src/include/gnunet_signatures.h +++ b/src/include/gnunet_signatures.h @@ -115,6 +115,12 @@ extern "C" */ #define GNUNET_SIGNATURE_PURPOSE_NSE_SEND 14 + +/** + * Signature of a gnunet naming system record block + */ +#define GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN 15 + #if 0 /* keep Emacsens' auto-indent happy */ { #endif diff --git a/src/include/gnunet_statistics_service.h b/src/include/gnunet_statistics_service.h index bfd65f8..0515331 100644 --- a/src/include/gnunet_statistics_service.h +++ b/src/include/gnunet_statistics_service.h @@ -145,6 +145,7 @@ struct GNUNET_STATISTICS_GetHandle; * @param timeout after how long should we give up (and call * notify with buf NULL and size 0)? * @param cont continuation to call when done (can be NULL) + * This callback CANNOT destroy the statistics handle in the same call. * @param proc function to call on each value * @param cls closure for proc and cont * @return NULL on error diff --git a/src/include/gnunet_stream_lib.h b/src/include/gnunet_stream_lib.h index 930cc1d..e09c264 100644 --- a/src/include/gnunet_stream_lib.h +++ b/src/include/gnunet_stream_lib.h @@ -62,7 +62,12 @@ enum GNUNET_STREAM_Status /** * A serious error occured while operating on this stream */ - GNUNET_STREAM_SYSERR = 3 + GNUNET_STREAM_SYSERR = 3, + + /** + * An error resulted in an unusable stream + */ + GNUNET_STREAM_BROKEN }; /** @@ -125,18 +130,51 @@ GNUNET_STREAM_open (const struct GNUNET_CONFIGURATION_Handle *cfg, /** - * Shutdown the stream for reading or writing (man 2 shutdown). + * Handle for shutdown + */ +struct GNUNET_STREAM_ShutdownHandle; + + +/** + * Completion callback for shutdown + * + * @param cls the closure from GNUNET_STREAM_shutdown call + * @param operation the operation that was shutdown (SHUT_RD, SHUT_WR, + * SHUT_RDWR) + */ +typedef void (*GNUNET_STREAM_ShutdownCompletion) (void *cls, + int operation); + + +/** + * Shutdown the stream for reading or writing (similar to man 2 shutdown). * * @param socket the stream socket - * @param how SHUT_RD, SHUT_WR or SHUT_RDWR + * @param operation SHUT_RD, SHUT_WR or SHUT_RDWR + * @param completion_cb the callback that will be called upon successful + * shutdown of given operation + * @param completion_cls the closure for the completion callback + * @return the shutdown handle; NULL in case of any error */ -void +struct GNUNET_STREAM_ShutdownHandle * GNUNET_STREAM_shutdown (struct GNUNET_STREAM_Socket *socket, - int how); + int operation, + GNUNET_STREAM_ShutdownCompletion completion_cb, + void *completion_cls); + + +/** + * Cancels a pending shutdown + * + * @param handle the shutdown handle returned from GNUNET_STREAM_shutdown + */ +void +GNUNET_STREAM_shutdown_cancel (struct GNUNET_STREAM_ShutdownHandle *handle); /** - * Closes the stream + * Closes the stream and frees the associated state. The stream should be + * shutdown before closing. * * @param socket the stream socket */ @@ -185,10 +223,10 @@ GNUNET_STREAM_listen (const struct GNUNET_CONFIGURATION_Handle *cfg, /** * Closes the listen socket * - * @param socket the listen socket + * @param lsocket the listen socket */ void -GNUNET_STREAM_listen_close (struct GNUNET_STREAM_ListenSocket *socket); +GNUNET_STREAM_listen_close (struct GNUNET_STREAM_ListenSocket *lsocket); /** @@ -217,15 +255,22 @@ struct GNUNET_STREAM_IOWriteHandle; struct GNUNET_STREAM_IOReadHandle; /** - * Tries to write the given data to the stream + * Tries to write the given data to the stream. The maximum size of data that + * can be written as part of a write operation is (64 * (64000 - sizeof (struct + * GNUNET_STREAM_DataMessage))). If size is greater than this it is not an API + * violation, however only the said number of maximum bytes will be written. * * @param socket the socket representing a stream * @param data the data buffer from where the data is written into the stream * @param size the number of bytes to be written from the data buffer * @param timeout the timeout period - * @param write_cont the function to call upon writing some bytes into the stream + * @param write_cont the function to call upon writing some bytes into the + * stream * @param write_cont_cls the closure - * @return handle to cancel the operation; NULL if a previous write is pending + * + * @return handle to cancel the operation; if a previous write is pending or + * the stream has been shutdown for this operation then write_cont is + * immediately called and NULL is returned. */ struct GNUNET_STREAM_IOWriteHandle * GNUNET_STREAM_write (struct GNUNET_STREAM_Socket *socket, @@ -243,7 +288,7 @@ GNUNET_STREAM_write (struct GNUNET_STREAM_Socket *socket, * @param cls the closure from GNUNET_STREAM_read * @param status the status of the stream at the time this function is called * @param data traffic from the other side - * @param size the number of bytes available in data read + * @param size the number of bytes available in data read; will be 0 on timeout * @return number of bytes of processed from 'data' (any data remaining should be * given to the next time the read processor is called). */ @@ -254,13 +299,16 @@ typedef size_t (*GNUNET_STREAM_DataProcessor) (void *cls, /** - * Tries to read data from the stream + * Tries to read data from the stream. * * @param socket the socket representing a stream * @param timeout the timeout period * @param proc function to call with data (once only) * @param proc_cls the closure for proc - * @return handle to cancel the operation + * + * @return handle to cancel the operation; if the stream has been shutdown for + * this type of opeartion then the DataProcessor is immediately + * called with GNUNET_STREAM_SHUTDOWN as status and NULL if returned */ struct GNUNET_STREAM_IOReadHandle * GNUNET_STREAM_read (struct GNUNET_STREAM_Socket *socket, @@ -270,12 +318,24 @@ GNUNET_STREAM_read (struct GNUNET_STREAM_Socket *socket, /** - * Cancel pending write operation. + * Cancels pending write operation. Also cancels packet retransmissions which + * may have resulted otherwise. + * + * CAUTION: Normally a write operation is considered successful if the data + * given to it is sent and acknowledged by the receiver. As data is divided + * into packets, it is possible that not all packets are received by the + * receiver. Any missing packets are then retransmitted till the receiver + * acknowledges all packets or until a timeout . During this scenario if the + * write operation is cancelled all such retransmissions are also + * cancelled. This may leave the receiver's receive buffer incompletely filled + * as some missing packets are never retransmitted. So this operation should be + * used before shutting down transmission from our side or before closing the + * socket. * * @param ioh handle to operation to cancel */ void -GNUNET_STREAM_io_write_cancel (struct GNUNET_STREAM_IOWriteHandle *ioh); +GNUNET_STREAM_io_write_cancel (struct GNUNET_STREAM_IOWriteHandle *iowh); /** @@ -284,7 +344,7 @@ GNUNET_STREAM_io_write_cancel (struct GNUNET_STREAM_IOWriteHandle *ioh); * @param ioh handle to operation to cancel */ void -GNUNET_STREAM_io_read_cancel (struct GNUNET_STREAM_IOReadHandle *ioh); +GNUNET_STREAM_io_read_cancel (struct GNUNET_STREAM_IOReadHandle *iorh); #if 0 diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h index 8101a81..54d2e30 100644 --- a/src/include/gnunet_strings_lib.h +++ b/src/include/gnunet_strings_lib.h @@ -66,12 +66,12 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, * Convert a given fancy human-readable time to our internal * representation. * - * @param fancy_size human readable string (i.e. 1 minute) + * @param fancy_time human readable string (i.e. 1 minute) * @param rtime set to the relative time * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_size, +GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time, struct GNUNET_TIME_Relative *rtime); @@ -121,6 +121,27 @@ GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset); char * GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset); +/** + * Convert the utf-8 input string to lowercase + * Output needs to be allocated appropriately + * + * @param input input string + * @param output output buffer + */ +void +GNUNET_STRINGS_utf8_tolower(const char* input, char** output); + + +/** + * Convert the utf-8 input string to lowercase + * Output needs to be allocated appropriately + * + * @param input input string + * @param output output buffer + */ +void +GNUNET_STRINGS_utf8_toupper(const char* input, char** output); + /** * Complete filename (a la shell) from abbrevition. @@ -213,6 +234,42 @@ GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta); const char * GNUNET_STRINGS_get_short_name (const char *filename); + +/** + * Convert binary data to ASCII encoding. The ASCII encoding is rather + * GNUnet specific. It was chosen such that it only uses characters + * in [0-9A-V], can be produced without complex arithmetics and uses a + * small number of characters. The GNUnet encoding uses 103 characters. + * Does not append 0-terminator, but returns a pointer to the place where + * it should be placed, if needed. + * + * @param data data to encode + * @param size size of data (in bytes) + * @param out buffer to fill + * @param out_size size of the buffer. Must be large enough to hold + * ((size*8) + (((size*8) % 5) > 0 ? 5 - ((size*8) % 5) : 0)) / 5 + * @return pointer to the next byte in 'out' or NULL on error. + */ +char * +GNUNET_STRINGS_data_to_string (const unsigned char *data, size_t size, + char *out, size_t out_size); + + +/** + * Convert ASCII encoding back to data + * out_size must match exactly the size of the data before it was encoded. + * + * @param enc the encoding + * @param enclen number of characters in 'enc' (without 0-terminator, which can be missing) + * @param out location where to store the decoded data + * @param out_size sizeof the output buffer + * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding + */ +int +GNUNET_STRINGS_string_to_data (const char *enc, size_t enclen, + unsigned char *out, size_t out_size); + + #if 0 /* keep Emacsens' auto-indent happy */ { #endif @@ -220,6 +277,118 @@ GNUNET_STRINGS_get_short_name (const char *filename); } #endif +enum GNUNET_STRINGS_FilenameCheck +{ + GNUNET_STRINGS_CHECK_EXISTS = 0x00000001, + GNUNET_STRINGS_CHECK_IS_DIRECTORY = 0x00000002, + GNUNET_STRINGS_CHECK_IS_LINK = 0x00000004, + GNUNET_STRINGS_CHECK_IS_ABSOLUTE = 0x00000008 +}; + +/** + * Parse a path that might be an URI. + * + * @param path path to parse. Must be NULL-terminated. + * @param scheme_part a pointer to 'char *' where a pointer to a string that + * represents the URI scheme will be stored. Can be NULL. The string is + * allocated by the function, and should be freed by GNUNET_free() when + * it is no longer needed. + * @param path_part a pointer to 'const char *' where a pointer to the path + * part of the URI will be stored. Can be NULL. Points to the same block + * of memory as 'path', and thus must not be freed. Might point to '\0', + * if path part is zero-length. + * @return GNUNET_YES if it's an URI, GNUNET_NO otherwise. If 'path' is not + * an URI, '* scheme_part' and '*path_part' will remain unchanged + * (if they weren't NULL). + */ +int +GNUNET_STRINGS_parse_uri (const char *path, char **scheme_part, + const char **path_part); + + +/** + * Check whether filename is absolute or not, and if it's an URI + * + * @param filename filename to check + * @param can_be_uri GNUNET_YES to check for being URI, GNUNET_NO - to + * assume it's not URI + * @param r_is_uri a pointer to an int that is set to GNUNET_YES if 'filename' + * is URI and to GNUNET_NO otherwise. Can be NULL. If 'can_be_uri' is + * not GNUNET_YES, *r_is_uri is set to GNUNET_NO. + * @param r_uri_scheme a pointer to a char * that is set to a pointer to URI scheme. + * The string is allocated by the function, and should be freed with + * GNUNET_free (). Can be NULL. + * @return GNUNET_YES if 'filename' is absolute, GNUNET_NO otherwise. + */ +int +GNUNET_STRINGS_path_is_absolute (const char *filename, + int can_be_uri, + int *r_is_uri, + char **r_uri_scheme); + + +/** + * Perform checks on 'filename; + * + * @param filename file to check + * @param checks checks to perform + * @return GNUNET_YES if all checks pass, GNUNET_NO if at least one of them + * fails, GNUNET_SYSERR when a check can't be performed + */ +int +GNUNET_STRINGS_check_filename (const char *filename, + enum GNUNET_STRINGS_FilenameCheck checks); + + +/** + * Tries to convert 'zt_addr' string to an IPv6 address. + * The string is expected to have the format "[ABCD::01]:80". + * + * @param zt_addr 0-terminated string. May be mangled by the function. + * @param addrlen length of zt_addr (not counting 0-terminator). + * @param r_buf a buffer to fill. Initially gets filled with zeroes, + * then its sin6_port, sin6_family and sin6_addr are set appropriately. + * @return GNUNET_OK if conversion succeded. GNUNET_SYSERR otherwise, in which + * case the contents of r_buf are undefined. + */ +int +GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, + uint16_t addrlen, + struct sockaddr_in6 *r_buf); + + +/** + * Tries to convert 'zt_addr' string to an IPv4 address. + * The string is expected to have the format "1.2.3.4:80". + * + * @param zt_addr 0-terminated string. May be mangled by the function. + * @param addrlen length of zt_addr (not counting 0-terminator). + * @param r_buf a buffer to fill. + * @return GNUNET_OK if conversion succeded. GNUNET_SYSERR otherwise, in which case + * the contents of r_buf are undefined. + */ +int +GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, + uint16_t addrlen, + struct sockaddr_in *r_buf); + + +/** + * Tries to convert 'addr' string to an IP (v4 or v6) address. + * Will automatically decide whether to treat 'addr' as v4 or v6 address. + * + * @param addr a string, may not be 0-terminated. + * @param addrlen number of bytes in addr (if addr is 0-terminated, + * 0-terminator should not be counted towards addrlen). + * @param r_buf a buffer to fill. + * @return GNUNET_OK if conversion succeded. GNUNET_SYSERR otherwise, in which + * case the contents of r_buf are undefined. + */ +int +GNUNET_STRINGS_to_address_ip (const char *addr, + uint16_t addrlen, + struct sockaddr_storage *r_buf); + /* ifndef GNUNET_UTIL_STRING_H */ #endif diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h new file mode 100644 index 0000000..ab8db87 --- /dev/null +++ b/src/include/gnunet_testbed_service.h @@ -0,0 +1,1029 @@ +/* + This file is part of GNUnet + (C) 2008, 2009, 2012 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 + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + 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. + */ + +/** + * @file include/gnunet_testbed_service.h + * @brief API for writing tests and creating large-scale + * emulation testbeds for GNUnet. + * @author Christian Grothoff + */ + +#ifndef GNUNET_TESTBED_SERVICE_H +#define GNUNET_TESTBED_SERVICE_H + +#include "gnunet_util_lib.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +/** + * Opaque handle to a host running experiments managed by the testbed framework. + * The master process must be able to SSH to this host without password (via + * ssh-agent). + */ +struct GNUNET_TESTBED_Host; + +/** + * Opaque handle to a peer controlled by the testbed framework. A peer runs + * at a particular host. + */ +struct GNUNET_TESTBED_Peer; + +/** + * Opaque handle to an abstract operation to be executed by the testbed framework. + */ +struct GNUNET_TESTBED_Operation; + +/** + * Handle to interact with a GNUnet testbed controller. Each controller has at + * least one master handle which is created when the controller is created; this + * master handle interacts with the controller via stdin/stdout of the controller + * process. Additionally, controllers can interact with each other (in a P2P + * fashion); those links are established via TCP/IP on the controller's service + * port. + */ +struct GNUNET_TESTBED_Controller; + +/** + * Handle to a large-scale testbed that is managed at a high level. + */ +struct GNUNET_TESTBED_Testbed; + + +/** + * Create a host to run peers and controllers on. + * + * @param hostname name of the host, use "NULL" for localhost + * @param username username to use for the login; may be NULL + * @param port port number to use for ssh; use 0 to let ssh decide + * @return handle to the host, NULL on error + */ +struct GNUNET_TESTBED_Host * +GNUNET_TESTBED_host_create (const char *hostname, + const char *username, + uint16_t port); + + +/** + * Load a set of hosts from a configuration file. + * + * @param filename file with the host specification + * @param hosts set to the hosts found in the file + * @return number of hosts returned in 'hosts', 0 on error + */ +unsigned int +GNUNET_TESTBED_hosts_load_from_file (const char *filename, + struct GNUNET_TESTBED_Host **hosts); + + +/** + * Destroy a host handle. Must only be called once everything + * running on that host has been stopped. + * + * @param host handle to destroy + */ +void +GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host); + + +/** + * Enumeration with (at most 64) possible event types that + * can be monitored using the testbed framework. + */ +enum GNUNET_TESTBED_EventType +{ + /** + * A peer has been started. + */ + GNUNET_TESTBED_ET_PEER_START = 0, + + /** + * A peer has been stopped. + */ + GNUNET_TESTBED_ET_PEER_STOP = 1, + + /** + * A connection between two peers was established. + */ + GNUNET_TESTBED_ET_CONNECT = 2, + + /** + * A connection between two peers was torn down. + */ + GNUNET_TESTBED_ET_DISCONNECT = 3, + + /** + * A requested testbed operation has been completed. + */ + GNUNET_TESTBED_ET_OPERATION_FINISHED = 4, + + /** + * The 'GNUNET_TESTBED_run' operation has been completed + */ + GNUNET_TESTBED_ET_TESTBED_ONLINE = 5 + +}; + + +/** + * Types of information that can be requested about a peer. + */ +enum GNUNET_TESTBED_PeerInformationType +{ + + /** + * Special value (not valid for requesting information) + * that is used in the event struct if a 'generic' pointer + * is returned (for other operations not related to this + * enumeration). + */ + GNUNET_TESTBED_PIT_GENERIC = 0, + + /** + * What host is the peer running on? Returns a 'const struct + * GNUNET_TESTBED_Host *'. Valid until + * 'GNUNET_TESTBED_operation_done' is called. + */ + GNUNET_TESTBED_PIT_HOST, + + /** + * What configuration is the peer using? Returns a 'const struct + * GNUNET_CONFIGURATION_Handle *'. Valid until + * 'GNUNET_TESTNIG_operation_done' is called. However, the + * values may be inaccurate if the peer is reconfigured in + * the meantime. + */ + GNUNET_TESTBED_PIT_CONFIGURATION, + + /** + * What is the identity of the peer? Returns a + * 'const struct GNUNET_PeerIdentity *'. Valid until + * 'GNUNET_TESTNIG_operation_done' is called. + */ + GNUNET_TESTBED_PIT_IDENTITY + +}; + + +/** + * Argument to GNUNET_TESTBED_ControllerCallback with details about + * the event. + */ +struct GNUNET_TESTBED_EventInformation +{ + + /** + * Type of the event. + */ + enum GNUNET_TESTBED_EventType type; + + /** + * Details about the event. + */ + union + { + + /** + * Details about peer start event. + */ + struct + { + /** + * Handle for the host where the peer + * was started. + */ + struct GNUNET_TESTBED_Host *host; + + /** + * Handle for the peer that was started. + */ + struct GNUNET_TESTBED_Peer *peer; + + } peer_start; + + /** + * Details about peer stop event. + */ + struct + { + + /** + * Handle for the peer that was started. + */ + struct GNUNET_TESTBED_Peer *peer; + + } peer_stop; + + /** + * Details about connect event. + */ + struct + { + /** + * Handle for one of the connected peers. + */ + struct GNUNET_TESTBED_Peer *peer1; + + /** + * Handle for one of the connected peers. + */ + struct GNUNET_TESTBED_Peer *peer2; + + } peer_connect; + + /** + * Details about disconnect event. + */ + struct + { + /** + * Handle for one of the disconnected peers. + */ + struct GNUNET_TESTBED_Peer *peer1; + + /** + * Handle for one of the disconnected peers. + */ + struct GNUNET_TESTBED_Peer *peer2; + + } peer_disconnect; + + /** + * Details about an operation finished event. + */ + struct + { + + /** + * Handle for the operation that was finished. + */ + struct GNUNET_TESTBED_Operation *operation; + + /** + * Closure that was passed in when the event was + * requested. + */ + void *op_cls; + + /** + * Error message for the operation, NULL on success. + */ + const char *emsg; + + /** + * Peer information type; captures which of the types + * in the 'op_result' is actually in use. + */ + enum GNUNET_TESTBED_PeerInformationType pit; + + /** + * Pointer to an operation-specific return value; NULL on error; + * can be NULL for certain operations. Valid until + * 'GNUNET_TESTBED_operation_done' is called. + */ + union + { + /** + * No result (NULL pointer) or generic result + * (whatever the GNUNET_TESTBED_ConnectAdapter returned). + */ + void *generic; + + /** + * Identity of host running the peer. + */ + struct GNUNET_TESTBED_Host *host; + + /** + * Identity of the peer. + */ + const struct GNUNET_PeerIdentity *pid; + + /** + * Configuration of the peer. + */ + const struct GNUNET_CONFIGURATION_Handle *cfg; + + } op_result; + + } operation_finished; + + + /** + * Details about an testbed run completed event. + */ + struct + { + + /** + * Error message for the operation, NULL on success. + */ + const char *emsg; + + /** + * Array of peers now running (valid until + * 'GNUNET_TESTBED_testbed_stop' is called). Note that it is + * not allowed to call 'GNUNET_TESTBED_peer_destroy' on peers + * from this array. + */ + struct GNUNET_TESTBED_Peer **peers; + + /** + * Size of the 'peers' array. + */ + unsigned int num_peers; + + } testbed_run_finished; + + } details; + +}; + + +/** + * Signature of the event handler function called by the + * respective event controller. + * + * @param cls closure + * @param event information about the event + */ +typedef void (*GNUNET_TESTBED_ControllerCallback)(void *cls, + const struct GNUNET_TESTBED_EventInformation *event); + + +/** + * Start a controller process using the given configuration at the + * given host. + * + * @param cfg configuration to use + * @param host host to run the controller on, NULL for 'localhost' + * @param event_mask bit mask with set of events to call 'cc' for; + * or-ed values of "1LL" shifted by the + * respective 'enum GNUNET_TESTBED_EventType' + * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) | ...") + * @param cc controller callback to invoke on events + * @param cc_cls closure for cc + * @return handle to the controller + */ +struct GNUNET_TESTBED_Controller * +GNUNET_TESTBED_controller_start (const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTBED_Host *host, + uint64_t event_mask, + GNUNET_TESTBED_ControllerCallback cc, + void *cc_cls); + + +/** + * Configure shared services at a controller. Using this function, + * you can specify that certain services (such as "resolver") + * should not be run for each peer but instead be shared + * across N peers on the specified host. This function + * must be called before any peers are created at the host. + * + * @param controller controller to configure + * @param service_name name of the service to share + * @param num_peers number of peers that should share one instance + * of the specified service (1 for no sharing is the default), + * use 0 to disable the service + */ +void +GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller *controller, + const char *service_name, + uint32_t num_peers); + + +/** + * Stop the given controller (also will terminate all peers and + * controllers dependent on this controller). This function + * blocks until the testbed has been fully terminated (!). + * + * @param controller handle to controller to stop + */ +void +GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_Controller *controller); + + +/** + * Create a link from a 'master' controller to a slave controller. + * Whenever the master controller is asked to start a peer at the + * given 'delegated_host', it will delegate the request to the + * specified slave controller. Note that the slave controller runs at + * the 'slave_host', which may or may not be the same host as the + * 'delegated_host' (for hierarchical delegations). The configuration + * of the slave controller is given and to be used to either create + * the slave controller or to connect to an existing slave controller + * process. 'is_subordinate' specifies if the given slave controller + * should be started and managed by the master controller, or if the + * slave already has a master and this is just a secondary master that + * is also allowed to use the existing slave. + * + * @param master handle to the master controller who creates the association + * @param delegated_host requests to which host should be delegated + * @param slave_host which host is used to run the slave controller + * @param slave_cfg configuration to use for the slave controller + * @param is_subordinate GNUNET_YES if the slave should be started (and stopped) + * by the master controller; GNUNET_NO if we are just + * allowed to use the slave via TCP/IP + */ +void +GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master, + struct GNUNET_TESTBED_Host *delegated_host, + struct GNUNET_TESTBED_Host *slave_host, + const struct GNUNET_CONFIGURATION_Handle *slave_cfg, + int is_subordinate); + + +/** + * Create the given peer at the specified host using the given + * controller. If the given controller is not running on the target + * host, it should find or create a controller at the target host and + * delegate creating the peer. Explicit delegation paths can be setup + * using 'GNUNET_TESTBED_controller_link'. If no explicit delegation + * path exists, a direct link with a subordinate controller is setup + * for the first delegated peer to a particular host; the subordinate + * controller is then destroyed once the last peer that was delegated + * to the remote host is stopped. + * + * Creating the peer only creates the handle to manipulate and further + * configure the peer; use "GNUNET_TESTBED_peer_start" and + * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's + * processes. + * + * Note that the given configuration will be adjusted by the + * controller to avoid port/path conflicts with other peers. + * The "final" configuration can be obtained using + * 'GNUNET_TESTBED_peer_get_information'. + * + * @param controller controller process to use + * @param host host to run the peer on + * @param cfg configuration to use for the peer + * @return handle to the peer (actual startup will happen asynchronously) + */ +struct GNUNET_TESTBED_Peer * +GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller, + struct GNUNET_TESTBED_Host *host, + const struct GNUNET_CONFIGURATION_Handle *cfg); + + +/** + * Start the given peer. + * + * @param peer peer to start + * @return handle to the operation + */ +struct GNUNET_TESTBED_Operation * +GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer); + + +/** + * Stop the given peer. The handle remains valid (use + * "GNUNET_TESTBED_peer_destroy" to fully clean up the + * state of the peer). + * + * @param peer peer to stop + * @return handle to the operation + */ +struct GNUNET_TESTBED_Operation * +GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer); + + +/** + * Request information about a peer. + * + * @param peer peer to request information about + * @param pit desired information + * @return handle to the operation + */ +struct GNUNET_TESTBED_Operation * +GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, + enum GNUNET_TESTBED_PeerInformationType pit); + + +/** + * Change peer configuration. Must only be called while the + * peer is stopped. Ports and paths cannot be changed this + * way. + * + * @param peer peer to change configuration for + * @param cfg new configuration (differences to existing + * configuration only) + * @return handle to the operation + */ +struct GNUNET_TESTBED_Operation * +GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer, + const struct GNUNET_CONFIGURATION_Handle *cfg); + + +/** + * Destroy the given peer; the peer should have been + * stopped first (if it was started). + * + * @param peer peer to stop + * @return handle to the operation + */ +struct GNUNET_TESTBED_Operation * +GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer); + + +/** + * Options for peer connections. + */ +enum GNUNET_TESTBED_ConnectOption +{ + /** + * No option (not valid as an argument). + */ + GNUNET_TESTBED_CO_NONE = 0, + + /** + * Allow or disallow a connection between the specified peers. + * Followed by GNUNET_NO (int) if a connection is disallowed + * or GNUNET_YES if a connection is allowed. Note that the + * default (all connections allowed or disallowed) is + * specified in the configuration of the controller. + */ + GNUNET_TESTBED_CO_ALLOW = 1, + + /** + * FIXME: add (and implement) options to limit connection to + * particular transports, force simulation of particular latencies + * or message loss rates, or set bandwidth limitations. + */ + +}; + + +/** + * Manipulate the P2P underlay topology by configuring a link + * between two peers. + * + * @param op_cls closure argument to give with the operation event + * @param p1 first peer + * @param p2 second peer + * @param co option to change + * @param ap option-specific values + * @return handle to the operation, NULL if configuring the link at this + * time is not allowed + */ +struct GNUNET_TESTBED_Operation * +GNUNET_TESTBED_underlay_configure_link_va (void *op_cls, + struct GNUNET_TESTBED_Peer *p1, + struct GNUNET_TESTBED_Peer *p2, + enum GNUNET_TESTBED_ConnectOption co, + va_list ap); + + +/** + * Manipulate the P2P underlay topology by configuring a link + * between two peers. + * + * @param op_cls closure argument to give with the operation event + * @param p1 first peer + * @param p2 second peer + * @param co option to change + * @param ... option-specific values + * @return handle to the operation, NULL if configuring the link at this + * time is not allowed + */ +struct GNUNET_TESTBED_Operation * +GNUNET_TESTBED_underlay_configure_link (void *op_cls, + struct GNUNET_TESTBED_Peer *p1, + struct GNUNET_TESTBED_Peer *p2, + enum GNUNET_TESTBED_ConnectOption co, ...); + + + +/** + * Topologies supported for testbeds. + */ +enum GNUNET_TESTBED_TopologyOption +{ + /** + * A clique (everyone connected to everyone else). No options. + */ + GNUNET_TESTBED_TOPOLOGY_CLIQUE, + + /** + * Small-world network (2d torus plus random links). Followed + * by the number of random links to add (unsigned int). + */ + GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD, + + /** + * Small-world network (ring plus random links). Followed + * by the number of random links to add (unsigned int). + */ + GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING, + + /** + * Ring topology. No options. + */ + GNUNET_TESTBED_TOPOLOGY_RING, + + /** + * 2-d torus. No options. + */ + GNUNET_TESTBED_TOPOLOGY_2D_TORUS, + + /** + * Random graph. Followed by the link density, that is the + * percentage of links present in relation to a clique + * (float). + */ + GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, + + /** + * Certain percentage of peers are unable to communicate directly + * replicating NAT conditions. Followed by the fraction of + * NAT'ed peers (float). + */ + GNUNET_TESTBED_TOPOLOGY_INTERNAT, + + /** + * Scale free topology. FIXME: options? + */ + GNUNET_TESTBED_TOPOLOGY_SCALE_FREE, + + /** + * Straight line topology. No options. + */ + GNUNET_TESTBED_TOPOLOGY_LINE, + + /** + * All peers are disconnected. No options. + */ + GNUNET_TESTBED_TOPOLOGY_NONE, + + /** + * Read a topology from a given file. Followed by the name of the file (const char *). + */ + GNUNET_TESTBED_TOPOLOGY_FROM_FILE +}; + + +/** + * Configure overall network topology to have a particular shape. + * + * @param op_cls closure argument to give with the operation event + * @param num_peers number of peers in 'peers' + * @param peers array of 'num_peers' with the peers to configure + * @param topo desired underlay topology to use + * @param ap topology-specific options + * @return handle to the operation, NULL if configuring the topology + * is not allowed at this time + */ +struct GNUNET_TESTBED_Operation * +GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + enum GNUNET_TESTBED_TopologyOption topo, + va_list ap); + + +/** + * Configure overall network topology to have a particular shape. + * + * @param op_cls closure argument to give with the operation event + * @param num_peers number of peers in 'peers' + * @param peers array of 'num_peers' with the peers to configure + * @param topo desired underlay topology to use + * @param ... topology-specific options + * @return handle to the operation, NULL if configuring the topology + * is not allowed at this time + */ +struct GNUNET_TESTBED_Operation * +GNUNET_TESTBED_underlay_configure_topology (void *op_cls, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + enum GNUNET_TESTBED_TopologyOption topo, + ...); + + +/** + * Both peers must have been started before calling this function. + * This function then obtains a HELLO from 'p1', gives it to 'p2' + * and asks 'p2' to connect to 'p1'. + * + * @param op_cls closure argument to give with the operation event + * @param p1 first peer + * @param p2 second peer + * @return handle to the operation, NULL if connecting these two + * peers is fundamentally not possible at this time (peers + * not running or underlay disallows) + */ +struct GNUNET_TESTBED_Operation * +GNUNET_TESTBED_overlay_connect (void *op_cls, + struct GNUNET_TESTBED_Peer *p1, + struct GNUNET_TESTBED_Peer *p2); + + +/** + * All peers must have been started before calling this function. + * This function then connects the given peers in the P2P overlay + * using the given topology. + * + * @param op_cls closure argument to give with the operation event + * @param num_peers number of peers in 'peers' + * @param peers array of 'num_peers' with the peers to configure + * @param topo desired underlay topology to use + * @param va topology-specific options + * @return handle to the operation, NULL if connecting these + * peers is fundamentally not possible at this time (peers + * not running or underlay disallows) + */ +struct GNUNET_TESTBED_Operation * +GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer *peers, + enum GNUNET_TESTBED_TopologyOption topo, + va_list va); + + +/** + * All peers must have been started before calling this function. + * This function then connects the given peers in the P2P overlay + * using the given topology. + * + * @param op_cls closure argument to give with the operation event + * @param num_peers number of peers in 'peers' + * @param peers array of 'num_peers' with the peers to configure + * @param topo desired underlay topology to use + * @param ... topology-specific options + * @return handle to the operation, NULL if connecting these + * peers is fundamentally not possible at this time (peers + * not running or underlay disallows) + */ +struct GNUNET_TESTBED_Operation * +GNUNET_TESTBED_overlay_configure_topology (void *op_cls, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer *peers, + enum GNUNET_TESTBED_TopologyOption topo, + ...); + + + +/** + * Ask the testbed controller to write the current overlay topology to + * a file. Naturally, the file will only contain a snapshot as the + * topology may evolve all the time. + * + * @param controller overlay controller to inspect + * @param filename name of the file the topology should + * be written to. + */ +void +GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller *controller, + const char *filename); + + +/** + * Adapter function called to establish a connection to + * a service. + * + * @param cls closure + * @param cfg configuration of the peer to connect to + * @return service handle to return in 'op_result', NULL on error + */ +typedef void * (*GNUNET_TESTBED_ConnectAdapter)(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg); + + +/** + * Adapter function called to destroy a connection to + * a service. + * + * @param cls closure + * @param op_result service handle returned from the connect adapter + */ +typedef void (*GNUNET_TESTBED_DisconnectAdapter)(void *cls, + void *op_result); + + +/** + * Connect to a service offered by the given peer. Will ensure that + * the request is queued to not overwhelm our ability to create and + * maintain connections with other systems. The actual service + * handle is then returned via the 'op_result' member in the event + * callback. The 'ca' callback is used to create the connection + * when the time is right; the 'da' callback will be used to + * destroy the connection (upon 'GNUNET_TESTBED_operation_done'). + * 'GNUNET_TESTBED_operation_cancel' can be used to abort this + * operation until the event callback has been called. + * + * @param op_cls closure to pass in operation event + * @param peer peer that runs the service + * @param service_name name of the service to connect to + * @param ca helper function to establish the connection + * @param da helper function to close the connection + * @param cada_cls closure for ca and da + * @return handle for the operation + */ +struct GNUNET_TESTBED_Operation * +GNUNET_TESTBED_service_connect (void *op_cls, + struct GNUNET_TESTBED_Peer *peer, + const char *service_name, + GNUNET_TESTBED_ConnectAdapter ca, + GNUNET_TESTBED_DisconnectAdapter da, + void *cada_cls); + + +/** + * Cancel a pending operation. Releases all resources + * of the operation and will ensure that no event + * is generated for the operation. Does NOT guarantee + * that the operation will be fully undone (or that + * nothing ever happened). + * + * @param operation operation to cancel + */ +void +GNUNET_TESTBED_operation_cancel (struct GNUNET_TESTBED_Operation *operation); + + +/** + * Signal that the information from an operation has been fully + * processed. This function MUST be called for each event + * of type 'operation_finished' to fully remove the operation + * from the operation queue. After calling this function, the + * 'op_result' becomes invalid (!). + * + * @param operation operation to signal completion for + */ +void +GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation); + + +/** + * Configure and run a testbed using the given + * master controller on 'num_hosts' starting + * 'num_peers' using the given peer configuration. + * + * @param controller master controller for the testbed + * (must not be destroyed until after the + * testbed is destroyed). + * @param num_hosts number of hosts in 'hosts', 0 to only + * use 'localhost' + * @param hosts list of hosts to use for the testbed + * @param num_peers number of peers to start + * @param peer_cfg peer configuration template to use + * @param underlay_topology underlay topology to create + * @param va topology-specific options + * @return handle to the testbed + */ +struct GNUNET_TESTBED_Testbed * +GNUNET_TESTBED_create_va (struct GNUNET_TESTBED_Controller *controller, + unsigned int num_hosts, + struct GNUNET_TESTBED_Host **hosts, + unsigned int num_peers, + const struct GNUNET_CONFIGURATION_Handle *peer_cfg, + enum GNUNET_TESTBED_TopologyOption underlay_topology, + va_list va); + + +/** + * Configure and run a testbed using the given + * master controller on 'num_hosts' starting + * 'num_peers' using the given peer configuration. + * + * @param controller master controller for the testbed + * (must not be destroyed until after the + * testbed is destroyed). + * @param num_hosts number of hosts in 'hosts', 0 to only + * use 'localhost' + * @param hosts list of hosts to use for the testbed + * @param num_peers number of peers to start + * @param peer_cfg peer configuration template to use + * @param underlay_topology underlay topology to create + * @param ... topology-specific options + */ +struct GNUNET_TESTBED_Testbed * +GNUNET_TESTBED_create (struct GNUNET_TESTBED_Controller *controller, + unsigned int num_hosts, + struct GNUNET_TESTBED_Host **hosts, + unsigned int num_peers, + const struct GNUNET_CONFIGURATION_Handle *peer_cfg, + enum GNUNET_TESTBED_TopologyOption underlay_topology, + ...); + + +/** + * Destroy a testbed. Stops all running peers and then + * destroys all peers. Does NOT destroy the master controller. + * + * @param testbed testbed to destroy + */ +void +GNUNET_TESTBED_destroy (struct GNUNET_TESTBED_Testbed *testbed); + + +/** + * Convenience method for running a testbed with + * a single call. Underlay and overlay topology + * are configured using the "UNDERLAY" and "OVERLAY" + * options in the "[testbed]" section of the configuration\ + * (with possible options given in "UNDERLAY_XXX" and/or + * "OVERLAY_XXX"). + * + * The testbed is to be terminated using a call to + * "GNUNET_SCHEDULER_shutdown". + * + * @param host_filename name of the file with the 'hosts', NULL + * to run everything on 'localhost' + * @param cfg configuration to use (for testbed, controller and peers) + * @param num_peers number of peers to start; FIXME: maybe put that ALSO into cfg? + * @param event_mask bit mask with set of events to call 'cc' for; + * or-ed values of "1LL" shifted by the + * respective 'enum GNUNET_TESTBED_EventType' + * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...") + * @param cc controller callback to invoke on events + * @param cc_cls closure for cc + * @param master task to run once the testbed is ready + * @param master_cls closure for 'task'. + */ +void +GNUNET_TESTBED_run (const char *host_filename, + const struct GNUNET_CONFIGURATION_Handle *cfg, + unsigned int num_peers, + uint64_t event_mask, + GNUNET_TESTBED_ControllerCallback cc, + void *cc_cls, + GNUNET_SCHEDULER_Task master, + void *master_cls); + + +/** + * Signature of a main function for a testcase. + * + * @param cls closure + * @param num_peers number of peers in 'peers' + * @param peers handle to peers run in the testbed + */ +typedef void (*GNUNET_TESTBED_TestMaster)(void *cls, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers); + + +/** + * Convenience method for running a "simple" test on the local system + * with a single call from 'main'. Underlay and overlay topology are + * configured using the "UNDERLAY" and "OVERLAY" options in the + * "[testbed]" section of the configuration (with possible options + * given in "UNDERLAY_XXX" and/or "OVERLAY_XXX"). + * + * The test is to be terminated using a call to + * "GNUNET_SCHEDULER_shutdown". If starting the test fails, + * the program is stopped without 'master' ever being run. + * + * NOTE: this function should be called from 'main', NOT from + * within a GNUNET_SCHEDULER-loop. This function will initialze + * the scheduler loop, the testbed and then pass control to + * 'master'. + * + * @param testname name of the testcase (to configure logging, etc.) + * @param cfg_filename configuration filename to use + * (for testbed, controller and peers) + * @param num_peers number of peers to start + * @param test_master task to run once the test is ready + * @param test_master_cls closure for 'task'. + */ +void +GNUNET_TESTBED_test_run (const char *testname, + const char *cfg_filename, + unsigned int num_peers, + GNUNET_TESTBED_TestMaster test_master, + void *test_master_cls); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/gnunet_testing_lib-new.h b/src/include/gnunet_testing_lib-new.h new file mode 100644 index 0000000..9b5f4c2 --- /dev/null +++ b/src/include/gnunet_testing_lib-new.h @@ -0,0 +1,299 @@ +/* + This file is part of GNUnet + (C) 2008, 2009, 2012 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 + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + 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. + */ + +/** + * @file include/gnunet_testing_lib-new.h + * @brief convenience API for writing testcases for GNUnet; + * can start/stop one or more peers on a system; + * testing is responsible for managing private keys, + * ports and paths; it is a low-level library that + * does not support higher-level functions such as + * P2P connection, topology management or distributed + * testbed maintenance (those are in gnunet_testbed_service.h) + * @author Christian Grothoff + */ + +#ifndef GNUNET_TESTING_LIB_NEW_H +#define GNUNET_TESTING_LIB_NEW_H + +#include "gnunet_util_lib.h" +#include "gnunet_statistics_service.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +/** + * Handle for a system on which GNUnet peers are executed; + * a system is used for reserving unique paths and ports. + */ +struct GNUNET_TESTING_System; + + +/** + * Handle for a GNUnet peer controlled by testing. + */ +struct GNUNET_TESTING_Peer; + + +/** + * Create a system handle. There must only be one system + * handle per operating system. + * + * @param tmppath prefix path to use for all service homes + * @param controller hostname of the controlling host, + * service configurations are modified to allow + * control connections from this host; can be NULL + * @return handle to this system, NULL on error + */ +struct GNUNET_TESTING_System * +GNUNET_TESTING_system_create (const char *tmppath, + const char *controller); + + + +/** + * Free system resources. + * + * @param system system to be freed + * @param remove_paths should the 'tmppath' and all subdirectories + * be removed (clean up on shutdown)? + */ +void +GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, + int remove_paths); + + +/** + * Testing includes a number of pre-created hostkeys for faster peer + * startup. This function loads such keys into memory from a file. + * + * @param system the testing system handle + * @param filename the path of the hostkeys file + * @return GNUNET_OK on success; GNUNET_SYSERR on error + */ +int +GNUNET_TESTING_hostkeys_load (struct GNUNET_TESTING_System *system, + const char *filename); + + +/** + * Function to remove the loaded hostkeys + * + * @param system the testing system handle + */ +void +GNUNET_TESTING_hostkeys_unload (struct GNUNET_TESTING_System *system); + + +/** + * Testing includes a number of pre-created hostkeys for + * faster peer startup. This function can be used to + * access the n-th key of those pre-created hostkeys; note + * that these keys are ONLY useful for testing and not + * secure as the private keys are part of the public + * GNUnet source code. + * + * This is primarily a helper function used internally + * by 'GNUNET_TESTING_peer_configure'. + * + * @param system the testing system handle + * @param key_number desired pre-created hostkey to obtain + * @param id set to the peer's identity (hash of the public + * key; if NULL, GNUNET_SYSERR is returned immediately + * @return GNUNET_SYSERR on error (not enough keys) + */ +int +GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, + uint32_t key_number, + struct GNUNET_PeerIdentity *id); + + +/** + * Reserve a TCP or UDP port for a peer. + * + * @param system system to use for reservation tracking + * @param is_tcp GNUNET_YES for TCP ports, GNUNET_NO for UDP + * @return 0 if no free port was available + */ +uint16_t +GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system, + int is_tcp); + + +/** + * Release reservation of a TCP or UDP port for a peer + * (used during GNUNET_TESTING_peer_destroy). + * + * @param system system to use for reservation tracking + * @param is_tcp GNUNET_YES for TCP ports, GNUNET_NO for UDP + * @param port reserved port to release + */ +void +GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, + int is_tcp, + uint16_t port); + + +/** + * Create a new configuration using the given configuration + * as a template; ports and paths will be modified to select + * available ports on the local system. If we run + * out of "*port" numbers, return SYSERR. + * + * This is primarily a helper function used internally + * by 'GNUNET_TESTING_peer_configure'. + * + * @param system system to use to coordinate resource usage + * @param cfg template configuration to update + * @return GNUNET_OK on success, GNUNET_SYSERR on error - the configuration will + * be incomplete and should not be used there upon + */ +int +GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, + struct GNUNET_CONFIGURATION_Handle *cfg); +// FIXME: add dual to 'release' ports again... + + +/** + * Configure a GNUnet peer. GNUnet must be installed on the local + * system and available in the PATH. + * + * @param system system to use to coordinate resource usage + * @param cfg configuration to use; will be UPDATED (to reflect needed + * changes in port numbers and paths) + * @param key_number number of the hostkey to use for the peer + * @param id identifier for the daemon, will be set, can be NULL + * @param emsg set to error message (set to NULL on success), can be NULL + * @return handle to the peer, NULL on error + */ +struct GNUNET_TESTING_Peer * +GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, + struct GNUNET_CONFIGURATION_Handle *cfg, + uint32_t key_number, + struct GNUNET_PeerIdentity *id, + char **emsg); + + +/** + * Start the peer. + * + * @param peer peer to start + * @return GNUNET_OK on success, GNUNET_SYSERR on error (i.e. peer already running) + */ +int +GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer); + + +/** + * Stop the peer. + * + * @param peer peer to stop + * @return GNUNET_OK on success, GNUNET_SYSERR on error (i.e. peer not running) + */ +int +GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer); + + +/** + * Destroy the peer. Releases resources locked during peer configuration. + * If the peer is still running, it will be stopped AND a warning will be + * printed (users of the API should stop the peer explicitly first). + * + * @param peer peer to destroy + */ +void +GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer); + + +/** + * Signature of the 'main' function for a (single-peer) testcase that + * is run using 'GNUNET_TESTING_peer_run'. + * + * @param cls closure + * @param cfg configuration of the peer that was started + */ +typedef void (*GNUNET_TESTING_TestMain)(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg); + + +/** + * Start a single peer and run a test using the testing library. + * Starts a peer using the given configuration and then invokes the + * given callback. This function ALSO initializes the scheduler loop + * and should thus be called directly from "main". The testcase + * should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'. + * + * @param tmppath path for storing temporary data for the test + * @param cfgfilename name of the configuration file to use; + * use NULL to only run with defaults + * @param tm main function of the testcase + * @param tm_cls closure for 'tm' + * @return 0 on success, 1 on error + */ +int +GNUNET_TESTING_peer_run (const char *tmppath, + const char *cfgfilename, + GNUNET_TESTING_TestMain tm, + void *tm_cls); + + + +/** + * Start a single service (no ARM, except of course if the given + * service name is 'arm') and run a test using the testing library. + * Starts a service using the given configuration and then invokes the + * given callback. This function ALSO initializes the scheduler loop + * and should thus be called directly from "main". The testcase + * should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'. + * + * This function is useful if the testcase is for a single service + * and if that service doesn't itself depend on other services. + * + * @param tmppath path for storing temporary data for the test + * @param service_name name of the service to run + * @param cfgfilename name of the configuration file to use; + * use NULL to only run with defaults + * @param tm main function of the testcase + * @param tm_cls closure for 'tm' + * @return 0 on success, 1 on error + */ +int +GNUNET_TESTING_service_run (const char *tmppath, + const char *service_name, + const char *cfgfilename, + GNUNET_TESTING_TestMain tm, + void *tm_cls); + + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h index 03b8376..b170670 100644 --- a/src/include/gnunet_testing_lib.h +++ b/src/include/gnunet_testing_lib.h @@ -304,9 +304,34 @@ struct GNUNET_TESTING_Daemon void *update_cb_cls; /** - * PID of the process that we started last. + * PID of the process we used to run gnunet-arm or SSH to start the peer. */ - struct GNUNET_OS_Process *proc; + struct GNUNET_OS_Process *proc_arm_start; + + /** + * PID of the process we used to run gnunet-arm or SSH to stop the peer. + */ + struct GNUNET_OS_Process *proc_arm_stop; + + /** + * PID of the process we used to run gnunet-arm or SSH to manage services at the peer. + */ + struct GNUNET_OS_Process *proc_arm_srv_start; + + /** + * PID of the process we used to run gnunet-arm or SSH to manage services at the peer. + */ + struct GNUNET_OS_Process *proc_arm_srv_stop; + + /** + * PID of the process we used to run copy files + */ + struct GNUNET_OS_Process *proc_arm_copying; + + /** + * PID of the process we used to run gnunet-peerinfo. + */ + struct GNUNET_OS_Process *proc_arm_peerinfo; /** * Handle to the server. diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h index 7090c33..35d180c 100644 --- a/src/include/gnunet_time_lib.h +++ b/src/include/gnunet_time_lib.h @@ -90,32 +90,32 @@ GNUNET_NETWORK_STRUCT_END /** * Relative time zero. */ -#define GNUNET_TIME_UNIT_ZERO GNUNET_TIME_relative_get_zero() +#define GNUNET_TIME_UNIT_ZERO GNUNET_TIME_relative_get_zero_() /** * Absolute time zero. */ -#define GNUNET_TIME_UNIT_ZERO_ABS GNUNET_TIME_absolute_get_zero() +#define GNUNET_TIME_UNIT_ZERO_ABS GNUNET_TIME_absolute_get_zero_() /** * One millisecond, our basic time unit. */ -#define GNUNET_TIME_UNIT_MILLISECONDS GNUNET_TIME_relative_get_unit() +#define GNUNET_TIME_UNIT_MILLISECONDS GNUNET_TIME_relative_get_unit_() /** * One second. */ -#define GNUNET_TIME_UNIT_SECONDS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 1000) +#define GNUNET_TIME_UNIT_SECONDS GNUNET_TIME_relative_get_second_() /** * One minute. */ -#define GNUNET_TIME_UNIT_MINUTES GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) +#define GNUNET_TIME_UNIT_MINUTES GNUNET_TIME_relative_get_minute_() /** * One hour. */ -#define GNUNET_TIME_UNIT_HOURS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60) +#define GNUNET_TIME_UNIT_HOURS GNUNET_TIME_relative_get_hour_() /** * One day. @@ -141,43 +141,70 @@ GNUNET_NETWORK_STRUCT_END * Constant used to specify "forever". This constant * will be treated specially in all time operations. */ -#define GNUNET_TIME_UNIT_FOREVER_REL GNUNET_TIME_relative_get_forever () +#define GNUNET_TIME_UNIT_FOREVER_REL GNUNET_TIME_relative_get_forever_ () /** * Constant used to specify "forever". This constant * will be treated specially in all time operations. */ -#define GNUNET_TIME_UNIT_FOREVER_ABS GNUNET_TIME_absolute_get_forever () +#define GNUNET_TIME_UNIT_FOREVER_ABS GNUNET_TIME_absolute_get_forever_ () + /** * Return relative time of 0ms. */ struct GNUNET_TIME_Relative -GNUNET_TIME_relative_get_zero (void); +GNUNET_TIME_relative_get_zero_ (void); + /** * Return absolute time of 0ms. */ struct GNUNET_TIME_Absolute -GNUNET_TIME_absolute_get_zero (void); +GNUNET_TIME_absolute_get_zero_ (void); + /** * Return relative time of 1ms. */ struct GNUNET_TIME_Relative -GNUNET_TIME_relative_get_unit (void); +GNUNET_TIME_relative_get_unit_ (void); + + +/** + * Return relative time of 1s. + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_relative_get_second_ (void); + + +/** + * Return relative time of 1 minute. + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_relative_get_minute_ (void); + + +/** + * Return relative time of 1 hour. + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_relative_get_hour_ (void); + /** * Return "forever". */ struct GNUNET_TIME_Relative -GNUNET_TIME_relative_get_forever (void); +GNUNET_TIME_relative_get_forever_ (void); + /** * Return "forever". */ struct GNUNET_TIME_Absolute -GNUNET_TIME_absolute_get_forever (void); +GNUNET_TIME_absolute_get_forever_ (void); + /** * Get the current time. @@ -187,6 +214,7 @@ GNUNET_TIME_absolute_get_forever (void); struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get (void); + /** * Convert relative time to an absolute time in the * future. @@ -197,6 +225,7 @@ GNUNET_TIME_absolute_get (void); struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel); + /** * Return the minimum of two relative time values. * @@ -209,6 +238,7 @@ GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2); + /** * Return the maximum of two relative time values. * @@ -220,6 +250,7 @@ struct GNUNET_TIME_Relative GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2); + /** * Return the minimum of two absolute time values. * @@ -231,6 +262,7 @@ struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2); + /** * Return the maximum of two absolute time values. * @@ -242,6 +274,7 @@ struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2); + /** * Given a timestamp in the future, how much time * remains until then? @@ -281,6 +314,7 @@ struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end); + /** * Get the duration of an operation as the * difference of the current time and the given start time "hence". @@ -317,6 +351,7 @@ struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration); + /** * Multiply relative time by a given factor. * @@ -328,6 +363,7 @@ struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, unsigned int factor); + /** * Divide relative time by a given factor. * @@ -339,6 +375,7 @@ struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel, unsigned int factor); + /** * Add relative times together. * @@ -350,6 +387,7 @@ struct GNUNET_TIME_Relative GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2); + /** * Subtract relative timestamp from the other. * @@ -371,6 +409,7 @@ GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton (struct GNUNET_TIME_Relative a); + /** * Convert relative time from network byte order. * @@ -380,6 +419,7 @@ GNUNET_TIME_relative_hton (struct GNUNET_TIME_Relative a); struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh (struct GNUNET_TIME_RelativeNBO a); + /** * Convert relative time to network byte order. * @@ -389,6 +429,7 @@ GNUNET_TIME_relative_ntoh (struct GNUNET_TIME_RelativeNBO a); struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a); + /** * Convert relative time from network byte order. * @@ -398,6 +439,7 @@ GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a); struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a); + /** * Convert a relative time to a string. * NOT reentrant! @@ -409,6 +451,7 @@ GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a); const char * GNUNET_TIME_relative_to_string (struct GNUNET_TIME_Relative time); + /** * Set the timestamp offset for this instance. * @@ -417,6 +460,7 @@ GNUNET_TIME_relative_to_string (struct GNUNET_TIME_Relative time); void GNUNET_TIME_set_offset (long long offset); + #if 0 /* keep Emacsens' auto-indent happy */ { #endif diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h index 9b39a41..d1e03d7 100644 --- a/src/include/gnunet_transport_plugin.h +++ b/src/include/gnunet_transport_plugin.h @@ -136,7 +136,7 @@ typedef struct * @param addrlen length of the address * @return ATS Information containing the network type */ -typedef const struct GNUNET_ATS_Information +typedef struct GNUNET_ATS_Information (*GNUNET_TRANSPORT_AddressToType) (void *cls, const struct sockaddr *addr, size_t addrlen); @@ -218,7 +218,11 @@ struct GNUNET_TRANSPORT_PluginEnvironment /** * Function that should be called by the transport plugin - * whenever a message is received. + * whenever a message is received. If this field is "NULL", + * the plugin should load in 'stub' mode and NOT fully + * initialize and instead only return an API with the + * 'address_pretty_printer', 'address_to_string' and + * 'string_to_address' functions. */ GNUNET_TRANSPORT_PluginReceiveCallback receive; @@ -309,11 +313,12 @@ typedef void (*GNUNET_TRANSPORT_TransmitContinuation) (void *cls, * and does NOT mean that the message was not transmitted (DV) */ typedef ssize_t (*GNUNET_TRANSPORT_TransmitFunction) (void *cls, - struct Session *session, - const char *msgbuf, size_t msgbuf_size, - unsigned int priority, - struct GNUNET_TIME_Relative to, - GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls); + struct Session *session, + const char *msgbuf, size_t msgbuf_size, + unsigned int priority, + struct GNUNET_TIME_Relative to, + GNUNET_TRANSPORT_TransmitContinuation cont, + void *cont_cls); /** @@ -423,6 +428,24 @@ typedef const char *(*GNUNET_TRANSPORT_AddressToString) (void *cls, const void *addr, size_t addrlen); +/** + * Function called to convert a string address to + * a binary address. + * + * @param cls closure ('struct Plugin*') + * @param addr string address + * @param addrlen length of the address + * @param buf location to store the buffer + * If the function returns GNUNET_SYSERR, its contents are undefined. + * @param added length of created address + * @return GNUNET_OK on success, GNUNET_SYSERR on failure + */ +typedef int (*GNUNET_TRANSPORT_StringToAddress) (void *cls, + const char *addr, + uint16_t addrlen, + void **buf, + size_t *added); + /** * Each plugin is required to return a pointer to a struct of this @@ -477,6 +500,12 @@ struct GNUNET_TRANSPORT_PluginFunctions GNUNET_TRANSPORT_AddressToString address_to_string; /** + * Function that will be called to convert a string address + * to binary (numeric conversion only). + */ + GNUNET_TRANSPORT_StringToAddress string_to_address; + + /** * Function that will be called tell the plugin to create a session * object */ diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h index dac11d6..3bb1ea3 100644 --- a/src/include/gnunet_tun_lib.h +++ b/src/include/gnunet_tun_lib.h @@ -119,7 +119,7 @@ struct GNUNET_TUN_IPv4Header * Destination of the packet. */ struct in_addr destination_address GNUNET_PACKED; -}; +} GNUNET_GCC_STRUCT_LAYOUT; /** @@ -163,7 +163,7 @@ struct GNUNET_TUN_IPv6Header * Destination of the packet. */ struct in6_addr destination_address GNUNET_PACKED; -}; +} GNUNET_GCC_STRUCT_LAYOUT; /** @@ -224,7 +224,7 @@ struct GNUNET_TUN_TcpHeader * Urgent pointer. */ uint16_t urgent_pointer GNUNET_PACKED; -}; +} GNUNET_GCC_STRUCT_LAYOUT; /** diff --git a/src/include/platform.h b/src/include/platform.h index 7383e48..9a5d164 100644 --- a/src/include/platform.h +++ b/src/include/platform.h @@ -241,6 +241,14 @@ atoll (const char *nptr); #define O_LARGEFILE 0 #endif +/** + * AI_NUMERICSERV not defined in windows. Then we just do without. + */ +#ifndef AI_NUMERICSERV +#define AI_NUMERICSERV 0 +#endif + + #if defined(__sparc__) #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove(&__tmp, &(val), sizeof((val))); __tmp; }) #else diff --git a/src/include/plibc.h b/src/include/plibc.h index 70cbd9e..1cb84e6 100644 --- a/src/include/plibc.h +++ b/src/include/plibc.h @@ -22,7 +22,7 @@ * @brief PlibC header * @attention This file is usually not installed under Unix, * so ship it with your application - * @version $Revision$ + * @version $Revision: 84 $ */ #ifndef _PLIBC_H_ @@ -336,9 +336,13 @@ typedef struct #define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__) BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest); +BOOL _plibc_CreateShortcutW(const wchar_t *pwszSrc, const wchar_t *pwszDest); BOOL _plibc_DereferenceShortcut(char *pszShortcut); +BOOL _plibc_DereferenceShortcutW(wchar_t *pwszShortcut); char *plibc_ChooseDir(char *pszTitle, unsigned long ulFlags); +wchar_t *plibc_ChooseDirW(wchar_t *pwszTitle, unsigned long ulFlags); char *plibc_ChooseFile(char *pszTitle, unsigned long ulFlags); +wchar_t *plibc_ChooseFileW(wchar_t *pwszTitle, unsigned long ulFlags); long QueryRegistry(HKEY hMainKey, const char *pszKey, const char *pszSubKey, char *pszBuffer, long *pdLength); @@ -376,6 +380,7 @@ const char *inet_ntop(int af, const void *src, char *dst, size_t size); struct tm *gmtime_r(const time_t *clock, struct tm *result); int plibc_init(char *pszOrg, char *pszApp); +int plibc_init_utf8(char *pszOrg, char *pszApp, int utf8_mode); void plibc_shutdown(); int plibc_initialized(); |