2 import java.nio.ByteBuffer;
3 import java.util.HashSet;
6 * Entry for tracking messages that the server rejected. We have to
7 * make sure that all clients know that this message was rejected to
8 * prevent the server from reusing these messages in an attack.
14 class RejectedMessage extends Entry {
15 /* Machine identifier */
16 private long machineid;
17 /* Oldest sequence number in range */
18 private long oldseqnum;
19 /* Newest sequence number in range */
20 private long newseqnum;
21 /* Is the machine identifier of the relevant slots equal to (or not
22 * equal to) the specified machine identifier. */
23 private boolean equalto;
24 /* Set of machines that have not received notification. */
25 private HashSet<Long> watchset;
27 RejectedMessage(Slot slot, long _machineid, long _oldseqnum, long _newseqnum, boolean _equalto) {
51 static Entry decode(Slot slot, ByteBuffer bb) {
52 long machineid=bb.getLong();
53 long oldseqnum=bb.getLong();
54 long newseqnum=bb.getLong();
55 byte equalto=bb.get();
56 return new RejectedMessage(slot, machineid, oldseqnum, newseqnum, equalto==1);
59 void setWatchSet(HashSet<Long> _watchset) {
63 void removeWatcher(long machineid) {
64 if (watchset.remove(machineid))
65 if (watchset.isEmpty())
69 void encode(ByteBuffer bb) {
70 bb.put(Entry.TypeRejectedMessage);
71 bb.putLong(machineid);
72 bb.putLong(oldseqnum);
73 bb.putLong(newseqnum);
74 bb.put(equalto?(byte)1:(byte)0);
78 return 3*Long.BYTES + 2*Byte.BYTES;
82 return Entry.TypeRejectedMessage;
85 Entry getCopy(Slot s) {
86 return new RejectedMessage(s, machineid, oldseqnum, newseqnum, equalto);