X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Finclude%2Fgnunet_nat_service.h;h=eb08515a28ee33001037a1ba6b0ba3d18edfcda9;hb=4e2504a967ba09643c6dd7e3b9ce400e30adcb3d;hp=1620c9433fd5644bdd12cd5a8a4de16852a8c772;hpb=7122f35e2c00c29b1af31bdd294e93e6fcc84498;p=oweals%2Fgnunet.git diff --git a/src/include/gnunet_nat_service.h b/src/include/gnunet_nat_service.h index 1620c9433..eb08515a2 100644 --- a/src/include/gnunet_nat_service.h +++ b/src/include/gnunet_nat_service.h @@ -1,21 +1,19 @@ /* This file is part of GNUnet. - Copyright (C) 2007-2016 GNUnet e.V. + Copyright (C) 2007-2017 GNUnet e.V. - 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 free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + 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., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ /** @@ -122,6 +120,12 @@ enum GNUNET_NAT_AddressClass */ GNUNET_NAT_AC_EXTERN = 128, + /** + * Addresses that were manually configured by the user. + * Used as a bit in combination with #GNUNET_NAT_AC_GLOBAL. + */ + GNUNET_NAT_AC_MANUAL = 256, + /** * Bitmask for "any" address. */ @@ -130,6 +134,144 @@ enum GNUNET_NAT_AddressClass }; +/** + * Error Types for the NAT subsystem (which can then later be converted/resolved to a string) + */ +enum GNUNET_NAT_StatusCode +{ + /** + * Just the default + */ + GNUNET_NAT_ERROR_SUCCESS = GNUNET_OK, + + /** + * IPC Failure + */ + GNUNET_NAT_ERROR_IPC_FAILURE, + + /** + * Failure in network subsystem, check permissions + */ + GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR, + + /** + * test timed out + */ + GNUNET_NAT_ERROR_TIMEOUT, + + /** + * detected that we are offline + */ + GNUNET_NAT_ERROR_NOT_ONLINE, + + /** + * `upnpc` command not found + */ + GNUNET_NAT_ERROR_UPNPC_NOT_FOUND, + + /** + * Failed to run `upnpc` command + */ + GNUNET_NAT_ERROR_UPNPC_FAILED, + + /** + * `upnpc' command took too long, process killed + */ + GNUNET_NAT_ERROR_UPNPC_TIMEOUT, + + /** + * `upnpc' command failed to establish port mapping + */ + GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED, + + /** + * `external-ip' command not found + */ + GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND, + + /** + * Failed to run `external-ip` command + */ + GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED, + + /** + * `external-ip' command output invalid + */ + GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID, + + /** + * "no valid address was returned by `external-ip'" + */ + GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID, + + /** + * Could not determine interface with internal/local network address + */ + GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO, + + /** + * No working gnunet-helper-nat-server found + */ + GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND, + + /** + * NAT test could not be initialized + */ + GNUNET_NAT_ERROR_NAT_TEST_START_FAILED, + + /** + * NAT test timeout + */ + GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT, + + /** + * NAT test failed to initiate + */ + GNUNET_NAT_ERROR_NAT_REGISTER_FAILED, + + /** + * + */ + GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND + +}; + + + +/** + * 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, + + /** + * We know nothing about the NAT. + */ + GNUNET_NAT_TYPE_UNKNOWN + +}; + + + /** * Signature of the callback passed to #GNUNET_NAT_register() for * a function to call whenever our set of 'valid' addresses changes. @@ -179,8 +321,8 @@ struct GNUNET_NAT_Handle; * address_callback for any 'plausible' external address. * * @param cfg configuration to use + * @param config_section name of the configuration section for options * @param proto protocol this is about, IPPROTO_TCP or IPPROTO_UDP - * @param hole_external hostname and port of manually punched hole in NAT, otherwise NULL (or empty string) * @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 @@ -192,8 +334,8 @@ struct GNUNET_NAT_Handle; */ struct GNUNET_NAT_Handle * GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *config_section, uint8_t proto, - const char *hole_external, unsigned int num_addrs, const struct sockaddr **addrs, const socklen_t *addrlens, @@ -250,127 +392,6 @@ void GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *nh); -/** - * Handle to a NAT test. - */ -struct GNUNET_NAT_Test; - - -/** - * Error Types for the NAT subsystem (which can then later be converted/resolved to a string) - */ -enum GNUNET_NAT_StatusCode -{ - /** - * Just the default - */ - GNUNET_NAT_ERROR_SUCCESS = GNUNET_OK, - - /** - * IPC Failure - */ - GNUNET_NAT_ERROR_IPC_FAILURE, - - /** - * Failure in network subsystem, check permissions - */ - GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR, - - /** - * test timed out - */ - GNUNET_NAT_ERROR_TIMEOUT, - - /** - * detected that we are offline - */ - GNUNET_NAT_ERROR_NOT_ONLINE, - - /** - * `upnpc` command not found - */ - GNUNET_NAT_ERROR_UPNPC_NOT_FOUND, - - /** - * Failed to run `upnpc` command - */ - GNUNET_NAT_ERROR_UPNPC_FAILED, - - /** - * `upnpc' command took too long, process killed - */ - GNUNET_NAT_ERROR_UPNPC_TIMEOUT, - - /** - * `upnpc' command failed to establish port mapping - */ - GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED, - - /** - * `external-ip' command not found - */ - GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND, - - /** - * Failed to run `external-ip` command - */ - GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED, - - /** - * `external-ip' command output invalid - */ - GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID, - - /** - * "no valid address was returned by `external-ip'" - */ - GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID, - - /** - * Could not determine interface with internal/local network address - */ - GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO, - - /** - * No working gnunet-helper-nat-server found - */ - GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND, - - /** - * NAT test could not be initialized - */ - GNUNET_NAT_ERROR_NAT_TEST_START_FAILED, - - /** - * NAT test timeout - */ - GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT, - - /** - * NAT test failed to initiate - */ - GNUNET_NAT_ERROR_NAT_REGISTER_FAILED, - - /** - * - */ - GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND - -}; - - -/** - * 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); - - /** * Handle an incoming STUN message. This function is useful as * some GNUnet service may be listening on a UDP port and might @@ -410,6 +431,18 @@ GNUNET_NAT_stun_handle_packet (struct GNUNET_NAT_Handle *nh, struct GNUNET_NAT_STUN_Handle; +/** + * 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); + + /** * Make Generic STUN request. Sends a generic stun request to the * server specified using the specified socket. If we do this, @@ -442,130 +475,6 @@ void GNUNET_NAT_stun_make_request_cancel (struct GNUNET_NAT_STUN_Handle *rh); -/** - * 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, - - /** - * We know nothing about the NAT. - */ - GNUNET_NAT_TYPE_UNKNOWN - -}; - - -/** - * Converts `enum GNUNET_NAT_StatusCode` to string - * - * @param err error code to resolve to a string - * @return point to a static string containing the error code - */ -const char * -GNUNET_NAT_status2string (enum GNUNET_NAT_StatusCode err); - - -/** - * Function called with the result from the autoconfiguration. - * - * @param cls closure - * @param diff minimal suggested changes to the original configuration - * to make it work (as best as we can) - * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code - * @param type what the situation of the NAT - */ -typedef void -(*GNUNET_NAT_AutoResultCallback)(void *cls, - const struct GNUNET_CONFIGURATION_Handle *diff, - enum GNUNET_NAT_StatusCode result, - enum GNUNET_NAT_Type type); - - -/** - * Start auto-configuration routine. The transport adapters should - * be stopped while this function is called. - * - * @param cfg initial configuration - * @param cb function to call with autoconfiguration result - * @param cb_cls closure for @a cb - * @return handle to cancel operation - */ -struct GNUNET_NAT_AutoHandle * -GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_NAT_AutoResultCallback cb, - void *cb_cls); - - -/** - * Abort autoconfiguration. - * - * @param ah handle for operation to abort - */ -void -GNUNET_NAT_autoconfig_cancel (struct GNUNET_NAT_AutoHandle *ah); - - #endif /** @} */ /* end of group */