Files
thehub/libs/api/NetProtect.h
T

52 lines
1.5 KiB
C++
Raw Permalink Normal View History

2021-02-17 22:49:19 +01:00
/*
* This file is part of the Flowee project
* Copyright (C) 2021 Tom Zander <tom@flowee.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NETPROTECT_H
#define NETPROTECT_H
#include <vector>
#include <mutex>
#include <boost/asio/ip/address.hpp>
class NetworkConnection;
class NetProtect
{
public:
/// create a new NetProtect
/// @param maxHosts is the maximum amount of hosts we serve at any time.
NetProtect(int maxHosts);
bool shouldAccept(const NetworkConnection &connection,
2021-02-18 10:06:25 +01:00
uint32_t connectionTime);
2021-02-17 22:49:19 +01:00
void addWhitelistedAddress(boost::asio::ip::address ipAddress);
2021-02-17 22:49:19 +01:00
private:
int m_maxHosts;
struct Connect {
boost::asio::ip::address ipAddress;
2021-02-18 10:06:25 +01:00
uint32_t connectionTime;
2021-02-17 22:49:19 +01:00
};
std::vector<Connect> m_log;
std::vector<boost::asio::ip::address> m_whitelist;
2021-02-17 22:49:19 +01:00
mutable std::mutex m_lock;
};
#endif