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
75894333
Unverified
Commit
75894333
authored
Apr 23, 2021
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-4131
parent
5fd70f78
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
40 deletions
+17
-40
ServerWorker.cpp
ServerWorker.cpp
+4
-23
ZMQClient.cpp
ZMQClient.cpp
+12
-14
ZMQServer.cpp
ZMQServer.cpp
+1
-1
common.h
common.h
+0
-2
No files found.
ServerWorker.cpp
View file @
75894333
...
...
@@ -82,30 +82,12 @@ void ServerWorker::doOneServerLoop() noexcept {
}
}
while
(
pollResult
==
0
);
zmq
::
message_t
msg
;
zmq
::
message_t
copied_msg
;
worker
->
recv
(
&
identity
);
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_STATE2
(
rc
==
0
,
ZMQ_COULD_NOT_GET_SOCKOPT
);
vector
<
uint8_t
>
msgData
(
msg
.
size
()
+
1
,
0
);
memcpy
(
msgData
.
data
(),
msg
.
data
(),
msg
.
size
());
CHECK_STATE2
(
msg
.
size
()
>
5
||
msgData
.
at
(
0
)
==
'{'
||
msgData
[
msg
.
size
()]
==
'}'
,
ZMQ_INVALID_MESSAGE
);
memcpy
(
msgData
.
data
(),
msg
.
data
(),
msg
.
size
());
string
stringToParse
=
s_recv
(
*
worker
);
auto
parsedMsg
=
ZMQMessage
::
parse
(
(
const
char
*
)
msgData
.
data
(),
msg
.
size
(),
true
,
checkSignature
);
stringToParse
.
c_str
(),
stringToParse
.
size
(),
true
,
checkSignature
);
CHECK_STATE2
(
parsedMsg
,
ZMQ_COULD_NOT_PARSE
);
...
...
@@ -133,17 +115,16 @@ void ServerWorker::doOneServerLoop() noexcept {
try
{
Json
::
FastWriter
fastWriter
;
fastWriter
.
omitEndingLineFeed
();
replyStr
=
fastWriter
.
write
(
result
);
replyStr
=
replyStr
.
substr
(
0
,
replyStr
.
size
()
-
1
);
CHECK_STATE
(
replyStr
.
size
()
>
2
);
CHECK_STATE
(
replyStr
.
front
()
==
'{'
);
CHECK_STATE
(
replyStr
.
back
()
==
'}'
);
zmq
::
message_t
replyMsg
(
replyStr
.
c_str
(),
replyStr
.
size
()
+
1
);
worker
->
send
(
copied_id
,
ZMQ_SNDMORE
);
worker
->
send
(
replyMsg
);
s_send
(
*
worker
,
replyStr
);
}
catch
(
std
::
exception
&
e
)
{
if
(
isExitRequested
)
{
...
...
ZMQClient.cpp
View file @
75894333
...
...
@@ -112,9 +112,7 @@ string ZMQClient::doZmqRequestReply(string &_req) {
// If we got a reply, process it
if
(
items
[
0
].
revents
&
ZMQ_POLLIN
)
{
string
reply
=
s_recv
(
*
clientSocket
);
CHECK_STATE
(
reply
.
size
()
>
5
);
reply
=
reply
.
substr
(
0
,
reply
.
size
()
-
1
);
spdlog
::
debug
(
"ZMQ client received reply:{}"
,
reply
);
CHECK_STATE
(
reply
.
front
()
==
'{'
);
CHECK_STATE
(
reply
.
back
()
==
'}'
);
...
...
@@ -285,28 +283,28 @@ ZMQClient::ZMQClient(const string &ip, uint16_t port, bool _sign, const string &
}
void
ZMQClient
::
reconnect
()
{
lock_guard
<
recursive_mutex
>
lock
(
mutex
);
lock_guard
<
recursive_mutex
>
lock
(
mutex
);
auto
pid
=
getProcessID
();
if
(
clientSockets
.
count
(
pid
)
>
0
)
{
clientSockets
.
erase
(
pid
);
if
(
clientSockets
.
count
(
pid
)
>
0
)
{
clientSockets
.
erase
(
pid
);
}
uint64_t
randNumber
;
CHECK_STATE
(
getrandom
(
&
randNumber
,
sizeof
(
uint64_t
),
0
)
==
sizeof
(
uint64_t
));
char
identity
[
10
]
;
getrandom
(
identity
,
10
,
0
);
auto
clientSocket
=
make_shared
<
zmq
::
socket_t
>
(
ctx
,
ZMQ_DEALER
);
clientSocket
->
setsockopt
(
ZMQ_IDENTITY
,
identity
,
10
);
string
identity
=
to_string
(
135
)
+
":"
+
to_string
(
randNumber
)
;
auto
clientSocket
=
make_shared
<
zmq
::
socket_t
>
(
ctx
,
ZMQ_DEALER
);
clientSocket
->
setsockopt
(
ZMQ_IDENTITY
,
identity
.
c_str
(),
identity
.
size
()
+
1
);
// 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
}
);
clientSocket
->
setsockopt
(
ZMQ_LINGER
,
&
linger
,
sizeof
(
linger
)
);
clientSocket
->
connect
(
url
);
clientSockets
.
insert
(
{
pid
,
clientSocket
}
);
}
string
ZMQClient
::
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
t
,
int
n
)
{
Json
::
Value
p
;
p
[
"type"
]
=
ZMQMessage
::
BLS_SIGN_REQ
;
...
...
ZMQServer.cpp
View file @
75894333
...
...
@@ -49,7 +49,7 @@ ZMQServer::ZMQServer(bool _checkSignature, const string &_caCertFile)
workerThreads
=
4
;
// do four threads
for now
workerThreads
=
1
;
// do one thread
for now
if
(
_checkSignature
)
{
CHECK_STATE
(
!
_caCertFile
.
empty
());
...
...
common.h
View file @
75894333
...
...
@@ -103,14 +103,12 @@ inline int getValue() { //Note: this value is in KB!
#define CHECK_STATE(_EXPRESSION_) \
if (!(_EXPRESSION_)) { \
auto __msg__ = std::string("State check failed::") + #_EXPRESSION_ + " " + std::string(__FILE__) + ":" + std::to_string(__LINE__); \
print_stack(__LINE__); \
\
BOOST_THROW_EXCEPTION(SGXException(-100, string(__CLASS_NAME__) + ":" + __msg__));}
#define CHECK_STATE2(_EXPRESSION_, __STATUS__) \
if (!(_EXPRESSION_)) { \
auto __msg__ = std::string("State check failed::") + #_EXPRESSION_ + " " + std::string(__FILE__) + ":" + std::to_string(__LINE__); \
print_stack(__LINE__); \
\
BOOST_THROW_EXCEPTION(SGXException(__STATUS__, string(__CLASS_NAME__) + ":" + __msg__));}
...
...
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