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
43a7d5b1
Unverified
Commit
43a7d5b1
authored
Jan 15, 2021
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug/SKALE-3662 Adding libzmq
parent
83888e7d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
17 deletions
+53
-17
ECDSASignReqMessage.cpp
ECDSASignReqMessage.cpp
+3
-3
ServerWorker.cpp
ServerWorker.cpp
+28
-11
ZMQClient.cpp
ZMQClient.cpp
+16
-2
ZMQClient.h
ZMQClient.h
+5
-0
ZMQServer.h
ZMQServer.h
+1
-1
No files found.
ECDSASignReqMessage.cpp
View file @
43a7d5b1
...
...
@@ -29,9 +29,9 @@
Json
::
Value
ECDSASignReqMessage
::
process
()
{
auto
base
=
getUint64Rapid
(
"b
s
"
);
auto
keyName
=
getStringRapid
(
"k
n
"
);
auto
hash
=
getStringRapid
(
"mh"
);
auto
base
=
getUint64Rapid
(
"b
ase
"
);
auto
keyName
=
getStringRapid
(
"k
eyName
"
);
auto
hash
=
getStringRapid
(
"m
essageHas
h"
);
auto
result
=
SGXWalletServer
::
ecdsaSignMessageHashImpl
(
base
,
keyName
,
hash
);
result
[
"type"
]
=
ZMQMessage
::
ECDSA_SIGN_RSP
;
return
result
;
...
...
ServerWorker.cpp
View file @
43a7d5b1
...
...
@@ -30,36 +30,47 @@ void ServerWorker::work() {
result
[
"status"
]
=
errStatus
;
result
[
"errorMessage"
]
=
"Server error"
;
zmq
::
message_t
identity
;
zmq
::
message_t
identit2
;
zmq
::
message_t
copied_id
;
try
{
zmq
::
message_t
msg
;
zmq
::
message_t
copied_msg
;
worker_
.
recv
(
&
identity
);
cerr
<<
identity
.
size
();
copied_id
.
copy
(
&
identity
);
worker_
.
recv
(
&
msg
);
int64_t
more
;
size_t
more_size
=
sizeof
(
more
);
auto
rc
=
zmq_getsockopt
(
worker_
,
ZMQ_RCVMORE
,
&
more
,
&
more_size
);
CHECK_STATE
(
rc
==
0
);
vector
<
uint8_t
>
msgData
(
msg
.
size
()
+
1
,
0
);
memcpy
(
msgData
.
data
(),
msg
.
data
(),
msg
.
size
());
if
(
msg
.
size
()
<
5
||
msgData
.
at
(
0
)
!=
'{'
||
msgData
[
msg
.
size
()]
!=
'}'
)
{
cerr
<<
"haha"
;
continue
;
}
cerr
<<
"Received:"
<<
msgData
.
data
();
auto
parsedMsg
=
ZMQMessage
::
parse
(
(
const
char
*
)
msgData
.
data
(),
msg
.
size
(),
true
);
CHECK_STATE
(
parsedMsg
);
result
=
parsedMsg
->
process
(
);
CHECK_STATE
(
msg
.
size
()
>
5
||
msgData
.
at
(
0
)
==
'{'
||
msgData
[
msg
.
size
()]
==
'}'
);
memcpy
(
msgData
.
data
(),
msg
.
data
(),
msg
.
size
());
auto
parsedMsg
=
ZMQMessage
::
parse
(
(
const
char
*
)
msgData
.
data
(),
msg
.
size
(),
true
);
}
CHECK_STATE
(
parsedMsg
);
result
=
parsedMsg
->
process
();
catch
(
SGXException
&
e
)
{
}
catch
(
SGXException
&
e
)
{
result
[
"status"
]
=
e
.
getStatus
();
result
[
"errorMessage"
]
=
e
.
getMessage
();
spdlog
::
error
(
"Exception in zmq server worker:{}"
,
e
.
what
());
...
...
@@ -83,7 +94,13 @@ void ServerWorker::work() {
CHECK_STATE
(
replyStr
.
front
()
==
'{'
);
CHECK_STATE
(
replyStr
.
back
()
==
'}'
);
zmq
::
message_t
replyMsg
(
replyStr
.
c_str
(),
replyStr
.
size
()
+
1
);
cerr
<<
"sending!!!"
;
worker_
.
send
(
copied_id
,
ZMQ_SNDMORE
);
worker_
.
send
(
replyMsg
);
cerr
<<
"sent!!!"
;
}
catch
(
std
::
exception
&
e
)
{
spdlog
::
error
(
"Exception in zmq server worker send :{}"
,
e
.
what
());
}
catch
(...)
{
...
...
ZMQClient.cpp
View file @
43a7d5b1
...
...
@@ -20,6 +20,9 @@
@author Stan Kladko
@date 2020
*/
#include "sys/random.h"
#include "common.h"
#include "BLSSignReqMessage.h"
#include "BLSSignRspMessage.h"
...
...
@@ -51,7 +54,6 @@ string ZMQClient::doZmqRequestReply(string &_req) {
CHECK_STATE
(
clientSocket
);
cerr
<<
"Sending:"
<<
_req
;
sleep
(
1
);
s_send
(
*
clientSocket
,
_req
);
...
...
@@ -63,6 +65,11 @@ string ZMQClient::doZmqRequestReply(string &_req) {
// If we got a reply, process it
if
(
items
[
0
].
revents
&
ZMQ_POLLIN
)
{
string
reply
=
s_recv
(
*
clientSocket
);
cerr
<<
"Received!"
+
reply
;
sleep
(
1000
);
return
reply
;
}
else
{
spdlog
::
error
(
"W: no response from server, retrying..."
);
...
...
@@ -79,12 +86,19 @@ ZMQClient::ZMQClient(string &ip, uint16_t port) : ctx(1) {
}
void
ZMQClient
::
reconnect
()
{
getrandom
(
identity
,
10
,
0
);
clientSocket
=
nullptr
;
// delete previous
clientSocket
=
make_unique
<
zmq
::
socket_t
>
(
ctx
,
ZMQ_DEALER
);
clientSocket
->
connect
(
url
);
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
);
}
...
...
ZMQClient.h
View file @
43a7d5b1
...
...
@@ -35,6 +35,8 @@
#include "ZMQMessage.h"
#define REQUEST_TIMEOUT 10000 // msecs, (> 1000!)
class
ZMQClient
{
...
...
@@ -46,6 +48,9 @@ private:
std
::
unique_ptr
<
zmq
::
socket_t
>
clientSocket
;
string
url
;
// generate random identity
char
identity
[
10
]
=
{};
shared_ptr
<
ZMQMessage
>
doRequestReply
(
Json
::
Value
&
_req
);
string
doZmqRequestReply
(
string
&
_req
);
...
...
ZMQServer.h
View file @
43a7d5b1
...
...
@@ -49,7 +49,7 @@ public:
atomic
<
bool
>
isExitRequested
;
enum
{
kMaxThread
=
5
kMaxThread
=
1
};
void
run
();
...
...
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