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
e4afc8fa
Unverified
Commit
e4afc8fa
authored
Dec 15, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
q
parent
5c3e16c7
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
145 additions
and
26 deletions
+145
-26
Makefile.am
Makefile.am
+3
-3
ServerInit.cpp
ServerInit.cpp
+15
-1
ServerInit.h
ServerInit.h
+2
-0
ServerWorker.cpp
ServerWorker.cpp
+11
-15
ServerWorker.h
ServerWorker.h
+2
-0
VERSION
VERSION
+1
-1
ZMQServer.cpp
ZMQServer.cpp
+92
-0
ZMQServer.h
ZMQServer.h
+11
-6
sgxwall.cpp
sgxwall.cpp
+5
-0
testw.cpp
testw.cpp
+3
-0
No files found.
Makefile.am
View file @
e4afc8fa
...
@@ -66,7 +66,7 @@ bin_PROGRAMS = sgxwallet testw cert_util
...
@@ -66,7 +66,7 @@ bin_PROGRAMS = sgxwallet testw cert_util
## have to be explicitly listed.
## have to be explicitly listed.
## have to be explicitly listed
## have to be explicitly listed
COMMON_SRC
=
InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp
\
COMMON_SRC
=
ZMQServer.cpp ServerWorker.cpp
InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp
\
SGXWalletServer.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp BLSCrypto.cpp
\
SGXWalletServer.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp BLSCrypto.cpp
\
ECDSACrypto.cpp
\
ECDSACrypto.cpp
\
DKGCrypto.cpp ServerInit.cpp BLSPrivateKeyShareSGX.cpp LevelDB.cpp ServerDataChecker.cpp SEKManager.cpp
\
DKGCrypto.cpp ServerInit.cpp BLSPrivateKeyShareSGX.cpp LevelDB.cpp ServerDataChecker.cpp SEKManager.cpp
\
...
@@ -113,8 +113,8 @@ nodist_testw_SOURCES=${nodist_sgxwallet_SOURCES}
...
@@ -113,8 +113,8 @@ nodist_testw_SOURCES=${nodist_sgxwallet_SOURCES}
EXTRA_testw_DEPENDENCIES
=
${
EXTRA_sgxwallet_DEPENDENCIES
}
EXTRA_testw_DEPENDENCIES
=
${
EXTRA_sgxwallet_DEPENDENCIES
}
testw_LDADD
=
${
sgxwallet_LDADD
}
testw_LDADD
=
${
sgxwallet_LDADD
}
cert_util_SOURCES
=
InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp cert_util.cpp stubclient.cpp LevelDB.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp
\
cert_util_SOURCES
=
InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp cert_util.cpp stubclient.cpp LevelDB.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp
ServerTask.cpp ServerWorker.cpp
cert_util_LDADD
=
-LlibBLS
/deps/deps_inst/x86_or_x64/lib
-Lleveldb
/build
-LlibBLS
/build
\
cert_util_LDADD
=
-LlibBLS
/deps/deps_inst/x86_or_x64/lib
-Lleveldb
/build
-LlibBLS
/build
\
-LlibBLS
/build/libff/libff
\
-LlibBLS
/build/libff/libff
\
-Llibzmq
/build/lib/
\
-Llibzmq
/build/lib/
\
...
...
ServerInit.cpp
View file @
e4afc8fa
...
@@ -57,6 +57,7 @@
...
@@ -57,6 +57,7 @@
#include "BLSCrypto.h"
#include "BLSCrypto.h"
#include "ServerInit.h"
#include "ServerInit.h"
#include "SGXException.h"
#include "SGXException.h"
#include "ZMQServer.h"
#include "SGXWalletServer.hpp"
#include "SGXWalletServer.hpp"
uint32_t
enclaveLogLevel
=
0
;
uint32_t
enclaveLogLevel
=
0
;
...
@@ -106,6 +107,9 @@ void systemHealthCheck() {
...
@@ -106,6 +107,9 @@ void systemHealthCheck() {
}
}
}
}
static
ZMQServer
*
zmqServer
=
nullptr
;
atomic
<
bool
>
exiting
(
false
);
void
initUserSpace
()
{
void
initUserSpace
()
{
libff
::
inhibit_profiling_counters
=
true
;
libff
::
inhibit_profiling_counters
=
true
;
...
@@ -118,6 +122,17 @@ void initUserSpace() {
...
@@ -118,6 +122,17 @@ void initUserSpace() {
systemHealthCheck
();
systemHealthCheck
();
#endif
#endif
zmqServer
=
new
ZMQServer
();
static
std
::
thread
serverThread
(
std
::
bind
(
&
ZMQServer
::
run
,
zmqServer
));
}
void
exitZMQServer
()
{
auto
doExit
=
!
exiting
.
exchange
(
true
);
if
(
doExit
)
{
delete
zmqServer
;
zmqServer
=
nullptr
;
}
}
}
...
@@ -180,7 +195,6 @@ uint64_t initEnclave() {
...
@@ -180,7 +195,6 @@ uint64_t initEnclave() {
void
initAll
(
uint32_t
_logLevel
,
bool
_checkCert
,
bool
_autoSign
)
{
void
initAll
(
uint32_t
_logLevel
,
bool
_checkCert
,
bool
_autoSign
)
{
static
atomic
<
bool
>
sgxServerInited
(
false
);
static
atomic
<
bool
>
sgxServerInited
(
false
);
...
...
ServerInit.h
View file @
e4afc8fa
...
@@ -38,6 +38,8 @@ EXTERNC void initUserSpace();
...
@@ -38,6 +38,8 @@ EXTERNC void initUserSpace();
EXTERNC
uint64_t
initEnclave
();
EXTERNC
uint64_t
initEnclave
();
EXTERNC
void
exitZMQServer
();
#endif //SGXWALLET_SERVERINIT_H
#endif //SGXWALLET_SERVERINIT_H
ServerWorker.cpp
View file @
e4afc8fa
...
@@ -6,31 +6,27 @@
...
@@ -6,31 +6,27 @@
ServerWorker
::
ServerWorker
(
zmq
::
context_t
&
ctx
,
int
sock_type
)
:
ctx_
(
ctx
),
ServerWorker
::
ServerWorker
(
zmq
::
context_t
&
ctx
,
int
sock_type
)
:
ctx_
(
ctx
),
worker_
(
ctx_
,
sock_type
){};
worker_
(
ctx_
,
sock_type
)
{};
void
ServerWorker
::
work
()
{
void
ServerWorker
::
work
()
{
worker_
.
connect
(
"inproc://backend"
);
worker_
.
connect
(
"inproc://backend"
);
try
{
try
{
while
(
true
)
{
while
(
true
)
{
zmq
::
message_t
identity
;
zmq
::
message_t
msg
;
zmq
::
message_t
msg
;
zmq
::
message_t
copied_id
;
zmq
::
message_t
copied_msg
;
zmq
::
message_t
copied_msg
;
worker_
.
recv
(
&
identity
);
worker_
.
recv
(
&
msg
);
worker_
.
recv
(
&
msg
);
copied_msg
.
copy
(
&
msg
);
int
replies
=
within
(
5
);
worker_
.
send
(
copied_msg
);
for
(
int
reply
=
0
;
reply
<
replies
;
++
reply
)
{
s_sleep
(
within
(
1000
)
+
1
);
copied_id
.
copy
(
&
identity
);
copied_msg
.
copy
(
&
msg
);
worker_
.
send
(
copied_id
,
ZMQ_SNDMORE
);
worker_
.
send
(
copied_msg
);
}
}
}
}
}
catch
(
std
::
exception
&
e
)
{}
catch
(
std
::
exception
&
e
)
{
spdlog
::
info
(
"Exiting zmq server worker:{}"
,
e
.
what
());
return
;
}
catch
(...)
{
spdlog
::
error
(
"Error in zmq server worker"
);
return
;
}
}
}
ServerWorker.h
View file @
e4afc8fa
...
@@ -13,6 +13,8 @@
...
@@ -13,6 +13,8 @@
#include <zmq.hpp>
#include <zmq.hpp>
#include "zhelpers.hpp"
#include "zhelpers.hpp"
#include "third_party/spdlog/spdlog.h"
class
ServerWorker
{
class
ServerWorker
{
...
...
VERSION
View file @
e4afc8fa
1.64.2
1.65.1
\ No newline at end of file
\ No newline at end of file
ServerTask
.cpp
→
ZMQServer
.cpp
View file @
e4afc8fa
...
@@ -16,49 +16,77 @@
...
@@ -16,49 +16,77 @@
You should have received a copy of the GNU Affero General Public License
You should have received a copy of the GNU Affero General Public License
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file
ServerTask
.cpp
@file
ZMQServer
.cpp
@author Stan Kladko
@author Stan Kladko
@date 2019
@date 2019
*/
*/
#include "third_party/spdlog/spdlog.h"
#include "ServerWorker.h"
#include "ServerWorker.h"
#include "
ServerTask
.h"
#include "
ZMQServer
.h"
#include "sgxwallet_common.h"
#include "sgxwallet_common.h"
using
namespace
std
;
using
namespace
std
;
ServerTask
::
ServerTask
()
ZMQServer
::
ZMQServer
()
:
ctx_
(
1
),
:
isExitRequested
(
false
),
ctx_
(
1
),
frontend_
(
ctx_
,
ZMQ_ROUTER
),
frontend_
(
ctx_
,
ZMQ_ROUTER
),
backend_
(
ctx_
,
ZMQ_DEALER
)
{}
backend_
(
ctx_
,
ZMQ_DEALER
)
{}
void
ServerTask
::
run
()
{
void
ZMQServer
::
run
()
{
frontend_
.
bind
(
"tcp://*:"
+
to_string
(
BASE_PORT
+
4
))
;
backend_
.
bind
(
"inproc://backend"
);
auto
port
=
BASE_PORT
+
4
;
spdlog
::
info
(
"Starting zmq server ..."
);
try
{
frontend_
.
bind
(
"tcp://*:"
+
to_string
(
BASE_PORT
+
4
));
}
catch
(...)
{
spdlog
::
error
(
"Server task could not bind to port:{}"
,
port
);
exit
(
-
100
);
}
std
::
vector
<
ServerWorker
*
>
worker
;
spdlog
::
info
(
"Bound port ..."
);
std
::
vector
<
std
::
thread
*
>
worker_thread
;
for
(
int
i
=
0
;
i
<
kMaxThread
;
++
i
)
{
worker
.
push_back
(
new
ServerWorker
(
ctx_
,
ZMQ_DEALER
));
worker_thread
.
push_back
(
new
std
::
thread
(
std
::
bind
(
&
ServerWorker
::
work
,
worker
[
i
])));
try
{
worker_thread
[
i
]
->
detach
();
backend_
.
bind
(
"inproc://backend"
);
}
catch
(
exception
&
e
)
{
spdlog
::
error
(
"Could not bind to zmq backend: {}"
,
e
.
what
());
exit
(
-
101
);
}
}
static
std
::
vector
<
ServerWorker
*>
worker
;
static
std
::
vector
<
std
::
thread
*>
worker_thread
;
spdlog
::
info
(
"Creating {} zmq server workers ..."
,
kMaxThread
);
try
{
try
{
zmq
::
proxy
(
static_cast
<
void
*>
(
frontend_
),
for
(
int
i
=
0
;
i
<
kMaxThread
;
++
i
)
{
static_cast
<
void
*>
(
backend_
),
worker
.
push_back
(
new
ServerWorker
(
ctx_
,
ZMQ_DEALER
));
nullptr
);
worker_thread
.
push_back
(
new
std
::
thread
(
std
::
bind
(
&
ServerWorker
::
work
,
worker
[
i
])));
}
}
catch
(
std
::
exception
&
e
)
{
spdlog
::
error
(
"Could not create zmq server workers:{} "
,
e
.
what
());
exit
(
-
102
);
}
}
catch
(
std
::
exception
&
e
)
{}
for
(
int
i
=
0
;
i
<
kMaxThread
;
++
i
)
{
delete
worker
[
i
];
try
{
delete
worker_thread
[
i
];
zmq
::
proxy
(
static_cast
<
void
*>
(
frontend_
),
static_cast
<
void
*>
(
backend_
),
nullptr
);
}
catch
(
exception
&
_e
)
{
spdlog
::
info
(
"Exiting zmq server {}"
,
_e
.
what
());
return
;
}
catch
(...)
{
spdlog
::
info
(
"Exiting zmq server"
);
return
;
}
}
}
}
ServerTask
.h
→
ZMQServer
.h
View file @
e4afc8fa
...
@@ -16,29 +16,34 @@
...
@@ -16,29 +16,34 @@
You should have received a copy of the GNU Affero General Public License
You should have received a copy of the GNU Affero General Public License
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file
ServerTask
.h
@file
ZMQServer
.h
@author Stan Kladko
@author Stan Kladko
@date 2020
@date 2020
*/
*/
#ifndef SGXWALLET_
SERVERTASK
_H
#ifndef SGXWALLET_
ZMQServer
_H
#define SGXWALLET_
SERVERTASK
_H
#define SGXWALLET_
ZMQServer
_H
#include <vector>
#include <vector>
#include <thread>
#include <thread>
#include <memory>
#include <memory>
#include <functional>
#include <functional>
#include <atomic>
#include <zmq.hpp>
#include <zmq.hpp>
#include "zhelpers.hpp"
#include "zhelpers.hpp"
using
namespace
std
;
class
ServerTask
{
class
ZMQServer
{
public
:
public
:
ServerTask
();
ZMQServer
();
atomic
<
bool
>
isExitRequested
;
enum
{
enum
{
kMaxThread
=
5
kMaxThread
=
5
...
@@ -52,4 +57,4 @@ private:
...
@@ -52,4 +57,4 @@ private:
zmq
::
socket_t
backend_
;
zmq
::
socket_t
backend_
;
};
};
#endif //SGXWALLET_
SERVERTASK
_H
#endif //SGXWALLET_
ZMQServer
_H
sgxwall.cpp
View file @
e4afc8fa
...
@@ -34,10 +34,13 @@
...
@@ -34,10 +34,13 @@
#include "TestUtils.h"
#include "TestUtils.h"
#include "ZMQServer.h"
#include "testw.h"
#include "testw.h"
#include "sgxwall.h"
#include "sgxwall.h"
#include "sgxwallet.h"
#include "sgxwallet.h"
void
SGXWallet
::
usage
()
{
void
SGXWallet
::
usage
()
{
cerr
<<
"usage: sgxwallet
\n
"
;
cerr
<<
"usage: sgxwallet
\n
"
;
exit
(
-
21
);
exit
(
-
21
);
...
@@ -201,6 +204,8 @@ int main(int argc, char *argv[]) {
...
@@ -201,6 +204,8 @@ int main(int argc, char *argv[]) {
cerr
<<
"Successfully completed generating test keys into sgx_data"
<<
endl
;
cerr
<<
"Successfully completed generating test keys into sgx_data"
<<
endl
;
}
}
while
(
true
)
{
while
(
true
)
{
sleep
(
10
);
sleep
(
10
);
}
}
...
...
testw.cpp
View file @
e4afc8fa
...
@@ -89,6 +89,7 @@ public:
...
@@ -89,6 +89,7 @@ public:
}
}
~
TestFixtureHTTPS
()
{
~
TestFixtureHTTPS
()
{
exitZMQServer
();
TestUtils
::
destroyEnclave
();
TestUtils
::
destroyEnclave
();
}
}
};
};
...
@@ -101,6 +102,7 @@ public:
...
@@ -101,6 +102,7 @@ public:
}
}
~
TestFixtureNoResetFromBackup
()
{
~
TestFixtureNoResetFromBackup
()
{
exitZMQServer
();
TestUtils
::
destroyEnclave
();
TestUtils
::
destroyEnclave
();
}
}
};
};
...
@@ -114,6 +116,7 @@ public:
...
@@ -114,6 +116,7 @@ public:
}
}
~
TestFixtureNoReset
()
{
~
TestFixtureNoReset
()
{
exitZMQServer
();
TestUtils
::
destroyEnclave
();
TestUtils
::
destroyEnclave
();
}
}
};
};
...
...
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