Class Segment

java.lang.Object
io.netty.buffer.DefaultByteBufHolder
org.drasyl.handler.connection.Segment
All Implemented Interfaces:
io.netty.buffer.ByteBufHolder, io.netty.util.ReferenceCounted

public class Segment extends io.netty.buffer.DefaultByteBufHolder
Message used by ConnectionHandler to provide reliable and ordered delivery of bytes between hosts.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
     
    static final long
     
    static final long
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Segment(int srcPort, int dstPort, long seq, byte ctl, long wnd)
     
    Segment(int srcPort, int dstPort, long seq, long ack, byte ctl)
     
    Segment(int srcPort, int dstPort, long seq, long ack, byte ctl, long wnd)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    ack()
    Returns the acknowledgement number (which is set to the next expected sequence number from the other party).
    static long
    add(long s, long n)
     
    static long
    advanceSeq(long seq, long advancement)
    Advances seq by advancement.
    int
    cks()
    Returns the checksum which is used for error-checking of the header and data, helping to ensure that the information has not been altered in transit due to network corruption.
     
    byte
    ctl()
    Returns the control byte which defines which flags (such as SYN, ACK, FIN, RST, and PSH) for this segment are set.
    int
    Returns the destination port of this segment.
    boolean
     
    static boolean
    greaterThan(long s1, long s2)
     
    static boolean
    greaterThanOrEqualTo(long s1, long s2)
     
    int
     
    boolean
    Returns true, if the ACK flag is set for this segment.
    boolean
    Returns true, if the FIN flag is set for this segment.
    boolean
    Returns true, if only ACK flag (and no other flag) is set for this segment.
    boolean
    Returns true, if only SYN flag (and no other flag) is set for this segment.
    boolean
    Returns true, if the PSH flag is set for this segment.
    boolean
    Returns true, if the RST flag is set for this segment.
    boolean
    Returns true, if the SYN flag is set for this segment.
    long
    Returns the sequence number of the last byte in this segment.
    int
    len()
    Returns the length (in segments) of this segment.
    static boolean
    lessThan(long s1, long s2)
     
    static boolean
    lessThanOrEqualTo(long s1, long s2)
     
    boolean
    Returns true, if this segment must be accepted by the receiver.
    long
     
    Map<org.drasyl.handler.connection.SegmentOption,Object>
     
    static long
    Returns a random sequence number between [0,4294967295].
     
    long
    seq()
    Returns the number of this segment.
    int
    Returns the source port of this segment.
    static long
    sub(long s, long n)
     
     
    long
    wnd()
    Returns the window size which indicates the amount of data, in bytes, that the sender of the segment is willing to accept from the other party, effectively controlling the flow of data and preventing buffer overflow.

    Methods inherited from class io.netty.buffer.DefaultByteBufHolder

    content, contentToString, duplicate, refCnt, release, release, replace, retain, retainedDuplicate, touch, touch

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • Segment

      public Segment(int srcPort, int dstPort, long seq, byte ctl, long wnd)
    • Segment

      public Segment(int srcPort, int dstPort, long seq, long ack, byte ctl, long wnd)
    • Segment

      public Segment(int srcPort, int dstPort, long seq, long ack, byte ctl)
  • Method Details

    • srcPort

      public int srcPort()
      Returns the source port of this segment.
      Returns:
      the source port of this segment
    • dstPort

      public int dstPort()
      Returns the destination port of this segment.
      Returns:
      the destination port of this segment
    • seq

      public long seq()
      Returns the number of this segment.
      Returns:
      the sequence number of this segment
    • ack

      public long ack()
      Returns the acknowledgement number (which is set to the next expected sequence number from the other party).
      Returns:
      the acknowledgement number (which is set to the next expected sequence number from the other party)
    • ctl

      public byte ctl()
      Returns the control byte which defines which flags (such as SYN, ACK, FIN, RST, and PSH) for this segment are set.
      Returns:
      the control byte which defines which flags (such as SYN, ACK, FIN, RST, and PSH) for this segment are set
    • wnd

      public long wnd()
      Returns the window size which indicates the amount of data, in bytes, that the sender of the segment is willing to accept from the other party, effectively controlling the flow of data and preventing buffer overflow.
      Returns:
      the window size which indicates the amount of data, in bytes, that the sender of the segment is willing to accept from the other party, effectively controlling the flow of data and preventing buffer overflow
    • cks

      public int cks()
      Returns the checksum which is used for error-checking of the header and data, helping to ensure that the information has not been altered in transit due to network corruption.
      Returns:
      the checksum which is used for error-checking of the header and data, helping to ensure that the information has not been altered in transit due to network corruption
    • isAck

      public boolean isAck()
      Returns true, if the ACK flag is set for this segment.
      Returns:
      true, if the ACK flag is set for this segment
    • isOnlyAck

      public boolean isOnlyAck()
      Returns true, if only ACK flag (and no other flag) is set for this segment.
      Returns:
      true, if only ACK flag (and no other flag) is set for this segment
    • isPsh

      public boolean isPsh()
      Returns true, if the PSH flag is set for this segment.
      Returns:
      true, if the PSH flag is set for this segment
    • isRst

      public boolean isRst()
      Returns true, if the RST flag is set for this segment.
      Returns:
      true, if the RST flag is set for this segment
    • isSyn

      public boolean isSyn()
      Returns true, if the SYN flag is set for this segment.
      Returns:
      true, if the SYN flag is set for this segment
    • isOnlySyn

      public boolean isOnlySyn()
      Returns true, if only SYN flag (and no other flag) is set for this segment.
      Returns:
      true, if only SYN flag (and no other flag) is set for this segment
    • isFin

      public boolean isFin()
      Returns true, if the FIN flag is set for this segment.
      Returns:
      true, if the FIN flag is set for this segment
    • options

      public Map<org.drasyl.handler.connection.SegmentOption,Object> options()
    • len

      public int len()
      Returns the length (in segments) of this segment.
      Returns:
      the length (in segments) of this segment
    • nxtSeq

      public long nxtSeq()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class io.netty.buffer.DefaultByteBufHolder
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class io.netty.buffer.DefaultByteBufHolder
    • toString

      public String toString()
      Overrides:
      toString in class io.netty.buffer.DefaultByteBufHolder
    • copy

      public Segment copy()
      Specified by:
      copy in interface io.netty.buffer.ByteBufHolder
      Overrides:
      copy in class io.netty.buffer.DefaultByteBufHolder
    • lastSeq

      public long lastSeq()
      Returns the sequence number of the last byte in this segment.
      Returns:
      the sequence number of the last byte in this segment
    • mustBeAcked

      public boolean mustBeAcked()
      Returns true, if this segment must be accepted by the receiver.
      Returns:
      true, if this segment must be accepted by the receiver
    • retain

      public Segment retain()
      Specified by:
      retain in interface io.netty.buffer.ByteBufHolder
      Specified by:
      retain in interface io.netty.util.ReferenceCounted
      Overrides:
      retain in class io.netty.buffer.DefaultByteBufHolder
    • advanceSeq

      public static long advanceSeq(long seq, long advancement)
      Advances seq by advancement. The addition operation is applying the rules specified in RFC 1982: Serial Number Arithmetic.
      Parameters:
      seq -
      advancement -
      Returns:
      advanced sequence number
    • randomSeq

      public static long randomSeq()
      Returns a random sequence number between [0,4294967295].
      Returns:
      random sequence number between [0,4294967295]
    • add

      public static long add(long s, long n)
      Parameters:
      s - sequence number we want increment. Must be non-negative.
      n - number to add. Must be within range [0, (2^(serialBits - 1) - 1)]
      Returns:
      resulting sequence number of the addition
    • sub

      public static long sub(long s, long n)
    • lessThan

      public static boolean lessThan(long s1, long s2)
      Parameters:
      s1 - first non-negative number
      s2 - second non-negative number
      Returns:
      true if s1 is less than s2. Otherwise false
    • lessThanOrEqualTo

      public static boolean lessThanOrEqualTo(long s1, long s2)
      Parameters:
      s1 - first non-negative number
      s2 - second non-negative number
      Returns:
      true if s1 is less than or equal to s2. Otherwise false
    • greaterThan

      public static boolean greaterThan(long s1, long s2)
      Parameters:
      s1 - first non-negative number
      s2 - second non-negative number
      Returns:
      true if s1 is greater than s2. Otherwise false
    • greaterThanOrEqualTo

      public static boolean greaterThanOrEqualTo(long s1, long s2)
      Parameters:
      s1 - first non-negative number
      s2 - second non-negative number
      Returns:
      true if s1 is greater than or equal to s2. Otherwise false