Changeset View
Changeset View
Standalone View
Standalone View
source/network/StunClient.cpp
Show First 20 Lines • Show All 356 Lines • ▼ Show 20 Lines | bool ParseStunResponse(const std::vector<u8>& buffer) | ||||||||||||||||
} | } | ||||||||||||||||
return true; | return true; | ||||||||||||||||
} | } | ||||||||||||||||
bool STUNRequestAndResponse(ENetHost& transactionHost) | bool STUNRequestAndResponse(ENetHost& transactionHost) | ||||||||||||||||
{ | { | ||||||||||||||||
if (!CreateStunRequest(transactionHost)) | if (!CreateStunRequest(transactionHost)) | ||||||||||||||||
return false; | return false; | ||||||||||||||||
Silier: nuke | |||||||||||||||||
std::vector<u8> buffer; | std::vector<u8> buffer; | ||||||||||||||||
return ReceiveStunResponse(transactionHost, buffer) && | return ReceiveStunResponse(transactionHost, buffer) && | ||||||||||||||||
ParseStunResponse(buffer); | ParseStunResponse(buffer); | ||||||||||||||||
} | } | ||||||||||||||||
bool StunClient::FindStunEndpoint(std::string& ip, u16& port) | |||||||||||||||||
SilierAuthorUnsubmitted Done Inline Actionskind of wrong, we are interested just in ip Silier: kind of wrong, we are interested just in ip | |||||||||||||||||
StanUnsubmitted Done Inline ActionsDo we need two methods? Stan: Do we need two methods? | |||||||||||||||||
{ | |||||||||||||||||
ENetAddress hostAddr{ ENET_HOST_ANY, static_cast<u16>(port) }; | |||||||||||||||||
ENetHost* transactionHost = enet_host_create(&hostAddr, 1, 1, 0, 0); | |||||||||||||||||
if (!transactionHost) | |||||||||||||||||
{ | |||||||||||||||||
LOGERROR("FindStunEndpointHost: Failed to create enet host"); | |||||||||||||||||
SilierAuthorUnsubmitted Done Inline Actionsnuke Silier: nuke | |||||||||||||||||
return false; | |||||||||||||||||
} | |||||||||||||||||
bool success = STUNRequestAndResponse(*transactionHost); | |||||||||||||||||
enet_host_destroy(transactionHost); | |||||||||||||||||
if (!success) | |||||||||||||||||
return false; | |||||||||||||||||
// Convert m_IP to string | |||||||||||||||||
char ipStr[256] = "(error)"; | |||||||||||||||||
ENetAddress addr; | |||||||||||||||||
addr.host = ntohl(m_IP); | |||||||||||||||||
enet_address_get_host_ip(&addr, ipStr, ARRAY_SIZE(ipStr)); | |||||||||||||||||
ip = ipStr; | |||||||||||||||||
port = m_Port; | |||||||||||||||||
return true; | |||||||||||||||||
} | |||||||||||||||||
JS::Value StunClient::FindStunEndpointHost(const ScriptInterface& scriptInterface, int port) | JS::Value StunClient::FindStunEndpointHost(const ScriptInterface& scriptInterface, int port) | ||||||||||||||||
{ | { | ||||||||||||||||
ENetAddress hostAddr{ENET_HOST_ANY, static_cast<u16>(port)}; | ENetAddress hostAddr{ENET_HOST_ANY, static_cast<u16>(port)}; | ||||||||||||||||
ENetHost* transactionHost = enet_host_create(&hostAddr, 1, 1, 0, 0); | ENetHost* transactionHost = enet_host_create(&hostAddr, 1, 1, 0, 0); | ||||||||||||||||
if (!transactionHost) | if (!transactionHost) | ||||||||||||||||
{ | { | ||||||||||||||||
LOGERROR("FindStunEndpointHost: Failed to create enet host"); | LOGERROR("FindStunEndpointHost: Failed to create enet host"); | ||||||||||||||||
return JS::UndefinedValue(); | return JS::UndefinedValue(); | ||||||||||||||||
} | } | ||||||||||||||||
bool success = STUNRequestAndResponse(*transactionHost); | bool success = STUNRequestAndResponse(*transactionHost); | ||||||||||||||||
enet_host_destroy(transactionHost); | enet_host_destroy(transactionHost); | ||||||||||||||||
if (!success) | if (!success) | ||||||||||||||||
return JS::UndefinedValue(); | return JS::UndefinedValue(); | ||||||||||||||||
Done Inline Actionsrevert Silier: revert | |||||||||||||||||
// Convert m_IP to string | // Convert m_IP to string | ||||||||||||||||
char ipStr[256] = "(error)"; | char ipStr[256] = "(error)"; | ||||||||||||||||
ENetAddress addr; | ENetAddress addr; | ||||||||||||||||
addr.host = ntohl(m_IP); | addr.host = ntohl(m_IP); | ||||||||||||||||
enet_address_get_host_ip(&addr, ipStr, ARRAY_SIZE(ipStr)); | enet_address_get_host_ip(&addr, ipStr, ARRAY_SIZE(ipStr)); | ||||||||||||||||
ScriptRequest rq(scriptInterface); | ScriptRequest rq(scriptInterface); | ||||||||||||||||
JS::RootedValue stunEndpoint(rq.cx); | JS::RootedValue stunEndpoint(rq.cx); | ||||||||||||||||
ScriptInterface::CreateObject(rq, &stunEndpoint, "ip", ipStr, "port", m_Port); | ScriptInterface::CreateObject(rq, &stunEndpoint, "ip", ipStr, "port", m_Port); | ||||||||||||||||
return stunEndpoint; | return stunEndpoint; | ||||||||||||||||
} | } | ||||||||||||||||
Not Done Inline Actions
/** Gives the printable form of the IP address specified in the address parameter. @param address address printed @param hostName destination for name, must not be NULL @param nameLength maximum length of hostName. @returns the null-terminated name of the host in hostName on success @retval 0 on success @retval < 0 on failure */ ENET_API int enet_address_get_host_ip (const ENetAddress * address, char * hostName, size_t nameLength); Stan: ```lang=cpp
/** Gives the printable form of the IP address specified in the address parameter. | |||||||||||||||||
Not Done Inline ActionsIt's better to check enet_address_get_host_ip for success. vladislavbelov: It's better to check `enet_address_get_host_ip` for success. | |||||||||||||||||
bool StunClient::FindStunEndpointJoin(ENetHost& transactionHost, StunClient::StunEndpoint& stunEndpoint) | bool StunClient::FindStunEndpointJoin(ENetHost& transactionHost, StunClient::StunEndpoint& stunEndpoint) | ||||||||||||||||
{ | { | ||||||||||||||||
if (!STUNRequestAndResponse(transactionHost)) | if (!STUNRequestAndResponse(transactionHost)) | ||||||||||||||||
return false; | return false; | ||||||||||||||||
// Convert m_IP to string | // Convert m_IP to string | ||||||||||||||||
char ipStr[256] = "(error)"; | char ipStr[256] = "(error)"; | ||||||||||||||||
ENetAddress addr; | ENetAddress addr; | ||||||||||||||||
Show All 26 Lines |
Wildfire Games · Phabricator
nuke