From aed64dfd1f5cc4b3c8b7d2d49c2e40ea58062934 Mon Sep 17 00:00:00 2001 From: Benau Date: Wed, 22 Jan 2020 15:56:47 +0800 Subject: [PATCH] Rename function to make it clearer --- lib/enet/unix.c | 14 +++++------ lib/enet/win32.c | 14 +++++------ src/network/network_config.cpp | 6 ++--- src/network/protocols/connect_to_server.cpp | 6 ++--- src/network/stk_host.cpp | 26 ++++++++++----------- src/network/stk_ipv6.cpp | 8 +++---- src/network/stk_ipv6.hpp | 4 ++-- 7 files changed, 39 insertions(+), 39 deletions(-) diff --git a/lib/enet/unix.c b/lib/enet/unix.c index 5d0793979..70627d47a 100644 --- a/lib/enet/unix.c +++ b/lib/enet/unix.c @@ -60,7 +60,7 @@ static enet_uint32 timeBase = 0; #ifdef ENABLE_IPV6 extern void stkInitialize(void); -extern int isIPV6(void); +extern int isIPv6Socket(void); extern void getIPV6FromMappedAddress(const ENetAddress* ea, struct sockaddr_in6* in6); extern void getMappedFromIPV6(const struct sockaddr_in6* in6, ENetAddress* ea); #endif @@ -201,7 +201,7 @@ enet_socket_bind (ENetSocket socket, const ENetAddress * address) { #ifdef ENABLE_IPV6 // In STK we only bind port and listen to any address - if (isIPV6()) + if (isIPv6Socket()) { struct sockaddr_in6 sin; memset (&sin, 0, sizeof (struct sockaddr_in6)); @@ -262,13 +262,13 @@ ENetSocket enet_socket_create (ENetSocketType type) { #ifdef ENABLE_IPV6 - int af_family = isIPV6() == 1 ? PF_INET6 : PF_INET; + int af_family = isIPv6Socket() == 1 ? PF_INET6 : PF_INET; #else int af_family = PF_INET; #endif int socket_fd = socket (af_family, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0); #ifdef ENABLE_IPV6 - if (isIPV6() && socket_fd != -1) + if (isIPv6Socket() && socket_fd != -1) { int no = 0; // Allow IPv6 socket listen to IPv4 connection (as long as the host has IPv4 address) @@ -432,7 +432,7 @@ enet_socket_send (ENetSocket socket, if (address != NULL) { #ifdef ENABLE_IPV6 - if (isIPV6()) + if (isIPv6Socket()) { getIPV6FromMappedAddress(address, &sin6); msgHdr.msg_name = & sin6; @@ -486,7 +486,7 @@ enet_socket_receive (ENetSocket socket, if (address != NULL) { #ifdef ENABLE_IPV6 - if (isIPV6()) + if (isIPv6Socket()) { msgHdr.msg_name = & sin6; msgHdr.msg_namelen = sizeof (struct sockaddr_in6); @@ -520,7 +520,7 @@ enet_socket_receive (ENetSocket socket, if (address != NULL) { #ifdef ENABLE_IPV6 - if (isIPV6()) + if (isIPv6Socket()) { getMappedFromIPV6(&sin6, address); } diff --git a/lib/enet/win32.c b/lib/enet/win32.c index 153a85d48..32c49eaa9 100644 --- a/lib/enet/win32.c +++ b/lib/enet/win32.c @@ -11,7 +11,7 @@ #ifdef ENABLE_IPV6 #include extern void stkInitialize(void); -extern int isIPV6(void); +extern int isIPv6Socket(void); extern void getIPV6FromMappedAddress(const ENetAddress* ea, struct sockaddr_in6* in6); extern void getMappedFromIPV6(const struct sockaddr_in6* in6, ENetAddress* ea); #endif @@ -134,7 +134,7 @@ enet_socket_bind (ENetSocket socket, const ENetAddress * address) { #ifdef ENABLE_IPV6 // In STK we only bind port and listen to any address - if (isIPV6()) + if (isIPv6Socket()) { struct sockaddr_in6 sin; memset (&sin, 0, sizeof (struct sockaddr_in6)); @@ -195,13 +195,13 @@ ENetSocket enet_socket_create (ENetSocketType type) { #ifdef ENABLE_IPV6 - int af_family = isIPV6() == 1 ? PF_INET6 : PF_INET; + int af_family = isIPv6Socket() == 1 ? PF_INET6 : PF_INET; #else int af_family = PF_INET; #endif SOCKET socket_fd = socket (af_family, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0); #ifdef ENABLE_IPV6 - if (isIPV6() && socket_fd != INVALID_SOCKET) + if (isIPv6Socket() && socket_fd != INVALID_SOCKET) { int no = 0; // Allow IPv6 socket listen to IPv4 connection (as long as the host has IPv4 address) @@ -352,7 +352,7 @@ enet_socket_send (ENetSocket socket, if (address != NULL) { #ifdef ENABLE_IPV6 - if (isIPV6()) + if (isIPv6Socket()) { getIPV6FromMappedAddress(address, &sin6); sin_send = (struct sockaddr*)&sin6; @@ -417,7 +417,7 @@ enet_socket_receive (ENetSocket socket, #ifdef ENABLE_IPV6 if (address != NULL) { - if (isIPV6()) + if (isIPv6Socket()) { sin_recv = (struct sockaddr*)&sin6; sinLength = sizeof(struct sockaddr_in6); @@ -456,7 +456,7 @@ enet_socket_receive (ENetSocket socket, if (address != NULL) { #ifdef ENABLE_IPV6 - if (isIPV6()) + if (isIPv6Socket()) { getMappedFromIPV6(&sin6, address); } diff --git a/src/network/network_config.cpp b/src/network/network_config.cpp index 67f591b92..823751dff 100644 --- a/src/network/network_config.cpp +++ b/src/network/network_config.cpp @@ -196,11 +196,11 @@ void NetworkConfig::detectIPType() // used in ipv4 or ipv6 uint8_t stun_tansaction_id[16] = {}; BareNetworkString s = STKHost::getStunRequest(stun_tansaction_id); - setIPV6(0); + setIPv6Socket(0); auto ipv4 = std::unique_ptr(new Network(1, 1, 0, 0, &addr)); - setIPV6(1); + setIPv6Socket(1); auto ipv6 = std::unique_ptr(new Network(1, 1, 0, 0, &addr)); - setIPV6(0); + setIPv6Socket(0); auto ipv4_it = UserConfigParams::m_stun_servers_v4.begin(); int adv = rand() % UserConfigParams::m_stun_servers_v4.size(); diff --git a/src/network/protocols/connect_to_server.cpp b/src/network/protocols/connect_to_server.cpp index 0406ecc36..11f988ac0 100644 --- a/src/network/protocols/connect_to_server.cpp +++ b/src/network/protocols/connect_to_server.cpp @@ -94,7 +94,7 @@ void ConnectToServer::setup() { m_state = GOT_SERVER_ADDRESS; if (m_server->useIPV6Connection()) - setIPV6(1); + setIPv6Socket(1); } else m_state = SET_PUBLIC_ADDRESS; @@ -227,7 +227,7 @@ void ConnectToServer::asynchronousUpdate() if (m_server->useIPV6Connection()) { // Disable STUN if using IPv6 (check in setPublicAddress) - setIPV6(1); + setIPv6Socket(1); } if (m_server->supportsEncryption()) { @@ -266,7 +266,7 @@ void ConnectToServer::asynchronousUpdate() // that has stun mapped, the first 8 seconds allow the server to // start the connect to peer protocol first before the port is // remapped. IPv6 has no stun so try once with any port - if (isIPV6()) + if (isIPv6Socket()) { if (!tryConnect(2000, 15, true/*another_port*/, true/*IPv6*/)) m_state = DONE; diff --git a/src/network/stk_host.cpp b/src/network/stk_host.cpp index 6d631563a..28c9125e2 100644 --- a/src/network/stk_host.cpp +++ b/src/network/stk_host.cpp @@ -259,7 +259,7 @@ STKHost::STKHost(bool server) if (server) { - setIPV6(ServerConfig::m_ipv6_server ? 1 : 0); + setIPv6Socket(ServerConfig::m_ipv6_server ? 1 : 0); addr.port = ServerConfig::m_server_port; if (addr.port == 0 && !UserConfigParams::m_random_server_port) addr.port = stk_config->m_server_port; @@ -432,7 +432,7 @@ std::string STKHost::getIPFromStun(int socket, const std::string& stun_address, return ""; struct sockaddr* stun_addr = NULL; - if (isIPV6()) + if (isIPv6Socket()) { if (ipv4) { @@ -472,7 +472,7 @@ std::string STKHost::getIPFromStun(int socket, const std::string& stun_address, constexpr uint32_t magic_cookie = 0x2112A442; BareNetworkString s = getStunRequest(stun_tansaction_id); - sendto(socket, s.getData(), s.size(), 0, stun_addr, isIPV6() ? + sendto(socket, s.getData(), s.size(), 0, stun_addr, isIPv6Socket() ? sizeof(sockaddr_in6) : sizeof(sockaddr_in)); // Recieve now @@ -482,9 +482,9 @@ std::string STKHost::getIPFromStun(int socket, const std::string& stun_address, struct sockaddr_in addr4_rev; struct sockaddr_in6 addr6_rev; - struct sockaddr* addr_rev = isIPV6() ? + struct sockaddr* addr_rev = isIPv6Socket() ? (struct sockaddr*)(&addr6_rev) : (struct sockaddr*)(&addr4_rev); - socklen_t from_len = isIPV6() ? sizeof(addr6_rev) : sizeof(addr4_rev); + socklen_t from_len = isIPv6Socket() ? sizeof(addr6_rev) : sizeof(addr4_rev); int len = -1; int count = 0; while (len < 0 && count < 2000) @@ -504,7 +504,7 @@ std::string STKHost::getIPFromStun(int socket, const std::string& stun_address, return ""; } - if (isIPV6()) + if (isIPv6Socket()) { if (!sameIPV6((sockaddr_in6*)stun_addr, &addr6_rev)) { @@ -705,7 +705,7 @@ std::string STKHost::getIPFromStun(int socket, const std::string& stun_address, */ void STKHost::setPublicAddress() { - if (isIPV6() && NetworkConfig::get()->isClient()) + if (isIPv6Socket() && NetworkConfig::get()->isClient()) { // IPv6 client doesn't support connection to firewalled server, // so no need to test STUN @@ -747,7 +747,7 @@ void STKHost::setPublicAddress() ping = StkTime::getMonoTimeMs() - ping; // Succeed, save ping UserConfigParams::m_stun_servers[server_name] = (uint32_t)(ping); - if (isIPV6()) + if (isIPv6Socket()) { m_public_ipv6_address = getIPFromStun( (int)m_network->getENetHost()->socket, server_name, @@ -768,7 +768,7 @@ void STKHost::setPublicAddress() //----------------------------------------------------------------------------- void STKHost::setPrivatePort() { - if (isIPV6()) + if (isIPv6Socket()) { struct sockaddr_in6 sin6; socklen_t len = sizeof(sin6); @@ -891,13 +891,13 @@ void STKHost::mainLoop() { TransportAddress address(0, stk_config->m_server_discovery_port); ENetAddress eaddr = address.toEnetAddress(); - bool socket_ipv6 = isIPV6() == 1 ? true : false; + bool socket_ipv6 = isIPv6Socket() == 1 ? true : false; if (socket_ipv6) - setIPV6(0); + setIPv6Socket(0); // direct_socket use IPv4 only atm direct_socket = new Network(1, 1, 0, 0, &eaddr); if (socket_ipv6) - setIPV6(1); + setIPv6Socket(1); if (direct_socket->getENetHost() == NULL) { Log::warn("STKHost", "No direct socket available, this " @@ -950,7 +950,7 @@ void STKHost::mainLoop() if (is_server) { - if (isIPV6() && + if (isIPv6Socket() && last_disconnect_time_update < StkTime::getMonoTimeMs()) { // Check per 20 second, don't need to check client because it diff --git a/src/network/stk_ipv6.cpp b/src/network/stk_ipv6.cpp index 59e6214d0..ccb4a61a8 100644 --- a/src/network/stk_ipv6.cpp +++ b/src/network/stk_ipv6.cpp @@ -197,13 +197,13 @@ extern "C" int insideIPv6CIDR(const char* ipv6_cidr, const char* ipv6_in) #ifndef ENABLE_IPV6 #include "network/stk_ipv6.hpp" // ---------------------------------------------------------------------------- -int isIPV6() +int isIPv6Socket() { return 0; } // isIPV6 // ---------------------------------------------------------------------------- -void setIPV6(int val) +void setIPv6Socket(int val) { } // setIPV6 @@ -253,13 +253,13 @@ struct MappedAddress }; std::vector g_mapped_ips; // ============================================================================ -int isIPV6() +int isIPv6Socket() { return g_ipv6; } // isIPV6 // ---------------------------------------------------------------------------- -void setIPV6(int val) +void setIPv6Socket(int val) { g_ipv6 = val; } // setIPV6 diff --git a/src/network/stk_ipv6.hpp b/src/network/stk_ipv6.hpp index 69623d377..ce5cc814e 100644 --- a/src/network/stk_ipv6.hpp +++ b/src/network/stk_ipv6.hpp @@ -21,8 +21,8 @@ #ifdef __cplusplus extern "C" { #endif -int isIPV6(); -void setIPV6(int val); +int isIPv6Socket(); +void setIPv6Socket(int val); void stkInitialize(); void getIPV6FromMappedAddress(const ENetAddress* ea, struct sockaddr_in6* in6); void getMappedFromIPV6(const struct sockaddr_in6* in6, ENetAddress* ea);