Use KeyData instead of tuple

This commit is contained in:
Benau 2018-06-05 10:23:14 +08:00
parent 402e447ba1
commit 47455a71f3
2 changed files with 19 additions and 15 deletions

View File

@ -699,8 +699,7 @@ void ServerLobby::checkIncomingConnectionRequests()
// Now start a ConnectToPeer protocol for each connection request // Now start a ConnectToPeer protocol for each connection request
const XMLNode * users_xml = result->getNode("users"); const XMLNode * users_xml = result->getNode("users");
std::map<uint32_t, std::tuple<std::string, std::string, std::map<uint32_t, KeyData> keys;
irr::core::stringw, bool> > keys;
auto sl = m_server_lobby.lock(); auto sl = m_server_lobby.lock();
if (!sl || sl->m_state.load() != ACCEPTING_CLIENTS) if (!sl || sl->m_state.load() != ACCEPTING_CLIENTS)
return; return;
@ -712,10 +711,10 @@ void ServerLobby::checkIncomingConnectionRequests()
users_xml->getNode(i)->get("ip", &addr); users_xml->getNode(i)->get("ip", &addr);
users_xml->getNode(i)->get("port", &port); users_xml->getNode(i)->get("port", &port);
users_xml->getNode(i)->get("id", &id); users_xml->getNode(i)->get("id", &id);
users_xml->getNode(i)->get("aes-key", &std::get<0>(keys[id])); users_xml->getNode(i)->get("aes-key", &keys[id].m_aes_key);
users_xml->getNode(i)->get("aes-iv", &std::get<1>(keys[id])); users_xml->getNode(i)->get("aes-iv", &keys[id].m_aes_iv);
users_xml->getNode(i)->get("username", &std::get<2>(keys[id])); users_xml->getNode(i)->get("username", &keys[id].m_name);
std::get<3>(keys[id]) = false; keys[id].m_tried = false;
if (UserConfigParams::m_firewalled_server) if (UserConfigParams::m_firewalled_server)
{ {
std::make_shared<ConnectToPeer> std::make_shared<ConnectToPeer>
@ -1690,18 +1689,18 @@ void ServerLobby::handlePendingConnection()
{ {
const uint32_t online_id = it->second.first; const uint32_t online_id = it->second.first;
auto key = m_keys.find(online_id); auto key = m_keys.find(online_id);
if (key != m_keys.end() && std::get<3>(key->second) == false) if (key != m_keys.end() && key->second.m_tried == false)
{ {
if (decryptConnectionRequest(peer, it->second.second, if (decryptConnectionRequest(peer, it->second.second,
std::get<0>(key->second), std::get<1>(key->second), key->second.m_aes_key, key->second.m_aes_iv,
online_id, std::get<2>(key->second))) online_id, key->second.m_name))
{ {
it = m_pending_connection.erase(it); it = m_pending_connection.erase(it);
m_keys.erase(online_id); m_keys.erase(online_id);
continue; continue;
} }
else else
std::get<3>(key->second) = true; key->second.m_tried = true;
} }
it++; it++;
} }

View File

@ -39,6 +39,14 @@ public:
EXITING EXITING
}; };
private: private:
struct KeyData
{
std::string m_aes_key;
std::string m_aes_iv;
irr::core::stringw m_name;
bool m_tried = false;
};
std::atomic<ServerState> m_state; std::atomic<ServerState> m_state;
/** Hold the next connected peer for server owner if current one expired /** Hold the next connected peer for server owner if current one expired
@ -87,9 +95,7 @@ private:
std::mutex m_keys_mutex; std::mutex m_keys_mutex;
std::map<uint32_t, std::map<uint32_t, KeyData> m_keys;
std::tuple</*aes 128 key*/std::string, /*iv*/std::string,
/*genuine player name*/irr::core::stringw, /*tried*/bool> > m_keys;
std::map<std::weak_ptr<STKPeer>, std::map<std::weak_ptr<STKPeer>,
std::pair<uint32_t, BareNetworkString>, std::pair<uint32_t, BareNetworkString>,
@ -159,8 +165,7 @@ private:
} }
} }
} }
void addAndReplaceKeys(const std::map<uint32_t, std::tuple<std::string, void addAndReplaceKeys(const std::map<uint32_t, KeyData>& new_keys)
std::string, irr::core::stringw, bool> >& new_keys)
{ {
std::lock_guard<std::mutex> lock(m_keys_mutex); std::lock_guard<std::mutex> lock(m_keys_mutex);
for (auto& k : new_keys) for (auto& k : new_keys)