edits
[iotcloud.git] / version2 / src / C / Slot.h
1 #ifndef SLOT_H
2 #define SLOT_H
3
4 #include "common.h"
5 #include "Liveness.h"
6
7 #define SLOT_SIZE 2048
8 #define HMAC_SIZE 32
9
10 class Slot : public Liveness {
11 private:
12         /** Sequence number of the slot. */
13         int64_t seqnum;
14         /** HMAC of previous slot. */
15         Array<char> *prevhmac;
16         /** HMAC of this slot. */
17         Array<char> *hmac;
18         /** Machine that sent this slot. */
19         int64_t machineid;
20         /** Vector of entries in this slot. */
21         Vector<Entry *> *entries;
22         /** Pieces of information that are live. */
23         int livecount;
24         /** Flag that indicates whether this slot is still live for
25          * recording the machine that sent it. */
26         bool seqnumlive;
27         /** Number of chars of free space. */
28         int freespace;
29         /** Reference to Table */
30         Table *table;
31         LastMessage * fakeLastMessage;
32         
33         int64_t localSequenceNumber;
34
35 public:
36         Slot(Table *_table, int64_t _seqnum, int64_t _machineid, Array<char> *_prevhmac, Array<char> *_hmac, int64_t _localSequenceNumber);
37         Slot(Table *_table, int64_t _seqnum, int64_t _machineid, Array<char> *_prevhmac, int64_t _localSequenceNumber);
38         Slot(Table *_table, int64_t _seqnum, int64_t _machineid, int64_t _localSequenceNumber);
39         ~Slot();
40         
41         Array<char> *getHMAC() { return hmac; }
42         Array<char> *getPrevHMAC() { return prevhmac; }
43         Entry *addEntry(Entry *e);
44         void addShallowEntry(Entry *e);
45         bool hasSpace(Entry *e);
46         Vector<Entry *> *getEntries();
47         Array<char> *encode(Mac *mac);
48         int getBaseSize() { return 2 * HMAC_SIZE + 2 * sizeof(int64_t) + sizeof(int); }
49         Vector<Entry *> *getLiveEntries(bool resize);
50         int64_t getSequenceNumber() { return seqnum; }
51         int64_t getMachineID() { return machineid; }
52         void setDead();
53         void decrementLiveCount();
54         bool isLive() { return livecount > 0; }
55         Array<char> *getSlotCryptIV();
56         friend Slot *Slot_decode(Table *table, Array<char> *array, Mac *mac);
57         char getType();
58 };
59
60 Slot *Slot_decode(Table *table, Array<char> *array, Mac *mac);
61 #endif