Percy++
A C++ implementation of Private Information Retrieval (PIR) protocols
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
datastore.h
1 // Percy++ Copyright 2007,2012,2013,2014
2 // Ian Goldberg <iang@cs.uwaterloo.ca>,
3 // Casey Devet <cjdevet@uwaterloo.ca>,
4 // Ryan Henry <rhenry@cs.uwaterloo.ca>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of version 2 of the GNU General Public License as
8 // published by the Free Software Foundation.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // There is a copy of the GNU General Public License in the COPYING file
16 // packaged with this plugin; if you cannot find it, write to the Free
17 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 
20 #ifndef __DATASTORE_H__
21 #define __DATASTORE_H__
22 #include <ZZ.h>
23 #include <NTL/mat_ZZ_p.h>
24 #include <set>
25 #include <map>
26 #include <vector>
27 #include "percyparams.h"
28 
29 NTL_CLIENT
30 
33 
34 class DataStore {
35 private:
36  unsigned char *database;
37 
38 protected:
44  dbsize_t block_size;
46  dbsize_t num_blocks;
48  dbsize_t database_size;
49 
50  // Distributed computation stuff
52  nservers_t num_workers;
55  std::vector<dbsize_t> subdb_offsets;
57  std::vector<DataStore*> subdatastores;
58 
59 public:
63  DataStore (unsigned char * database, const PercyServerParams * params);
64 
66  virtual ~DataStore ();
67 
70  const unsigned char *get_data() const {return database;}
71 
74  void set_database (unsigned char * data = NULL);
75 
78  vector<DataStore*> get_worker_datastores () const {
79  return subdatastores;
80  }
84  DataStore * get_worker_datastore (nservers_t worker_index) const {
85  return (worker_index < num_workers ? subdatastores[worker_index] : NULL);
86  }
87 };
88 
89 
91 
92 class FileDataStore : public DataStore {
93 private:
94  int dbfd;
95  unsigned char *mapptr;
96  dboffset_t map_offset;
97 
98 public:
104  FileDataStore(const char *filename, const PercyServerParams * params,
105  dboffset_t offset = 0);
106 
108  virtual ~FileDataStore();
109 };
110 
111 #endif
virtual ~FileDataStore()
Destructor.
const PercyParams * params
Parameters for the protocol.
Definition: datastore.h:42
dbsize_t num_blocks
Number of blocks in the database.
Definition: datastore.h:46
A simple database object.
Definition: datastore.h:34
vector< DataStore * > get_worker_datastores() const
Get the database objects for the threads/workers.
Definition: datastore.h:78
void set_database(unsigned char *data=NULL)
Change the database pointer.
dbsize_t block_size
Size of each database block in bytes.
Definition: datastore.h:44
DataStore * get_worker_datastore(nservers_t worker_index) const
Get the database object for a thread/worker.
Definition: datastore.h:84
A database that is backed by one contiguous file.
Definition: datastore.h:92
An abstract base class for a protocol's parameters.
Definition: percyparams.h:80
const unsigned char * get_data() const
Get a pointer to the database in memory.
Definition: datastore.h:70
std::vector< DataStore * > subdatastores
The database objects for the threads/workers.
Definition: datastore.h:57
std::vector< dbsize_t > subdb_offsets
The distance from the beginning of the database that each thread/worker's portion of the database beg...
Definition: datastore.h:55
dbsize_t database_size
Total size of the database in bytes.
Definition: datastore.h:48
FileDataStore(const char *filename, const PercyServerParams *params, dboffset_t offset=0)
Constructor.
const PercyServerParams * serverparams
Parameters for the server.
Definition: datastore.h:40
nservers_t num_workers
Number of threads/workers.
Definition: datastore.h:52
Server parameters.
Definition: percyparams.h:251
Defines the basic structure of protocol parameters (PercyParams), client parameters (PercyClientParam...
virtual ~DataStore()
Destructor.
DataStore(unsigned char *database, const PercyServerParams *params)
Constructor.