Skip to content

Commit

Permalink
Optimize internal packets whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
katursis committed Sep 11, 2021
1 parent 96288fb commit 1d65965
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ class Config {
continue;
}

whitelist_internal_packets_.insert(static_cast<unsigned char>(packet_id));
whitelist_internal_packets_[packet_id] = true;

whitelist_is_empty_ = false;
}

use_caching_ = config->get_as<bool>("UseCaching").value_or(false);
Expand All @@ -96,8 +98,13 @@ class Config {
intercept_outgoing_internal_packet_);

auto packet_ids = cpptoml::make_array();
for (auto &packet_id : whitelist_internal_packets_) {
packet_ids->push_back(packet_id);
if (!whitelist_is_empty_) {
for (int packet_id{}; packet_id < whitelist_internal_packets_.size();
packet_id++) {
if (whitelist_internal_packets_[packet_id]) {
packet_ids->push_back(packet_id);
}
}
}
config->insert("WhiteListInternalPackets", packet_ids);

Expand Down Expand Up @@ -128,8 +135,7 @@ class Config {
}

bool IsWhiteListedInternalPacket(unsigned char packet_id) const {
return whitelist_internal_packets_.empty() ||
whitelist_internal_packets_.count(packet_id);
return whitelist_is_empty_ || whitelist_internal_packets_[packet_id];
}

bool UseCaching() const { return use_caching_; }
Expand All @@ -145,7 +151,8 @@ class Config {
bool intercept_incoming_internal_packet_{};
bool intercept_outgoing_internal_packet_{};

std::set<unsigned char> whitelist_internal_packets_;
std::array<bool, PR_MAX_HANDLERS> whitelist_internal_packets_{};
bool whitelist_is_empty_{true};

bool use_caching_{};
};
Expand Down

0 comments on commit 1d65965

Please sign in to comment.