Percy++
A C++ implementation of Private Information Retrieval (PIR) protocols
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
recursiveparams.h
1 // Percy++ Copyright 2007,2012,2013,2014
2 // Ian Goldberg <iang@cs.uwaterloo.ca>,
3 // Casey Devet <cjdevet@uwaterloo.ca>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of version 2 of the GNU General Public License as
7 // published by the Free Software Foundation.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // There is a copy of the GNU General Public License in the COPYING file
15 // packaged with this plugin; if you cannot find it, write to the Free
16 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 // 02110-1301 USA
18 
19 #ifndef __RECURSIVEPARAMS_H__
20 #define __RECURSIVEPARAMS_H__
21 
22 #include "percyparams.h"
23 
24 class RecursiveParams : public PercyParams {
25 public:
26  RecursiveParams(dbsize_t num_blocks, dbsize_t block_size,
27  dbsize_t word_size, PercyMode mode,
28  std::vector<const PercyParams*> iterations, nservers_t tau = 0);
29 
30  virtual ~RecursiveParams () {}
31 
32  // Find the indices needed at each iteration for a given record index
33  std::vector<dbsize_t> iteration_indices (dbsize_t index) const;
34 
35  // Accessors
36  std::vector<const PercyParams*> get_iterations () const {
37  return iterations;
38  }
39  const PercyParams * get_iteration (nqueries_t index) const {
40  return (index < iterations.size() ? iterations[index] : NULL);
41  }
42  nqueries_t depth () const {
43  return iterations.size();
44  }
45 
46  // Return the size of the request/response
47  dbsize_t request_size (nqueries_t num_queries = 1) const;
48  dbsize_t response_size (nqueries_t num_queries = 1) const;
49 
50  // Prints the mode-specfic paramaters. Meant to be overloaded by
51  // mode-specific classes
52  virtual void print_mode_specific (std::ostream& os) const {}
53 
54  // For use in distributed computation.
55  virtual std::vector<const PercyParams*> create_worker_params (
56  std::vector<Dimension> worker_dims) const;
57 
58  virtual bool is_recursive () const { return true; }
59 
60 protected:
61  // Write the parameters to a stream to check compatibility
62  virtual void write (std::ostream &os) const;
63 
64  // Read the parameters from a stream (as written by write()) and check that
65  // they are compatible with these parameters.
66  virtual bool check_compatible (std::istream &is) const;
67 
68  // Members
69  std::vector<const PercyParams*> iterations;
70 };
71 
72 
74 public:
75  RecursiveClientParams (const RecursiveParams * rparams,
76  nservers_t num_servers = 1, bool is_null = false);
77 
78  virtual ~RecursiveClientParams ();
79 
80  // Accessors
81  const RecursiveParams * recursive_params () const { return rparams; }
82 
83  std::vector<const PercyClientParams*> get_iterations () const {
84  return iterations;
85  }
86  const PercyClientParams * get_iteration (nqueries_t index) const {
87  return (index < iterations.size() ? iterations[index] : NULL);
88  }
89  nqueries_t depth () const {
90  return iterations.size();
91  }
92 
93 protected:
94  // Recursive params
95  const RecursiveParams * rparams;
96 
97  // Members
98  std::vector<const PercyClientParams*> iterations;
99 };
100 
101 
103 public:
104  RecursiveServerParams (const RecursiveParams * rparams, nservers_t sid,
105  bool is_worker = false, bool be_byzantine = false);
106 
107  // Distributed computation constructor
108 /*
109  RecursiveServerParams (const RecursiveParams * rparams, nservers_t sid,
110  nservers_t num_workers, DistType dtype = DIST_TYPE_NONE,
111  DistSplit dsplit = DIST_SPLIT_RECORDS,
112  std::vector<nservers_t> worker_sids = std::vector<nservers_t>(),
113  bool first_only = false, bool be_byzantine = false);
114 */
115 
116  RecursiveServerParams (const RecursiveParams * rparams, nservers_t sid,
119  std::vector<nservers_t> worker_sids = std::vector<nservers_t>(),
120  bool fork = false, bool first_only = false,
121  bool be_byzantine = false, bool is_worker = false);
122 
123  virtual ~RecursiveServerParams ();
124 
125  // Accessors
126  const RecursiveParams * recursive_params () const { return rparams; }
127  bool dist_first_only () const { return first_only; }
128  bool is_worker () const { return _is_worker; }
129 
130  std::vector<const PercyServerParams*> get_iterations () const {
131  return iterations;
132  }
133  const PercyServerParams * get_iteration (nqueries_t index) const {
134  return (index < iterations.size() ? iterations[index] : NULL);
135  }
136  nqueries_t depth () const {
137  return iterations.size();
138  }
139 
140  std::vector<const RecursiveParams*> get_worker_rparams () const {
141  return worker_rparams;
142  }
143 
144  virtual void print_distributed (std::ostream& os) const;
145 
146 protected:
147  // Recursive params
148  const RecursiveParams * rparams;
149 
150  // Members
151  std::vector<const PercyServerParams*> iterations;
152  bool first_only;
153  bool _is_worker;
154  std::vector<const RecursiveParams*> worker_rparams;
155 };
156 
157 #endif
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 request_size(nqueries_t num_queries=1) const
Get the size of a client to server request.
Definition: recursiveparams.h:24
nservers_t num_threads() const
Get the number of threads being used.
Definition: percyparams.h:305
nservers_t sid
Server ID.
Definition: percyparams.h:378
DistSplit
The method used to partition work between threads/workers.
Definition: percyparams.h:58
nservers_t num_servers() const
Get the number of servers being queried.
Definition: percyparams.h:217
virtual void print_distributed(std::ostream &os) const
Print the distributed properties of the server.
Definition: recursiveparams.h:73
dbsize_t num_blocks() const
Get the number of blocks in the database.
Definition: percyparams.h:102
virtual bool is_recursive() const
Check if the protocol is recursive.
Definition: recursiveparams.h:58
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...
PercyMode mode
Protocol being used.
Definition: percyparams.h:176
bool be_byzantine
Whether or not the server is Byzantine.
Definition: percyparams.h:380
DistSplit tsplit
The method of partitioning work between threads.
Definition: percyparams.h:386
An abstract base class for a protocol's parameters.
Definition: percyparams.h:80
virtual void write(std::ostream &os) const
Write the parameters to a stream to check compatibility.
virtual std::vector< const PercyParams * > create_worker_params(std::vector< Dimension > worker_dims) const
Create protocol parameters for threads/workers.
virtual void print_mode_specific(std::ostream &os) const
Print mode-specific parameters.
Definition: recursiveparams.h:52
Partition the database records.
Definition: percyparams.h:60
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
PercyMode
A PIR protocol.
Definition: percyparams.h:40
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
dbsize_t response_size(nqueries_t num_queries=1) const
Get the size of a server to client response.
nservers_t num_workers() const
Get the number of worker processes being used.
Definition: percyparams.h:316
Defines the basic structure of protocol parameters (PercyParams), client parameters (PercyClientParam...
Definition: recursiveparams.h:102