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 long
static final long
static final long
static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlong
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) Advancesseq
byadvancement
.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.copy()
byte
ctl()
Returns the control byte which defines which flags (such as SYN, ACK, FIN, RST, and PSH) for this segment are set.int
dstPort()
Returns the destination port of this segment.boolean
static boolean
greaterThan
(long s1, long s2) static boolean
greaterThanOrEqualTo
(long s1, long s2) int
hashCode()
boolean
isAck()
Returnstrue
, if the ACK flag is set for this segment.boolean
isFin()
Returnstrue
, if the FIN flag is set for this segment.boolean
Returnstrue
, if only ACK flag (and no other flag) is set for this segment.boolean
Returnstrue
, if only SYN flag (and no other flag) is set for this segment.boolean
isPsh()
Returnstrue
, if the PSH flag is set for this segment.boolean
isRst()
Returnstrue
, if the RST flag is set for this segment.boolean
isSyn()
Returnstrue
, if the SYN flag is set for this segment.long
lastSeq()
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
Returnstrue
, if this segment must be accepted by the receiver.long
nxtSeq()
options()
static long
Returns a random sequence number between [0,4294967295].retain()
long
seq()
Returns the number of this segment.int
srcPort()
Returns the source port of this segment.static long
sub
(long s, long n) toString()
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
-
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:
equals
in classio.netty.buffer.DefaultByteBufHolder
-
hashCode
public int hashCode()- Overrides:
hashCode
in classio.netty.buffer.DefaultByteBufHolder
-
toString
- Overrides:
toString
in classio.netty.buffer.DefaultByteBufHolder
-
copy
- Specified by:
copy
in interfaceio.netty.buffer.ByteBufHolder
- Overrides:
copy
in 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:
retain
in interfaceio.netty.buffer.ByteBufHolder
- Specified by:
retain
in interfaceio.netty.util.ReferenceCounted
- Overrides:
retain
in classio.netty.buffer.DefaultByteBufHolder
-
advanceSeq
public static long advanceSeq(long seq, long advancement) Advancesseq
byadvancement
. 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:
true
ifs1
is less thans2
. Otherwisefalse
-
lessThanOrEqualTo
public static boolean lessThanOrEqualTo(long s1, long s2) - Parameters:
s1
- first non-negative numbers2
- second non-negative number- Returns:
true
ifs1
is 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:
true
ifs1
is greater thans2
. Otherwisefalse
-
greaterThanOrEqualTo
public static boolean greaterThanOrEqualTo(long s1, long s2) - Parameters:
s1
- first non-negative numbers2
- second non-negative number- Returns:
true
ifs1
is greater than or equal tos2
. Otherwisefalse
-