Reformatting using AStyle

This commit is contained in:
Vinnie Falco
2013-06-14 08:45:13 -07:00
parent 36bd8f7173
commit 521e812fc4
294 changed files with 54609 additions and 47598 deletions

View File

@@ -7,83 +7,86 @@ SETUP_LOG (RPCDoor)
using namespace std;
using namespace boost::asio::ip;
extern void initSSLContext(boost::asio::ssl::context& context,
std::string key_file, std::string cert_file, std::string chain_file);
extern void initSSLContext (boost::asio::ssl::context& context,
std::string key_file, std::string cert_file, std::string chain_file);
RPCDoor::RPCDoor(boost::asio::io_service& io_service) :
mAcceptor(io_service, tcp::endpoint(address::from_string(theConfig.RPC_IP), theConfig.RPC_PORT)),
mDelayTimer(io_service), mSSLContext(boost::asio::ssl::context::sslv23)
RPCDoor::RPCDoor (boost::asio::io_service& io_service) :
mAcceptor (io_service, tcp::endpoint (address::from_string (theConfig.RPC_IP), theConfig.RPC_PORT)),
mDelayTimer (io_service), mSSLContext (boost::asio::ssl::context::sslv23)
{
WriteLog (lsINFO, RPCDoor) << "RPC port: " << theConfig.RPC_IP << " " << theConfig.RPC_PORT << " allow remote: " << theConfig.RPC_ALLOW_REMOTE;
WriteLog (lsINFO, RPCDoor) << "RPC port: " << theConfig.RPC_IP << " " << theConfig.RPC_PORT << " allow remote: " << theConfig.RPC_ALLOW_REMOTE;
if (theConfig.RPC_SECURE != 0)
initSSLContext(mSSLContext, theConfig.RPC_SSL_KEY, theConfig.RPC_SSL_CERT, theConfig.RPC_SSL_CHAIN);
if (theConfig.RPC_SECURE != 0)
initSSLContext (mSSLContext, theConfig.RPC_SSL_KEY, theConfig.RPC_SSL_CERT, theConfig.RPC_SSL_CHAIN);
startListening();
startListening ();
}
RPCDoor::~RPCDoor()
RPCDoor::~RPCDoor ()
{
WriteLog (lsINFO, RPCDoor) << "RPC port: " << theConfig.RPC_IP << " " << theConfig.RPC_PORT << " allow remote: " << theConfig.RPC_ALLOW_REMOTE;
WriteLog (lsINFO, RPCDoor) << "RPC port: " << theConfig.RPC_IP << " " << theConfig.RPC_PORT << " allow remote: " << theConfig.RPC_ALLOW_REMOTE;
}
void RPCDoor::startListening()
void RPCDoor::startListening ()
{
RPCServer::pointer new_connection = RPCServer::create(mAcceptor.get_io_service(), mSSLContext, &theApp->getOPs());
mAcceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
RPCServer::pointer new_connection = RPCServer::create (mAcceptor.get_io_service (), mSSLContext, &theApp->getOPs ());
mAcceptor.set_option (boost::asio::ip::tcp::acceptor::reuse_address (true));
mAcceptor.async_accept(new_connection->getRawSocket(),
boost::bind(&RPCDoor::handleConnect, this, new_connection,
boost::asio::placeholders::error));
mAcceptor.async_accept (new_connection->getRawSocket (),
boost::bind (&RPCDoor::handleConnect, this, new_connection,
boost::asio::placeholders::error));
}
bool RPCDoor::isClientAllowed(const std::string& ip)
bool RPCDoor::isClientAllowed (const std::string& ip)
{
if (theConfig.RPC_ALLOW_REMOTE)
return true;
if (theConfig.RPC_ALLOW_REMOTE)
return true;
if (ip == "127.0.0.1")
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)
void RPCDoor::handleConnect (RPCServer::pointer new_connection, const boost::system::error_code& error)
{
bool delay = false;
if (!error)
{
// Restrict callers by IP
try
{
if (!isClientAllowed(new_connection->getRawSocket().remote_endpoint().address().to_string()))
{
startListening();
return;
}
}
catch (...)
{ // client may have disconnected
startListening();
return;
}
bool delay = false;
new_connection->getSocket().async_handshake(AutoSocket::ssl_socket::server,
boost::bind(&RPCServer::connected, new_connection));
}
else
{
if (error == boost::system::errc::too_many_files_open)
delay = true;
WriteLog (lsINFO, RPCDoor) << "RPCDoor::handleConnect Error: " << error;
}
if (!error)
{
// Restrict callers by IP
try
{
if (!isClientAllowed (new_connection->getRawSocket ().remote_endpoint ().address ().to_string ()))
{
startListening ();
return;
}
}
catch (...)
{
// client may have disconnected
startListening ();
return;
}
if (delay)
{
mDelayTimer.expires_from_now(boost::posix_time::milliseconds(1000));
mDelayTimer.async_wait(boost::bind(&RPCDoor::startListening, this));
}
else
startListening();
new_connection->getSocket ().async_handshake (AutoSocket::ssl_socket::server,
boost::bind (&RPCServer::connected, new_connection));
}
else
{
if (error == boost::system::errc::too_many_files_open)
delay = true;
WriteLog (lsINFO, RPCDoor) << "RPCDoor::handleConnect Error: " << error;
}
if (delay)
{
mDelayTimer.expires_from_now (boost::posix_time::milliseconds (1000));
mDelayTimer.async_wait (boost::bind (&RPCDoor::startListening, this));
}
else
startListening ();
}
// vim:ts=4