more code
[iotcloud.git] / src / java / iotcloud / Slot.java
index 848edb31f936d05a54a7dcaa6dd171dc85daa8a1..e111f225d785a0e14500f2f78ec0cfb1d0245894 100644 (file)
@@ -5,21 +5,23 @@ import javax.crypto.Mac;
 import java.util.Arrays;
 
 class Slot {
-       public static final int SLOT_SIZE=2048;
-       public static final int HMAC_SIZE=32;
+       static final int SLOT_SIZE=2048;
+       static final int HMAC_SIZE=32;
 
        private long seqnum;
        private byte[] prevhmac;
        private byte[] hmac;
        private long machineid;
        private Vector<Entry> entries;
-
-       Slot(long _seqnum, long _machineid, byte[] _prevhmac, byte[] _hmac, Vector<Entry> _entries) {
+       private int livecount;
+       
+       Slot(long _seqnum, long _machineid, byte[] _prevhmac, byte[] _hmac) {
                seqnum=_seqnum;
                machineid=_machineid;
                prevhmac=_prevhmac;
                hmac=_hmac;
-               entries=_entries;
+               entries=new Vector<Entry>();
+               livecount=1;
        }
        
        Slot(long _seqnum, byte[] _bytes) {
@@ -34,6 +36,11 @@ class Slot {
                return prevhmac;
        }
 
+       void addEntry(Entry e) {
+               entries.add(e);
+               livecount++;
+       }
+       
        Vector<Entry> getEntries() {
                return entries;
        }
@@ -53,12 +60,13 @@ class Slot {
                long seqnum=bb.getLong();
                long machineid=bb.getLong();
                int numentries=bb.getInt();
-               Vector<Entry> entries=new Vector<Entry>();
+               Slot slot=new Slot(seqnum, machineid, prevhmac, hmac);
+               
                for(int i=0;i<numentries;i++) {
-                       entries.add(Entry.decode(bb));
+                       slot.addEntry(Entry.decode(slot, bb));
                }
                
-               return new Slot(seqnum, machineid, prevhmac, hmac, entries);
+               return slot;
        }
 
        byte[] encode(Mac mac) {
@@ -91,7 +99,15 @@ class Slot {
        byte[] getBytes() {
                return null;
        }
+
+       void decrementLiveCount() {
+               livecount--;
+       }
        
+       boolean isLive() {
+               return livecount > 0;
+       }
+
        public String toString() {
                return "<"+getSequenceNumber()+", "+new String(getBytes())+">";
        }