TcpReassembler: Provide method for retreiving reassembled conversations
authorJanus Varmarken <varmarken@gmail.com>
Wed, 18 Jul 2018 01:56:07 +0000 (18:56 -0700)
committerJanus Varmarken <varmarken@gmail.com>
Wed, 18 Jul 2018 01:56:07 +0000 (18:56 -0700)
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/TcpReassembler.java

index 0a66934..cffe9ec 100644 (file)
@@ -4,12 +4,10 @@ import org.pcap4j.core.PcapPacket;
 import org.pcap4j.packet.IpV4Packet;
 import org.pcap4j.packet.TcpPacket;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 /**
- * TODO add class documentation.
+ * Reassembles TCP conversations (streams).
  *
  * @author Janus Varmarken {@literal <jvarmark@uci.edu>}
  * @author Rahmadi Trimananda {@literal <rtrimana@uci.edu>}
@@ -48,6 +46,18 @@ public class TcpReassembler implements PcapPacketConsumer {
         processPacket(pcapPacket);
     }
 
+    /**
+     * Get the reassembled TCP connections. Note that if this is called while packets are still being processed (by
+     * calls to {@link #consumePacket(PcapPacket)}), the behavior is undefined and the returned list may be inconsistent.
+     * @return The reassembled TCP connections.
+     */
+    public List<Conversation> getTcpConversations() {
+        ArrayList<Conversation> combined = new ArrayList<>();
+        combined.addAll(mTerminatedConversations.values());
+        combined.addAll(mOpenConversations.values());
+        return combined;
+    }
+
     private void processPacket(PcapPacket pcapPacket) {
         TcpPacket tcpPacket = pcapPacket.get(TcpPacket.class);
         // Handle client connection initiation attempts.