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
8 #define SLOT_SIZE 2048
9 #define HMAC_SIZE 32
10
11 class Slot : public Liveness {
12 private:
13         /** Sequence number of the slot. */
14         int64_t seqnum;
15         /** HMAC of previous slot. */
16         Array<char> *prevhmac;
17         /** HMAC of this slot. */
18         Array<char> *hmac;
19         /** Machine that sent this slot. */
20         int64_t machineid;
21         /** Vector of entries in this slot. */
22         Vector<Entry *> *entries;
23         /** Pieces of information that are live. */
24         int livecount;
25         /** Flag that indicates whether this slot is still live for
26          * recording the machine that sent it. */
27         bool seqnumlive;
28         /** Number of chars of free space. */
29         int freespace;
30         /** Reference to Table */
31         Table *table;
32
33         int64_t localSequenceNumber;
34         void addShallowEntry(Entry *e);
35
36 public:
37         Slot(Table *_table, int64_t _seqnum, int64_t _machineid, Array<char> *_prevhmac, Array<char> *_hmac, int64_t _localSequenceNumber);
38         Slot(Table *_table, int64_t _seqnum, int64_t _machineid, Array<char> *_prevhmac, int64_t _localSequenceNumber);
39         Slot(Table *_table, int64_t _seqnum, int64_t _machineid, int64_t _localSequenceNumber);
40
41         Array<char> *getHMAC() { return hmac; }
42         Array<char> *getPrevHMAC() { return prevhmac; }
43         Entry *addEntry(Entry *e);
44         void removeEntry(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 *Slotdecode(Table *table, Array<char> *array, Mac *mac);
57 };
58
59 Slot *Slotdecode(Table *table, Array<char> *array, Mac *mac);
60 #endif