From 10f9bc91ab9d758d0d60dd672206027cd136342a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 23 Oct 2016 19:53:59 +0000 Subject: new NAT lib client api skeleton --- src/include/gnunet_nat_service.h | 198 ++++++++++++++++++--------------------- src/include/gnunet_protocols.h | 14 +-- 2 files changed, 96 insertions(+), 116 deletions(-) (limited to 'src/include') diff --git a/src/include/gnunet_nat_service.h b/src/include/gnunet_nat_service.h index 5ac936065..28a6bc59f 100644 --- a/src/include/gnunet_nat_service.h +++ b/src/include/gnunet_nat_service.h @@ -108,7 +108,8 @@ enum GNUNET_NAT_AddressClass * a function to call whenever our set of 'valid' addresses changes. * * @param cls closure - * @param add_remove #GNUNET_YES to add a new public IP address, #GNUNET_NO to remove a previous (now invalid) one + * @param add_remove #GNUNET_YES to add a new public IP address, + * #GNUNET_NO to remove a previous (now invalid) one * @param ac address class the address belongs to * @param addr either the previous or the new public IP address * @param addrlen actual length of the @a addr @@ -136,24 +137,6 @@ typedef void socklen_t addrlen); -/** - * Signature of a callback that is given an IPv4 address - * which is now presumably a global IPv4 address under which - * this peer is visible (external IP address of our NAT). - * Note that the NAT may not have punched holes, so it is - * possible that while this is "our" IPv4 address, it still - * does not work for receiving traffic. - * - * @param cls closure - * @param add_remove #GNUNET_YES to add a new public IP address, #GNUNET_NO to remove a previous (now invalid) one - * @param addr the address to add or remove - */ -typedef void -(*GNUNET_NAT_IPv4Callback) (void *cls, - int add_remove, - const struct in_addr *addr); - - /** * Handle for active NAT registrations. */ @@ -175,7 +158,6 @@ struct GNUNET_NAT_Handle; * @param num_addrs number of addresses in @a addrs * @param addrs list of local addresses packets should be redirected to * @param addrlens actual lengths of the addresses in @a addrs - * @param ip_callback function to call whenever our (external) IPv4 address changes (or becomes known) * @param address_callback function to call everytime the public IP address changes * @param reversal_callback function to call if someone wants connection reversal from us, * NULL if connection reversal is not supported @@ -184,12 +166,11 @@ struct GNUNET_NAT_Handle; */ struct GNUNET_NAT_Handle * GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, - int proto, + uint8_t proto, uint16_t adv_port, unsigned int num_addrs, const struct sockaddr **addrs, const socklen_t *addrlens, - GNUNET_NAT_IPv4Callback ip_callback, GNUNET_NAT_AddressCallback address_callback, GNUNET_NAT_ReversalCallback reversal_callback, void *callback_cls); @@ -209,7 +190,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, * At the moment this only processes BIND requests, and returns the * externally visible address of the request. * - * @param nat handle to the NAT service + * @param nh handle to the NAT service * @param sender_addr address from which we got @a data * @param data the packet * @param data_size number of bytes in @a data @@ -218,7 +199,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, * #GNUNET_SYSERR on internal error handling the packet */ int -GNUNET_NAT_stun_handle_packet (struct GNUNET_NAT_Handle *nat, +GNUNET_NAT_stun_handle_packet (struct GNUNET_NAT_Handle *nh, const struct sockaddr *sender_addr, const void *data, size_t data_size); @@ -230,7 +211,7 @@ GNUNET_NAT_stun_handle_packet (struct GNUNET_NAT_Handle *nat, * have to explicitly track all IPs that the #GNUNET_NAT_AddressCallback * has returned so far. * - * @param h the handle returned by register + * @param nh the handle returned by register * @param addr IP address to test (IPv4 or IPv6) * @param addrlen number of bytes in @a addr * @return #GNUNET_YES if the address is plausible, @@ -238,7 +219,7 @@ GNUNET_NAT_stun_handle_packet (struct GNUNET_NAT_Handle *nat, * #GNUNET_SYSERR if the address is malformed */ int -GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h, +GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *nh, const void *addr, socklen_t addrlen); @@ -248,7 +229,7 @@ GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h, * gnunet-nat-client to send dummy ICMP responses to cause * that peer to connect to us (connection reversal). * - * @param h handle (used for configuration) + * @param nh handle (used for configuration) * @param local_sa our local address of the peer (IPv4-only) * @param remote_sa the remote address of the peer (IPv4-only) * @return #GNUNET_SYSERR on error, @@ -256,7 +237,7 @@ GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h, * #GNUNET_OK otherwise (presumably in progress) */ int -GNUNET_NAT_request_reversal (struct GNUNET_NAT_Handle *h, +GNUNET_NAT_request_reversal (struct GNUNET_NAT_Handle *nh, const struct sockaddr_in *local_sa, const struct sockaddr_in *remote_sa); @@ -266,10 +247,10 @@ GNUNET_NAT_request_reversal (struct GNUNET_NAT_Handle *h, * handle. This frees the handle, after having sent the needed * commands to close open ports. * - * @param h the handle to stop + * @param nh the handle to unregister */ void -GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h); +GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *nh); /** @@ -278,82 +259,6 @@ GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h); struct GNUNET_NAT_Test; -/** - * Function called to report success or failure for - * NAT configuration test. - * - * @param cls closure - * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code - */ -typedef void -(*GNUNET_NAT_TestCallback) (void *cls, - enum GNUNET_NAT_StatusCode result); - - -/** - * Start testing if NAT traversal works using the given configuration - * (IPv4-only). The transport adapters should be down while using - * this function. - * - * @param cfg configuration for the NAT traversal - * @param proto protocol to test, i.e. IPPROTO_TCP or IPPROTO_UDP - * @param bnd_port port to bind to, 0 to test connection reversal - * @param adv_port externally advertised port to use - * @param report function to call with the result of the test - * @param report_cls closure for @a report - * @return handle to cancel NAT test - */ -struct GNUNET_NAT_Test * -GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, - int proto, - uint16_t bnd_port, - uint16_t adv_port, - GNUNET_NAT_TestCallback report, - void *report_cls); - - -/** - * Stop an active NAT test. - * - * @param tst test to stop. - */ -void -GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst); - - -/** - * Handle to auto-configuration in progress. - */ -struct GNUNET_NAT_AutoHandle; - - -/** - * What the situation of the NAT connectivity - */ -enum GNUNET_NAT_Type -{ - /** - * We have a direct connection - */ - GNUNET_NAT_TYPE_NO_NAT = GNUNET_OK, - - /** - * We are under a NAT but cannot traverse it - */ - GNUNET_NAT_TYPE_UNREACHABLE_NAT, - - /** - * We can traverse using STUN - */ - GNUNET_NAT_TYPE_STUN_PUNCHED_NAT, - - /** - * WE can traverse using UPNP - */ - GNUNET_NAT_TYPE_UPNP_NAT - -}; - /** * Error Types for the NAT subsystem (which can then later be converted/resolved to a string) */ @@ -457,6 +362,87 @@ enum GNUNET_NAT_StatusCode }; +/** + * Function called to report success or failure for + * NAT configuration test. + * + * @param cls closure + * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code + */ +typedef void +(*GNUNET_NAT_TestCallback) (void *cls, + enum GNUNET_NAT_StatusCode result); + + +/** + * Start testing if NAT traversal works using the given configuration + * (IPv4-only). The transport adapters should be down while using + * this function. + * + * @param cfg configuration for the NAT traversal + * @param proto protocol to test, i.e. IPPROTO_TCP or IPPROTO_UDP + * @param bind_ip IPv4 address to bind to + * @param bnd_port port to bind to, 0 to test connection reversal + * @param extern_ip IPv4 address to externally advertise + * @param extern_port externally advertised port to use + * @param report function to call with the result of the test + * @param report_cls closure for @a report + * @return handle to cancel NAT test + */ +struct GNUNET_NAT_Test * +GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, + uint8_t proto, + struct in_addr bind_ip, + uint16_t bnd_port, + struct in_addr extern_ip, + uint16_t extern_port, + GNUNET_NAT_TestCallback report, + void *report_cls); + + +/** + * Stop an active NAT test. + * + * @param tst test to stop. + */ +void +GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst); + + +/** + * Handle to auto-configuration in progress. + */ +struct GNUNET_NAT_AutoHandle; + + +/** + * What the situation of the NAT connectivity + */ +enum GNUNET_NAT_Type +{ + /** + * We have a direct connection + */ + GNUNET_NAT_TYPE_NO_NAT = GNUNET_OK, + + /** + * We are under a NAT but cannot traverse it + */ + GNUNET_NAT_TYPE_UNREACHABLE_NAT, + + /** + * We can traverse using STUN + */ + GNUNET_NAT_TYPE_STUN_PUNCHED_NAT, + + /** + * WE can traverse using UPNP + */ + GNUNET_NAT_TYPE_UPNP_NAT + +}; + + /** * Converts `enum GNUNET_NAT_StatusCode` to string * diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index aeb55f99f..ea94645c5 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -2809,31 +2809,25 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE 1064 -/** - * Message to from NAT service notifying us that one of our - * "global" IPv4 addresses changed. - */ -#define GNUNET_MESSAGE_TYPE_NAT_IPV4_CHANGE 1065 - /** * Message to ask NAT service to test an address. */ -#define GNUNET_MESSAGE_TYPE_NAT_REQUEST_TEST 1066 +#define GNUNET_MESSAGE_TYPE_NAT_REQUEST_TEST 1065 /** * Message from NAT service with the address test result. */ -#define GNUNET_MESSAGE_TYPE_NAT_TEST_RESULT 1067 +#define GNUNET_MESSAGE_TYPE_NAT_TEST_RESULT 1066 /** * Message to ask NAT service to request autoconfiguration. */ -#define GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG 1068 +#define GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG 1067 /** * Message from NAT service with the autoconfiguration result. */ -#define GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT 1069 +#define GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT 1068 /** -- cgit v1.2.3