Percy++
A C++ implementation of Private Information Retrieval (PIR) protocols
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
percyserver.h
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 // Wouter Lueks <wouter@telox.net>,
6 // Ryan Henry <rhenry@cs.uwaterloo.ca>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of version 2 of the GNU General Public License as
10 // published by the Free Software Foundation.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // There is a copy of the GNU General Public License in the COPYING file
18 // packaged with this plugin; if you cannot find it, write to the Free
19 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 // 02110-1301 USA
21 
22 #ifndef __PERCYSERVER_H__
23 #define __PERCYSERVER_H__
24 
25 #include <iostream>
26 #include "datastore.h"
27 #include "percyparams.h"
28 #include "percystats.h"
29 #include "streams.h"
30 
34 class PercyServer {
35 public:
37  virtual ~PercyServer();
38 
46  const PercyServerParams * params, PercyStats * stats = NULL);
47 
49  void be_byzantine ();
50 
53  static const nqueries_t STRASSEN_OPTIMAL = -1;
54 
57  void set_strassen_max_depth(nqueries_t depth);
58 
61  nqueries_t get_strassen_max_depth();
62 
69  virtual bool handle_request (std::istream &is, std::ostream &os,
70  const std::vector<std::iostream*> &workers =
71  std::vector<std::iostream*>());
72 
79  virtual bool handle_request (const std::vector<std::istream *> &isv,
80  const std::vector<std::ostream *> &osv,
81  const std::vector<std::iostream*> &workers =
82  std::vector<std::iostream*>());
83 
84 protected:
85  friend class RecursiveServer;
86  friend void * thread_work (void * arg);
87 
93  virtual bool handle_request_impl (
94  const std::vector<unsigned char*> &requests,
95  const std::vector<unsigned char*> &responses) = 0;
96 
104  virtual bool handle_request_distributed (
105  const std::vector<unsigned char*> &requests,
106  const std::vector<unsigned char*> &responses,
107  const std::vector<std::iostream*> &workers);
108 
114  virtual bool handle_request_threaded (
115  const std::vector<unsigned char*> &requests,
116  const std::vector<unsigned char*> &responses);
117 
123  virtual void combine_results (unsigned char * result,
124  const std::vector<unsigned char*> &worker_results) = 0;
125 
131  PercyServer (DataStore * datastore, const PercyServerParams * serverparams,
132  PercyStats * stats = NULL);
133 
135  bool byzantine;
143  nqueries_t strassen_max_depth;
147  std::vector<PercyServer*> subservers;
148 
149  // Lightweight matrix implementation
150  template <typename GF2E_Element> class Matrix;
151  template <typename GF2E_Element> class SubMatrix;
152  template <typename GF2E_Element> class Col;
153  template <typename GF2E_Element> class Row;
154  template <typename GF2E_Element> class Elem;
155 
156  template <typename GF2E_Element_>
157  friend std::ostream &operator<<(std::ostream &os,
158  const Matrix<GF2E_Element_> &m);
159  template <typename GF2E_Element_>
160  friend std::ostream &operator<<(std::ostream &os,
161  const SubMatrix<GF2E_Element_> &m);
162 };
163 
164 std::vector<nqueries_t> split_queries (nqueries_t num_queries,
165  nservers_t num_workers);
166 
167 #include "gf2e_matrix.h"
168 
169 #endif
nqueries_t get_strassen_max_depth()
Get the strassen max level.
virtual bool handle_request_threaded(const std::vector< unsigned char * > &requests, const std::vector< unsigned char * > &responses)
Implementation of handle_request() to be used when using multithreading.
std::ostream & operator<<(std::ostream &os, PercyMode mode)
Prints a PercyMode string to a stream.
Definition: percystats.h:66
virtual bool handle_request_impl(const std::vector< unsigned char * > &requests, const std::vector< unsigned char * > &responses)=0
Implementation of handle_request().
nqueries_t strassen_level_reached
The strassen level reached in computation.
Definition: percyserver.h:145
const PercyServerParams * serverparams
The parameters for the server.
Definition: percyserver.h:139
bool byzantine
Whether or not the server is Byzantine.
Definition: percyserver.h:135
A simple database object.
Definition: datastore.h:34
virtual void combine_results(unsigned char *result, const std::vector< unsigned char * > &worker_results)=0
Combines the results of threads/workers when partitioning database records (DIST_SPLIT_RECORDS).
virtual bool handle_request_distributed(const std::vector< unsigned char * > &requests, const std::vector< unsigned char * > &responses, const std::vector< std::iostream * > &workers)
Implementation of handle_request() used for master servers.
Definition: gf2e_matrix.h:110
PercyStats * stats
Statistics collection object.
Definition: percyserver.h:141
An abstract base class for a PIR server.
Definition: percyserver.h:34
void set_strassen_max_depth(nqueries_t depth)
Set the strassen max level.
Definition: gf2e_matrix.h:129
virtual ~PercyServer()
Destructor.
Definition: gf2e_matrix.h:95
virtual bool handle_request(std::istream &is, std::ostream &os, const std::vector< std::iostream * > &workers=std::vector< std::iostream * >())
Handle a request from a single client.
void be_byzantine()
Tell the server to be Byzantine.
PercyServer(DataStore *datastore, const PercyServerParams *serverparams, PercyStats *stats=NULL)
Constructor.
Definition: gf2e_matrix.h:31
A PIR server for recursive PIR protocols.
Definition: recursiveserver.h:31
nqueries_t strassen_max_depth
Maximum depth allowed when using Strassen's matrix multiplication.
Definition: percyserver.h:143
static const nqueries_t STRASSEN_OPTIMAL
Special strassen max level, when set to this value, the optimal strategy is used. ...
Definition: percyserver.h:53
Server parameters.
Definition: percyparams.h:251
DataStore * datastore
The database used by the server.
Definition: percyserver.h:137
Defines the basic structure of protocol parameters (PercyParams), client parameters (PercyClientParam...
std::vector< PercyServer * > subservers
When using multithreading, the server objects for the threads.
Definition: percyserver.h:147
Definition: gf2e_matrix.h:61
static PercyServer * make_server(DataStore *datastore, const PercyServerParams *params, PercyStats *stats=NULL)
Factory method called to get a server object for the given parameters.