2 * Copyright (c) 2015, Facebook, Inc.
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
10 #include <folly/wangle/acceptor/LoadShedConfiguration.h>
12 #include <folly/Conv.h>
13 #include <openssl/ssl.h>
19 void LoadShedConfiguration::addWhitelistAddr(folly::StringPiece input) {
20 auto addr = input.str();
21 size_t separator = addr.find_first_of('/');
22 if (separator == string::npos) {
23 whitelistAddrs_.insert(SocketAddress(addr, 0));
25 unsigned prefixLen = folly::to<unsigned>(addr.substr(separator + 1));
26 addr.erase(separator);
27 whitelistNetworks_.insert(NetworkAddress(SocketAddress(addr, 0), prefixLen));
31 bool LoadShedConfiguration::isWhitelisted(const SocketAddress& address) const {
32 if (whitelistAddrs_.find(address) != whitelistAddrs_.end()) {
35 for (auto& network : whitelistNetworks_) {
36 if (network.contains(address)) {