Unverified Commit 5bf09563 authored by kladko's avatar kladko

bug/SKALE-3751-enable-zeromq

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