Merge branch 'master' of github.com:jedmccaleb/NewCoin

This commit is contained in:
JoelKatz
2012-12-21 07:13:43 -08:00
3 changed files with 57 additions and 15 deletions

View File

@@ -158,7 +158,17 @@ void Application::run()
//
if (!theConfig.RUN_STANDALONE && !theConfig.PEER_IP.empty() && theConfig.PEER_PORT)
{
mPeerDoor = new PeerDoor(mIOService);
try
{
mPeerDoor = new PeerDoor(mIOService);
}
catch (const std::exception& e)
{
// Must run as directed or exit.
cLog(lsFATAL) << boost::str(boost::format("Can not open peer service: %s") % e.what());
exit(3);
}
}
else
{
@@ -170,7 +180,17 @@ void Application::run()
//
if (!theConfig.RPC_IP.empty() && theConfig.RPC_PORT)
{
mRPCDoor = new RPCDoor(mIOService);
try
{
mRPCDoor = new RPCDoor(mIOService);
}
catch (const std::exception& e)
{
// Must run as directed or exit.
cLog(lsFATAL) << boost::str(boost::format("Can not open RPC service: %s") % e.what());
exit(3);
}
}
else
{
@@ -182,7 +202,17 @@ void Application::run()
//
if (!theConfig.WEBSOCKET_IP.empty() && theConfig.WEBSOCKET_PORT)
{
mWSPrivateDoor = WSDoor::createWSDoor(theConfig.WEBSOCKET_IP, theConfig.WEBSOCKET_PORT, false);
try
{
mWSPrivateDoor = WSDoor::createWSDoor(theConfig.WEBSOCKET_IP, theConfig.WEBSOCKET_PORT, false);
}
catch (const std::exception& e)
{
// Must run as directed or exit.
cLog(lsFATAL) << boost::str(boost::format("Can not open private websocket service: %s") % e.what());
exit(3);
}
}
else
{
@@ -194,7 +224,17 @@ void Application::run()
//
if (!theConfig.WEBSOCKET_PUBLIC_IP.empty() && theConfig.WEBSOCKET_PUBLIC_PORT)
{
mWSPublicDoor = WSDoor::createWSDoor(theConfig.WEBSOCKET_PUBLIC_IP, theConfig.WEBSOCKET_PUBLIC_PORT, true);
try
{
mWSPublicDoor = WSDoor::createWSDoor(theConfig.WEBSOCKET_PUBLIC_IP, theConfig.WEBSOCKET_PUBLIC_PORT, true);
}
catch (const std::exception& e)
{
// Must run as directed or exit.
cLog(lsFATAL) << boost::str(boost::format("Can not open public websocket service: %s") % e.what());
exit(3);
}
}
else
{

View File

@@ -5,18 +5,20 @@
#include <boost/bind.hpp>
#include <iostream>
SETUP_LOG();
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))
{
Log(lsINFO) << "RPC port: " << theConfig.RPC_IP << " " << theConfig.RPC_PORT << " allow remote: " << theConfig.RPC_ALLOW_REMOTE;
cLog(lsINFO) << "RPC port: " << theConfig.RPC_IP << " " << theConfig.RPC_PORT << " allow remote: " << theConfig.RPC_ALLOW_REMOTE;
startListening();
}
RPCDoor::~RPCDoor()
{
Log(lsINFO) << "RPC port: " << theConfig.RPC_IP << " " << theConfig.RPC_PORT << " allow remote: " << theConfig.RPC_ALLOW_REMOTE;
cLog(lsINFO) << "RPC port: " << theConfig.RPC_IP << " " << theConfig.RPC_PORT << " allow remote: " << theConfig.RPC_ALLOW_REMOTE;
}
void RPCDoor::startListening()
@@ -31,25 +33,26 @@ 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);
}
void RPCDoor::handleConnect(RPCServer::pointer new_connection,
const boost::system::error_code& error)
{
if(!error)
if (!error)
{
// Restrict callers by IP
if(!isClientAllowed(new_connection->getSocket().remote_endpoint().address().to_string()))
if (!isClientAllowed(new_connection->getSocket().remote_endpoint().address().to_string()))
{
return;
}
new_connection->connected();
}
else Log(lsINFO) << "RPCDoor::handleConnect Error: " << error;
else cLog(lsINFO) << "RPCDoor::handleConnect Error: " << error;
startListening();
}

View File

@@ -58,7 +58,7 @@ void WSDoor::startListening()
SSL_CTX_set_tmp_dh_callback(mCtx->native_handle(), handleTmpDh);
if(theConfig.WEBSOCKET_SECURE)
if (theConfig.WEBSOCKET_SECURE)
{
// Construct a single handler for all requests.
websocketpp::server_tls::handler::ptr handler(new WSServerHandler<websocketpp::server_tls>(mCtx, mPublic));
@@ -94,7 +94,8 @@ void WSDoor::startListening()
}
delete mSEndpoint;
}else
}
else
{
// Construct a single handler for all requests.
websocketpp::server::handler::ptr handler(new WSServerHandler<websocketpp::server>(mCtx, mPublic));
@@ -131,7 +132,6 @@ void WSDoor::startListening()
delete mEndpoint;
}
}
WSDoor* WSDoor::createWSDoor(const std::string& strIp, const int iPort, bool bPublic)
@@ -163,5 +163,4 @@ void WSDoor::stop()
}
}
// vim:ts=4