-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.h
50 lines (40 loc) · 1.08 KB
/
client.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
#ifndef __CLIENT_H__
#define __CLIENT_H__
#include <cstring>
#include <map>
#include <mutex>
#include <random>
#include <string>
#include <thread>
#include "socket_client.h"
#include "socket_server.h"
#include "Utils.h"
class Client;
std::string strRand(int length);
int keyRand();
std::pair<std::string, int> gendata();
void listen_to_master(Client* client);
class Client{
public:
Client(const char* ip, int port, const char* master_ip, int master_port, time_t _interval);
~Client();
void run_client();
friend void listen_to_master(Client* client);
std::string get_distribution(std::string key);
std::string request_master(std::string sendline);
void clear_local();
char* request_cache(const char* ip, int port, std::string data);
private:
char* _ip;
int _port_to_master;
char* _master_ip;
int _master_port;
SocketClient _socket_client;
const static int MAXLEN = 4096;
char* buff;
std::map<std::string, std::string> _local_hash;
std::mutex _hash_lock;
bool _is_write = true;
time_t _interval;
};
#endif