Apply resource limits to proxied clients:

Resource limits were not properly applied to connections with
known IP addresses but no corresponding users.

Add unit tests for unlimited vs. limited ports.
This commit is contained in:
Mark Travis
2019-02-02 02:54:10 -08:00
committed by Nik Bougalis
parent 872478d965
commit 504b3441dd
26 changed files with 399 additions and 197 deletions

View File

@@ -27,6 +27,10 @@
#include <boost/beast/websocket.hpp>
#include <condition_variable>
#include <string>
#include <unordered_map>
#include <iostream>
#include <ripple/beast/unit_test.h>
@@ -125,7 +129,8 @@ class WSClientImpl : public WSClient
}
public:
WSClientImpl(Config const& cfg, bool v2, unsigned rpc_version)
WSClientImpl(Config const& cfg, bool v2, unsigned rpc_version,
std::unordered_map<std::string, std::string> const& headers = {})
: work_(ios_)
, strand_(ios_)
, thread_([&]{ ios_.run(); })
@@ -137,8 +142,13 @@ public:
{
auto const ep = getEndpoint(cfg, v2);
stream_.connect(ep);
ws_.handshake(ep.address().to_string() +
":" + std::to_string(ep.port()), "/");
ws_.handshake_ex(ep.address().to_string() +
":" + std::to_string(ep.port()), "/",
[&](boost::beast::websocket::request_type &req)
{
for (auto const& h : headers)
req.set(h.first, h.second);
});
ws_.async_read(rb_,
strand_.wrap(std::bind(&WSClientImpl::on_read_msg,
this, std::placeholders::_1)));
@@ -294,9 +304,10 @@ private:
};
std::unique_ptr<WSClient>
makeWSClient(Config const& cfg, bool v2, unsigned rpc_version)
makeWSClient(Config const& cfg, bool v2, unsigned rpc_version,
std::unordered_map<std::string, std::string> const& headers)
{
return std::make_unique<WSClientImpl>(cfg, v2, rpc_version);
return std::make_unique<WSClientImpl>(cfg, v2, rpc_version, headers);
}
} // test