Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sgxwallet
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董子豪
sgxwallet
Commits
2d186486
Unverified
Commit
2d186486
authored
Jan 18, 2021
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug/SKALE-3751-enable-zeromq
parent
6545d811
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
100 additions
and
59 deletions
+100
-59
ZMQClient.cpp
ZMQClient.cpp
+32
-6
ZMQClient.h
ZMQClient.h
+9
-3
ZMQServer.h
ZMQServer.h
+1
-1
testw.cpp
testw.cpp
+58
-49
No files found.
ZMQClient.cpp
View file @
2d186486
...
...
@@ -22,6 +22,9 @@
*/
#include "sys/random.h"
#include <sys/types.h>
#include <sys/syscall.h>
#include "common.h"
#include "BLSSignReqMessage.h"
...
...
@@ -62,14 +65,25 @@ shared_ptr <ZMQMessage> ZMQClient::doRequestReply(Json::Value &_req) {
throw
;
}
}
string
ZMQClient
::
doZmqRequestReply
(
string
&
_req
)
{
stringstream
request
;
if
(
!
clientSocket
)
reconnect
();
shared_ptr
<
zmq
::
socket_t
>
clientSocket
=
nullptr
;
{
lock_guard
<
recursive_mutex
>
m
(
mutex
);
if
(
!
clientSockets
.
count
(
getProcessID
()))
reconnect
();
clientSocket
=
clientSockets
.
at
(
getProcessID
());
CHECK_STATE
(
clientSocket
);
}
CHECK_STATE
(
clientSocket
);
spdlog
::
debug
(
"ZMQ client sending:
\n
{}"
,
_req
);
...
...
@@ -108,18 +122,24 @@ ZMQClient::ZMQClient(string &ip, uint16_t port) : ctx(1) {
void
ZMQClient
::
reconnect
()
{
getrandom
(
identity
,
10
,
0
);
lock_guard
<
recursive_mutex
>
lock
(
mutex
);
auto
pid
=
getProcessID
();
if
(
clientSockets
.
count
(
pid
)
>
0
)
{
clientSockets
.
erase
(
pid
);
}
clientSocket
=
nullptr
;
// delete previous
clientSocket
=
make_unique
<
zmq
::
socket_t
>
(
ctx
,
ZMQ_DEALER
);
char
identity
[
10
];
getrandom
(
identity
,
10
,
0
);
auto
clientSocket
=
make_shared
<
zmq
::
socket_t
>
(
ctx
,
ZMQ_DEALER
);
clientSocket
->
setsockopt
(
ZMQ_IDENTITY
,
identity
,
10
);
// Configure socket to not wait at close time
int
linger
=
0
;
clientSocket
->
setsockopt
(
ZMQ_LINGER
,
&
linger
,
sizeof
(
linger
));
clientSocket
->
connect
(
url
);
clientSockets
.
insert
({
pid
,
clientSocket
});
}
...
...
@@ -147,4 +167,10 @@ string ZMQClient::ecdsaSignMessageHash(int base, const std::string &keyName, con
CHECK_STATE
(
result
);
CHECK_STATE
(
result
->
getStatus
()
==
0
);
return
result
->
getSignature
();
}
uint64_t
ZMQClient
::
getProcessID
()
{
return
syscall
(
__NR_gettid
);
}
\ No newline at end of file
ZMQClient.h
View file @
2d186486
...
...
@@ -44,23 +44,29 @@ class ZMQClient {
private
:
recursive_mutex
mutex
;
zmq
::
context_t
ctx
;
std
::
unique_ptr
<
zmq
::
socket_t
>
clientSocket
;
string
url
;
// generate random identity
char
identity
[
10
]
=
{};
map
<
uint64_t
,
shared_ptr
<
zmq
::
socket_t
>>
clientSockets
;
shared_ptr
<
ZMQMessage
>
doRequestReply
(
Json
::
Value
&
_req
);
string
doZmqRequestReply
(
string
&
_req
);
uint64_t
getProcessID
();
public
:
ZMQClient
(
string
&
ip
,
uint16_t
port
);
void
reconnect
()
;
string
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
t
,
int
n
);
...
...
ZMQServer.h
View file @
2d186486
...
...
@@ -47,7 +47,7 @@ public:
ZMQServer
();
enum
{
kMaxThread
=
1
6
kMaxThread
=
1
};
void
run
();
...
...
testw.cpp
View file @
2d186486
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment