Unverified Commit 5bf09563 authored by kladko's avatar kladko

bug/SKALE-3751-enable-zeromq

parent b0d5ac3e
......@@ -15,9 +15,17 @@
std::atomic <uint64_t> ServerWorker::workerCount(1);
ServerWorker::ServerWorker(zmq::context_t &ctx, int sock_type) : ctx_(ctx),
ServerWorker::ServerWorker(zmq::context_t &ctx, int sock_type, bool _checkSignature,
const string& _caCert ) : checkSignature(_checkSignature),
caCert(_caCert),
ctx_(ctx),
worker_(ctx_, sock_type),
isExitRequested(false) {
if (checkSignature) {
CHECK_STATE(!caCert.empty())
}
index = workerCount.fetch_add(1);
int linger = 0;
zmq_setsockopt(worker_, ZMQ_LINGER, &linger, sizeof(linger));
......
......@@ -19,8 +19,11 @@
class ServerWorker {
bool checkSignature = true;
string caCert = "";
public:
ServerWorker(zmq::context_t &ctx, int sock_type );
ServerWorker(zmq::context_t &ctx, int sock_type, bool _checkSignature, const string& _caCert );
void work();
......
......@@ -25,6 +25,9 @@
#include <sys/types.h>
#include <sys/syscall.h>
#include <fstream>
#include <streambuf>
#include "common.h"
#include "BLSSignReqMessage.h"
......@@ -38,6 +41,10 @@ shared_ptr <ZMQMessage> ZMQClient::doRequestReply(Json::Value &_req) {
Json::FastWriter fastWriter;
string reqStr = fastWriter.write(_req);
//if (sign) {
_req["cert"] = certificate;
//}
reqStr = reqStr.substr(0, reqStr.size() - 1);
CHECK_STATE(reqStr.front() == '{');
CHECK_STATE(reqStr.at(reqStr.size() - 1) == '}');
......@@ -116,6 +123,13 @@ ZMQClient::ZMQClient(const string &ip, uint16_t port, bool _sign, const string &
if (_sign) {
CHECK_STATE(!_certFileName.empty());
CHECK_STATE(!_certKeyName.empty());
ifstream t(_certFileName);
string str((istreambuf_iterator<char>(t)), istreambuf_iterator<char>());
certificate = str;
CHECK_STATE(!certificate.empty());
} else {
CHECK_STATE(_certFileName.empty());
CHECK_STATE(_certKeyName.empty());
......
......@@ -46,8 +46,9 @@ private:
bool sign;
string certFileName;
string certKeyName;
string certFileName = "";
string certificate = "";
string certKeyName = "";
recursive_mutex mutex;
......
......@@ -21,6 +21,9 @@
@date 2019
*/
#include <fstream>
#include <streambuf>
#include "third_party/spdlog/spdlog.h"
......@@ -42,6 +45,10 @@ ZMQServer::ZMQServer(bool _checkSignature, const string& _caCertFile)
if (_checkSignature) {
CHECK_STATE(!_caCertFile.empty());
ifstream t(_caCertFile);
string str((istreambuf_iterator<char>(t)), istreambuf_iterator<char>());
caCert = str;
CHECK_STATE(!caCert.empty())
}
int linger = 0;
......@@ -78,7 +85,8 @@ void ZMQServer::run() {
try {
for (int i = 0; i < kMaxThread; ++i) {
workers.push_back(make_shared<ServerWorker>(*ctx_, ZMQ_DEALER));
workers.push_back(make_shared<ServerWorker>(*ctx_, ZMQ_DEALER,
this->checkSignature, this->caCert));
auto th = make_shared<std::thread>(std::bind(&ServerWorker::work, workers[i]));
th->detach();
worker_threads.push_back(th);
......
......@@ -46,6 +46,7 @@ public:
bool checkSignature = false;
string caCertFile = "";
string caCert = "";
static ZMQServer *zmqServer;
......
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