From: Janus Varmarken Date: Sun, 19 Aug 2018 04:34:14 +0000 (-0700) Subject: Conversation.java: make Direction enum public, and add toCompactString method. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=482c473c7b56282a2f85b5d7afb09b9192f0b82a;p=pingpong.git Conversation.java: make Direction enum public, and add toCompactString method. --- 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 c227ce7..e7ebf3b 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 @@ -442,11 +442,13 @@ public class Conversation { } /** - * Determine the direction of {@code packet}. + * Determine the direction of {@code packet}. An {@link IllegalArgumentException} is thrown if {@code packet} does + * not pertain to this conversation. + * * @param packet The packet whose direction is to be determined. * @return A {@link Direction} indicating the direction of the packet. */ - private Direction getDirection(PcapPacket packet) { + public Direction getDirection(PcapPacket packet) { IpV4Packet ipPacket = packet.get(IpV4Packet.class); String ipSrc = ipPacket.getHeader().getSrcAddr().getHostAddress(); String ipDst = ipPacket.getHeader().getDstAddr().getHostAddress(); @@ -465,8 +467,28 @@ public class Conversation { /** * Utility enum for expressing the direction of a packet pertaining to this {@code Conversation}. */ - private enum Direction { - CLIENT_TO_SERVER, SERVER_TO_CLIENT + public enum Direction { + + CLIENT_TO_SERVER { + @Override + public String toCompactString() { + return "C->S"; + } + }, + SERVER_TO_CLIENT { + @Override + public String toCompactString() { + return "S->C"; + } + }; + + + /** + * Get a compact string representation of this {@code Direction}. + * @return a compact string representation of this {@code Direction}. + */ + abstract public String toCompactString(); + } -} \ No newline at end of file +}