Rename function to make it clearer

This commit is contained in:
Benau 2020-01-22 15:56:47 +08:00
parent 2ca1c5555c
commit aed64dfd1f
7 changed files with 39 additions and 39 deletions

@ -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);
}

@ -11,7 +11,7 @@
#ifdef ENABLE_IPV6
#include <ws2tcpip.h>
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);
}

@ -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<Network>(new Network(1, 1, 0, 0, &addr));
setIPV6(1);
setIPv6Socket(1);
auto ipv6 = std::unique_ptr<Network>(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();

@ -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;

@ -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

@ -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<MappedAddress> g_mapped_ips;
// ============================================================================
int isIPV6()
int isIPv6Socket()
{
return g_ipv6;
} // isIPV6
// ----------------------------------------------------------------------------
void setIPV6(int val)
void setIPv6Socket(int val)
{
g_ipv6 = val;
} // setIPV6

@ -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);