76e0fb4e5fbe3d62e6a54afcaf5da0011036cd59
[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         char *prevhmac;
17         /** HMAC of this slot. */
18         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, char *_prevhmac, char *_hmac, int64_t _localSequenceNumber);
38         Slot(Table _table, int64_t _seqnum, int64_t _machineid, char *_prevhmac, int64_t _localSequenceNumber);
39         Slot(Table _table, int64_t _seqnum, int64_t _machineid, int64_t _localSequenceNumber);
40
41         char *getHMAC() { return hmac; }
42         char *getPrevHMAC() { return prevhmac; }
43         Entry *addEntry(Entry *e);
44         void removeEntry(Entry *e);
45         bool hasSpace(Entry *e);
46         Vector<Entry *> *getEntries();
47         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         char *getSlotCryptIV();
56 };
57
58 Slot *Slotdecode(Table *table, char *array, Mac *mac);
59 #endif