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

This commit is contained in:
Arthur Britto
2012-12-21 13:49:54 -08:00
10 changed files with 63 additions and 27 deletions

View File

@@ -103,9 +103,7 @@ void Application::run()
LogPartition::setSeverity(lsDEBUG);
}
boost::thread auxThread(boost::bind(&boost::asio::io_service::run, &mAuxService));
auxThread.detach();
boost::thread(boost::bind(&boost::asio::io_service::run, &mAuxService)).detach();
if (!theConfig.RUN_STANDALONE)
mSNTPClient.init(theConfig.SNTP_SERVERS);

View File

@@ -42,8 +42,7 @@ bool HashedObjectStore::store(HashedObjectType type, uint32 index,
if (!mWritePending)
{
mWritePending = true;
boost::thread t(boost::bind(&HashedObjectStore::bulkWrite, this));
t.detach();
boost::thread(boost::bind(&HashedObjectStore::bulkWrite, this)).detach();
}
}
// else

View File

@@ -204,8 +204,7 @@ void JobQueue::setThreadCount(int c)
while (mThreadCount < c)
{
++mThreadCount;
boost::thread t(boost::bind(&JobQueue::threadEntry, this));
t.detach();
boost::thread(boost::bind(&JobQueue::threadEntry, this)).detach();
}
while (mThreadCount > c)
{

View File

@@ -1167,9 +1167,8 @@ void Ledger::pendSave(bool fromConsensus)
if (!fromConsensus && !theApp->isNewFlag(getHash(), SF_SAVED))
return;
boost::thread thread(boost::bind(&Ledger::saveAcceptedLedger, shared_from_this(),
fromConsensus, theApp->getJobQueue().getLoadEvent(jtDISK)));
thread.detach();
boost::thread(boost::bind(&Ledger::saveAcceptedLedger, shared_from_this(),
fromConsensus, theApp->getJobQueue().getLoadEvent(jtDISK))).detach();
boost::recursive_mutex::scoped_lock sl(sPendingSaveLock);
++sPendingSaves;

View File

@@ -167,9 +167,9 @@ void Log::setLogFile(boost::filesystem::path path)
if (outStream != NULL)
delete outStream;
outStream = newStream;
if (outStream)
Log(lsINFO) << "Starting up";
if (pathToLog != NULL)
delete pathToLog;
pathToLog = new boost::filesystem::path(path);
}

View File

@@ -9,6 +9,9 @@
#include "Application.h"
#include "Config.h"
#include "utils.h"
#include "Log.h"
SETUP_LOG();
using namespace std;
using namespace boost::asio::ip;
@@ -21,7 +24,7 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength)
PeerDoor::PeerDoor(boost::asio::io_service& io_service) :
mAcceptor(io_service, tcp::endpoint(address().from_string(theConfig.PEER_IP), theConfig.PEER_PORT)),
mCtx(boost::asio::ssl::context::sslv23)
mCtx(boost::asio::ssl::context::sslv23), mDelayTimer(io_service)
{
mCtx.set_options(
boost::asio::ssl::context::default_workarounds
@@ -32,7 +35,7 @@ PeerDoor::PeerDoor(boost::asio::io_service& io_service) :
if (1 != SSL_CTX_set_cipher_list(mCtx.native_handle(), theConfig.PEER_SSL_CIPHER_LIST.c_str()))
std::runtime_error("Error setting cipher list (no valid ciphers).");
cerr << "Peer port: " << theConfig.PEER_IP << " " << theConfig.PEER_PORT << endl;
Log(lsINFO) << "Peer port: " << theConfig.PEER_IP << " " << theConfig.PEER_PORT;
startListening();
}
@@ -50,13 +53,25 @@ void PeerDoor::startListening()
void PeerDoor::handleConnect(Peer::pointer new_connection,
const boost::system::error_code& error)
{
bool delay = false;
if (!error)
{
new_connection->connected(error);
}
else cerr << "Error: " << error;
else
{
if (error == boost::system::errc::too_many_files_open)
delay = true;
cLog(lsERROR) << error;
}
startListening();
if (delay)
{
mDelayTimer.expires_from_now(boost::posix_time::milliseconds(500));
mDelayTimer.async_wait(boost::bind(&PeerDoor::startListening, this));
}
else
startListening();
}
void initSSLContext(boost::asio::ssl::context& context,

View File

@@ -18,6 +18,7 @@ class PeerDoor
private:
boost::asio::ip::tcp::acceptor mAcceptor;
boost::asio::ssl::context mCtx;
boost::asio::deadline_timer mDelayTimer;
void startListening();
void handleConnect(Peer::pointer new_connection, const boost::system::error_code& error);

View File

@@ -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

View File

@@ -7,7 +7,9 @@ Handles incoming connections from people making RPC Requests
class RPCDoor
{
boost::asio::ip::tcp::acceptor mAcceptor;
boost::asio::ip::tcp::acceptor mAcceptor;
boost::asio::deadline_timer mDelayTimer;
void startListening();
void handleConnect(RPCServer::pointer new_connection,
const boost::system::error_code& error);

View File

@@ -388,6 +388,8 @@ template <class endpoint>
void server<endpoint>::handle_accept(connection_ptr con,
const boost::system::error_code& error)
{
bool delay = false;
boost::lock_guard<boost::recursive_mutex> lock(m_endpoint.m_lock);
try
@@ -398,10 +400,8 @@ void server<endpoint>::handle_accept(connection_ptr con,
if (error == boost::system::errc::too_many_files_open) {
con->m_fail_reason = "too many files open";
delay = true;
// TODO: make this configurable
//m_timer.expires_from_now(boost::posix_time::milliseconds(1000));
//m_timer.async_wait(boost::bind(&type::start_accept,this));
} else if (error == boost::asio::error::operation_aborted) {
con->m_fail_reason = "io_service operation canceled";
@@ -426,7 +426,13 @@ void server<endpoint>::handle_accept(connection_ptr con,
<< "handle_accept caught exception: " << e.what() << log::endl;
}
this->start_accept();
if (delay)
{ // Don't spin if too many files are open DJS
m_timer.expires_from_now(boost::posix_time::milliseconds(500));
m_timer.async_wait(boost::bind(&type::start_accept,this));
}
else
this->start_accept();
}
// server<endpoint>::connection<connnection_type> Implimentation