Unverified Commit 3a73a043 authored by kladko's avatar kladko

bug/SKALE-3751-enable-zeromq

parent dbf340bd
......@@ -173,7 +173,6 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
exit(-12);
}
httpServer = make_shared<HttpServer>(BASE_PORT, certPath, keyPath, rootCAPath, _checkCerts,
NUM_THREADS);
......
......@@ -116,7 +116,21 @@ string ZMQClient::doZmqRequestReply(string &_req) {
}
ZMQClient::ZMQClient(string &ip, uint16_t port) : ctx(1) {
ZMQClient::ZMQClient(const string &ip, uint16_t port, bool _sign, const string& _certFileName,
const string& _certKeyName) : ctx(1) {
if (_sign) {
CHECK_STATE(!_certFileName.empty());
CHECK_STATE(!_certKeyName.empty());
} else {
CHECK_STATE(_certFileName.empty());
CHECK_STATE(_certKeyName.empty());
}
certFileName = _certFileName;
certKeyName = _certKeyName;
url = "tcp://" + ip + ":" + to_string(port);
}
......
......@@ -45,6 +45,9 @@ class ZMQClient {
private:
bool sign;
string certFileName;
string certKeyName;
recursive_mutex mutex;
......@@ -66,7 +69,9 @@ private:
public:
ZMQClient(string &ip, uint16_t port);
ZMQClient(const string &ip, uint16_t port, bool _sign, const string& _certPathName,
const string& _certKeyName);
void reconnect() ;
string blsSignMessageHash(const std::string &keyShareName, const std::string &messageHash, int t, int n);
......
......@@ -34,11 +34,15 @@ using namespace std;
ZMQServer *ZMQServer::zmqServer = nullptr;
ZMQServer::ZMQServer()
: isExitRequested(false), ctx_(make_shared<zmq::context_t>(1)),
ZMQServer::ZMQServer(bool _checkSignature, const string& _caCertFile)
: checkSignature(_checkSignature),
caCertFile(_caCertFile), isExitRequested(false), ctx_(make_shared<zmq::context_t>(1)),
frontend_(*ctx_, ZMQ_ROUTER),
backend_(*ctx_, ZMQ_DEALER) {
if (_checkSignature) {
CHECK_STATE(!_caCertFile.empty());
}
int linger = 0;
zmq_setsockopt (frontend_, ZMQ_LINGER, &linger, sizeof (linger));
......@@ -151,23 +155,26 @@ void ZMQServer::exitZMQServer() {
zmqServer = nullptr;
}
void ZMQServer::initZMQServer(bool _useClientCert) {
void ZMQServer::initZMQServer(bool _checkSignature) {
static bool initedServer = false;
CHECK_STATE(!initedServer)
initedServer = true;
spdlog::info("Initing zmq server ...");
zmqServer = new ZMQServer();
serverThread =make_shared<thread> (std::bind(&ZMQServer::run, ZMQServer::zmqServer));
string rootCAPath = "";
serverThread->detach();
if (_useClientCert) {
if (_checkSignature) {
string rootCAPath = string(SGXDATA_FOLDER) + "cert_data/rootCA.pem";
CHECK_STATE(access(rootCAPath.c_str(), F_OK) == 0);
};
zmqServer = new ZMQServer(_checkSignature, rootCAPath);
serverThread =make_shared<thread> (std::bind(&ZMQServer::run, ZMQServer::zmqServer));
serverThread->detach();
spdlog::info("Inited zmq server ...");
}
......
......@@ -44,11 +44,14 @@ using namespace std;
class ZMQServer {
public:
bool checkSignature = false;
string caCertFile = "";
static ZMQServer *zmqServer;
static shared_ptr<std::thread> serverThread;
ZMQServer();
ZMQServer(bool _checkSignature, const string& _caCertFile);
enum {
kMaxThread = 1
......@@ -58,7 +61,7 @@ public:
void exitWorkers();
static void initZMQServer(bool _useClientCert);
static void initZMQServer(bool _checkSignature);
static void exitZMQServer();
......
......@@ -492,7 +492,9 @@ TEST_CASE_METHOD(TestFixture, "DKG_BLS ZMQ test", "[dkgblszmq]") {
StubClient c(client, JSONRPC_CLIENT_V2);
string ip = ZMQ_IP;
auto zmqClient = make_shared<ZMQClient>(ip, ZMQ_PORT);
string empty = "";
auto zmqClient = make_shared<ZMQClient>(ip, ZMQ_PORT, false, empty, empty);
vector <string> ecdsaKeyNames;
vector <string> blsKeyNames;
......@@ -935,7 +937,7 @@ TEST_CASE_METHOD(TestFixture, "ZMQ-ecdsa", "[zmq-ecdsa]") {
string ip = ZMQ_IP;
auto client = make_shared<ZMQClient>(ip, ZMQ_PORT);
auto client = make_shared<ZMQClient>(ip, ZMQ_PORT, false, "", "");
string keyName = "";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment