-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
133 lines (122 loc) · 4.77 KB
/
main.cpp
File metadata and controls
133 lines (122 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: main.cpp
* Author: mahdi
*
* Created on August 24, 2019, 12:10 AM
*/
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include <string>
#include <cmath>
#include <random>
#include <cstring>
#include <fstream>
#include <sstream>
#include <sys/stat.h>
#include <sys/types.h>
#include <chrono>
#include <thread>
#include "ServerOps.hpp"
#include "DBManager.hpp"
#include "RandomDBgenerator.hpp"
#include "lib.hpp"
#include "cxxopts.hpp"
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
string dbDir = "../../1GB/";
int a = 1; // aggregation
size_t M = 1048576; // file size
size_t N = 1024; // number of files
int portNumber = 12345;
int verbose = 0;
int pirVersion = 1;
int DBinOneFile = 0;
string dbFile = "";
int nthreads = 128;
try
{
cxxopts::Options options("hybridPIR", "Truly practical private information retrieval");
options.add_options()
// Mandatory:
("d,directory", "Working DB directory -default:../../10GB", cxxopts::value<string>())
// or
("oneFileDB", "The database is saved in one file", cxxopts::value<string>())
// Optional:
("N", "Number of files in DB", cxxopts::value<int>())
("M", "Size of one file (in bytes)", cxxopts::value<int>())
("a", "Aggregation parameter", cxxopts::value<int>())
("version", "PIR method (1:primePIR256, 2:rsaPRI, 3:hybridPIR, 4:primePIR512) -default:1", cxxopts::value<int>()) // PIR version: 1:primePIR256, 2:rsaPRI, 3:hybridPIR, 4:primePIR512
("generateRandom", "Generate random DB files (requires N and M)") // requires setting N and M
("port", "Server port number -default:12345", cxxopts::value<int>())
("t,threads", "Number of parallel to use -default:16", cxxopts::value<int>())
// General:
("v,verbose", "Show additional details", cxxopts::value<int>())
("h,help", "Print help");
// ("test", "Test program features...TODO to be removed");
auto result = options.parse(argc, argv);
if (result.count("help")) {
cout << options.help();
exit(0);
}
if (!result.count("directory") && !(result.count("oneFileDB") && result.count("M") && result.count("N")))
error("Error, usage: ./server -d DBdirectory\n or: ./server -oneFileDB dbfile.bin -M 1024 -N 1024");
if (result.count("generateRandom") && !(result.count("directory") && result.count("M") && result.count("N")))
error("Error, usage: vPIR -generateRandom -m oneFileSize -n numberOfFiles -d DBdirectory");
if (result.count("directory"))
dbDir = result["directory"].as<string>();
if (result.count("oneFileDB")){
DBinOneFile = 1;
dbFile = result["oneFileDB"].as<string>();
}
if (result.count("threads"))
nthreads = result["threads"].as<int>();
if (result.count("verbose"))
verbose = result["verbose"].as<int>();
if (result.count("M"))
M = result["M"].as<int>();
if (result.count("N"))
N = result["N"].as<int>();
if (result.count("a"))
a = result["a"].as<int>();
if (result.count("version"))
pirVersion = result["version"].as<int>();
if (result.count("port"))
portNumber = result["port"].as<int>();
if (result.count("generateRandom")) {
RandomDBgenerator randomDB;
randomDB.setParameters(dbDir, N, M, verbose);
size_t dbSize = N * M;
if (verbose) cout << "dbSize=" << dbSize << endl;
if (dbSize < 1024*1024*1024) randomDB.generate();
else randomDB.fastGenerate();
}
DBManager newDB(verbose, DBinOneFile, pirVersion);
if (!DBinOneFile)
newDB.processDBDirectory(dbDir);
else
newDB.processDBFile(dbFile, M, N);
if (pirVersion == 1 || pirVersion == 3 || pirVersion == 4)
newDB.loadEntireDBtoMemory();
else if (pirVersion == 2 || pirVersion == 5)
newDB.loadEntireDBtoMemory_mpz();
cout << "main: The DB has been loaded successfully to memory." << endl;
ServerOps serverOperator(&newDB, portNumber, nthreads, verbose);
serverOperator.openConnection();
}
catch (const cxxopts::OptionException& e) {
cout << "main: error parsing options: " << e.what() << endl;
exit(1);
}
return 0;
}