Package org.drasyl.handler.connection
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
FieldsModifier and TypeFieldDescriptionstatic final longstatic final longstatic final longstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongack()Returns the acknowledgement number (which is set to the next expected sequence number from the other party).static longadd(long s, long n) static longadvanceSeq(long seq, long advancement) Advancesseqbyadvancement.intcks()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.copy()bytectl()Returns the control byte which defines which flags (such as SYN, ACK, FIN, RST, and PSH) for this segment are set.intdstPort()Returns the destination port of this segment.booleanstatic booleangreaterThan(long s1, long s2) static booleangreaterThanOrEqualTo(long s1, long s2) inthashCode()booleanisAck()Returnstrue, if the ACK flag is set for this segment.booleanisFin()Returnstrue, if the FIN flag is set for this segment.booleanReturnstrue, if only ACK flag (and no other flag) is set for this segment.booleanReturnstrue, if only SYN flag (and no other flag) is set for this segment.booleanisPsh()Returnstrue, if the PSH flag is set for this segment.booleanisRst()Returnstrue, if the RST flag is set for this segment.booleanisSyn()Returnstrue, if the SYN flag is set for this segment.longlastSeq()Returns the sequence number of the last byte in this segment.intlen()Returns the length (in segments) of this segment.static booleanlessThan(long s1, long s2) static booleanlessThanOrEqualTo(long s1, long s2) booleanReturnstrue, if this segment must be accepted by the receiver.longnxtSeq()options()static longReturns a random sequence number between [0,4294967295].retain()longseq()Returns the number of this segment.intsrcPort()Returns the source port of this segment.static longsub(long s, long n) toString()longwnd()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
-
Field Details
-
MIN_SEQ_NO
public static final long MIN_SEQ_NO- See Also:
-
MAX_SEQ_NO
public static final long MAX_SEQ_NO- See Also:
-
HALF_MAX_SEQ_NO
public static final long HALF_MAX_SEQ_NO- See Also:
-
SEG_HDR_SIZE
public static final int SEG_HDR_SIZE- See Also:
-
-
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()Returnstrue, if the ACK flag is set for this segment.- Returns:
true, if the ACK flag is set for this segment
-
isOnlyAck
public boolean isOnlyAck()Returnstrue, 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()Returnstrue, if the PSH flag is set for this segment.- Returns:
true, if the PSH flag is set for this segment
-
isRst
public boolean isRst()Returnstrue, if the RST flag is set for this segment.- Returns:
true, if the RST flag is set for this segment
-
isSyn
public boolean isSyn()Returnstrue, if the SYN flag is set for this segment.- Returns:
true, if the SYN flag is set for this segment
-
isOnlySyn
public boolean isOnlySyn()Returnstrue, 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()Returnstrue, if the FIN flag is set for this segment.- Returns:
true, if the FIN flag is set for this segment
-
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
- Overrides:
equalsin classio.netty.buffer.DefaultByteBufHolder
-
hashCode
public int hashCode()- Overrides:
hashCodein classio.netty.buffer.DefaultByteBufHolder
-
toString
- Overrides:
toStringin classio.netty.buffer.DefaultByteBufHolder
-
copy
- Specified by:
copyin interfaceio.netty.buffer.ByteBufHolder- Overrides:
copyin classio.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()Returnstrue, if this segment must be accepted by the receiver.- Returns:
true, if this segment must be accepted by the receiver
-
retain
- Specified by:
retainin interfaceio.netty.buffer.ByteBufHolder- Specified by:
retainin interfaceio.netty.util.ReferenceCounted- Overrides:
retainin classio.netty.buffer.DefaultByteBufHolder
-
advanceSeq
public static long advanceSeq(long seq, long advancement) Advancesseqbyadvancement. 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 numbers2- second non-negative number- Returns:
trueifs1is less thans2. Otherwisefalse
-
lessThanOrEqualTo
public static boolean lessThanOrEqualTo(long s1, long s2) - Parameters:
s1- first non-negative numbers2- second non-negative number- Returns:
trueifs1is less than or equal tos2. Otherwisefalse
-
greaterThan
public static boolean greaterThan(long s1, long s2) - Parameters:
s1- first non-negative numbers2- second non-negative number- Returns:
trueifs1is greater thans2. Otherwisefalse
-
greaterThanOrEqualTo
public static boolean greaterThanOrEqualTo(long s1, long s2) - Parameters:
s1- first non-negative numbers2- second non-negative number- Returns:
trueifs1is greater than or equal tos2. Otherwisefalse
-