From: Janus Varmarken Date: Fri, 17 Aug 2018 23:37:10 +0000 (-0700) Subject: Conversation.java: add infrastructure for tracking TCP segments which have the RST... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=b25db2f55921c78e1caab543fbdaa7ce68700c6d;p=pingpong.git Conversation.java: add infrastructure for tracking TCP segments which have the RST flag set. --- diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Conversation.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Conversation.java index b8681f5..c227ce7 100644 --- a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Conversation.java +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Conversation.java @@ -64,12 +64,17 @@ public class Conversation { /** * List of SYN packets pertaining to this conversation. */ - private List mSynPackets; + private final List mSynPackets; /** * List of pairs FINs and their corresponding ACKs associated with this conversation. */ - private List mFinPackets; + private final List mFinPackets; + + /** + * List of RST packets associated with this conversation. + */ + private final List mRstPackets; /* End instance properties */ /** @@ -113,6 +118,7 @@ public class Conversation { this.mSeqNumbersSrv = new HashSet<>(); this.mSynPackets = new ArrayList<>(); this.mFinPackets = new ArrayList<>(); + this.mRstPackets = new ArrayList<>(); } /** @@ -281,6 +287,37 @@ public class Conversation { mFinPackets.stream().anyMatch(finAckPair -> finAckPair.isAcknowledged() && PcapPacketUtils.isSource(finAckPair.getFinPacket(), mServerIp, mServerPort)); } + /** + * Add a TCP segment for which the RST flag is set to this {@code Conversation}. + * @param packet A {@link PcapPacket} wrapping a TCP segment pertaining to this {@code Conversation} for which the + * RST flag is set. + */ + public void addRstPacket(PcapPacket packet) { + /* + * TODO: + * When now also keeping track of RST packets, should we also...? + * 1) Prevent later packets from being added once a RST segment has been added? + * 2) Extend 'isGracefullyShutdown()' to also consider RST segments, or add another method, 'isShutdown()' that + * both considers FIN/ACK (graceful) as well as RST (abrupt/"ungraceful") shutdown? + * 3) Should it be impossible to associate more than one RST segment with each Conversation? + */ + onAddPrecondition(packet); + TcpPacket tcpPacket = packet.get(TcpPacket.class); + if (tcpPacket == null || !tcpPacket.getHeader().getRst()) { + throw new IllegalArgumentException("not a RST packet"); + } + mRstPackets.add(packet); + } + + /** + * Get the TCP segments pertaining to this {@code Conversation} for which it was detected that the RST flag is set. + * @return the TCP segments pertaining to this {@code Conversation} for which it was detected that the RST flag is + * set. + */ + public List getRstPackets() { + return Collections.unmodifiableList(mRstPackets); + } + // ========================================================================================================= // We simply reuse equals and hashCode methods of String.class to be able to use this class as a key // in a Map.