Repository navigation
Expand file tree
/
Copy pathpercyclient.h
More file actions
237 lines (192 loc) · 8.59 KB
/
Copy pathpercyclient.h
File metadata and controls
237 lines (192 loc) · 8.59 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// Percy++ Copyright 2007,2012,2013 Ian Goldberg <iang@cs.uwaterloo.ca>,
// Casey Devet <cjdevet@cs.uwaterloo.ca>,
// Paul Hendry <pshdenry@uwaterloo.ca>,
// Ryan Henry <rhenry@cs.uwaterloo.ca>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of version 2 of the GNU General Public License as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// There is a copy of the GNU General Public License in the COPYING file
// packaged with this plugin; if you cannot find it, write to the Free
// Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301 USA
#ifndef __PERCYCLIENT_H__
#define __PERCYCLIENT_H__
#include <vector>
#include <set>
#include <iostream>
#include <string.h>
#include <vec_vec_ZZ_p.h>
#include <vec_GF2E.h>
#include "percyresult.h"
#include "percyparams.h"
#include "gf2e.h"
#include "rsdecoder.h"
NTL_CLIENT
// Sorry for being a terrible programmer, but...
// this is also defined in percyserver.h!
constexpr dbsize_t WORDS_PER_BLOCK = 1024;
class PercyClient {
public:
virtual ~PercyClient ();
// A factory method used to get a PercyClient for the given mode
static PercyClient * make_client (PercyClientParams ¶ms,
nservers_t num_servers, nservers_t t, sid_t * sids = NULL);
// Send a request for the given block number (0-based) to the
// servers connected with the ostreams in the given vector.
virtual int send_request(vector<dbsize_t> block_numbers,
std::vector<ostream*> &osvec) = 0;
// Send a request for the synchronization info to the
// servers connected with the ostreams in the given vector.
virtual int send_sync_request(std::vector<ostream*> &osvec)
{ return 0; }
// Receive the servers' replies for all requests. Return k, the number of
// servers that returned anything.
virtual nservers_t receive_replies(std::vector<istream*> &isvec) = 0;
// Receive the servers' replies for all requests. Return k, the number of
// servers that returned anything.
virtual nservers_t receive_sync_replies(std::vector<istream*> &isvec)
{ return 0; }
// Process the server's replies and pass the results to results. The
// number of queries that did not successfully decode is returned.
virtual nqueries_t process_replies(nservers_t h,
vector<PercyBlockResults> &results) = 0;
// Do all of the above in one shot.
// current_results will be set to be the results of decoding the blocks
// requested with the current call.
// previous_results will be set to be the results of decoding all blocks
// that were not decoded previously.
nqueries_t fetch_blocks(vector<dbsize_t> block_numbers,
vector<ostream*> &osvec, vector<istream*> &isvec,
vector<PercyBlockResults> ¤t_results,
vector<PercyBlockResults> &previous_results);
nqueries_t fetch_blocks(vector<dbsize_t> block_numbers,
vector<ostream*> &osvec, vector<istream*> &isvec,
vector<PercyBlockResults> ¤t_results);
protected:
// The constructor is protected so that only make_client can be used to
// create one of the derived client types
PercyClient (PercyClientParams ¶ms, nservers_t num_servers,
nservers_t t);
PercyClient (const PercyClient &other);
// Members needed for all modes
PercyClientParams params;
nservers_t num_servers, t;
vector<nservers_t> goodservers;
static const bool randomize = false;
vector<dbsize_t> requested_blocks;
vector<dbsize_t> received_blocks;
};
class PercyClient_ZZ_p : public PercyClient {
public:
PercyClient_ZZ_p (PercyClientParams ¶ms, nservers_t num_servers,
nservers_t t, sid_t * sids);
PercyClient_ZZ_p (const PercyClient_ZZ_p &other);
PercyClient_ZZ_p& operator= (PercyClient_ZZ_p other);
virtual ~PercyClient_ZZ_p ();
// Virtual members as described in PercyClient class
virtual int send_request(vector<dbsize_t> block_numbers,
std::vector<ostream*> &osvec);
virtual nservers_t receive_replies(std::vector<istream*> &isvec);
virtual nqueries_t process_replies(nservers_t h,
vector<PercyBlockResults> &results);
private:
// Based on the sids of the servers, choose the index that will
// correspond with each server. This function is called by the
// constructor.
virtual void choose_indices(sid_t *sids);
// Private ZZ_p members
vec_ZZ_p indices;
vector<vector<ZZ_p> > randmults;
vector<vector<vec_ZZ_p> > answers;
vector<vector<DecoderResult<ZZ_p> > > unfinished_results;
vector<std::set<dbsize_t> > decoded;
};
class PercyClient_Chor : public PercyClient {
public:
PercyClient_Chor (PercyClientParams ¶ms, nservers_t num_servers,
nservers_t t);
PercyClient_Chor (const PercyClient_Chor &other);
PercyClient_Chor& operator= (PercyClient_Chor other);
virtual ~PercyClient_Chor ();
// Virtual members as described in PercyClient class
virtual int send_request(vector<dbsize_t> block_numbers,
std::vector<ostream*> &osvec);
virtual nservers_t receive_replies(std::vector<istream*> &isvec);
virtual nqueries_t process_replies(nservers_t h,
vector<PercyBlockResults> &results);
private:
// Private Chor members
vector<unsigned char *> answers;
};
template<typename GF2E_Element>
class PercyClient_GF2E : public PercyClient {
public:
PercyClient_GF2E (PercyClientParams ¶ms, nservers_t num_servers,
nservers_t t, sid_t * sids);
PercyClient_GF2E (const PercyClient_GF2E &other);
PercyClient_GF2E& operator= (PercyClient_GF2E other);
virtual ~PercyClient_GF2E ();
// Virtual members as described in PercyClient class
virtual int send_request(vector<dbsize_t> block_numbers,
std::vector<ostream*> &osvec);
virtual nservers_t receive_replies(std::vector<istream*> &isvec);
virtual nqueries_t process_replies(nservers_t h,
vector<PercyBlockResults> &results);
protected:
virtual void choose_indices(sid_t *sids);
// A NTL-less method to attempt a fast recovery
bool try_fast_recover (nservers_t h, vector<PercyBlockResults> &results);
// Some helpers for it
void construct_lagrange_coeffs(GF2E_Element *coeffs, GF2E_Element alpha,
nservers_t firstpoint, nservers_t numpoints);
inline GF2E_Element interpolate(const GF2E_Element *word_answers,
const GF2E_Element *coeffs, nservers_t firstpoint,
nservers_t numpoints);
// protected GF2E members
GF2E_Element * indices;
vec_GF2E indices_ntl;
vector<vector<GF2E_Element> > randmults;
vector<GF2E_Element *> answers;
vector<vector<vec_GF2E> > answers_ntl;
vector<vector<DecoderResult<GF2E> > > unfinished_results;
vector<std::set<dbsize_t> > decoded;
};
template<typename GF2E_Element>
class PercyClient_RS_Sync : public PercyClient_GF2E<GF2E_Element> {
public:
PercyClient_RS_Sync (PercyClientParams ¶ms, nservers_t num_servers,
nservers_t t, sid_t * sids);
PercyClient_RS_Sync (const PercyClient_RS_Sync &other);
PercyClient_RS_Sync& operator= (PercyClient_RS_Sync other);
virtual ~PercyClient_RS_Sync ();
// Virtual members as described in PercyClient class
virtual int send_request(vector<dbsize_t> block_numbers,
std::vector<ostream*> &osvec);
virtual int send_sync_request(std::vector<ostream*> &osvec);
virtual nservers_t receive_replies(std::vector<istream*> &isvec);
virtual nservers_t receive_sync_replies(std::vector<istream*> &isvec);
// virtual nqueries_t process_sync_replies(nservers_t h,
// vector<PercyBlockResults> &results);
virtual void interpolate_results (std::vector<GF2E_Element*> &replies,
nservers_t num_servers, dbsize_t num_rows, std::vector<GF2E_Element*> &compressed_results);
virtual int checkSingletonRatio(const std::vector<GF2E_Element*> &compressed_results, dbsize_t i);
virtual void find_unsynchronized_files(nservers_t num_servers, dbsize_t num_rows,
std::vector<GF2E_Element*> &compressed_results);
virtual nqueries_t process_replies(nservers_t h,
vector<PercyBlockResults> &results);
protected:
std::vector<dbsize_t> sync_error_locs; // the locations of the synchronization errors in the database
private:
virtual void choose_indices(sid_t *sids);
// Private RS_SYNC members
// dbsize_t max_unsynchronized; //(appears in the params item)
};
#include "percyclient_impl.h"
#endif