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
32         int64_t localSequenceNumber;
33         void addShallowEntry(Entry *e);
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
40         Array<char> *getHMAC() { return hmac; }
41         Array<char> *getPrevHMAC() { return prevhmac; }
42         Entry *addEntry(Entry *e);
43         void removeEntry(Entry *e);
44         bool hasSpace(Entry *e);
45         Vector<Entry *> *getEntries();
46         Array<char> *encode(Mac *mac);
47         int getBaseSize() { return 2 * HMAC_SIZE + 2 * sizeof(int64_t) + sizeof(int); }
48         Vector<Entry *> *getLiveEntries(bool resize);
49         int64_t getSequenceNumber() { return seqnum; }
50         int64_t getMachineID() { return machineid; }
51         void setDead();
52         void decrementLiveCount();
53         bool isLive() { return livecount > 0; }
54         Array<char> *getSlotCryptIV();
55         friend Slot *Slot_decode(Table *table, Array<char> *array, Mac *mac);
56 };
57
58 Slot *Slot_decode(Table *table, Array<char> *array, Mac *mac);
59 #endif