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
2bd3b05e
Unverified
Commit
2bd3b05e
authored
Dec 10, 2020
by
Oleh Nikolaiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-3023 add getLatestCreatedKey
parent
591d503b
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
50 additions
and
27 deletions
+50
-27
LevelDB.cpp
LevelDB.cpp
+25
-1
SGXInfoServer.cpp
SGXInfoServer.cpp
+1
-1
SGXInfoServer.h
SGXInfoServer.h
+1
-1
ServerInit.cpp
ServerInit.cpp
+1
-20
common.h
common.h
+18
-0
sgx_util.cpp
sgx_util.cpp
+2
-2
stubclient.h
stubclient.h
+2
-2
No files found.
LevelDB.cpp
View file @
2bd3b05e
...
...
@@ -181,7 +181,9 @@ stringstream LevelDB::getAllKeys() {
Json
::
Value
key_data
;
Json
::
Reader
reader
;
reader
.
parse
(
it
->
value
().
ToString
().
c_str
(),
key_data
);
value
=
" VALUE: "
+
key_data
[
"value"
].
asString
()
+
", TIMESTAMP: "
+
key_data
[
"timestamp"
].
asString
();
string
timestamp_to_date_command
=
"date -d @"
+
key_data
[
"timestamp"
].
asString
();
value
=
" VALUE: "
+
key_data
[
"value"
].
asString
()
+
", TIMESTAMP: "
+
exec
(
timestamp_to_date_command
.
c_str
());
}
else
{
// old style keys
value
=
" VALUE: "
+
it
->
value
().
ToString
();
...
...
@@ -194,7 +196,29 @@ stringstream LevelDB::getAllKeys() {
}
pair
<
string
,
uint64_t
>
LevelDB
::
getLatestCreatedKey
()
{
leveldb
::
Iterator
*
it
=
db
->
NewIterator
(
readOptions
);
uint64_t
latest_timestamp
=
0
;
string
latest_created_key_name
=
""
;
for
(
it
->
SeekToFirst
();
it
->
Valid
();
it
->
Next
())
{
if
(
it
->
value
().
ToString
()[
0
]
==
'{'
)
{
// new style keys
Json
::
Value
key_data
;
Json
::
Reader
reader
;
reader
.
parse
(
it
->
value
().
ToString
().
c_str
(),
key_data
);
if
(
key_data
[
"timestamp"
].
asUInt64
()
>
latest_timestamp
)
{
latest_timestamp
=
key_data
[
"timestamp"
].
asUInt64
();
latest_created_key_name
=
it
->
key
().
ToString
();
}
}
else
{
// old style keys
// assuming server has at least one new-style key created
continue
;
}
}
return
{
latest_created_key_name
,
latest_timestamp
};
}
...
...
SGXInfoServer.cpp
View file @
2bd3b05e
...
...
@@ -56,7 +56,7 @@ Json::Value SGXInfoServer::getAllKeysInfo() {
RETURN_SUCCESS
(
result
)
}
Json
::
Value
SGXInfoServer
::
getLastCreatedKey
()
{
Json
::
Value
SGXInfoServer
::
getLa
te
stCreatedKey
()
{
Json
::
Value
result
;
try
{
...
...
SGXInfoServer.h
View file @
2bd3b05e
...
...
@@ -49,7 +49,7 @@ public:
virtual
Json
::
Value
getAllKeysInfo
();
virtual
Json
::
Value
getLastCreatedKey
();
virtual
Json
::
Value
getLa
te
stCreatedKey
();
virtual
Json
::
Value
getServerConfiguration
();
...
...
ServerInit.cpp
View file @
2bd3b05e
...
...
@@ -64,25 +64,6 @@ uint32_t enclaveLogLevel = 0;
using
namespace
std
;
// Copy from libconsensus
string
exec
(
const
char
*
cmd
)
{
CHECK_STATE
(
cmd
);
std
::
array
<
char
,
128
>
buffer
;
std
::
string
result
;
std
::
unique_ptr
<
FILE
,
decltype
(
&
pclose
)
>
pipe
(
popen
(
cmd
,
"r"
),
pclose
);
if
(
!
pipe
)
{
BOOST_THROW_EXCEPTION
(
std
::
runtime_error
(
"popen() failed!"
)
);
}
while
(
fgets
(
buffer
.
data
(),
buffer
.
size
(),
pipe
.
get
()
)
!=
nullptr
)
{
result
+=
buffer
.
data
();
}
return
result
;
}
void
systemHealthCheck
()
{
string
ulimit
;
try
{
...
...
common.h
View file @
2bd3b05e
...
...
@@ -96,6 +96,24 @@ BOOST_THROW_EXCEPTION(runtime_error(__ERR_STRING__)); \
#define SAFE_CHAR_BUF(__X__, __Y__) ;char __X__ [ __Y__ ]; memset(__X__, 0, __Y__);
#define SAFE_UINT8_BUF(__X__, __Y__) ;uint8_t __X__ [ __Y__ ]; memset(__X__, 0, __Y__);
// Copy from libconsensus
inline
string
exec
(
const
char
*
cmd
)
{
CHECK_STATE
(
cmd
);
std
::
array
<
char
,
128
>
buffer
;
std
::
string
result
;
std
::
unique_ptr
<
FILE
,
decltype
(
&
pclose
)
>
pipe
(
popen
(
cmd
,
"r"
),
pclose
);
if
(
!
pipe
)
{
BOOST_THROW_EXCEPTION
(
std
::
runtime_error
(
"popen() failed!"
)
);
}
while
(
fgets
(
buffer
.
data
(),
buffer
.
size
(),
pipe
.
get
()
)
!=
nullptr
)
{
result
+=
buffer
.
data
();
}
return
result
;
}
#include <shared_mutex>
extern
std
::
shared_timed_mutex
sgxInitMutex
;
...
...
sgx_util.cpp
View file @
2bd3b05e
...
...
@@ -52,11 +52,11 @@ void getAllKeysInfo() {
exit
(
0
);
}
void
getLastCreatedKey
()
{
void
getLa
te
stCreatedKey
()
{
jsonrpc
::
HttpClient
client
(
"http://localhost:1030"
);
StubClient
c
(
client
,
jsonrpc
::
JSONRPC_CLIENT_V2
);
std
::
cout
<<
"Info client inited"
<<
std
::
endl
;
Json
::
Value
lastCreatedKey
=
c
.
getLastCreatedKey
();
Json
::
Value
lastCreatedKey
=
c
.
getLa
te
stCreatedKey
();
std
::
cout
<<
"Last created key name: "
<<
lastCreatedKey
[
"keyName"
]
<<
std
::
endl
;
std
::
cout
<<
"Last created key creation time: "
<<
lastCreatedKey
[
"creationTime"
]
<<
std
::
endl
;
exit
(
0
);
...
...
stubclient.h
View file @
2bd3b05e
...
...
@@ -324,11 +324,11 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
getLastCreatedKey
()
Json
::
Value
getLa
te
stCreatedKey
()
{
Json
::
Value
p
;
p
=
Json
::
nullValue
;
Json
::
Value
result
=
this
->
CallMethod
(
"getLastCreatedKey"
,
p
);
Json
::
Value
result
=
this
->
CallMethod
(
"getLa
te
stCreatedKey"
,
p
);
if
(
result
.
isObject
())
return
result
;
else
...
...
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