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
6cede695
Commit
6cede695
authored
Jan 15, 2018
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new version of load and store
parent
5ce6414e
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
47 deletions
+66
-47
.common.hh.swp
debug/.common.hh.swp
+0
-0
common.hh
debug/common.hh
+9
-5
load.cc
debug/load.cc
+35
-16
load.hh
debug/load.hh
+1
-0
store.cc
debug/store.cc
+6
-13
store.hh
debug/store.hh
+15
-13
No files found.
debug/.common.hh.swp
0 → 100644
View file @
6cede695
File added
debug/common.hh
View file @
6cede695
#pragma once
#pragma once
class
metadata_file
{
/*class metadata_file{
string db,table;
string db,table;
int num_of_fields;
int num_of_fields;
vector<string> field_types;
vector<string> field_types;
vector<int> field_lengths;
vector<int> field_lengths;
vector<string> field_names;
vector<string> field_names;
vector
<
int
>
choosen_onions
;
/*choosen onion for decryption, only one per field.The value could be 0,1,2,3...*/
vector<int> choosen_onions;
public:
public:
void set_db(std::string idb){db=idb;}
void set_db(std::string idb){db=idb;}
std::string get_db(){return db;}
std::string get_db(){return db;}
...
@@ -177,11 +178,14 @@ void metadata_file::show(){
...
@@ -177,11 +178,14 @@ void metadata_file::show(){
}
}
cout<<endl;
cout<<endl;
}
}
*/
/*******************************************************************************************************************/
/*******************************************************************************************************************/
class
metadata_files
{
class
metadata_files
{
public
:
string
db
,
table
;
string
db
,
table
;
/*selected fields*/
/*selected fields*/
vector
<
vector
<
int
>>
selected_field_types
;
vector
<
vector
<
int
>>
selected_field_types
;
...
@@ -266,7 +270,7 @@ public:
...
@@ -266,7 +270,7 @@ public:
void
metadata_files
::
serialize
(){
void
metadata_files
::
serialize
(){
FILE
*
localmeta
=
NULL
;
FILE
*
localmeta
=
NULL
;
string
prefix
=
string
(
"
a
data/"
)
+
db
+
"/"
+
table
;
string
prefix
=
string
(
"data/"
)
+
db
+
"/"
+
table
;
make_path
(
prefix
);
make_path
(
prefix
);
localmeta
=
fopen
((
prefix
+
"/metadata.data"
).
c_str
(),
"w"
);
localmeta
=
fopen
((
prefix
+
"/metadata.data"
).
c_str
(),
"w"
);
...
@@ -304,7 +308,7 @@ void metadata_files::serialize(){
...
@@ -304,7 +308,7 @@ void metadata_files::serialize(){
}
}
void
metadata_files
::
deserialize
(
std
::
string
filename
){
void
metadata_files
::
deserialize
(
std
::
string
filename
){
filename
=
string
(
"
a
data/"
)
+
db
+
"/"
+
table
+
"/"
+
filename
;
filename
=
string
(
"data/"
)
+
db
+
"/"
+
table
+
"/"
+
filename
;
std
::
ifstream
infile
(
filename
);
std
::
ifstream
infile
(
filename
);
string
line
;
string
line
;
while
(
std
::
getline
(
infile
,
line
)){
while
(
std
::
getline
(
infile
,
line
)){
...
...
debug/load.cc
View file @
6cede695
...
@@ -18,8 +18,8 @@ std::shared_ptr<ReturnMeta> getReturnMeta(std::vector<FieldMeta*> fms, std::vect
...
@@ -18,8 +18,8 @@ std::shared_ptr<ReturnMeta> getReturnMeta(std::vector<FieldMeta*> fms, std::vect
return
myReturnMeta
;
return
myReturnMeta
;
}
}
static
metadata_file
load_meta
(
string
db
=
"tdb"
,
string
table
=
"student"
,
string
filename
=
"metadata.data"
){
static
metadata_file
s
load_meta
(
string
db
=
"tdb"
,
string
table
=
"student"
,
string
filename
=
"metadata.data"
){
metadata_file
mf
;
metadata_file
s
mf
;
mf
.
set_db
(
db
);
mf
.
set_db
(
db
);
mf
.
set_table
(
table
);
mf
.
set_table
(
table
);
mf
.
deserialize
(
filename
);
mf
.
deserialize
(
filename
);
...
@@ -44,23 +44,38 @@ static void load_string(string filename, vector<string> &res,unsigned long lengt
...
@@ -44,23 +44,38 @@ static void load_string(string filename, vector<string> &res,unsigned long lengt
close
(
fd
);
close
(
fd
);
}
}
static
vector
<
vector
<
string
>>
load_table_fields
(
metadata_file
&
input
)
{
template
<
class
T
>
vector
<
T
>
flat_vec
(
vector
<
vector
<
T
>>
&
input
){
vector
<
T
>
res
;
for
(
auto
item
:
input
){
for
(
auto
i
:
item
){
res
.
push_back
(
i
);
}
}
return
res
;
}
static
vector
<
vector
<
string
>>
load_table_fields
(
metadata_files
&
input
)
{
string
db
=
input
.
get_db
();
string
db
=
input
.
get_db
();
string
table
=
input
.
get_table
();
string
table
=
input
.
get_table
();
vector
<
vector
<
string
>>
res
;
vector
<
vector
<
string
>>
res
;
string
prefix
=
string
(
"data/"
)
+
db
+
"/"
+
table
+
"/"
;
string
prefix
=
string
(
"data/"
)
+
db
+
"/"
+
table
+
"/"
;
vector
<
string
>
datafiles
;
vector
<
string
>
datafiles
;
for
(
auto
item
:
input
.
get_field_names
()){
auto
field_names
=
flat_vec
(
input
.
selected_field_names
);
auto
field_types
=
flat_vec
(
input
.
selected_field_types
);
auto
field_lengths
=
flat_vec
(
input
.
selected_field_lengths
);
for
(
auto
item
:
field_names
){
datafiles
.
push_back
(
prefix
+
item
);
datafiles
.
push_back
(
prefix
+
item
);
}
}
for
(
unsigned
int
i
=
0u
;
i
<
input
.
get_field_names
()
.
size
();
i
++
){
for
(
unsigned
int
i
=
0u
;
i
<
field_names
.
size
();
i
++
){
vector
<
string
>
column
;
vector
<
string
>
column
;
if
(
IS_NUM
(
std
::
stoi
(
input
.
get_field_types
()[
i
])
)){
if
(
IS_NUM
(
field_types
[
i
]
)){
load_num
(
datafiles
[
i
],
column
);
load_num
(
datafiles
[
i
],
column
);
}
else
{
}
else
{
load_string
(
datafiles
[
i
],
column
,
input
.
get_field_lengths
()
[
i
]);
load_string
(
datafiles
[
i
],
column
,
field_lengths
[
i
]);
}
}
for
(
unsigned
int
j
=
0u
;
j
<
column
.
size
();
j
++
){
for
(
unsigned
int
j
=
0u
;
j
<
column
.
size
();
j
++
){
if
(
j
>=
res
.
size
()){
if
(
j
>=
res
.
size
()){
...
@@ -86,12 +101,12 @@ static ResType load_files(std::string db="tdb", std::string table="student"){
...
@@ -86,12 +101,12 @@ static ResType load_files(std::string db="tdb", std::string table="student"){
if
(
types
.
size
()
==
1
){
if
(
types
.
size
()
==
1
){
//to be
//to be
}
}
metadata_file
res_meta
=
load_meta
(
db
,
table
);
metadata_files
res_meta
=
load_meta
(
db
,
table
);
for
(
unsigned
int
i
=
0
;
i
<
res_meta
.
get_choosen_onions
().
size
();
i
++
){
//choosen onion for each field
res
[
i
].
choosenOnions
.
push_back
(
res_meta
.
get_choosen_onions
()[
i
]);
}
// for(unsigned int i=0;i<res_meta.dec_onion_index.size();i++){
//choosen onion for each field
// res[i].choosenOnions.push_back(res_meta.get_choosen_onions()[i]);
// }
std
::
shared_ptr
<
ReturnMeta
>
rm
=
getReturnMeta
(
fms
,
res
);
std
::
shared_ptr
<
ReturnMeta
>
rm
=
getReturnMeta
(
fms
,
res
);
//why do we need this??
//why do we need this??
...
@@ -103,10 +118,14 @@ static ResType load_files(std::string db="tdb", std::string table="student"){
...
@@ -103,10 +118,14 @@ static ResType load_files(std::string db="tdb", std::string table="student"){
//load fields in the stored file
//load fields in the stored file
vector
<
vector
<
string
>>
res_field
=
load_table_fields
(
res_meta
);
vector
<
vector
<
string
>>
res_field
=
load_table_fields
(
res_meta
);
resraw2
.
rowValues
=
res_field
;
resraw2
.
rowValues
=
res_field
;
resraw2
.
fieldNames
=
res_meta
.
get_field_names
();
auto
field_names
=
flat_vec
(
res_meta
.
selected_field_names
);
resraw2
.
choosen_onions
=
res_meta
.
get_choosen_onions
();
auto
field_types
=
flat_vec
(
res_meta
.
selected_field_types
);
for
(
unsigned
int
i
=
0
;
i
<
res_meta
.
get_field_types
().
size
();
++
i
)
{
auto
field_lengths
=
flat_vec
(
res_meta
.
selected_field_lengths
);
resraw2
.
fieldTypes
.
push_back
(
static_cast
<
enum_field_types
>
(
std
::
stoi
(
res_meta
.
get_field_types
()[
i
])));
resraw2
.
fieldNames
=
field_names
;
// resraw2.choosen_onions = ;
for
(
unsigned
int
i
=
0
;
i
<
field_types
.
size
();
++
i
)
{
resraw2
.
fieldTypes
.
push_back
(
static_cast
<
enum_field_types
>
(
field_types
[
i
]));
}
}
ResType
rawtorestype
=
MygetResTypeFromLuaTable
(
false
,
&
resraw2
);
ResType
rawtorestype
=
MygetResTypeFromLuaTable
(
false
,
&
resraw2
);
auto
finalresults
=
decryptResults
(
rawtorestype
,
*
rm
);
auto
finalresults
=
decryptResults
(
rawtorestype
,
*
rm
);
...
...
debug/load.hh
View file @
6cede695
...
@@ -259,6 +259,7 @@ static std::vector<transField> getTransField(std::vector<FieldMeta *> pfms){
...
@@ -259,6 +259,7 @@ static std::vector<transField> getTransField(std::vector<FieldMeta *> pfms){
tf
.
numOfOnions
++
;
tf
.
numOfOnions
++
;
tf
.
fields
.
push_back
((
ompair
.
second
)
->
getAnonOnionName
());
tf
.
fields
.
push_back
((
ompair
.
second
)
->
getAnonOnionName
());
tf
.
onions
.
push_back
(
ompair
.
first
->
getValue
());
tf
.
onions
.
push_back
(
ompair
.
first
->
getValue
());
tf
.
originalOm
.
push_back
(
ompair
.
second
);
}
}
if
(
pfm
->
getHasSalt
()){
if
(
pfm
->
getHasSalt
()){
tf
.
hasSalt
=
true
;
tf
.
hasSalt
=
true
;
...
...
debug/store.cc
View file @
6cede695
#include "debug/store.hh"
#include "debug/store.hh"
#include "debug/common.hh"
#include "debug/common.hh"
static
void
write_meta
(
rawMySQLReturnValue
&
resraw
,
std
::
vector
<
transField
>
&
res
,
string
db
,
string
table
){
static
void
write_meta
(
rawMySQLReturnValue
&
resraw
,
std
::
vector
<
transField
>
&
res
,
string
db
,
string
table
){
metadata_files
mf
;
metadata_files
mf
;
mf
.
set_db_table
(
db
,
table
);
mf
.
set_db_table
(
db
,
table
);
...
@@ -32,15 +34,6 @@ static void write_meta(rawMySQLReturnValue& resraw,std::vector<transField> &res,
...
@@ -32,15 +34,6 @@ static void write_meta(rawMySQLReturnValue& resraw,std::vector<transField> &res,
mf
.
set_selected_field_names
(
selected_field_names
);
mf
.
set_selected_field_names
(
selected_field_names
);
mf
.
set_dec_onion_index
(
dec_onion_index
);
mf
.
set_dec_onion_index
(
dec_onion_index
);
mf
.
set_has_salt
(
has_salt
);
mf
.
set_has_salt
(
has_salt
);
// std::vector<std::string> temp;
// for(auto item:resraw.fieldTypes){
// temp.push_back(std::to_string(static_cast<int>(item)));
// }
// mf.set_field_types(temp);
// mf.set_field_lengths(resraw.lengths);
// mf.set_field_names(resraw.fieldNames);
// mf.set_choosen_onions(resraw.choosen_onions);
// mf.serilize();
mf
.
serialize
();
mf
.
serialize
();
}
}
static
void
write_row_data
(
rawMySQLReturnValue
&
resraw
,
string
db
,
string
table
){
static
void
write_row_data
(
rawMySQLReturnValue
&
resraw
,
string
db
,
string
table
){
...
@@ -77,13 +70,13 @@ static void store(std::string db, std::string table){
...
@@ -77,13 +70,13 @@ static void store(std::string db, std::string table){
std
::
vector
<
FieldMeta
*>
fms
=
getFieldMeta
(
*
schema
,
db
,
table
);
std
::
vector
<
FieldMeta
*>
fms
=
getFieldMeta
(
*
schema
,
db
,
table
);
//transform the field so that selected onions can be used
//transform the field so that selected onions can be used
std
::
vector
<
transField
>
res
=
getTransField
(
fms
);
std
::
vector
<
transField
>
res
=
getTransField
(
fms
);
//generate the backup query and then fetch the tuples
std
::
string
backup_query
=
getTestQuery
(
*
schema
,
res
,
db
,
table
);
rawMySQLReturnValue
resraw
=
executeAndGetResultRemote
(
globalConn
,
backup_query
);
for
(
auto
&
item
:
res
){
for
(
auto
&
item
:
res
){
(
void
)
item
;
(
void
)
item
;
resraw
.
choosen_o
nions
.
push_back
(
0
);
item
.
choosenO
nions
.
push_back
(
0
);
}
}
//generate the backup query and then fetch the tuples
std
::
string
backup_query
=
getTestQuery
(
*
schema
,
res
,
db
,
table
);
rawMySQLReturnValue
resraw
=
executeAndGetResultRemote
(
globalConn
,
backup_query
);
//write the tuples into files
//write the tuples into files
write_raw_data_to_files
(
resraw
,
res
,
db
,
table
);
write_raw_data_to_files
(
resraw
,
res
,
db
,
table
);
}
}
...
...
debug/store.hh
View file @
6cede695
...
@@ -53,6 +53,20 @@ private:
...
@@ -53,6 +53,20 @@ private:
std
::
unique_ptr
<
QueryRewrite
>
qr
;
std
::
unique_ptr
<
QueryRewrite
>
qr
;
};
};
//representation of one field.
struct
transField
{
bool
hasSalt
;
FieldMeta
*
originalFm
;
vector
<
int
>
choosenOnions
;
//used to construct return meta
int
onionIndex
=
0
;
int
numOfOnions
=
0
;
//onions
std
::
vector
<
std
::
string
>
fields
;
std
::
vector
<
onion
>
onions
;
};
static
std
::
string
embeddedDir
=
"/t/cryt/shadow"
;
static
std
::
string
embeddedDir
=
"/t/cryt/shadow"
;
//global map, for each client, we have one WrapperState which contains ProxyState.
//global map, for each client, we have one WrapperState which contains ProxyState.
static
std
::
map
<
std
::
string
,
WrapperState
*>
clients
;
static
std
::
map
<
std
::
string
,
WrapperState
*>
clients
;
...
@@ -103,19 +117,7 @@ void rawMySQLReturnValue::show(){
...
@@ -103,19 +117,7 @@ void rawMySQLReturnValue::show(){
cout
<<
endl
;
cout
<<
endl
;
}
}
//representation of one field.
struct
transField
{
bool
hasSalt
;
FieldMeta
*
originalFm
;
vector
<
int
>
choosenOnions
;
//used to construct return meta
int
onionIndex
=
0
;
int
numOfOnions
=
0
;
//onions
std
::
vector
<
std
::
string
>
fields
;
std
::
vector
<
onion
>
onions
;
// std::vector<OnionMeta*>originalOm;
};
static
void
init
(){
static
void
init
(){
...
...
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