-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclientInstance.h
More file actions
60 lines (44 loc) · 1.79 KB
/
Copy pathclientInstance.h
File metadata and controls
60 lines (44 loc) · 1.79 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
#ifndef CLIENTINSTANCE_H
#define CLIENTINSTANCE_H
#include "network.h"
#define MAXFILENAMESIZE 128
#define INIT_OP 0
#define OPEN_OP 1
#define VOTE_OP 2
#define COMMIT_OP 3
#define ABORT_OP 4
#define CLOSE_OP 5
enum {
NormalReturn = 0,
ErrorReturn = -1,
};
class ClientInstance : public NetworkInstance {
public:
int numServers;
std::set<uint32_t> serverIds;
bool isFileOpen;
uint32_t nextFd; // next file id, a monotonically increasing number
uint32_t updateId; // client total update count in one commit
std::map<uint32_t, Update> updateMap; // cache one commit all updates
std::map<uint32_t, uint32_t> recvServerUpdateId; // all servers response VoteAck updateId. use to find the smallest updateId
ClientInstance(int packetLoss, uint32_t nodeId, int numServers);
~ClientInstance();
int execute(int opCode, int timeout, std::set<uint32_t> *recvServerId, uint32_t fd, char *fileName);
void reset();
bool isRecvMsgMatchCurrOp(unsigned char msgType, int opCode);
bool isRecvMsgInServerIds(uint32_t nodeId);
void sendInitMessage();
int procInitAckMessage(char *buf);
void sendOpenFileMessage(uint32_t fileId, char *fileName);
int procOpenFileAckMessage(char *buf, std::set<uint32_t> *recvServerId);
void sendWriteBlockMessage(uint32_t fileId, uint32_t updateId, int byteOffset, int blockSize, char *buffer, int isStore);
void sendVoteMessage(uint32_t fileId);
int procVoteAckMessage(char *buf, std::set<uint32_t> *recvServerId, uint32_t fd);
void sendCommitMessage(uint32_t fileId);
int procCommitAckMessage(char *buf, std::set<uint32_t> *recvServerId);
void sendAbortMessage(uint32_t fileId);
int procAbortAckMessage(char *buf, std::set<uint32_t> *recvServerId);
void sendCloseMessage(uint32_t fileId);
int procCloseAckMessage(char *buf, std::set<uint32_t> *recvServerId);
};
#endif