-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaster.h
More file actions
53 lines (36 loc) · 1.48 KB
/
master.h
File metadata and controls
53 lines (36 loc) · 1.48 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
#ifndef MASTER_H
#define MASTER_H
#include "utils.h"
#include <iostream>
using namespace std;
class Master{
/* @brief Contains list of servers that contains the chunks of this file.
Chunk size is also included.
*/
typedef struct {
std::string filename;
/* (ip_address, port number, chunk_size). The vector order specifies the chunks order.*/
std::vector<std::tuple<ip_addr, uint32_t, uint32_t>> chunks;
bool is_deleted = false;
size_t hash_value = 0;
// when the file needs to be deleted, the client should send a delete request to the master.
// clean up thread will send the update to the servers.
} client_file;
std::vector<ServerConnection *> chunk_servers;
Logger logger;
size_t available_space;
std::unordered_map<handle_t, client_file> all_files; // mapping of file handle and chunks information.
std::atomic<bool> acceptClients = {false};
std::vector<handle_t> deleted_files;
std::mutex m; // to access `deleted_files` vector.
public:
Master() = default;
void connect(size_t server);
void start(); // should start and accept for chunk server connections.
void startAcceptingClients(); // should start listening for clients.
bool is_enough_space(uint32_t filesize);
ServerConnection *handleNewConnection(int fd);
void handleServerRead(ServerConnection *connection);
void handleServerWrite(ServerConnection *connection);
};
#endif // MASTER_H