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
51ff0337
Commit
51ff0337
authored
Jan 25, 2018
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
able to execute and get column data directly
parent
90fd537c
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
221 additions
and
345 deletions
+221
-345
final_load.cc
debug/final_load.cc
+0
-298
final_store.cc
debug/final_store.cc
+14
-23
test_connect.cc
debug/test_connect.cc
+75
-0
reuse.cc
wrapper/reuse.cc
+98
-18
reuse.hh
wrapper/reuse.hh
+34
-6
No files found.
debug/final_load.cc
deleted
100644 → 0
View file @
90fd537c
This diff is collapsed.
Click to expand it.
debug/final_store.cc
View file @
51ff0337
...
@@ -64,24 +64,22 @@ static void write_meta(rawMySQLReturnValue& resraw,std::vector<FieldMetaTrans> &
...
@@ -64,24 +64,22 @@ static void write_meta(rawMySQLReturnValue& resraw,std::vector<FieldMetaTrans> &
}
}
static
static
void
write_raw_data_to_files
(
rawMySQLReturnValue
&
resraw
,
void
write_raw_data_to_files
(
rawMySQLReturnValue
&
resraw
,
std
::
vector
<
FieldMetaTrans
>
&
res
,
string
db
,
string
table
){
std
::
vector
<
FieldMetaTrans
>
&
res
,
string
db
,
string
table
,
std
::
vector
<
int
>
vlen
,
std
::
vector
<
std
::
string
>
vstr
,
std
::
string
vname
)
{
//write metafiles
//write metafiles
write_meta
(
resraw
,
res
,
db
,
table
);
write_meta
(
resraw
,
res
,
db
,
table
);
//write datafiles
//write datafiles
write_row_data
(
resraw
,
db
,
table
);
write_row_data
(
resraw
,
db
,
table
);
std
::
string
prefix
=
std
::
string
(
"data/"
)
+
db
+
"/"
+
table
+
"/"
;
std
::
vector
<
std
::
string
>
filenames
;
for
(
auto
item
:
resraw
.
fieldNames
){
item
=
prefix
+
item
;
filenames
.
push_back
(
item
);
}
//write special swap
std
::
string
prefix
=
std
::
string
(
"data/"
)
+
db
+
"/"
+
table
+
"/"
;
std
::
string
swpfile
=
prefix
+
vname
;
std
::
string
swpkeyfile
=
prefix
+
vname
+
"key"
;
(
void
)
swpfile
;
(
void
)
swpkeyfile
;
}
}
static
void
store
(
std
::
string
db
,
std
::
string
table
){
static
void
store
(
std
::
string
db
,
std
::
string
table
){
...
@@ -103,14 +101,7 @@ static void store(std::string db, std::string table){
...
@@ -103,14 +101,7 @@ static void store(std::string db, std::string table){
//generate the backup query and then fetch the tuples
//generate the backup query and then fetch the tuples
std
::
string
backup_query
=
getTestQuery
(
*
schema
,
res
,
db
,
table
);
std
::
string
backup_query
=
getTestQuery
(
*
schema
,
res
,
db
,
table
);
std
::
vector
<
int
>
vlen
;
rawMySQLReturnValue
resraw
=
executeAndGetResultRemote
(
globalConn
,
backup_query
);
std
::
vector
<
std
::
string
>
vstr
;
std
::
string
vname
;
rawMySQLReturnValue
resraw
=
executeAndGetResultRemoteWithOneVariableLen
(
globalConn
,
backup_query
,
vlen
,
vstr
,
vname
);
//then we should set the type and length of FieldMetaTrans
//then we should set the type and length of FieldMetaTrans
auto
types
=
resraw
.
fieldTypes
;
auto
types
=
resraw
.
fieldTypes
;
...
@@ -133,7 +124,7 @@ static void store(std::string db, std::string table){
...
@@ -133,7 +124,7 @@ static void store(std::string db, std::string table){
}
}
//write the tuples into files
//write the tuples into files
write_raw_data_to_files
(
resraw
,
res
,
db
,
table
,
vlen
,
vstr
,
vname
);
write_raw_data_to_files
(
resraw
,
res
,
db
,
table
);
}
}
int
int
...
...
debug/test_connect.cc
0 → 100644
View file @
51ff0337
/*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"
#include "wrapper/insert_lib.hh"
#include "util/constants.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
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
);
}
//========================================================================================//
int
main
(
int
argc
,
char
*
argv
[]){
init
();
create_embedded_thd
(
0
);
std
::
string
db
=
"tdb"
,
table
=
"student"
;
std
::
string
ip
=
"localhost"
;
if
(
argc
==
4
){
ip
=
std
::
string
(
argv
[
1
]);
db
=
std
::
string
(
argv
[
2
]);
table
=
std
::
string
(
argv
[
3
]);
}
std
::
string
query
=
"select * from ttt.student;"
;
executeAndGetColumnData
(
globalConn
,
query
);
return
0
;
}
wrapper/reuse.cc
View file @
51ff0337
...
@@ -361,6 +361,47 @@ executeAndGetResultRemote(Connect * curConn,std::string query){
...
@@ -361,6 +361,47 @@ executeAndGetResultRemote(Connect * curConn,std::string query){
}
}
MySQLColumnData
executeAndGetColumnData
(
Connect
*
curConn
,
std
::
string
query
){
std
::
unique_ptr
<
DBResult
>
dbres
;
curConn
->
execute
(
query
,
&
dbres
);
MySQLColumnData
myRaw
;
if
(
dbres
==
nullptr
||
dbres
->
n
==
NULL
){
std
::
cout
<<
"no results"
<<
std
::
endl
;
return
myRaw
;
}
int
num
=
mysql_num_rows
(
dbres
->
n
);
int
numOfFields
=
mysql_num_fields
(
dbres
->
n
);
MYSQL_FIELD
*
field
;
MYSQL_ROW
row
;
while
(
(
field
=
mysql_fetch_field
(
dbres
->
n
))
)
{
myRaw
.
fieldNames
.
push_back
(
std
::
string
(
field
->
name
));
myRaw
.
fieldTypes
.
push_back
(
field
->
type
);
myRaw
.
maxLengths
.
push_back
(
field
->
max_length
);
}
for
(
int
i
=
0
;
i
<
numOfFields
;
i
++
){
myRaw
.
columnData
.
push_back
(
std
::
vector
<
std
::
string
>
());
}
if
(
num
!=
0
){
while
(
(
row
=
mysql_fetch_row
(
dbres
->
n
))
){
//what's the difference between fieldlen
unsigned
long
*
fieldLen
=
mysql_fetch_lengths
(
dbres
->
n
);
for
(
int
i
=
0
;
i
<
numOfFields
;
i
++
){
if
(
row
[
i
]
==
NULL
)
myRaw
.
columnData
[
i
].
push_back
(
"NULL"
);
else
myRaw
.
columnData
[
i
].
push_back
(
std
::
string
(
row
[
i
],
fieldLen
[
i
]));
}
}
}
return
myRaw
;
}
rawMySQLReturnValue
rawMySQLReturnValue
executeAndGetResultRemoteWithOneVariableLen
(
Connect
*
curConn
,
executeAndGetResultRemoteWithOneVariableLen
(
Connect
*
curConn
,
std
::
string
query
,
std
::
string
query
,
...
@@ -437,8 +478,6 @@ write_row_data(rawMySQLReturnValue& resraw,std::string db,std::string table,std:
...
@@ -437,8 +478,6 @@ write_row_data(rawMySQLReturnValue& resraw,std::string db,std::string table,std:
string should be escaped before being written into the file */
string should be escaped before being written into the file */
void
void
writeRowdataEscapeString
(
const
std
::
vector
<
std
::
string
>
&
column
,
writeRowdataEscapeString
(
const
std
::
vector
<
std
::
string
>
&
column
,
std
::
string
db
,
std
::
string
table
,
std
::
string
columnFilename
,
std
::
string
columnFilename
,
unsigned
int
maxLength
)
{
unsigned
int
maxLength
)
{
FILE
*
dataFileHandler
=
fopen
(
columnFilename
.
c_str
(),
"w"
);
FILE
*
dataFileHandler
=
fopen
(
columnFilename
.
c_str
(),
"w"
);
...
@@ -458,8 +497,6 @@ writeRowdataEscapeString(const std::vector<std::string> &column,
...
@@ -458,8 +497,6 @@ writeRowdataEscapeString(const std::vector<std::string> &column,
*/
*/
void
void
writeRowdataNum
(
const
std
::
vector
<
std
::
string
>
&
column
,
writeRowdataNum
(
const
std
::
vector
<
std
::
string
>
&
column
,
std
::
string
db
,
std
::
string
table
,
std
::
string
columnFilename
)
{
std
::
string
columnFilename
)
{
FILE
*
dataFileHandler
=
fopen
(
columnFilename
.
c_str
(),
"w"
);
FILE
*
dataFileHandler
=
fopen
(
columnFilename
.
c_str
(),
"w"
);
const
std
::
string
token
=
"
\n
"
;
const
std
::
string
token
=
"
\n
"
;
...
@@ -471,6 +508,63 @@ writeRowdataNum(const std::vector<std::string> &column,
...
@@ -471,6 +508,63 @@ writeRowdataNum(const std::vector<std::string> &column,
}
}
void
loadFileEscape
(
std
::
string
filename
,
std
::
vector
<
std
::
string
>
&
res
,
unsigned
int
maxLength
)
{
std
::
ifstream
infile
(
filename
);
std
::
string
line
;
char
*
buf
=
new
char
[
2
*
maxLength
+
1u
];
while
(
std
::
getline
(
infile
,
line
)){
size_t
len
=
reverse_escape_string_for_mysql_modify
(
buf
,
line
.
c_str
());
std
::
string
temp
(
buf
,
len
);
res
.
push_back
(
temp
);
}
infile
.
close
();
}
void
loadFileEscapeLimitCount
(
std
::
string
filename
,
std
::
vector
<
std
::
string
>
&
res
,
unsigned
int
maxLength
,
int
limit
)
{
std
::
ifstream
infile
(
filename
);
std
::
string
line
;
char
*
buf
=
new
char
[
2
*
maxLength
+
1u
];
int
localCount
=
0
;
while
(
std
::
getline
(
infile
,
line
)){
size_t
len
=
reverse_escape_string_for_mysql_modify
(
buf
,
line
.
c_str
());
std
::
string
temp
(
buf
,
len
);
res
.
push_back
(
temp
);
localCount
++
;
if
(
localCount
==
limit
)
break
;
}
infile
.
close
();
}
void
loadFileNoEscape
(
std
::
string
filename
,
std
::
vector
<
std
::
string
>
&
res
)
{
std
::
ifstream
infile
(
filename
);
std
::
string
line
;
while
(
std
::
getline
(
infile
,
line
))
{
res
.
push_back
(
line
);
}
}
void
loadFileNoEscapeLimitCount
(
std
::
string
filename
,
std
::
vector
<
std
::
string
>
&
res
,
int
limit
){
std
::
ifstream
infile
(
filename
);
std
::
string
line
;
int
localCount
=
0
;
while
(
std
::
getline
(
infile
,
line
))
{
res
.
push_back
(
line
);
localCount
++
;
if
(
localCount
==
limit
)
break
;
}
}
STORE_STRATEGY
currentStrategy
=
STORE_STRATEGY
::
ALL
;
STORE_STRATEGY
currentStrategy
=
STORE_STRATEGY
::
ALL
;
...
@@ -529,17 +623,6 @@ void load_num_file(std::string filename,std::vector<std::string> &res){
...
@@ -529,17 +623,6 @@ void load_num_file(std::string filename,std::vector<std::string> &res){
infile
.
close
();
infile
.
close
();
}
}
void
load_file_escape
(
std
::
string
filename
,
std
::
vector
<
std
::
string
>
&
res
)
{
std
::
ifstream
infile
(
filename
);
std
::
string
line
;
while
(
std
::
getline
(
infile
,
line
)){
res
.
push_back
(
std
::
move
(
line
));
}
infile
.
close
();
}
void
void
load_num_file_count
(
std
::
string
filename
,
load_num_file_count
(
std
::
string
filename
,
std
::
vector
<
std
::
string
>
&
res
,
std
::
vector
<
std
::
string
>
&
res
,
...
@@ -613,6 +696,3 @@ getStringItem(std::string s){
...
@@ -613,6 +696,3 @@ getStringItem(std::string s){
}
}
wrapper/reuse.hh
View file @
51ff0337
...
@@ -40,6 +40,17 @@ struct rawMySQLReturnValue {
...
@@ -40,6 +40,17 @@ struct rawMySQLReturnValue {
void
show
();
void
show
();
};
};
/*Raw return value from mysql*/
struct
MySQLColumnData
{
std
::
vector
<
std
::
vector
<
std
::
string
>>
columnData
;
/*data tuples*/
std
::
vector
<
std
::
string
>
fieldNames
;
std
::
vector
<
enum_field_types
>
fieldTypes
;
std
::
vector
<
int
>
maxLengths
;
/*what's the difference between length and maxlength?*/
};
//representation of one field.
//representation of one field.
struct
FieldMeta_Wrapper
{
struct
FieldMeta_Wrapper
{
bool
hasSalt
;
bool
hasSalt
;
...
@@ -148,6 +159,9 @@ void transform_to_rawMySQLReturnValue(rawMySQLReturnValue & str,ResType & item);
...
@@ -148,6 +159,9 @@ void transform_to_rawMySQLReturnValue(rawMySQLReturnValue & str,ResType & item);
rawMySQLReturnValue
rawMySQLReturnValue
executeAndGetResultRemote
(
Connect
*
curConn
,
std
::
string
query
);
executeAndGetResultRemote
(
Connect
*
curConn
,
std
::
string
query
);
MySQLColumnData
executeAndGetColumnData
(
Connect
*
conn
,
std
::
string
query
);
rawMySQLReturnValue
rawMySQLReturnValue
...
@@ -206,21 +220,35 @@ load_string_file_count(std::string filename,
...
@@ -206,21 +220,35 @@ load_string_file_count(std::string filename,
int
count
);
int
count
);
void
loadFileEscape
(
std
::
string
filename
,
std
::
vector
<
std
::
string
>
&
res
,
unsigned
int
maxLength
);
void
load_file_escape
(
std
::
string
filename
,
void
loadFileNoEscape
(
std
::
string
filename
,
std
::
vector
<
std
::
string
>
&
res
);
std
::
vector
<
std
::
string
>
&
res
);
void
void
writeRowdataEscapeString
(
const
std
::
vector
<
std
::
string
>
&
column
,
writeRowdataEscapeString
(
const
std
::
vector
<
std
::
string
>
&
column
,
std
::
string
db
,
std
::
string
table
,
std
::
string
columnFilename
,
std
::
string
columnFilename
,
unsigned
int
maxLength
);
unsigned
int
maxLength
);
void
void
writeRowdataNum
(
const
std
::
vector
<
std
::
string
>
&
column
,
writeRowdataNum
(
const
std
::
vector
<
std
::
string
>
&
column
,
std
::
string
db
,
std
::
string
table
,
std
::
string
columnFilename
);
std
::
string
columnFilename
);
void
loadFileEscapeLimitCount
(
std
::
string
filename
,
std
::
vector
<
std
::
string
>
&
res
,
unsigned
int
maxLength
,
int
limit
);
void
loadFileNoEscapeLimitCount
(
std
::
string
filename
,
std
::
vector
<
std
::
string
>
&
res
,
int
limit
);
//Connect * initEmbeddedAndRemoteConnection(std::string ip,int port);
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