-
Notifications
You must be signed in to change notification settings - Fork 1
/
UServerT1V2.h
executable file
·87 lines (75 loc) · 2.07 KB
/
UServerT1V2.h
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
//
// Created by george on 16/11/2017.
//
#ifndef USERVER_USERVER_H
#define USERVER_USERVER_H
#include <istream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <arpa/inet.h>
#include <sys/socket.h>
#include "userverfhesiutils.h"
#include <utility>
#include <map>
#include <bitset>
#include "Serialization.h"
#include <random>
#include "Ciphertext.h"
#include "unistd.h"
using namespace std;
class UServerT1V2 {
private:
// K-means
unsigned k;
map<uint32_t ,bitset<6>> A;
map<uint32_t ,bitset<6>> A_r;
map<uint32_t ,string> cipherMAP;
map<uint32_t ,vector<Ciphertext>> cipherpoints;
map<uint32_t,vector<Ciphertext>> centroids;
map<uint32_t,int> centroids_clusters;
map<int,uint32_t> rev_centroids_clusters;
map<uint32_t,uint32_t> cipherIDs;
int max_round;
int variance_bound;
unsigned dim;
unsigned number_of_points;
// Networking
string u_serverIP;
int u_serverPort;
int u_serverSocket;
string t_serverIP;
int t_serverPort;
int t_serverSocket;
int clientSocket;
map<unsigned,long> clusters_counter;
// Cryptography
FHEcontext *client_context;
FHESIPubKey *client_pubkey;
KeySwitchSI *client_SM;
void socketCreate();
void socketBind();
void socketListen();
void socketAccept();
void handleRequest(int);
void receiveEncryptionParamFromClient(int);
void receiveEncryptedData(int);
void connectToTServer();
ifstream distanceToStream(const Ciphertext &);
void initializeClusters();
void initializeCentroids();
long calculateVariance();
void swapA();
void initializeKMToTServer();
void endKMToTserver();
ifstream centroidsCoefToStream(const Ciphertext &);
void resultsToKClient();
public:
UServerT1V2(string,int,string,int,unsigned ,int max_round=5,int variance_bound=0);
bool sendStream(ifstream,int);
bool sendMessage(int,string);
string receiveMessage(int, int buffersize=64);
ifstream receiveStream(int,string filename="temp.dat");
void log(int,string);
};
#endif //UServerT1V2_UServerT1V2_H