Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
Practical-Cryptdb
Project
Project
Details
Activity
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
Zhaozhen
Practical-Cryptdb
Commits
1f128066
Commit
1f128066
authored
May 19, 2018
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new version of store
parent
65ae5e4b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
189 additions
and
28 deletions
+189
-28
simple_store_new.cc
tools/simple_store_new.cc
+71
-27
util.cc
util/util.cc
+28
-0
util.hh
util/util.hh
+4
-0
reuse.cc
wrapper/reuse.cc
+79
-1
reuse.hh
wrapper/reuse.hh
+7
-0
No files found.
tools/simple_store_new.cc
View file @
1f128066
#include "wrapper/common.hh"
#include "wrapper/reuse.hh"
#include "util/util.hh"
static
std
::
string
embeddedDir
=
"/t/cryt/shadow"
;
//global map, for each client, we have one WrapperState which contains ProxyState.
static
std
::
map
<
std
::
string
,
WrapperState
*>
clients
;
...
...
@@ -84,12 +85,54 @@ void write_raw_data_to_files(MySQLColumnData& resraw,std::vector<FieldMetaTrans>
}
}
}
static
std
::
string
getSelectField
(
SchemaInfo
&
schema
,
FieldMetaTrans
&
tf
,
std
::
string
db
,
std
::
string
table
){
std
::
string
res
=
"SELECT "
;
const
std
::
unique_ptr
<
IdentityMetaKey
>
dbmeta_key
(
new
IdentityMetaKey
(
db
));
//get databaseMeta, search in the map
DatabaseMeta
*
dbm
=
schema
.
getChild
(
*
dbmeta_key
);
const
TableMeta
&
tbm
=
*
((
*
dbm
).
getChild
(
IdentityMetaKey
(
table
)));
std
::
string
annotablename
=
tbm
.
getAnonTableName
();
//then a list of onion names
for
(
auto
item
:
tf
.
getChoosenOnionName
()){
res
+=
item
;
res
+=
" , "
;
}
//actually the salt should be selected if RND is used,this should be changed later.
if
(
tf
.
getHasSalt
()){
res
+=
tf
.
getSaltName
()
+
" , "
;
}
res
=
res
.
substr
(
0
,
res
.
size
()
-
2
);
res
=
res
+
"FROM `"
+
db
+
std
::
string
(
"`.`"
)
+
annotablename
+
"`"
;
return
res
;
}
static
void
write_field_data_to_files
(
MySQLColumnData
&
resraw
,
FieldMetaTrans
&
res
,
string
db
,
string
table
,
string
field
)
{
std
::
string
prefix
=
std
::
string
(
"data/"
)
+
db
+
"/"
+
table
+
"/"
+
field
+
"/"
;
g_make_path
(
prefix
);
std
::
vector
<
std
::
string
>
filenames
;
for
(
auto
item
:
resraw
.
fieldNames
){
item
=
prefix
+
item
;
filenames
.
push_back
(
item
);
}
int
len
=
resraw
.
fieldNames
.
size
();
for
(
int
i
=
0
;
i
<
len
;
i
++
){
if
(
IS_NUM
(
resraw
.
fieldTypes
[
i
])){
writeColumndataNum
(
resraw
.
columnData
[
i
],
filenames
[
i
]);
}
else
{
writeColumndataEscapeString
(
resraw
.
columnData
[
i
],
filenames
[
i
],
resraw
.
maxLengths
[
i
]);
}
}
}
static
void
store
(
std
::
string
db
,
std
::
string
table
){
std
::
unique_ptr
<
SchemaInfo
>
schema
=
myLoadSchemaInfo
(
embeddedDir
);
//get all the fields in the tables
std
::
vector
<
FieldMeta
*>
fms
=
getFieldMeta
(
*
schema
,
db
,
table
);
//transform the field so that selected onions can be used
std
::
vector
<
FieldMetaTrans
>
res
;
for
(
auto
i
=
0u
;
i
<
fms
.
size
();
i
++
){
...
...
@@ -97,37 +140,38 @@ static void store(std::string db, std::string table){
res
.
push_back
(
ft
);
res
.
back
().
trans
(
fms
[
i
]);
}
/*this is our strategy, each field should be able to choose the selected onion*/
storeStrategies
(
res
);
//generate the backup query and then fetch the tuples
std
::
string
backup_query
=
getSelectQuery
(
*
schema
,
res
,
db
,
table
);
MySQLColumnData
resraw
=
executeAndGetColumnData
(
globalConn
,
backup_query
);
//then we should set the type and length of FieldMetaTrans
auto
types
=
resraw
.
fieldTypes
;
auto
lengths
=
resraw
.
maxLengths
;
int
base_types
=
0
;
int
base_lengths
=
0
;
for
(
auto
&
item
:
res
){
vector
<
int
>
tempTypes
;
vector
<
int
>
tempLengths
;
for
(
unsigned
int
i
=
0u
;
i
<
item
.
getChoosenOnionName
().
size
();
i
++
){
tempTypes
.
push_back
(
types
[
base_types
++
]);
tempLengths
.
push_back
(
lengths
[
base_lengths
++
]);
}
item
.
setChoosenFieldTypes
(
tempTypes
);
item
.
setChoosenFieldLengths
(
tempLengths
);
if
(
item
.
getHasSalt
()){
//also this should be changed.
item
.
setSaltType
(
types
[
base_types
++
]);
item
.
setSaltLength
(
lengths
[
base_lengths
++
]);
storeStrategyNew
(
res
);
for
(
auto
&
tf
:
res
){
std
::
string
back_field_query
=
getSelectField
(
*
schema
,
tf
,
db
,
table
);
std
::
cout
<<
back_field_query
<<
std
::
endl
;
MySQLColumnData
resraw
=
executeAndGetColumnData
(
globalConn
,
back_field_query
);
std
::
vector
<
int
>
types
;
for
(
unsigned
int
i
=
0u
;
i
<
resraw
.
fieldTypes
.
size
();
i
++
){
types
.
push_back
((
int
)(
resraw
.
fieldTypes
[
i
]));
}
auto
lengths
=
resraw
.
maxLengths
;
auto
stype
=
types
.
back
();
auto
slength
=
lengths
.
back
();
types
.
pop_back
();
lengths
.
pop_back
();
tf
.
setChoosenFieldTypes
(
types
);
tf
.
setChoosenFieldLengths
(
lengths
);
tf
.
setSaltType
(
stype
);
tf
.
setSaltLength
(
slength
);
write_field_data_to_files
(
resraw
,
tf
,
db
,
table
,
tf
.
getOriginalFieldMeta
()
->
getFieldName
());
}
//write the tuples into files
//generate the backup query and then fetch the tuples
(
void
)
getSelectQuery
;
(
void
)
getSelectField
;
/*
write_raw_data_to_files(resraw,res,db,table);
*/
(
void
)
executeAndGetColumnData
;
(
void
)
write_raw_data_to_files
;
}
int
...
...
util/util.cc
View file @
1f128066
...
...
@@ -4,6 +4,8 @@
#include <stdexcept>
#include <assert.h>
#include <memory>
#include <sys/stat.h>
#include <sys/types.h>
#include <gmp.h>
...
...
@@ -670,3 +672,29 @@ reverse_escape_string_for_mysql_modify(char *to,
*
to
=
'\0'
;
return
to
-
to_start
;
}
bool
g_make_path
(
std
::
string
directory
){
struct
stat
st
;
if
(
directory
.
size
()
==
0
||
directory
[
0
]
==
'/'
)
return
false
;
if
(
directory
.
back
()
==
'/'
)
directory
.
pop_back
();
int
start
=
0
,
next
=
0
;
while
(
stat
(
directory
.
c_str
(),
&
st
)
==-
1
&&
next
!=-
1
){
next
=
directory
.
find
(
'/'
,
start
);
if
(
next
!=-
1
){
std
::
string
sub
=
directory
.
substr
(
0
,
next
);
if
(
stat
(
sub
.
c_str
(),
&
st
)
==-
1
)
mkdir
(
sub
.
c_str
(),
0700
);
start
=
next
+
1
;
}
else
{
mkdir
(
directory
.
c_str
(),
0700
);
}
}
return
true
;
}
util/util.hh
View file @
1f128066
...
...
@@ -28,6 +28,8 @@
#include <util/errstream.hh>
#include <util/params.hh>
#define POINT printf("LINE %d IN FILE %s",__LINE__,__FILE__);
#define RETURN_FALSE_IF_FALSE(status) \
{ \
if (!(status)) { \
...
...
@@ -585,3 +587,5 @@ reverse_escape_string_for_mysql_modify(char *to,
size_t
escape_string_for_mysql_modify
(
char
*
to
,
const
char
*
from
,
size_t
length
);
bool
g_make_path
(
std
::
string
directory
);
wrapper/reuse.cc
View file @
1f128066
...
...
@@ -67,7 +67,11 @@ void FieldMetaTrans::trans(FieldMeta *fm) {
void
FieldMetaTrans
::
choose
(
std
::
vector
<
onion
>
onionSet
){
choosenOnionO
=
onionSet
;
for
(
auto
o
:
onionsO
){
if
(
std
::
find
(
onionSet
.
begin
(),
onionSet
.
end
(),
o
)
!=
onionSet
.
end
()){
choosenOnionO
.
push_back
(
o
);
}
}
for
(
auto
&
o
:
onionSet
){
choosenOnionName
.
push_back
(
originalFm
->
getOnionMeta
(
o
)
->
getAnonOnionName
()
);
...
...
@@ -593,6 +597,80 @@ void storeStrategies(std::vector<FieldMetaTrans>& res){
}
STORE_STRATEGY
INT_ASHE_STRATEGY
=
STORE_STRATEGY
::
MIN
;
STORE_STRATEGY
INT_HOM_STRATEGY
=
STORE_STRATEGY
::
INVALID
;
static
void
integerStrategy
(
FieldMetaTrans
&
item
){
std
::
vector
<
onion
>
select
;
if
(
INT_HOM_STRATEGY
==
STORE_STRATEGY
::
INVALID
){
//ashe
if
(
INT_ASHE_STRATEGY
==
STORE_STRATEGY
::
MIN
){
select
.
push_back
(
oDET
);
}
else
if
(
INT_ASHE_STRATEGY
==
STORE_STRATEGY
::
MEDIAN
){
select
.
push_back
(
oDET
);
select
.
push_back
(
oOPE
);
}
else
if
(
INT_ASHE_STRATEGY
==
STORE_STRATEGY
::
FULL
){
select
.
push_back
(
oDET
);
select
.
push_back
(
oOPE
);
select
.
push_back
(
oASHE
);
}
else
{
POINT
assert
(
0
);
}
}
else
{
//hom
if
(
INT_HOM_STRATEGY
==
STORE_STRATEGY
::
MIN
){
select
.
push_back
(
oDET
);
}
else
if
(
INT_HOM_STRATEGY
==
STORE_STRATEGY
::
MEDIAN
){
select
.
push_back
(
oDET
);
select
.
push_back
(
oAGG
);
}
else
if
(
INT_HOM_STRATEGY
==
STORE_STRATEGY
::
FULL
){
select
.
push_back
(
oDET
);
select
.
push_back
(
oAGG
);
select
.
push_back
(
oOPE
);
}
else
{
POINT
assert
(
0
);
}
}
item
.
choose
(
select
);
}
STORE_STRATEGY
STR_STRATEGY
=
STORE_STRATEGY
::
MIN
;
static
void
stringStrategy
(
FieldMetaTrans
&
item
){
std
::
vector
<
onion
>
select
;
if
(
STR_STRATEGY
==
STORE_STRATEGY
::
MIN
){
select
.
push_back
(
oDET
);
}
else
if
(
STR_STRATEGY
==
STORE_STRATEGY
::
MEDIAN
){
select
.
push_back
(
oDET
);
select
.
push_back
(
oOPE
);
}
else
if
(
STR_STRATEGY
==
STORE_STRATEGY
::
FULL
){
select
.
push_back
(
oDET
);
select
.
push_back
(
oOPE
);
select
.
push_back
(
oSWP
);
}
else
{
POINT
assert
(
0
);
}
item
.
choose
(
select
);
}
void
storeStrategyNew
(
std
::
vector
<
FieldMetaTrans
>&
res
){
for
(
auto
&
item
:
res
){
if
(
IS_NUM
(
item
.
getOriginalFieldMeta
()
->
getSqlType
())){
//integer field
integerStrategy
(
item
);
}
else
{
//string field
stringStrategy
(
item
);
}
}
}
static
const
std
::
vector
<
onion
>
onion_order
=
{
oDET
,
oOPE
,
...
...
wrapper/reuse.hh
View file @
1f128066
...
...
@@ -188,8 +188,15 @@ write_row_data(rawMySQLReturnValue& resraw,std::string db,std::string table,std:
void
storeStrategies
(
std
::
vector
<
FieldMetaTrans
>&
res
);
void
storeStrategyNew
(
std
::
vector
<
FieldMetaTrans
>&
res
);
enum
class
STORE_STRATEGY
{
INVALID
,
FIRST
,
MIN
,
MEDIAN
,
FULL
,
ALL
};
...
...
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