This is an automated email from the ASF dual-hosted git repository.
amc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 2602da1 Cleanup: replace multiple HashMap with STL unordered_map
2602da1 is described below
commit 2602da13eebe80d873ae3045e8c3da9bade16ac6
Author: Xavier Chi <[email protected]>
AuthorDate: Mon Nov 12 10:29:35 2018 -0600
Cleanup: replace multiple HashMap with STL unordered_map
---
iocore/net/P_SNIActionPerformer.h | 9 ++--
iocore/net/P_SSLConfig.h | 2 +-
iocore/net/P_SSLSNI.h | 9 ++--
iocore/net/SNIActionPerformer.cc | 2 +-
iocore/net/SSLSNIConfig.cc | 104 ++++++++++++++++----------------------
iocore/net/SSLUtils.cc | 11 ++--
6 files changed, 61 insertions(+), 76 deletions(-)
diff --git a/iocore/net/P_SNIActionPerformer.h
b/iocore/net/P_SNIActionPerformer.h
index 001ac00..488c1cd 100644
--- a/iocore/net/P_SNIActionPerformer.h
+++ b/iocore/net/P_SNIActionPerformer.h
@@ -31,13 +31,13 @@
#pragma once
#include "I_EventSystem.h"
-#include "tscore/Map.h"
//#include"P_UnixNetProcessor.h"
#include <vector>
#include "P_SSLNextProtocolAccept.h"
#include "tscore/ink_inet.h"
+#include <unordered_map>
-extern Map<int, SSLNextProtocolSet *> snpsMap;
+extern std::unordered_map<int, SSLNextProtocolSet *> snpsMap;
// enum of all the actions
enum AllActions {
TS_DISABLE_H2 = 0,
@@ -67,8 +67,9 @@ public:
auto ssl_vc = reinterpret_cast<SSLNetVConnection *>(cont);
auto accept_obj = ssl_vc ? ssl_vc->accept_object : nullptr;
if (accept_obj && accept_obj->snpa && ssl_vc) {
- auto nps = snpsMap.get(accept_obj->id);
- ssl_vc->registerNextProtocolSet(reinterpret_cast<SSLNextProtocolSet
*>(nps));
+ if (auto it = snpsMap.find(accept_obj->id); it != snpsMap.end()) {
+ ssl_vc->registerNextProtocolSet(it->second);
+ }
}
return SSL_TLSEXT_ERR_OK;
}
diff --git a/iocore/net/P_SSLConfig.h b/iocore/net/P_SSLConfig.h
index 5ea0c95..aa86ad9 100644
--- a/iocore/net/P_SSLConfig.h
+++ b/iocore/net/P_SSLConfig.h
@@ -123,7 +123,7 @@ struct SSLConfigParams : public ConfigInfo {
SSL_CTX *client_ctx;
- mutable HashMap<cchar *, class StringHashFns, SSL_CTX *> ctx_map;
+ mutable std::unordered_map<std::string, SSL_CTX *> ctx_map;
mutable ink_mutex ctxMapLock;
SSL_CTX *getClientSSL_CTX(void) const;
diff --git a/iocore/net/P_SSLSNI.h b/iocore/net/P_SSLSNI.h
index 33543da..05318a7 100644
--- a/iocore/net/P_SSLSNI.h
+++ b/iocore/net/P_SSLSNI.h
@@ -31,7 +31,6 @@
#pragma once
#include "ProxyConfig.h"
-#include "tscore/Map.h"
#include "P_SNIActionPerformer.h"
#include "tscore/MatcherUtils.h"
#include "openssl/ossl_typ.h"
@@ -39,6 +38,8 @@
#include <strings.h>
#include "YamlSNIConfig.h"
+#include <unordered_map>
+
// Properties for the next hop server
struct NextHopProperty {
const char *name = nullptr;
// name of the server
@@ -48,9 +49,9 @@ struct NextHopProperty {
NextHopProperty();
};
-typedef std::vector<ActionItem *> actionVector;
-typedef HashMap<cchar *, StringHashFns, actionVector *> SNIMap;
-typedef HashMap<cchar *, StringHashFns, NextHopProperty *>
NextHopPropertyTable;
+using actionVector = std::vector<ActionItem *>;
+using SNIMap = std::unordered_map<std::string, actionVector *>;
+using NextHopPropertyTable = std::unordered_map<std::string, NextHopProperty
*>;
struct SNIConfigParams : public ConfigInfo {
char *sni_filename = nullptr;
diff --git a/iocore/net/SNIActionPerformer.cc b/iocore/net/SNIActionPerformer.cc
index d381e06..fa5116e 100644
--- a/iocore/net/SNIActionPerformer.cc
+++ b/iocore/net/SNIActionPerformer.cc
@@ -35,7 +35,7 @@
#include "P_SSLNextProtocolAccept.h"
#include "P_SSLUtils.h"
-extern Map<int, SSLNextProtocolSet *> snpsMap;
+extern std::unordered_map<int, SSLNextProtocolSet *> snpsMap;
int
SNIActionPerformer::PerformAction(Continuation *cont, cchar *servername)
diff --git a/iocore/net/SSLSNIConfig.cc b/iocore/net/SSLSNIConfig.cc
index 7813287..aa963a3 100644
--- a/iocore/net/SSLSNIConfig.cc
+++ b/iocore/net/SSLSNIConfig.cc
@@ -38,19 +38,20 @@
static ConfigUpdateHandler<SNIConfig> *sniConfigUpdate;
struct NetAccept;
-Map<int, SSLNextProtocolSet *> snpsMap;
+std::unordered_map<int, SSLNextProtocolSet *> snpsMap;
extern TunnelHashMap TunnelMap;
NextHopProperty::NextHopProperty() {}
NextHopProperty *
SNIConfigParams::getPropertyConfig(cchar *servername) const
{
- NextHopProperty *nps = nullptr;
- nps = next_hop_table.get(servername);
- if (!nps) {
- nps = wild_next_hop_table.get(servername);
+ if (auto it = next_hop_table.find(servername); it != next_hop_table.end()) {
+ return it->second;
}
- return nps;
+ if (auto it = wild_next_hop_table.find(servername); it !=
wild_next_hop_table.end()) {
+ return it->second;
+ }
+ return nullptr;
}
void
@@ -72,10 +73,10 @@ SNIConfigParams::loadSNIConfig()
ts::TextView domain{servername, strlen(servername)};
domain.take_prefix_at('.');
if (!domain.empty()) {
- wild_sni_action_map.put(ats_stringdup(domain), aiVec);
+ wild_sni_action_map.emplace(domain, aiVec);
}
} else {
- sni_action_map.put(ats_strdup(servername), aiVec);
+ sni_action_map.emplace(servername, aiVec);
}
if (item.tunnel_destination.length()) {
@@ -92,15 +93,18 @@ SNIConfigParams::loadSNIConfig()
if (certFile) {
clientCTX = params->getNewCTX(certFile, keyFile);
}
- NextHopProperty *nps = new NextHopProperty();
- nps->name = ats_strdup(servername);
- nps->verifyServerPolicy = item.verify_server_policy;
- nps->verifyServerProperties = item.verify_server_properties;
- nps->ctx = clientCTX;
- if (wildcard) {
- wild_next_hop_table.put(nps->name, nps);
- } else {
- next_hop_table.put(nps->name, nps);
+ if (servername) { // a safety check
+ NextHopProperty *nps = new NextHopProperty();
+
+ nps->name = ats_strdup(servername);
+ nps->verifyServerPolicy = item.verify_server_policy;
+ nps->verifyServerProperties = item.verify_server_properties;
+ nps->ctx = clientCTX;
+ if (wildcard) {
+ wild_next_hop_table.emplace(nps->name, nps);
+ } else {
+ next_hop_table.emplace(nps->name, nps);
+ }
}
} // end for
}
@@ -112,29 +116,25 @@ SNIConfigParams::SNIConfigParams() {}
actionVector *
SNIConfigParams::get(cchar *servername) const
{
- auto actionVec = sni_action_map.get(servername);
- if (!actionVec) {
- Vec<cchar *> keys;
- wild_sni_action_map.get_keys(keys);
- for (int i = 0; i < static_cast<int>(keys.length()); i++) {
- std::string_view sv{servername, strlen(servername)};
- std::string_view key_sv{keys.get(i)};
+ auto action_it = sni_action_map.find(servername);
+ if (action_it != sni_action_map.end()) {
+ for (const auto &it : wild_sni_action_map) {
+ std::string_view sv{servername};
+ std::string_view key_sv{it.first};
if (sv.size() >= key_sv.size() && sv.substr(sv.size() - key_sv.size())
== key_sv) {
- return wild_sni_action_map.get(key_sv.data());
+ auto wild_action_it = wild_sni_action_map.find(key_sv.data());
+ return wild_action_it != wild_sni_action_map.end() ?
wild_action_it->second : nullptr;
}
}
}
- return actionVec;
+ return action_it != sni_action_map.end() ? action_it->second : nullptr;
}
void
SNIConfigParams::printSNImap() const
{
- Vec<cchar *> keys;
- sni_action_map.get_keys(keys);
- for (size_t i = 0; i < keys.length(); i++) {
- Debug("ssl", "Domain name in the map %s: # of registered action items
%lu", (char *)keys.get(i),
- sni_action_map.get(keys.get(i))->size());
+ for (const auto &it : sni_action_map) {
+ Debug("ssl", "Domain name in the map %s: # of registered action items
%lu", it.first.c_str(), it.second->size());
}
}
@@ -169,42 +169,26 @@ SNIConfigParams::Initialize()
void
SNIConfigParams::cleanup()
{
- Vec<cchar *> keys;
- sni_action_map.get_keys(keys);
- for (int i = keys.length() - 1; i >= 0; i--) {
- auto actionVec = sni_action_map.get(keys.get(i));
- for (auto &ai : *actionVec) {
+ for (const auto &it : sni_action_map) {
+ auto actionVec = it.second;
+ for (const auto &ai : *actionVec) {
delete ai;
}
-
- actionVec->clear();
+ delete actionVec;
}
- keys.free_and_clear();
-
- wild_sni_action_map.get_keys(keys);
- for (int i = keys.length() - 1; i >= 0; i--) {
- auto actionVec = wild_sni_action_map.get(keys.get(i));
- for (auto &ai : *actionVec) {
+ for (const auto &it : wild_sni_action_map) {
+ auto actionVec = it.second;
+ for (const auto &ai : *actionVec) {
delete ai;
}
-
- actionVec->clear();
+ delete actionVec;
}
- keys.free_and_clear();
-
- next_hop_table.get_keys(keys);
- for (int i = 0; i < static_cast<int>(keys.length()); i++) {
- auto *nps = next_hop_table.get(keys.get(i));
- delete (nps);
+ for (const auto &it : next_hop_table) {
+ delete it.second;
}
- keys.free_and_clear();
-
- wild_next_hop_table.get_keys(keys);
- for (int i = 0; static_cast<int>(keys.length()); i++) {
- auto *nps = wild_next_hop_table.get(keys.get(i));
- delete (nps);
+ for (const auto &it : wild_next_hop_table) {
+ delete it.second;
}
- keys.free_and_clear();
}
SNIConfigParams::~SNIConfigParams()
@@ -229,7 +213,7 @@ SNIConfig::cloneProtoSet()
if (na->snpa) {
auto snps = na->snpa->cloneProtoSet();
snps->unregisterEndpoint(TS_ALPN_PROTOCOL_HTTP_2_0, nullptr);
- snpsMap.put(na->id, snps);
+ snpsMap.emplace(na->id, snps);
}
}
}
diff --git a/iocore/net/SSLUtils.cc b/iocore/net/SSLUtils.cc
index c5a2915..8830d70 100644
--- a/iocore/net/SSLUtils.cc
+++ b/iocore/net/SSLUtils.cc
@@ -140,7 +140,7 @@ static ink_mutex *mutex_buf = nullptr;
static bool open_ssl_initialized = false;
RecRawStatBlock *ssl_rsb = nullptr;
-HashMap<cchar *, class StringHashFns, intptr_t> cipher_map;
+std::unordered_map<std::string, intptr_t> cipher_map;
/* Using pthread thread ID and mutex functions directly, instead of
* ATS this_ethread / ProxyMutex, so that other linked libraries
@@ -1137,8 +1137,8 @@ SSLInitializeStatistics()
}
// If not already registered ...
- if (0 == cipher_map.get(cipherName)) {
- cipher_map.put(cipherName, (intptr_t)(ssl_cipher_stats_start + index));
+ if (cipherName && cipher_map.find(cipherName) == cipher_map.end()) {
+ cipher_map.emplace(cipherName, (intptr_t)(ssl_cipher_stats_start +
index));
// Register as non-persistent since the order/index is dependent upon
configuration.
RecRegisterRawStat(ssl_rsb, RECT_PROCESS, statName.c_str(), RECD_INT,
RECP_NON_PERSISTENT,
(int)ssl_cipher_stats_start + index,
RecRawStatSyncSum);
@@ -1550,9 +1550,8 @@ ssl_callback_info(const SSL *ssl, int where, int ret)
if (cipher) {
const char *cipherName = SSL_CIPHER_get_name(cipher);
// lookup index of stat by name and incr count
- auto data = cipher_map.get(cipherName);
- if (data != 0) {
- SSL_INCREMENT_DYN_STAT((intptr_t)data);
+ if (auto it = cipher_map.find(cipherName); it != cipher_map.end()) {
+ SSL_INCREMENT_DYN_STAT((intptr_t)it->second);
}
}
}