All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.sidnlabs.pcap.packet.FlowData Maven / Gradle / Ivy

There is a newer version: 0.2.24
Show newest version
package nl.sidnlabs.pcap.packet;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.Data;

@Data
public class FlowData {

  private int bytesAvail;

  private long lastSequence;
  private long lastSize;

  // add all payloads to a set, this should prevent issues when there are
  // duplicates caused by retransmissions
  private Set payloads = new HashSet<>();

  /**
   * Add new SequencePayload to the list of sequences, if the sequence is out-of-order then it will
   * not be added to the list
   * 
   * @param p SequencePayload
   */
  public void addPayload(SequencePayload p) {
    payloads.add(p);
    lastSequence = p.getSeq().longValue();
    // do not update the lastSize when adding partial data
    // otherwise matching retransmission based on next expected seq will fail
    lastSize = p.getBytes().length;
  }


  public int size() {
    return payloads.size();
  }

  public List getSortedPayloads() {
    return payloads.stream().sorted().collect(Collectors.toList());
  }

  public boolean isMinPayloadAvail() {
    // check if we have enough bytes received for the next dns message
    // add 2 bytes for the dns msg size prefix
    return bytesAvail > 2;
  }



  public long getNextExpectedSequence() {
    return lastSequence + lastSize;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy