Percy++
A C++ implementation of Private Information Retrieval (PIR) protocols
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
percyparams.h
Go to the documentation of this file.
1 // Percy++ Copyright 2007,2012,2013,2014
2 // Ian Goldberg <iang@cs.uwaterloo.ca>,
3 // Casey Devet <cjdevet@uwaterloo.ca>,
4 // Paul Hendry <pshendry@uwaterloo.ca>,
5 // Ryan Henry <rhenry@cs.uwaterloo.ca>
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of version 2 of the GNU General Public License as
9 // published by the Free Software Foundation.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // There is a copy of the GNU General Public License in the COPYING file
17 // packaged with this plugin; if you cannot find it, write to the Free
18 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 // 02110-1301 USA
20 
21 #ifndef __PERCYPARAMS_H__
22 #define __PERCYPARAMS_H__
23 
24 #include <iostream>
25 #include <vector>
26 #include <utility>
27 #include "version.h"
28 #include "percytypes.h"
29 
35 /******************************************************************************
36  ENUMERATED TYPES AND TYPEDEFS
37 ******************************************************************************/
38 
40 enum PercyMode {
41  MODE_NONE = 0,
49 };
50 
52 extern const char * PercyModeStrings[];
53 
55 extern std::ostream& operator<< (std::ostream &os, PercyMode mode);
56 
58 enum DistSplit {
62 };
63 
65 extern const char * DistSplitStrings[];
66 
68 extern std::ostream& operator<< (std::ostream &os, DistSplit mode);
69 
71 typedef std::pair<dbsize_t, dbsize_t> Dimension;
72 
73 
74 /******************************************************************************
75  CLASS DEFINITIONS
76 ******************************************************************************/
77 
79 
80 class PercyParams {
81 public:
93  PercyParams (dbsize_t num_blocks, dbsize_t block_size, dbsize_t word_size,
94  PercyMode mode, nservers_t tau = 0,
95  dbsize_t virtual_block_size = 1);
96 
98  virtual ~PercyParams () {}
99 
100  // Access parameters
102  dbsize_t num_blocks () const { return _num_blocks; }
104  dbsize_t block_size () const { return _block_size; }
108  virtual dbsize_t server_block_size () const { return _block_size; }
110  dbsize_t word_size () const { return _word_size; }
112  dbsize_t words_per_block () const { return _words_per_block; }
114  PercyMode get_mode () const { return mode; }
117  nservers_t tau () const { return _tau; }
120  dbsize_t num_virtual_blocks () const { return _num_virtual_blocks; }
123  dbsize_t virtual_block_size () const { return _virtual_block_size; }
124 
127  virtual dbsize_t request_size (nqueries_t num_queries = 1) const = 0;
130  virtual dbsize_t response_size (nqueries_t num_queries = 1) const = 0;
131 
136  void print (std::ostream& os) const;
137 
142  virtual void print_mode_specific (std::ostream& os) const {}
143 
146  virtual void write (std::ostream &os) const;
147 
153  virtual bool check_compatible (std::istream &is) const;
154 
158  virtual std::vector<const PercyParams*> create_worker_params (
159  std::vector<Dimension> worker_dims) const = 0;
160 
162  virtual bool is_recursive () const { return false; }
163 
164 protected:
166  unsigned char version[3];
168  dbsize_t _num_blocks;
170  dbsize_t _block_size;
172  dbsize_t _word_size;
178  nservers_t _tau;
184 };
185 
186 
188 
190 public:
196  PercyClientParams (const PercyParams * params, nservers_t num_servers = 1,
197  bool is_null = false);
198 
200  virtual ~PercyClientParams () {};
201 
205  void send (std::ostream &os, nservers_t sid) const;
206 
213  bool is_compatible (std::istream &is, nservers_t sid) const;
214 
215  // Access parameters
217  nservers_t num_servers () const { return _num_servers; }
218 
223  void print (std::ostream& os) const;
224 
226  const PercyParams * percy_params () const { return params; }
227 
230  bool is_null () const { return null; }
231 
232 protected:
235 
237  nservers_t _num_servers;
239  bool null;
240 };
241 
242 
244 struct serverinfo {
245  nservers_t sid;
246  char * addr;
247  uint16_t port;
248 };
249 
252 public:
257  PercyServerParams (const PercyParams * params, nservers_t sid,
258  bool be_byzantine = false);
259 
270  PercyServerParams (const PercyParams * params, nservers_t sid,
273  std::vector<nservers_t> worker_sids = std::vector<nservers_t>(),
274  bool fork = false, bool be_byzantine = false);
275 
277  virtual ~PercyServerParams ();
278 
282  void send (std::ostream &os, bool to_worker = false) const;
283 
289  bool is_compatible (std::istream &is) const;
290 
292  bool is_recursive () const { return params->is_recursive(); }
293 
294  // Access parameters
296  nservers_t get_sid () const { return sid; }
298  bool is_byzantine () const { return be_byzantine; }
299 
301  bool is_threaded () const {
302  return (_num_workers == 0 && _num_threads > 0);
303  }
305  nservers_t num_threads () const { return _num_threads; }
307  DistSplit thread_split () const { return tsplit; }
309  bool use_forked_threads () const { return is_forked; }
310 
312  bool is_distributed () const {
313  return _num_workers > 0;
314  }
316  nservers_t num_workers () const { return _num_workers; }
318  DistSplit worker_split () const { return wsplit; }
319 
322  const PercyParams * get_worker_params (nservers_t wid) const {
323  return (wid < worker_params.size() ? worker_params[wid] : NULL);
324  }
326  std::vector<const PercyParams*> get_all_worker_params () const {
327  return worker_params;
328  }
329 
332  const PercyServerParams * get_worker_serverparams (nservers_t wid) const {
333  return (wid < worker_serverparams.size() ? worker_serverparams[wid] : NULL);
334  }
336  std::vector<const PercyServerParams*> get_all_worker_serverparams () const {
337  return worker_serverparams;
338  }
339 
342  const PercyParams * get_thread_params (nservers_t wid) const {
343  return (wid < thread_params.size() ? thread_params[wid] : NULL);
344  }
346  std::vector<const PercyParams*> get_all_thread_params () const {
347  return thread_params;
348  }
349 
352  const PercyServerParams * get_thread_serverparams (nservers_t wid) const {
353  return (wid < thread_serverparams.size() ? thread_serverparams[wid] : NULL);
354  }
356  std::vector<const PercyServerParams*> get_all_thread_serverparams () const {
357  return thread_serverparams;
358  }
359 
365  void print (std::ostream& os) const;
366 
368  virtual void print_distributed (std::ostream& os) const;
369 
371  const PercyParams * percy_params () const { return params; }
372 
373 protected:
376 
378  nservers_t sid;
381 
382  // Distributed members
384  nservers_t _num_threads;
388  bool is_forked;
390  nservers_t _num_workers;
393 
395  std::vector<const PercyParams*> worker_params;
397  std::vector<const PercyServerParams*> worker_serverparams;
398 
400  std::vector<const PercyParams*> thread_params;
402  std::vector<const PercyServerParams*> thread_serverparams;
403 };
404 
405 #endif
bool null
Whether or not the client a null client.
Definition: percyparams.h:239
nservers_t tau() const
Get the level of tau-independence.
Definition: percyparams.h:117
Client parameters.
Definition: percyparams.h:189
dbsize_t word_size() const
Get the word size used to split blocks.
Definition: percyparams.h:110
dbsize_t _num_blocks
Number of database blocks.
Definition: percyparams.h:168
std::ostream & operator<<(std::ostream &os, PercyMode mode)
Prints a PercyMode string to a stream.
const PercyParams * percy_params() const
Get the protocol parameters.
Definition: percyparams.h:371
PercyParams(dbsize_t num_blocks, dbsize_t block_size, dbsize_t word_size, PercyMode mode, nservers_t tau=0, dbsize_t virtual_block_size=1)
Constructor.
PercyServerParams(const PercyParams *params, nservers_t sid, bool be_byzantine=false)
Constructor.
PercyClientParams(const PercyParams *params, nservers_t num_servers=1, bool is_null=false)
Constructor.
dbsize_t _words_per_block
Number of words per database block.
Definition: percyparams.h:174
DistSplit thread_split() const
Get the method of partitioning work amoung threads.
Definition: percyparams.h:307
bool is_compatible(std::istream &is, nservers_t sid) const
Test compatibility with a server.
virtual dbsize_t server_block_size() const
Get the size of each block in the database that the datastore will actually use.
Definition: percyparams.h:108
nservers_t num_threads() const
Get the number of threads being used.
Definition: percyparams.h:305
Aguilar Melchor and Gaborit (2007) CPIR.
Definition: percyparams.h:46
PercyMode get_mode() const
Get the protocol being used.
Definition: percyparams.h:114
std::vector< const PercyParams * > worker_params
The workers' protocol parameters.
Definition: percyparams.h:395
This header contains typedefs for seamless switching between 32- and 64-bit builds of Percy++...
virtual void write(std::ostream &os) const
Write the parameters to a stream to check compatibility.
std::vector< const PercyServerParams * > get_all_worker_serverparams() const
Get the server parameters for all workers.
Definition: percyparams.h:336
nservers_t sid
Server ID.
Definition: percyparams.h:378
const PercyServerParams * get_worker_serverparams(nservers_t wid) const
Get the server parameters for a worker.
Definition: percyparams.h:332
DistSplit
The method used to partition work between threads/workers.
Definition: percyparams.h:58
const PercyParams * get_worker_params(nservers_t wid) const
Get the protocol parameters for a worker.
Definition: percyparams.h:322
nservers_t _num_threads
The number of threads.
Definition: percyparams.h:384
nservers_t _num_servers
The number of servers being queried.
Definition: percyparams.h:237
nservers_t num_servers() const
Get the number of servers being queried.
Definition: percyparams.h:217
uint16_t port
Port.
Definition: percyparams.h:247
const char * DistSplitStrings[]
Strings associated with DistSplit values.
Devet and Goldberg (2014) Hybrid PIR.
Definition: percyparams.h:48
char * addr
Address.
Definition: percyparams.h:246
void print(std::ostream &os) const
Prints the parameters in CSV form.
const PercyParams * params
The protocol parameters.
Definition: percyparams.h:234
bool is_compatible(std::istream &is) const
Test compatibility with client.
dbsize_t _block_size
Size of database blocks in bytes.
Definition: percyparams.h:170
dbsize_t words_per_block() const
Get the number of words per database block.
Definition: percyparams.h:112
bool is_byzantine() const
Check if the server is Byzantine (responses incorrectly/maliciously).
Definition: percyparams.h:298
bool is_distributed() const
Check if the server is using distributed computation.
Definition: percyparams.h:312
dbsize_t virtual_block_size() const
Get the number of actual blocks in a virtual block when being used as one iteration of a recursive pr...
Definition: percyparams.h:123
const PercyServerParams * get_thread_serverparams(nservers_t wid) const
Get the server parameters for a thread.
Definition: percyparams.h:352
const char * PercyModeStrings[]
Strings associated with PercyMode values.
virtual ~PercyParams()
Destructor.
Definition: percyparams.h:98
dbsize_t num_blocks() const
Get the number of blocks in the database.
Definition: percyparams.h:102
void print(std::ostream &os) const
Prints the parameters in CSV form.
DistSplit worker_split() const
Get the method of partitioning work amoung workers.
Definition: percyparams.h:318
bool is_recursive() const
Check if the server is recursive.
Definition: percyparams.h:292
virtual ~PercyClientParams()
Destructor.
Definition: percyparams.h:200
std::pair< dbsize_t, dbsize_t > Dimension
A 2-dimensional coordinate.
Definition: percyparams.h:71
PercyMode mode
Protocol being used.
Definition: percyparams.h:176
void send(std::ostream &os, nservers_t sid) const
Send parameters and sid to server to test compatibility.
const PercyParams * params
The protocol parameters.
Definition: percyparams.h:375
virtual std::vector< const PercyParams * > create_worker_params(std::vector< Dimension > worker_dims) const =0
Create protocol parameters for threads/workers.
bool be_byzantine
Whether or not the server is Byzantine.
Definition: percyparams.h:380
const PercyParams * get_thread_params(nservers_t wid) const
Get the protocol parameters for a thread.
Definition: percyparams.h:342
DistSplit tsplit
The method of partitioning work between threads.
Definition: percyparams.h:386
std::vector< const PercyServerParams * > get_all_thread_serverparams() const
Get the server parameters for all threads.
Definition: percyparams.h:356
dbsize_t _virtual_block_size
Number of actual blocks per virtual block when part of a recursive protocol.
Definition: percyparams.h:183
An abstract base class for a protocol's parameters.
Definition: percyparams.h:80
Partition the bytes of the records.
Definition: percyparams.h:61
std::vector< const PercyParams * > get_all_thread_params() const
Get the protocol parameters for all threads.
Definition: percyparams.h:346
std::vector< const PercyParams * > thread_params
The threads' protocol parameters.
Definition: percyparams.h:400
bool use_forked_threads() const
Check if the server is using forked processes instead of threading.
Definition: percyparams.h:309
nservers_t get_sid() const
Get the server ID.
Definition: percyparams.h:296
virtual void print_mode_specific(std::ostream &os) const
Print mode-specific parameters.
Definition: percyparams.h:142
virtual bool check_compatible(std::istream &is) const
Read the parameters from a stream (as written by write()) and check that they are compatible with the...
Information needed to connect to a server.
Definition: percyparams.h:244
Partition the queries.
Definition: percyparams.h:59
dbsize_t _num_virtual_blocks
Number of virtual blocks when part of a recursive protocol.
Definition: percyparams.h:180
bool is_threaded() const
Check if the server is using multithreading.
Definition: percyparams.h:301
Partition the database records.
Definition: percyparams.h:60
const PercyParams * percy_params() const
Get the protocol parameters.
Definition: percyparams.h:226
std::vector< const PercyServerParams * > worker_serverparams
The workers' server parameters.
Definition: percyparams.h:397
unsigned char version[3]
Percy++ version.
Definition: percyparams.h:166
DistSplit wsplit
The method of partitioning work between workers.
Definition: percyparams.h:392
bool is_null() const
Check if the client is a null client.
Definition: percyparams.h:230
nservers_t _tau
Level of tau-independence.
Definition: percyparams.h:178
nservers_t sid
Server ID.
Definition: percyparams.h:245
PercyMode
A PIR protocol.
Definition: percyparams.h:40
Goldberg (2007) IT-PIR over GF(2^8).
Definition: percyparams.h:43
Server parameters.
Definition: percyparams.h:251
dbsize_t block_size() const
Get the size of each block in the database in bytes.
Definition: percyparams.h:104
nservers_t _num_workers
The number of workers.
Definition: percyparams.h:390
Goldberg (2007) IT-PIR over GF(2^16).
Definition: percyparams.h:44
void print(std::ostream &os) const
Prints the parameters in CSV form.
bool is_forked
Whether or not the server is using forked processes instead of threading.
Definition: percyparams.h:388
std::vector< const PercyParams * > get_all_worker_params() const
Get the protocol parameters for all workers.
Definition: percyparams.h:326
nservers_t num_workers() const
Get the number of worker processes being used.
Definition: percyparams.h:316
virtual bool is_recursive() const
Check if the protocol is recursive.
Definition: percyparams.h:162
std::vector< const PercyServerParams * > thread_serverparams
The threads' server parameters.
Definition: percyparams.h:402
Chor et al. (1995) IT-PIR.
Definition: percyparams.h:45
dbsize_t num_virtual_blocks() const
Get the number of virtual blocks when being used as one iteration of a recursive protocol.
Definition: percyparams.h:120
void send(std::ostream &os, bool to_worker=false) const
Send parameters and sid to client to test compatibility.
Aguilar Melchor and Gaborit (2007) CPIR with recursion.
Definition: percyparams.h:47
virtual void print_distributed(std::ostream &os) const
Print the distributed properties of the server.
virtual dbsize_t request_size(nqueries_t num_queries=1) const =0
Get the size of a client to server request.
Goldberg (2007) IT-PIR over the integers modulo p.
Definition: percyparams.h:42
dbsize_t _word_size
Word size used to split blocks.
Definition: percyparams.h:172
virtual ~PercyServerParams()
Destructor.
virtual dbsize_t response_size(nqueries_t num_queries=1) const =0
Get the size of a server to client response.