mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Split websocket connections to two ports.
This commit is contained in:
@@ -148,7 +148,7 @@ void Application::run()
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Peer interface: disabled" << std::endl;
|
||||
cLog(lsINFO) << "Peer interface: disabled";
|
||||
}
|
||||
|
||||
//
|
||||
@@ -160,10 +160,32 @@ void Application::run()
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "RPC interface: disabled" << std::endl;
|
||||
cLog(lsINFO) << "RPC interface: disabled";
|
||||
}
|
||||
|
||||
mWSDoor = WSDoor::createWSDoor();
|
||||
//
|
||||
// Allow private WS connections.
|
||||
//
|
||||
if (!theConfig.WEBSOCKET_IP.empty() && theConfig.WEBSOCKET_PORT)
|
||||
{
|
||||
mWSPrivateDoor = WSDoor::createWSDoor(theConfig.WEBSOCKET_IP, theConfig.WEBSOCKET_PORT, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
cLog(lsINFO) << "WS private interface: disabled";
|
||||
}
|
||||
|
||||
//
|
||||
// Allow public WS connections.
|
||||
//
|
||||
if (!theConfig.WEBSOCKET_PUBLIC_IP.empty() && theConfig.WEBSOCKET_PUBLIC_PORT)
|
||||
{
|
||||
mWSPublicDoor = WSDoor::createWSDoor(theConfig.WEBSOCKET_PUBLIC_IP, theConfig.WEBSOCKET_PUBLIC_PORT, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
cLog(lsINFO) << "WS public interface: disabled";
|
||||
}
|
||||
|
||||
//
|
||||
// Begin connecting to network.
|
||||
@@ -182,9 +204,13 @@ void Application::run()
|
||||
|
||||
mIOService.run(); // This blocks
|
||||
|
||||
mWSDoor->stop();
|
||||
if (mWSPublicDoor)
|
||||
mWSPublicDoor->stop();
|
||||
|
||||
std::cout << "Done." << std::endl;
|
||||
if (mWSPrivateDoor)
|
||||
mWSPrivateDoor->stop();
|
||||
|
||||
cLog(lsINFO) << "Done.";
|
||||
}
|
||||
|
||||
void Application::sweep()
|
||||
|
||||
@@ -62,7 +62,8 @@ class Application
|
||||
ConnectionPool mConnectionPool;
|
||||
PeerDoor* mPeerDoor;
|
||||
RPCDoor* mRPCDoor;
|
||||
WSDoor* mWSDoor;
|
||||
WSDoor* mWSPublicDoor;
|
||||
WSDoor* mWSPrivateDoor;
|
||||
|
||||
uint256 mNonce256;
|
||||
std::size_t mNonceST;
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#define SECTION_UNL_DEFAULT "unl_default"
|
||||
#define SECTION_VALIDATION_QUORUM "validation_quorum"
|
||||
#define SECTION_VALIDATION_SEED "validation_seed"
|
||||
#define SECTION_WEBSOCKET_PUBLIC_IP "websocket_public_ip"
|
||||
#define SECTION_WEBSOCKET_PUBLIC_PORT "websocket_public_port"
|
||||
#define SECTION_WEBSOCKET_IP "websocket_ip"
|
||||
#define SECTION_WEBSOCKET_PORT "websocket_port"
|
||||
#define SECTION_VALIDATORS "validators"
|
||||
@@ -124,6 +126,7 @@ void Config::setup(const std::string& strConf)
|
||||
PEER_PORT = SYSTEM_PEER_PORT;
|
||||
RPC_PORT = 5001;
|
||||
WEBSOCKET_PORT = SYSTEM_WEBSOCKET_PORT;
|
||||
WEBSOCKET_PUBLIC_PORT = SYSTEM_WEBSOCKET_PUBLIC_PORT;
|
||||
NUMBER_CONNECTIONS = 30;
|
||||
|
||||
// a new ledger every minute
|
||||
@@ -235,6 +238,11 @@ void Config::load()
|
||||
if (sectionSingleB(secConfig, SECTION_WEBSOCKET_PORT, strTemp))
|
||||
WEBSOCKET_PORT = boost::lexical_cast<int>(strTemp);
|
||||
|
||||
(void) sectionSingleB(secConfig, SECTION_WEBSOCKET_PUBLIC_IP, WEBSOCKET_PUBLIC_IP);
|
||||
|
||||
if (sectionSingleB(secConfig, SECTION_WEBSOCKET_PUBLIC_PORT, strTemp))
|
||||
WEBSOCKET_PUBLIC_PORT = boost::lexical_cast<int>(strTemp);
|
||||
|
||||
if (sectionSingleB(secConfig, SECTION_VALIDATION_SEED, strTemp))
|
||||
{
|
||||
VALIDATION_SEED.setSeedGeneric(strTemp);
|
||||
|
||||
@@ -24,8 +24,9 @@
|
||||
#define DEFAULT_VALIDATORS_SITE "redstem.com"
|
||||
#define VALIDATORS_FILE_NAME "validators.txt"
|
||||
|
||||
const int SYSTEM_PEER_PORT = 6561;
|
||||
const int SYSTEM_WEBSOCKET_PORT = 6562;
|
||||
const int SYSTEM_PEER_PORT = 6561;
|
||||
const int SYSTEM_WEBSOCKET_PORT = 6562;
|
||||
const int SYSTEM_WEBSOCKET_PUBLIC_PORT = 6563; // XXX Going away.
|
||||
|
||||
// Allow anonymous DH.
|
||||
#define DEFAULT_PEER_SSL_CIPHER_LIST "ALL:!LOW:!EXP:!MD5:@STRENGTH"
|
||||
@@ -82,6 +83,9 @@ public:
|
||||
unsigned int PEER_CONNECT_LOW_WATER;
|
||||
|
||||
// Websocket networking parameters
|
||||
std::string WEBSOCKET_PUBLIC_IP; // XXX Going away. Merge with the inbound peer connction.
|
||||
int WEBSOCKET_PUBLIC_PORT;
|
||||
|
||||
std::string WEBSOCKET_IP;
|
||||
int WEBSOCKET_PORT;
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ void WSConnection::doSubscribe(Json::Value& jvResult, Json::Value& jvRequest)
|
||||
mNetwork.subServer(this);
|
||||
}else if(streamName=="ledger")
|
||||
{
|
||||
mNetwork.subLedger(this);
|
||||
mNetwork.subLedger(this, jvResult);
|
||||
}else if(streamName=="transactions")
|
||||
{
|
||||
mNetwork.subTransactions(this);
|
||||
@@ -276,13 +276,14 @@ void WSConnection::doUnsubscribe(Json::Value& jvResult, Json::Value& jvRequest)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void WSConnection::doRPC(Json::Value& jvResult, Json::Value& jvRequest)
|
||||
{
|
||||
if (jvRequest.isMember("rpc_command") )
|
||||
{
|
||||
jvResult=theApp->getRPCHandler().doCommand(jvRequest["rpc_command"].asString(),jvRequest["params"],RPCHandler::GUEST);
|
||||
jvResult=theApp->getRPCHandler().doCommand(
|
||||
jvRequest["rpc_command"].asString(),
|
||||
jvRequest["params"],
|
||||
mHandler->getPublic() ? RPCHandler::GUEST : RPCHandler::ADMIN);
|
||||
|
||||
}else jvResult["error"] = "fieldNotCommand";
|
||||
|
||||
@@ -304,4 +305,5 @@ void WSConnection::doSubmit(Json::Value& jvResult, Json::Value& jvRequest)
|
||||
// TODO: track the transaction mNetwork.subSubmit(this, jvResult["tx hash"] );
|
||||
}
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -52,4 +52,6 @@ public:
|
||||
void doSubscribe(Json::Value& jvResult, Json::Value& jvRequest);
|
||||
void doUnsubscribe(Json::Value& jvResult, Json::Value& jvRequest);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -40,10 +40,6 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength)
|
||||
return 512 == iKeyLength ? theApp->getWallet().getDh512() : theApp->getWallet().getDh1024();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void WSDoor::startListening()
|
||||
{
|
||||
// Generate a single SSL context for use by all connections.
|
||||
@@ -58,7 +54,7 @@ void WSDoor::startListening()
|
||||
SSL_CTX_set_tmp_dh_callback(mCtx->native_handle(), handleTmpDh);
|
||||
|
||||
// Construct a single handler for all requests.
|
||||
websocketpp::WSDOOR_SERVER::handler::ptr handler(new WSServerHandler<websocketpp::WSDOOR_SERVER>(mCtx));
|
||||
websocketpp::WSDOOR_SERVER::handler::ptr handler(new WSServerHandler<websocketpp::WSDOOR_SERVER>(mCtx, mPublic));
|
||||
|
||||
// Construct a websocket server.
|
||||
mEndpoint = new websocketpp::WSDOOR_SERVER(handler);
|
||||
@@ -69,25 +65,22 @@ void WSDoor::startListening()
|
||||
// Call the main-event-loop of the websocket server.
|
||||
mEndpoint->listen(
|
||||
boost::asio::ip::tcp::endpoint(
|
||||
boost::asio::ip::address().from_string(theConfig.WEBSOCKET_IP), theConfig.WEBSOCKET_PORT));
|
||||
boost::asio::ip::address().from_string(mIp), mPort));
|
||||
|
||||
delete mEndpoint;
|
||||
}
|
||||
|
||||
WSDoor* WSDoor::createWSDoor()
|
||||
WSDoor* WSDoor::createWSDoor(const std::string& strIp, const int iPort, bool bPublic)
|
||||
{
|
||||
WSDoor* wdpResult = new WSDoor();
|
||||
WSDoor* wdpResult = new WSDoor(strIp, iPort, bPublic);
|
||||
|
||||
if (!theConfig.WEBSOCKET_IP.empty() && theConfig.WEBSOCKET_PORT)
|
||||
{
|
||||
Log(lsINFO) << "Websocket: Listening: " << theConfig.WEBSOCKET_IP << " " << theConfig.WEBSOCKET_PORT;
|
||||
cLog(lsINFO) <<
|
||||
boost::str(boost::format("Websocket: %s: Listening: %s %d ")
|
||||
% (bPublic ? "Public" : "Private")
|
||||
% strIp
|
||||
% iPort);
|
||||
|
||||
wdpResult->mThread = new boost::thread(boost::bind(&WSDoor::startListening, wdpResult));
|
||||
}
|
||||
else
|
||||
{
|
||||
Log(lsINFO) << "Websocket: Disabled";
|
||||
}
|
||||
wdpResult->mThread = new boost::thread(boost::bind(&WSDoor::startListening, wdpResult));
|
||||
|
||||
return wdpResult;
|
||||
}
|
||||
|
||||
@@ -21,16 +21,19 @@ class WSDoor
|
||||
private:
|
||||
websocketpp::WSDOOR_SERVER* mEndpoint;
|
||||
boost::thread* mThread;
|
||||
bool mPublic;
|
||||
std::string mIp;
|
||||
int mPort;
|
||||
|
||||
void startListening();
|
||||
|
||||
public:
|
||||
|
||||
WSDoor() : mEndpoint(0), mThread(0) { ; }
|
||||
WSDoor(const std::string& strIp, int iPort, bool bPublic) : mEndpoint(0), mThread(0), mPublic(bPublic), mIp(strIp), mPort(iPort) { ; }
|
||||
|
||||
void stop();
|
||||
|
||||
static WSDoor* createWSDoor();
|
||||
static WSDoor* createWSDoor(const std::string& strIp, const int iPort, bool bPublic);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -18,15 +18,18 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
boost::shared_ptr<boost::asio::ssl::context> mCtx;
|
||||
boost::shared_ptr<boost::asio::ssl::context> mCtx;
|
||||
|
||||
protected:
|
||||
boost::mutex mMapLock;
|
||||
boost::mutex mMapLock;
|
||||
// For each connection maintain an associated object to track subscriptions.
|
||||
boost::unordered_map<connection_ptr, boost::shared_ptr<WSConnection> > mMap;
|
||||
bool mPublic;
|
||||
|
||||
public:
|
||||
WSServerHandler(boost::shared_ptr<boost::asio::ssl::context> spCtx) : mCtx(spCtx) {}
|
||||
WSServerHandler(boost::shared_ptr<boost::asio::ssl::context> spCtx, bool bPublic) : mCtx(spCtx), mPublic(bPublic) {}
|
||||
|
||||
bool getPublic() { return mPublic; };
|
||||
|
||||
boost::shared_ptr<boost::asio::ssl::context> on_tls_init()
|
||||
{
|
||||
@@ -122,3 +125,5 @@ public:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
Reference in New Issue
Block a user