mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Make running out of file descriptors non fatal.
Fix a bug that kills the RPC door if it gets a prohibited connection
This commit is contained in:
@@ -11,11 +11,13 @@ using namespace std;
|
||||
using namespace boost::asio::ip;
|
||||
|
||||
RPCDoor::RPCDoor(boost::asio::io_service& io_service) :
|
||||
mAcceptor(io_service, tcp::endpoint(address::from_string(theConfig.RPC_IP), theConfig.RPC_PORT))
|
||||
mAcceptor(io_service, tcp::endpoint(address::from_string(theConfig.RPC_IP), theConfig.RPC_PORT)),
|
||||
mDelayTimer(io_service)
|
||||
{
|
||||
cLog(lsINFO) << "RPC port: " << theConfig.RPC_IP << " " << theConfig.RPC_PORT << " allow remote: " << theConfig.RPC_ALLOW_REMOTE;
|
||||
startListening();
|
||||
}
|
||||
|
||||
RPCDoor::~RPCDoor()
|
||||
{
|
||||
cLog(lsINFO) << "RPC port: " << theConfig.RPC_IP << " " << theConfig.RPC_PORT << " allow remote: " << theConfig.RPC_ALLOW_REMOTE;
|
||||
@@ -33,27 +35,42 @@ void RPCDoor::startListening()
|
||||
|
||||
bool RPCDoor::isClientAllowed(const std::string& ip)
|
||||
{
|
||||
if (theConfig.RPC_ALLOW_REMOTE) return(true);
|
||||
if (ip=="127.0.0.1") return(true);
|
||||
if (theConfig.RPC_ALLOW_REMOTE)
|
||||
return true;
|
||||
if (ip == "127.0.0.1")
|
||||
return true;
|
||||
|
||||
return(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
void RPCDoor::handleConnect(RPCServer::pointer new_connection,
|
||||
const boost::system::error_code& error)
|
||||
{
|
||||
bool delay = false;
|
||||
if (!error)
|
||||
{
|
||||
// Restrict callers by IP
|
||||
if (!isClientAllowed(new_connection->getSocket().remote_endpoint().address().to_string()))
|
||||
{
|
||||
startListening();
|
||||
return;
|
||||
}
|
||||
|
||||
new_connection->connected();
|
||||
}
|
||||
else cLog(lsINFO) << "RPCDoor::handleConnect Error: " << error;
|
||||
else
|
||||
{
|
||||
if (error == boost::system::errc::too_many_files_open)
|
||||
delay = true;
|
||||
cLog(lsINFO) << "RPCDoor::handleConnect Error: " << error;
|
||||
}
|
||||
|
||||
startListening();
|
||||
if (delay)
|
||||
{
|
||||
mDelayTimer.expires_from_now(boost::posix_time::milliseconds(1000));
|
||||
mDelayTimer.async_wait(boost::bind(&RPCDoor::startListening, this));
|
||||
}
|
||||
else
|
||||
startListening();
|
||||
}
|
||||
// vim:ts=4
|
||||
|
||||
Reference in New Issue
Block a user