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
fc14f7df
Commit
fc14f7df
authored
Jan 18, 2018
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new version of load and store
parent
98606d82
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
718 additions
and
11 deletions
+718
-11
load.cc
debug/load.cc
+9
-4
loadtemp.cc
debug/loadtemp.cc
+248
-0
store.cc
debug/store.cc
+3
-1
store_new.cc
debug/store_new.cc
+85
-0
storetemp.cc
debug/storetemp.cc
+129
-0
.reuse.cc.swp
wrapper/.reuse.cc.swp
+0
-0
common.cc
wrapper/common.cc
+182
-4
common.hh
wrapper/common.hh
+34
-2
reuse.hh
wrapper/reuse.hh
+28
-0
No files found.
debug/load.cc
View file @
fc14f7df
...
@@ -220,9 +220,16 @@ static ResType load_files(std::string db="tdb", std::string table="student"){
...
@@ -220,9 +220,16 @@ static ResType load_files(std::string db="tdb", std::string table="student"){
std
::
unique_ptr
<
SchemaInfo
>
schema
=
myLoadSchemaInfo
(
embeddedDir
);
std
::
unique_ptr
<
SchemaInfo
>
schema
=
myLoadSchemaInfo
(
embeddedDir
);
//get all the fields in the tables.
//get all the fields in the tables.
std
::
vector
<
FieldMeta
*>
fms
=
getFieldMeta
(
*
schema
,
db
,
table
);
std
::
vector
<
FieldMeta
*>
fms
=
getFieldMeta
(
*
schema
,
db
,
table
);
auto
res
=
FieldMeta_to_Wrapper
(
fms
);
auto
res
=
FieldMeta_to_Wrapper
(
fms
);
std
::
vector
<
enum_field_types
>
types
;
//Added
std
::
vector
<
FieldMetaTrans
>
res2
;
for
(
auto
fm
:
fms
){
FieldMetaTrans
tf
;
res2
.
push_back
(
tf
);
res2
.
back
().
trans
(
fm
);
}
metadata_files
res_meta
=
load_meta
(
db
,
table
);
metadata_files
res_meta
=
load_meta
(
db
,
table
);
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??
create_embedded_thd
(
0
);
create_embedded_thd
(
0
);
...
@@ -230,9 +237,7 @@ static ResType load_files(std::string db="tdb", std::string table="student"){
...
@@ -230,9 +237,7 @@ 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
,
res
);
vector
<
vector
<
string
>>
res_field
=
load_table_fields
(
res_meta
,
res
);
resraw
.
rowValues
=
res_field
;
resraw
.
rowValues
=
res_field
;
// auto field_names = flat_vec(res_meta.selected_field_names);
// auto field_types = flat_vec(res_meta.selected_field_types);
// auto field_lengths = flat_vec(res_meta.selected_field_lengths);
auto
bt
=
get_batch
(
res_meta
,
res
);
auto
bt
=
get_batch
(
res_meta
,
res
);
vector
<
string
>
field_names
=
bt
.
field_names
;
vector
<
string
>
field_names
=
bt
.
field_names
;
vector
<
int
>
field_types
=
bt
.
field_types
;
vector
<
int
>
field_types
=
bt
.
field_types
;
...
...
debug/loadtemp.cc
0 → 100644
View file @
fc14f7df
/*1. store data as column files, and restore data as plaintext insert query
* 2. plaintext insert query should be able to recover directly
* 3. should be able to used exsisting data to reduce the computation overhead(to be implemented)
*/
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <map>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include "wrapper/reuse.hh"
#include "wrapper/common.hh"
using
std
::
cout
;
using
std
::
cin
;
using
std
::
endl
;
using
std
::
vector
;
using
std
::
string
;
using
std
::
to_string
;
static
std
::
string
embeddedDir
=
"/t/cryt/shadow"
;
char
*
globalEsp
=
NULL
;
int
num_of_pipe
=
4
;
//global map, for each client, we have one WrapperState which contains ProxyState.
static
std
::
map
<
std
::
string
,
WrapperState
*>
clients
;
//This connection mimics the behaviour of MySQL-Proxy
Connect
*
globalConn
;
/*for each field, convert the format to FieldMeta_Wrapper*/
static
void
construct_insert
(
rawMySQLReturnValue
&
str
,
std
::
string
table
,
std
::
vector
<
std
::
string
>
&
res
){
std
::
string
head
=
string
(
"INSERT INTO `"
)
+
table
+
"` VALUES "
;
int
cnt
=
0
;
string
cur
=
head
;
for
(
unsigned
int
i
=
0u
;
i
<
str
.
rowValues
.
size
();
i
++
){
++
cnt
;
cur
+=
"("
;
for
(
unsigned
int
j
=
0u
;
j
<
str
.
rowValues
[
i
].
size
();
j
++
){
if
(
IS_NUM
(
str
.
fieldTypes
[
j
]))
{
cur
+=
str
.
rowValues
[
i
][
j
]
+=
","
;
}
else
{
int
len
=
str
.
rowValues
[
i
][
j
].
size
();
mysql_real_escape_string
(
globalConn
->
get_conn
(),
globalEsp
,
str
.
rowValues
[
i
][
j
].
c_str
(),
len
);
cur
+=
string
(
"
\"
"
)
+=
string
(
globalEsp
)
+=
"
\"
,"
;
}
}
cur
.
back
()
=
')'
;
cur
+=
","
;
if
(
cnt
==
num_of_pipe
){
cnt
=
0
;
cur
.
back
()
=
';'
;
res
.
push_back
(
cur
);
cur
=
head
;
}
}
if
(
cnt
!=
0
){
cur
.
back
()
=
';'
;
res
.
push_back
(
cur
);
}
}
static
void
init
(){
std
::
string
client
=
"192.168.1.1:1234"
;
//one Wrapper per user.
clients
[
client
]
=
new
WrapperState
();
//Connect phase
ConnectionInfo
ci
(
"localhost"
,
"root"
,
"letmein"
,
3306
);
const
std
::
string
master_key
=
"113341234"
;
char
*
buffer
;
if
((
buffer
=
getcwd
(
NULL
,
0
))
==
NULL
){
perror
(
"getcwd error"
);
}
embeddedDir
=
std
::
string
(
buffer
)
+
"/shadow"
;
SharedProxyState
*
shared_ps
=
new
SharedProxyState
(
ci
,
embeddedDir
,
master_key
,
determineSecurityRating
());
assert
(
0
==
mysql_thread_init
());
//we init embedded database here.
clients
[
client
]
->
ps
=
std
::
unique_ptr
<
ProxyState
>
(
new
ProxyState
(
*
shared_ps
));
clients
[
client
]
->
ps
->
safeCreateEmbeddedTHD
();
//Connect end!!
globalConn
=
new
Connect
(
ci
.
server
,
ci
.
user
,
ci
.
passwd
,
ci
.
port
);
}
struct
batch
{
vector
<
string
>
field_names
;
vector
<
int
>
field_types
;
vector
<
int
>
field_lengths
;
};
batch
ggbt
;
/*should choose the right decryption onion*/
static
std
::
shared_ptr
<
ReturnMeta
>
getReturnMeta
(
std
::
vector
<
FieldMeta
*>
fms
,
std
::
vector
<
FieldMetaTrans
>
&
tfds
){
assert
(
fms
.
size
()
==
tfds
.
size
());
std
::
shared_ptr
<
ReturnMeta
>
myReturnMeta
=
std
::
make_shared
<
ReturnMeta
>
();
int
pos
=
0
;
//construct OLK
for
(
auto
i
=
0u
;
i
<
tfds
.
size
();
i
++
){
onion
o
=
tfds
[
i
].
getChoosenOnionO
()[
0
];
SECLEVEL
l
=
tfds
[
i
].
getOriginalFieldMeta
()
->
getOnionMeta
(
o
)
->
getSecLevel
();
FieldMeta
*
k
=
tfds
[
i
].
getOriginalFieldMeta
();
OLK
curOLK
(
o
,
l
,
k
);
addToReturn
(
myReturnMeta
.
get
(),
pos
++
,
curOLK
,
true
,
k
->
getFieldName
());
addSaltToReturn
(
myReturnMeta
.
get
(),
pos
++
);
ggbt
.
field_types
.
push_back
(
tfds
[
i
].
getChoosenFieldTypes
()[
0
]);
ggbt
.
field_names
.
push_back
(
tfds
[
i
].
getChoosenOnionName
()[
0
]);
ggbt
.
field_lengths
.
push_back
(
tfds
[
i
].
getChoosenFieldLengths
()[
0
]);
ggbt
.
field_types
.
push_back
(
tfds
[
i
].
getSaltType
());
ggbt
.
field_names
.
push_back
(
tfds
[
i
].
getSaltName
());
ggbt
.
field_lengths
.
push_back
(
tfds
[
i
].
getSaltLength
());
}
return
myReturnMeta
;
}
static
TableMetaTrans
load_meta
(
string
db
=
"tdb"
,
string
table
=
"student"
,
string
filename
=
"metadata.data"
){
TableMetaTrans
mf
;
mf
.
set_db_table
(
db
,
table
);
mf
.
deserialize
();
return
mf
;
}
static
void
load_num
(
string
filename
,
vector
<
string
>
&
res
){
std
::
ifstream
infile
(
filename
);
string
line
;
while
(
std
::
getline
(
infile
,
line
)){
res
.
push_back
(
line
);
}
infile
.
close
();
}
static
void
load_string
(
string
filename
,
vector
<
string
>
&
res
,
unsigned
long
length
){
char
*
buf
=
new
char
[
length
];
int
fd
=
open
(
filename
.
c_str
(),
O_RDONLY
);
while
(
read
(
fd
,
buf
,
length
)
!=
0
){
res
.
push_back
(
string
(
buf
,
length
));
}
close
(
fd
);
}
/*load fields in string, only part of it can be decrypted*/
static
vector
<
vector
<
string
>>
load_table_fields
(
TableMetaTrans
&
input
,
std
::
vector
<
FieldMetaTrans
>
&
tfms
)
{
string
db
=
input
.
get_db
();
string
table
=
input
.
get_table
();
vector
<
vector
<
string
>>
res
;
string
prefix
=
string
(
"data/"
)
+
db
+
"/"
+
table
+
"/"
;
vector
<
string
>
field_names
=
ggbt
.
field_names
;
vector
<
int
>
field_types
=
ggbt
.
field_types
;
vector
<
int
>
field_lengths
=
ggbt
.
field_lengths
;
vector
<
string
>
datafiles
;
for
(
auto
item
:
field_names
){
datafiles
.
push_back
(
prefix
+
item
);
}
for
(
unsigned
int
i
=
0u
;
i
<
field_names
.
size
();
i
++
){
vector
<
string
>
column
;
if
(
IS_NUM
(
field_types
[
i
])){
load_num
(
datafiles
[
i
],
column
);
}
else
{
load_string
(
datafiles
[
i
],
column
,
field_lengths
[
i
]);
}
for
(
unsigned
int
j
=
0u
;
j
<
column
.
size
();
j
++
){
if
(
j
>=
res
.
size
()){
res
.
push_back
(
vector
<
string
>
());
}
res
[
j
].
push_back
(
column
[
j
]);
}
}
return
res
;
}
static
ResType
load_files
(
std
::
string
db
=
"tdb"
,
std
::
string
table
=
"student"
){
std
::
unique_ptr
<
SchemaInfo
>
schema
=
myLoadSchemaInfo
(
embeddedDir
);
//get all the fields in the tables.
std
::
vector
<
FieldMeta
*>
fms
=
getFieldMeta
(
*
schema
,
db
,
table
);
/* std::vector<FieldMetaTrans> res2;
for(auto fm:fms){
FieldMetaTrans tf;
res2.push_back(tf);
res2.back().trans(fm);
}
*/
TableMetaTrans
res_meta
=
load_meta
(
db
,
table
);
std
::
vector
<
FieldMetaTrans
>
res2
=
res_meta
.
getFts
();
for
(
unsigned
int
i
=
0
;
i
<
fms
.
size
();
i
++
){
res2
[
i
].
trans
(
fms
[
i
]);
}
std
::
shared_ptr
<
ReturnMeta
>
rm
=
getReturnMeta
(
fms
,
res2
);
//why do we need this??
create_embedded_thd
(
0
);
rawMySQLReturnValue
resraw
;
//load fields in the stored file
vector
<
vector
<
string
>>
res_field
=
load_table_fields
(
res_meta
,
res2
);
resraw
.
rowValues
=
res_field
;
vector
<
string
>
field_names
=
ggbt
.
field_names
;
vector
<
int
>
field_types
=
ggbt
.
field_types
;
vector
<
int
>
field_lengths
=
ggbt
.
field_lengths
;
resraw
.
fieldNames
=
field_names
;
for
(
unsigned
int
i
=
0
;
i
<
field_types
.
size
();
++
i
){
resraw
.
fieldTypes
.
push_back
(
static_cast
<
enum_field_types
>
(
field_types
[
i
]));
}
ResType
rawtorestype
=
rawMySQLReturnValue_to_ResType
(
false
,
&
resraw
);
auto
finalresults
=
decryptResults
(
rawtorestype
,
*
rm
);
return
finalresults
;
}
int
main
(
int
argc
,
char
*
argv
[]){
init
();
create_embedded_thd
(
0
);
std
::
string
db
=
"tdb"
,
table
=
"student"
;
globalEsp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
5000
);
if
(
globalEsp
==
NULL
){
printf
(
"unable to allocate esp
\n
"
);
return
0
;
}
/*load and decrypt*/
ResType
res
=
load_files
(
db
,
table
);
/*transform*/
rawMySQLReturnValue
str
;
transform_to_rawMySQLReturnValue
(
str
,
res
);
std
::
vector
<
string
>
res_query
;
/*get piped insert*/
construct_insert
(
str
,
table
,
res_query
);
for
(
auto
item
:
res_query
){
cout
<<
item
<<
endl
;
}
free
(
globalEsp
);
/*the next step is to construct encrypted insert query*/
return
0
;
}
debug/store.cc
View file @
fc14f7df
...
@@ -113,6 +113,8 @@ static void write_meta(rawMySQLReturnValue& resraw,std::vector<FieldMetaTrans> &
...
@@ -113,6 +113,8 @@ static void write_meta(rawMySQLReturnValue& resraw,std::vector<FieldMetaTrans> &
mf
.
serialize
();
mf
.
serialize
();
}
}
static
static
void
write_raw_data_to_files
(
rawMySQLReturnValue
&
resraw
,
std
::
vector
<
FieldMetaTrans
>
&
res
,
string
db
,
string
table
){
void
write_raw_data_to_files
(
rawMySQLReturnValue
&
resraw
,
std
::
vector
<
FieldMetaTrans
>
&
res
,
string
db
,
string
table
){
//write metafiles
//write metafiles
...
...
debug/store_new.cc
0 → 100644
View file @
fc14f7df
#include "wrapper/common.hh"
#include "wrapper/reuse.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
;
//This connection mimics the behaviour of MySQL-Proxy
Connect
*
globalConn
;
//must be static, or we get "no previous declaration"
//execute the query and get the rawReturnVale, this struct can be copied.
static
void
init
(){
std
::
string
client
=
"192.168.1.1:1234"
;
//one Wrapper per user.
clients
[
client
]
=
new
WrapperState
();
//Connect phase
ConnectionInfo
ci
(
"localhost"
,
"root"
,
"letmein"
,
3306
);
const
std
::
string
master_key
=
"113341234"
;
char
*
buffer
;
if
((
buffer
=
getcwd
(
NULL
,
0
))
==
NULL
){
perror
(
"getcwd error"
);
}
embeddedDir
=
std
::
string
(
buffer
)
+
"/shadow"
;
SharedProxyState
*
shared_ps
=
new
SharedProxyState
(
ci
,
embeddedDir
,
master_key
,
determineSecurityRating
());
assert
(
0
==
mysql_thread_init
());
//we init embedded database here.
clients
[
client
]
->
ps
=
std
::
unique_ptr
<
ProxyState
>
(
new
ProxyState
(
*
shared_ps
));
clients
[
client
]
->
ps
->
safeCreateEmbeddedTHD
();
//Connect end!!
globalConn
=
new
Connect
(
ci
.
server
,
ci
.
user
,
ci
.
passwd
,
ci
.
port
);
}
static
void
write_meta
(
std
::
vector
<
FieldMetaTrans
>
&
res
,
string
db
,
string
table
){
vector
<
int
>
in
{
1
,
2
,
3
,
4
};
for
(
auto
&
item
:
res
){
item
.
setChoosenFieldLengths
(
in
);
item
.
setChoosenFieldTypes
(
in
);
}
TableMetaTrans
mf
(
db
,
table
,
res
);
mf
.
set_db_table
(
db
,
table
);
mf
.
serialize
();
TableMetaTrans
mf2
;
mf2
.
set_db_table
(
db
,
table
);
mf2
.
deserialize
();
return
;
}
static
void
write_raw_data_to_files
(
std
::
vector
<
FieldMetaTrans
>
&
res
,
string
db
,
string
table
){
//write metafiles
write_meta
(
res
,
db
,
table
);
}
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
++
){
FieldMetaTrans
ft
;
res
.
push_back
(
ft
);
res
.
back
().
trans
(
fms
[
i
]);
std
::
vector
<
int
>
in
{
0
};
res
.
back
().
choose
(
in
);
}
write_raw_data_to_files
(
res
,
db
,
table
);
}
int
main
(
int
argc
,
char
*
argv
[]){
init
();
std
::
string
db
=
"tdb"
,
table
=
"student"
;
store
(
db
,
table
);
return
0
;
}
debug/storetemp.cc
0 → 100644
View file @
fc14f7df
#include "wrapper/common.hh"
#include "wrapper/reuse.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
;
//This connection mimics the behaviour of MySQL-Proxy
Connect
*
globalConn
;
//must be static, or we get "no previous declaration"
//execute the query and get the rawReturnVale, this struct can be copied.
static
void
init
(){
std
::
string
client
=
"192.168.1.1:1234"
;
//one Wrapper per user.
clients
[
client
]
=
new
WrapperState
();
//Connect phase
ConnectionInfo
ci
(
"localhost"
,
"root"
,
"letmein"
,
3306
);
const
std
::
string
master_key
=
"113341234"
;
char
*
buffer
;
if
((
buffer
=
getcwd
(
NULL
,
0
))
==
NULL
){
perror
(
"getcwd error"
);
}
embeddedDir
=
std
::
string
(
buffer
)
+
"/shadow"
;
SharedProxyState
*
shared_ps
=
new
SharedProxyState
(
ci
,
embeddedDir
,
master_key
,
determineSecurityRating
());
assert
(
0
==
mysql_thread_init
());
//we init embedded database here.
clients
[
client
]
->
ps
=
std
::
unique_ptr
<
ProxyState
>
(
new
ProxyState
(
*
shared_ps
));
clients
[
client
]
->
ps
->
safeCreateEmbeddedTHD
();
//Connect end!!
globalConn
=
new
Connect
(
ci
.
server
,
ci
.
user
,
ci
.
passwd
,
ci
.
port
);
}
//query for testing purposes
static
std
::
string
getTestQuery
(
SchemaInfo
&
schema
,
std
::
vector
<
FieldMetaTrans
>
&
tfds
,
std
::
string
db
=
"tdb"
,
std
::
string
table
=
"student1"
){
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
tf
:
tfds
){
for
(
auto
item
:
tf
.
getChoosenOnionName
()){
res
+=
item
;
res
+=
" , "
;
}
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_meta
(
rawMySQLReturnValue
&
resraw
,
std
::
vector
<
FieldMetaTrans
>
&
res
,
string
db
,
string
table
){
TableMetaTrans
mf
(
db
,
table
,
res
);
mf
.
set_db_table
(
db
,
table
);
mf
.
serialize
();
}
static
void
write_raw_data_to_files
(
rawMySQLReturnValue
&
resraw
,
std
::
vector
<
FieldMetaTrans
>
&
res
,
string
db
,
string
table
){
//write metafiles
write_meta
(
resraw
,
res
,
db
,
table
);
//write datafiles
write_row_data
(
resraw
,
db
,
table
);
}
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
++
){
FieldMetaTrans
ft
;
res
.
push_back
(
ft
);
res
.
back
().
trans
(
fms
[
i
]);
std
::
vector
<
int
>
in
{
0
};
//this is our strategy !!!!!
res
.
back
().
choose
(
in
);
}
//generate the backup query and then fetch the tuples
std
::
string
backup_query
=
getTestQuery
(
*
schema
,
res
,
db
,
table
);
rawMySQLReturnValue
resraw
=
executeAndGetResultRemote
(
globalConn
,
backup_query
);
//then we should set the type and length of FieldMetaTrans
auto
types
=
resraw
.
fieldTypes
;
auto
lengths
=
resraw
.
lengths
;
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
]);
base_types
++
;
base_lengths
++
;
}
item
.
setChoosenFieldTypes
(
tempTypes
);
item
.
setChoosenFieldLengths
(
tempLengths
);
if
(
item
.
getHasSalt
()){
item
.
setSaltType
(
types
[
base_types
++
]);
item
.
setSaltLength
(
lengths
[
base_lengths
++
]);
}
}
//write the tuples into files
write_raw_data_to_files
(
resraw
,
res
,
db
,
table
);
}
int
main
(
int
argc
,
char
*
argv
[]){
init
();
std
::
string
db
=
"tdb"
,
table
=
"student"
;
store
(
db
,
table
);
return
0
;
}
wrapper/.reuse.
hh
.swp
→
wrapper/.reuse.
cc
.swp
View file @
fc14f7df
No preview for this file type
wrapper/common.cc
View file @
fc14f7df
...
@@ -71,9 +71,9 @@ bool metadata_files::make_path(string directory){
...
@@ -71,9 +71,9 @@ bool metadata_files::make_path(string directory){
}
}
void
metadata_files
::
serialize
(){
void
metadata_files
::
serialize
(
std
::
string
prefix
){
FILE
*
localmeta
=
NULL
;
FILE
*
localmeta
=
NULL
;
string
prefix
=
string
(
"data/"
)
+
db
+
"/"
+
table
;
prefix
=
prefix
+
db
+
"/"
+
table
;
make_path
(
prefix
);
make_path
(
prefix
);
localmeta
=
fopen
((
prefix
+
"/metadata.data"
).
c_str
(),
"w"
);
localmeta
=
fopen
((
prefix
+
"/metadata.data"
).
c_str
(),
"w"
);
...
@@ -110,8 +110,8 @@ void metadata_files::serialize(){
...
@@ -110,8 +110,8 @@ void metadata_files::serialize(){
fclose
(
localmeta
);
fclose
(
localmeta
);
}
}
void
metadata_files
::
deserialize
(
st
ring
filename
){
void
metadata_files
::
deserialize
(
st
d
::
string
filename
,
std
::
string
prefix
){
filename
=
string
(
"data/"
)
+
db
+
"/"
+
table
+
"/"
+
filename
;
filename
=
prefix
+
db
+
"/"
+
table
+
"/"
+
filename
;
ifstream
infile
(
filename
);
ifstream
infile
(
filename
);
string
line
;
string
line
;
while
(
getline
(
infile
,
line
)){
while
(
getline
(
infile
,
line
)){
...
@@ -145,3 +145,181 @@ void metadata_files::deserialize(string filename){
...
@@ -145,3 +145,181 @@ void metadata_files::deserialize(string filename){
infile
.
close
();
infile
.
close
();
}
}
//-==========================================================
string
TableMetaTrans
::
serialize_vec_int
(
string
s
,
vector
<
int
>
vec_int
){
s
+=
":"
;
for
(
auto
item
:
vec_int
){
s
+=
to_string
(
item
)
+=
" "
;
}
s
.
back
()
=
'\n'
;
return
s
;
}
string
TableMetaTrans
::
serialize_vec_str
(
string
s
,
vector
<
string
>
vec_str
){
s
+=
":"
;
for
(
auto
item
:
vec_str
){
s
+=
item
+=
" "
;
}
s
.
back
()
=
'\n'
;
return
s
;
}
vector
<
string
>
TableMetaTrans
::
string_to_vec_str
(
string
line
){
int
start
=
0
,
next
=
0
;
vector
<
string
>
tmp
;
while
((
next
=
line
.
find
(
' '
,
start
))
!=-
1
){
string
item
=
line
.
substr
(
start
,
next
-
start
);
tmp
.
push_back
(
item
);
start
=
next
+
1
;
}
string
item
=
line
.
substr
(
start
);
tmp
.
push_back
(
item
);
return
tmp
;
}
vector
<
int
>
TableMetaTrans
::
string_to_vec_int
(
string
line
){
int
start
=
0
,
next
=
0
;
vector
<
int
>
tmp
;
while
((
next
=
line
.
find
(
' '
,
start
))
!=-
1
){
string
item
=
line
.
substr
(
start
,
next
-
start
);
tmp
.
push_back
(
stoi
(
item
));
start
=
next
+
1
;
}
string
item
=
line
.
substr
(
start
);
tmp
.
push_back
(
stoi
(
item
));
return
tmp
;
}
bool
TableMetaTrans
::
make_path
(
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
){
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
;
}
void
TableMetaTrans
::
serialize
(
std
::
string
filename
,
std
::
string
prefix
){
FILE
*
localmeta
=
NULL
;
prefix
=
prefix
+
db
+
"/"
+
table
+
"/"
;
make_path
(
prefix
);
localmeta
=
fopen
((
prefix
+
filename
).
c_str
(),
"w"
);
string
s
=
string
(
"database:"
)
+
db
;
s
+=
"
\n
"
;
fwrite
(
s
.
c_str
(),
1
,
s
.
size
(),
localmeta
);
s
=
string
(
"table:"
)
+
table
;
s
+=
"
\n
"
;
fwrite
(
s
.
c_str
(),
1
,
s
.
size
(),
localmeta
);
for
(
unsigned
int
i
=
0u
;
i
<
fts
.
size
();
i
++
){
s
=
string
(
"INDEX:"
)
+
fts
[
i
].
getFieldPlainName
()
+
"
\n
"
;
fwrite
(
s
.
c_str
(),
1
,
s
.
size
(),
localmeta
);
//then for each index, that is, for each plain field
s
=
serialize_vec_str
(
"ChoosenOnionName"
,
fts
[
i
].
getChoosenOnionName
());
fwrite
(
s
.
c_str
(),
1
,
s
.
size
(),
localmeta
);
std
::
vector
<
int
>
tmp
;
for
(
auto
item
:
fts
[
i
].
getChoosenOnionO
()){
tmp
.
push_back
(
static_cast
<
int
>
(
item
));
}
s
=
serialize_vec_int
(
"choosenOnionO"
,
tmp
);
fwrite
(
s
.
c_str
(),
1
,
s
.
size
(),
localmeta
);
if
(
fts
[
i
].
getHasSalt
()){
s
=
std
::
string
(
"hasSalt:true
\n
"
);
fwrite
(
s
.
c_str
(),
1
,
s
.
size
(),
localmeta
);
s
=
std
::
string
(
"saltName:"
)
+
fts
[
i
].
getSaltName
()
+
"
\n
"
;
fwrite
(
s
.
c_str
(),
1
,
s
.
size
(),
localmeta
);
s
=
std
::
string
(
"saltType:"
)
+
std
::
to_string
(
fts
[
i
].
getSaltType
())
+
"
\n
"
;
fwrite
(
s
.
c_str
(),
1
,
s
.
size
(),
localmeta
);
s
=
std
::
string
(
"saltLength:"
)
+
std
::
to_string
(
fts
[
i
].
getSaltLength
())
+
"
\n
"
;
fwrite
(
s
.
c_str
(),
1
,
s
.
size
(),
localmeta
);
}
else
{
s
=
std
::
string
(
"hasSalt:false
\n
"
);
fwrite
(
s
.
c_str
(),
1
,
s
.
size
(),
localmeta
);
}
s
=
serialize_vec_int
(
"choosenFieldTypes"
,
fts
[
i
].
getChoosenFieldTypes
());
fwrite
(
s
.
c_str
(),
1
,
s
.
size
(),
localmeta
);
s
=
serialize_vec_int
(
"choosenFieldLengths"
,
fts
[
i
].
getChoosenFieldLengths
());
fwrite
(
s
.
c_str
(),
1
,
s
.
size
(),
localmeta
);
}
fclose
(
localmeta
);
}
void
TableMetaTrans
::
deserialize
(
std
::
string
filename
,
std
::
string
prefix
){
filename
=
prefix
+
db
+
"/"
+
table
+
"/"
+
filename
;
ifstream
infile
(
filename
);
string
line
;
while
(
getline
(
infile
,
line
)){
int
index
=
line
.
find
(
":"
);
string
head
=
line
.
substr
(
0
,
index
);
if
(
head
==
"INDEX"
){
FieldMetaTrans
ft
;
fts
.
push_back
(
ft
);
}
else
if
(
head
==
"database"
){
set_db
(
line
.
substr
(
index
+
1
));
}
else
if
(
head
==
"table"
){
set_table
(
line
.
substr
(
index
+
1
));
}
else
if
(
head
==
"choosenOnionO"
){
string
onionO
=
line
.
substr
(
index
+
1
);
auto
res
=
string_to_vec_int
(
onionO
);
std
::
vector
<
onion
>
tmp
;
for
(
auto
item
:
res
){
tmp
.
push_back
(
static_cast
<
onion
>
(
item
));
}
fts
.
back
().
setChoosenOnionO
(
tmp
);
}
else
if
(
head
==
"ChoosenOnionName"
){
string
names
=
line
.
substr
(
index
+
1
);
auto
res
=
string_to_vec_str
(
names
);
fts
.
back
().
setChoosenOnionName
(
res
);
}
else
if
(
head
==
"choosenFieldTypes"
){
string
fieldTypes
=
line
.
substr
(
index
+
1
);
auto
res
=
string_to_vec_int
(
fieldTypes
);
fts
.
back
().
setChoosenFieldTypes
(
res
);
}
else
if
(
head
==
"choosenFieldLengths"
){
string
fieldLengths
=
line
.
substr
(
index
+
1
);
auto
res
=
string_to_vec_int
(
fieldLengths
);
fts
.
back
().
setChoosenFieldLengths
(
res
);
}
else
if
(
head
==
"hasSalt"
){
std
::
string
hasSaltStr
=
line
.
substr
(
index
+
1
);
if
(
hasSaltStr
==
"true"
){
fts
.
back
().
setHasSalt
(
true
);
}
else
{
fts
.
back
().
setHasSalt
(
false
);
}
}
else
if
(
head
==
"saltName"
){
std
::
string
saltName
=
line
.
substr
(
index
+
1
);
fts
.
back
().
setSaltName
(
saltName
);
}
else
if
(
head
==
"saltType"
){
std
::
string
saltTypeStr
=
line
.
substr
(
index
+
1
);
fts
.
back
().
setSaltType
(
std
::
stoi
(
saltTypeStr
));
}
else
if
(
head
==
"saltLength"
){
std
::
string
saltLengthStr
=
line
.
substr
(
index
+
1
);
fts
.
back
().
setSaltLength
(
std
::
stoi
(
saltLengthStr
));
}
else
{
exit
(
-
1
);
}
}
infile
.
close
();
}
wrapper/common.hh
View file @
fc14f7df
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
#include <fstream>
#include <fstream>
#include <sstream>
#include <sstream>
#include <vector>
#include <vector>
#include "wrapper/reuse.hh"
using
std
::
cout
;
using
std
::
cout
;
using
std
::
cin
;
using
std
::
cin
;
...
@@ -16,6 +17,7 @@ using std::string;
...
@@ -16,6 +17,7 @@ using std::string;
using
std
::
to_string
;
using
std
::
to_string
;
class
metadata_files
{
class
metadata_files
{
public
:
public
:
string
db
,
table
;
string
db
,
table
;
...
@@ -55,6 +57,36 @@ public:
...
@@ -55,6 +57,36 @@ public:
void
set_has_salt
(
vector
<
string
>
input
){
has_salt
=
input
;}
void
set_has_salt
(
vector
<
string
>
input
){
has_salt
=
input
;}
vector
<
string
>
&
get_has_salt
(){
return
has_salt
;}
vector
<
string
>
&
get_has_salt
(){
return
has_salt
;}
void
serialize
();
void
serialize
(
std
::
string
prefix
=
"data/"
);
void
deserialize
(
st
ring
filename
);
void
deserialize
(
st
d
::
string
filename
,
std
::
string
prefix
=
"data/"
);
};
};
class
TableMetaTrans
{
string
db
,
table
;
std
::
vector
<
FieldMetaTrans
>
fts
;
string
serialize_vec_int
(
string
s
,
vector
<
int
>
vec_int
);
string
serialize_vec_str
(
string
s
,
vector
<
string
>
vec_str
);
vector
<
string
>
string_to_vec_str
(
string
line
);
vector
<
int
>
string_to_vec_int
(
string
line
);
static
bool
make_path
(
string
directory
);
public
:
TableMetaTrans
(
std
::
string
idb
,
std
::
string
itable
,
std
::
vector
<
FieldMetaTrans
>
ifts
)
:
db
(
idb
),
table
(
itable
),
fts
(
ifts
){}
TableMetaTrans
(){}
void
set_db
(
std
::
string
idb
){
db
=
idb
;}
string
get_db
(){
return
db
;}
void
set_table
(
string
itable
){
table
=
itable
;}
string
get_table
(){
return
table
;}
std
::
vector
<
FieldMetaTrans
>
getFts
(){
return
fts
;}
void
set_db_table
(
string
idb
,
string
itable
){
db
=
idb
;
table
=
itable
;}
void
serialize
(
std
::
string
filename
=
"metadata.data"
,
std
::
string
prefix
=
"data/"
);
void
deserialize
(
std
::
string
filename
=
"metadata.data"
,
std
::
string
prefix
=
"data/"
);
};
wrapper/reuse.hh
View file @
fc14f7df
...
@@ -64,6 +64,8 @@ class FieldMetaTrans{
...
@@ -64,6 +64,8 @@ class FieldMetaTrans{
FieldMeta
*
originalFm
;
FieldMeta
*
originalFm
;
bool
hasSalt
;
bool
hasSalt
;
std
::
string
saltName
;
std
::
string
saltName
;
int
saltType
;
int
saltLength
;
std
::
vector
<
OnionMeta
*>
onionsOm
;
std
::
vector
<
OnionMeta
*>
onionsOm
;
std
::
vector
<
onion
>
onionsO
;
std
::
vector
<
onion
>
onionsO
;
...
@@ -72,14 +74,40 @@ class FieldMetaTrans{
...
@@ -72,14 +74,40 @@ class FieldMetaTrans{
std
::
vector
<
int
>
choosenIndex
;
std
::
vector
<
int
>
choosenIndex
;
std
::
vector
<
onion
>
choosenOnionO
;
std
::
vector
<
onion
>
choosenOnionO
;
std
::
vector
<
std
::
string
>
choosenOnionName
;
std
::
vector
<
std
::
string
>
choosenOnionName
;
std
::
vector
<
int
>
choosenFieldTypes
;
std
::
vector
<
int
>
choosenFieldLengths
;
public
:
public
:
FieldMeta
*
getOriginalFieldMeta
(){
return
originalFm
;}
void
trans
(
FieldMeta
*
fm
);
void
trans
(
FieldMeta
*
fm
);
void
choose
(
std
::
vector
<
onion
>
onionSet
);
void
choose
(
std
::
vector
<
onion
>
onionSet
);
void
choose
(
std
::
vector
<
int
>
onionIndexSet
);
void
choose
(
std
::
vector
<
int
>
onionIndexSet
);
const
std
::
vector
<
std
::
string
>
getChoosenOnionName
(){
return
choosenOnionName
;}
const
std
::
vector
<
std
::
string
>
getChoosenOnionName
(){
return
choosenOnionName
;}
void
setChoosenOnionName
(
const
std
::
vector
<
std
::
string
>
input
){
choosenOnionName
=
input
;}
const
std
::
vector
<
onion
>
getChoosenOnionO
(){
return
choosenOnionO
;}
void
setChoosenOnionO
(
std
::
vector
<
onion
>
input
){
choosenOnionO
=
input
;}
bool
getHasSalt
(){
return
hasSalt
;}
bool
getHasSalt
(){
return
hasSalt
;}
void
setHasSalt
(
bool
input
){
hasSalt
=
input
;}
std
::
string
getSaltName
(){
return
saltName
;}
std
::
string
getSaltName
(){
return
saltName
;}
void
setSaltName
(
std
::
string
input
){
saltName
=
input
;}
std
::
vector
<
int
>
getChoosenFieldTypes
(){
return
choosenFieldTypes
;}
void
setChoosenFieldTypes
(
std
::
vector
<
int
>
input
){
choosenFieldTypes
=
input
;}
std
::
vector
<
int
>
getChoosenFieldLengths
(){
return
choosenFieldLengths
;}
void
setChoosenFieldLengths
(
std
::
vector
<
int
>
input
){
choosenFieldLengths
=
input
;}
std
::
string
getFieldPlainName
(){
return
originalFm
->
getFieldName
();
}
int
getSaltType
(){
return
saltType
;}
void
setSaltType
(
int
input
){
saltType
=
input
;}
int
getSaltLength
(){
return
saltLength
;}
void
setSaltLength
(
int
input
){
saltLength
=
input
;}
};
};
/*Functions*/
/*Functions*/
...
...
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