public class PseudoTCPBase extends Object
connect()
,
recv(byte[], int, int)
,
send(byte[], int)
,
PseudoTcpNotify
Modifier and Type | Field and Description |
---|---|
private Object |
ack_notify |
(package private) static long |
CLOSED_TIMEOUT
If the connection is closed, once per minute
|
(package private) static short |
CTL_CONNECT |
(package private) static short |
CTL_EXTRA |
(package private) static int |
CTRL_BOUND |
(package private) String |
debugName
Debug name used to identify peers in log messages
|
(package private) static long |
DEF_ACK_DELAY |
(package private) static long |
DEF_RTO |
static int |
DEFAULT_RCV_BUF_SIZE |
static int |
DEFAULT_SND_BUF_SIZE |
(package private) static long |
DEFAULT_TIMEOUT
If there are no pending clocks, wake up every 4 seconds
|
(package private) static short |
FLAG_CTL |
(package private) static short |
FLAG_RST |
(package private) static int |
HEADER_SIZE |
(package private) static int |
ICMP_HEADER_SIZE |
(package private) static int |
IDLE_PING
Idle ping interval
|
(package private) static int |
IDLE_TIMEOUT
Idle timeout(used if keepalive is enabled)
|
(package private) static int |
IP_HEADER_SIZE |
(package private) static int |
JINGLE_HEADER_SIZE |
private static Logger |
logger
The logger.
|
(package private) long |
m_ack_delay |
(package private) boolean |
m_bOutgoing |
(package private) boolean |
m_bReadEnable |
(package private) boolean |
m_bWriteEnable |
(package private) long |
m_conv
Conversation number
|
(package private) long |
m_cwnd
Congestion avoidance, Fast retransmit/recovery, Delayed ACKs
|
(package private) short |
m_dup_acks |
(package private) long |
m_largest |
(package private) long |
m_lastrecv
Last receive timestamp
|
(package private) long |
m_lastsend
Last send timestamp
|
(package private) long |
m_lasttraffic
Last traffic timestamp
|
(package private) long |
m_mss |
(package private) int |
m_msslevel |
(package private) long |
m_mtu_advise |
(package private) PseudoTcpNotify |
m_notify |
(package private) ByteFifoBuffer |
m_rbuf
The receive buffer
|
(package private) int |
m_rbuf_len
Receive buffer length
|
(package private) int |
m_rcv_nxt
The sequence number of the next byte of data that is expected from the
other device
|
(package private) int |
m_rcv_wnd
Receive window size
|
(package private) long |
m_recover |
(package private) List<RSegment> |
m_rlist
List of incoming segments.
|
(package private) long |
m_rto_base
Retransmit timer
|
private short |
m_rwnd_scale
Window scale factor
|
(package private) long |
m_rx_rto
Round-trip calculation
|
(package private) long |
m_rx_rttvar
Round-trip calculation
|
(package private) long |
m_rx_srtt
Round-trip calculation
|
(package private) ByteFifoBuffer |
m_sbuf
The send buffer
|
(package private) int |
m_sbuf_len
The send buffer's size
|
(package private) EnShutdown |
m_shutdown |
(package private) List<SSegment> |
m_slist
Outgoing segments list
|
(package private) long |
m_snd_nxt
The sequence number of the next byte of data to be sent
|
(package private) long |
m_snd_una
The sequence number of the first byte of data that has been sent but not
yet acknowledged
|
private int |
m_snd_wnd
Send window size
|
(package private) long |
m_ssthresh
Congestion avoidance, Fast retransmit/recovery, Delayed ACKs
|
(package private) PseudoTcpState |
m_state
Tcp state
|
(package private) boolean |
m_support_wnd_scale |
private short |
m_swnd_scale
Send window scale factor
|
(package private) long |
m_t_ack |
(package private) long |
m_ts_lastack
Timestamp tracking
|
(package private) long |
m_ts_recent
Timestamp tracking
|
(package private) boolean |
m_use_nagling
Use nagling
|
(package private) static int |
MAX_PACKET |
(package private) static long |
MAX_RTO |
(package private) static long |
MAX_SEQ |
(package private) static int |
MIN_PACKET |
(package private) static long |
MIN_RTO |
(package private) static int[] |
PACKET_MAXIMUMS
Packet maximum levels
|
(package private) static int |
PACKET_OVERHEAD |
private static boolean |
PSEUDO_KEEPALIVE
Keepalive - disabled by default
|
(package private) static short |
TCP_OPT_EOL
End of list
|
(package private) static short |
TCP_OPT_MSS
Maximum segment size
|
(package private) static short |
TCP_OPT_NOOP
No-op
|
(package private) static short |
TCP_OPT_WND_SCALE
Window scale factor
|
(package private) static int |
UDP_HEADER_SIZE |
Constructor and Description |
---|
PseudoTCPBase(PseudoTcpNotify notify,
long conv) |
Modifier and Type | Method and Description |
---|---|
(package private) void |
adjustMTU()
Adjusts MTU
|
(package private) void |
applyOption(short kind,
byte[] data,
long len)
Applies kind of option and it's data
|
(package private) void |
applyWindowScaleOption(short scale_factor)
Applies window scale option with given scale_factor
|
(package private) void |
attemptSend(SendFlags sflags)
This method checks if it's time to send a packet(ack or retransmit
anything)
|
private long |
bound(long lower,
long middle,
long upper) |
private static long |
bytes_to_long(byte[] buffer,
int offset)
Reads 32 bit unsigned int from the buffer at specified offset
|
private static int |
bytes_to_short(byte[] buffer,
int offset)
Reads 16 bit unsigned int from the buffer at specified offset
|
(package private) long |
clock_check(long now)
Calculates timeout in ms for current operation
|
(package private) void |
close(boolean force)
Shuts down the protocol which enters closed state
|
(package private) void |
closedown(IOException e)
This metod is called in case of en error.
|
void |
connect()
Enqueues connect message and starts connection procedure
|
private static byte[] |
copy_buffer(byte[] buffer,
int sOffset,
int len)
Wrapped system function arrayCopy
|
(package private) void |
disableWindowScale()
Disables window scaling.
|
Object |
getAckNotify() |
(package private) int |
getAvailable() |
(package private) int |
getAvailableSendBuffer() |
(package private) long |
getBytesBufferedNotSent() |
(package private) long |
getBytesInFlight() |
(package private) long |
getCongestionWindow() |
(package private) long |
getConversationID() |
short |
getM_rwnd_scale() |
(package private) int |
getM_snd_wnd() |
short |
getM_swnd_scale() |
int |
getMTU() |
long |
getNextClock(long now)
Evaluate next interval between getNextClock calls.
|
(package private) long |
getOption(Option opt)
Retrieve option's value.
|
(package private) int |
getRecvBufferSize() |
(package private) long |
getRoundTripTimeEstimateMs() |
(package private) int |
getSendBufferSize() |
PseudoTcpState |
getState() |
(package private) boolean |
isReceiveBufferFull() |
private static void |
long_to_bytes(long anUnsignedInt,
byte[] buf,
int offset)
Stores 32 bit unsigned int in a buffer at specified offset
|
void |
notifyClock(long now)
This method should be called in time intervals retrieved
from getNextClock
|
void |
notifyMTU(int mtu)
Set the MTU (maximum transmission unit) value
|
boolean |
notifyPacket(byte[] buffer,
int len)
Use this method to notify protocol about packets received from the
network
|
static long |
now() |
(package private) WriteResult |
packet(long seq,
short flags,
long offset,
long len)
Creates a packet starting at offset in the send buffer of
specified length and sends it with help of PseudoTcpNotify.
|
(package private) boolean |
parse(byte[] buffer,
int size)
Creates new segment from the data in buffer which is processed
by the protocol.
|
(package private) boolean |
parseOptions(byte[] data,
int offset,
int len)
Parse and process option in given buffer/offset/length
|
static Segment |
parseSeg(byte[] buffer,
int size)
Method can be used in debugging utilities to parse PTCP segment
|
(package private) boolean |
process(Segment seg)
Process given segment
|
(package private) int |
queue(byte[] buffer,
int offset,
int len,
boolean bCtrl)
Enqueues data segment in the send buffer
|
(package private) void |
queueConnectMessage()
Enqueues connect message
|
int |
recv(byte[] buffer,
int len)
Reads the data available in receive buffer.
|
int |
recv(byte[] buffer,
int offset,
int len)
Reads the data available in receive buffer.
|
(package private) void |
resizeReceiveBuffer(int new_size)
Resizes receive buffer to new_size
|
(package private) void |
resizeSendBuffer(int new_size)
Resizes send buffer to new_size
|
private byte[] |
scrollBuffer(byte[] data,
int nAdjust) |
static String |
segToStr(Segment seg)
Can be used to convert segments to text
|
int |
send(byte[] buffer,
int len)
Enqueues data in the send buffer
|
int |
send(byte[] buffer,
int offset,
int len)
Enqueues data in the send buffer
|
(package private) void |
setConversationID(long convID) |
(package private) void |
setOption(Option opt,
long value)
Sets
Option value |
private static void |
short_to_bytes(int anUnsignedShort,
byte[] buf,
int offset)
Stores 16 bit unsigned int in the buffer at specified offset
|
private static long |
timeDiff(long later,
long earlier)
Util time method
|
(package private) boolean |
transmit(SSegment seg,
long now)
Transmits given segment
|
private static final Logger logger
private static boolean PSEUDO_KEEPALIVE
static final int[] PACKET_MAXIMUMS
static final int MAX_PACKET
static final int MIN_PACKET
static final int IP_HEADER_SIZE
static final int ICMP_HEADER_SIZE
static final int UDP_HEADER_SIZE
static final int JINGLE_HEADER_SIZE
public static final int DEFAULT_RCV_BUF_SIZE
public static final int DEFAULT_SND_BUF_SIZE
static final long MAX_SEQ
static final int HEADER_SIZE
static final int PACKET_OVERHEAD
static final long MIN_RTO
static final long DEF_RTO
static final long MAX_RTO
static final long DEF_ACK_DELAY
static final short FLAG_CTL
static final short FLAG_RST
static final short CTL_CONNECT
static final short CTL_EXTRA
static final short TCP_OPT_EOL
static final short TCP_OPT_NOOP
static final short TCP_OPT_MSS
static final short TCP_OPT_WND_SCALE
static final int CTRL_BOUND
static final long DEFAULT_TIMEOUT
static final long CLOSED_TIMEOUT
static final int IDLE_PING
static final int IDLE_TIMEOUT
PseudoTcpState m_state
long m_conv
boolean m_bReadEnable
boolean m_bWriteEnable
boolean m_bOutgoing
long m_lasttraffic
List<RSegment> m_rlist
long m_lastrecv
int m_rbuf_len
int m_rcv_nxt
int m_rcv_wnd
private short m_rwnd_scale
ByteFifoBuffer m_rbuf
long m_lastsend
long m_snd_nxt
long m_snd_una
int m_sbuf_len
private int m_snd_wnd
private short m_swnd_scale
ByteFifoBuffer m_sbuf
long m_mss
long m_largest
long m_mtu_advise
int m_msslevel
long m_rto_base
long m_ts_recent
long m_ts_lastack
long m_rx_rttvar
long m_rx_srtt
long m_rx_rto
long m_ssthresh
long m_cwnd
short m_dup_acks
long m_recover
long m_t_ack
boolean m_use_nagling
long m_ack_delay
boolean m_support_wnd_scale
PseudoTcpNotify m_notify
EnShutdown m_shutdown
String debugName
private final Object ack_notify
public PseudoTCPBase(PseudoTcpNotify notify, long conv)
notify
- PseudoTcpNotify
implementationconv
- the conversation number used by this instancepublic void connect() throws IOException
IOException
- if the protocol is not in initial statepublic void notifyMTU(int mtu)
mtu
- the new MTU valuepublic int getMTU()
public static long now()
public long getNextClock(long now)
now
- current timestamppublic void notifyClock(long now)
now
- current timestampgetNextClock(long)
public boolean notifyPacket(byte[] buffer, int len)
buffer
- packet's datalen
- data lengthlong getOption(Option opt)
Option
for available optionsopt
- option which value will be retrievedvoid setOption(Option opt, long value)
Option
valueopt
- option whose value will be setvalue
- the value to be setlong getCongestionWindow()
long getBytesInFlight()
long getBytesBufferedNotSent()
int getAvailable()
int getAvailableSendBuffer()
long getRoundTripTimeEstimateMs()
public int recv(byte[] buffer, int offset, int len) throws IOException
buffer
- destination bufferoffset
- destination buffer's offsetlen
- bytes to be readIOException
- if the protocol is not in the connected statepublic int recv(byte[] buffer, int len) throws IOException
buffer
- destination bufferlen
- bytes to be readIOException
- if the protocol is not in the connected statepublic int send(byte[] buffer, int len) throws IOException
buffer
- source data bufferlen
- bytes count to be sentIOException
- if the protocol is not in connected statepublic int send(byte[] buffer, int offset, int len) throws IOException
buffer
- source data bufferoffset
- offset of the source data bufferlen
- bytes count to be sentIOException
- if the protocol is not in connected statevoid close(boolean force)
force
- if true all data received from this moment will be discardedint queue(byte[] buffer, int offset, int len, boolean bCtrl)
buffer
- source bufferoffset
- source buffer's offsetlen
- data lengthbCtrl
- true for control dataWriteResult packet(long seq, short flags, long offset, long len)
seq
- used sequence numberflags
- offset
- in the send bufferlen
- length of data fromPseudoTcpNotify
,
WriteResult
public static Segment parseSeg(byte[] buffer, int size)
buffer
- data to parsesize
- length of the data in the bufferpublic static String segToStr(Segment seg)
seg
- the Segment
to formatboolean parse(byte[] buffer, int size)
buffer
- source buffersize
- data lengthlong clock_check(long now)
now
- current timestamp in msboolean process(Segment seg)
seg
- private static long timeDiff(long later, long earlier)
later
- timestamp in msearlier
- timestamp in msprivate static void long_to_bytes(long anUnsignedInt, byte[] buf, int offset)
anUnsignedInt
- buf
- destination bufferoffset
- destination buffer's offsetprivate static void short_to_bytes(int anUnsignedShort, byte[] buf, int offset)
anUnsignedShort
- buf
- destination bufferoffset
- destination buffer's offsetprivate static long bytes_to_long(byte[] buffer, int offset)
buffer
- offset
- private static int bytes_to_short(byte[] buffer, int offset)
buffer
- offset
- private static byte[] copy_buffer(byte[] buffer, int sOffset, int len)
buffer
- source buffersOffset
- source buffer offsetlen
- bytes count to be copiedprivate long bound(long lower, long middle, long upper)
lower
- middle
- upper
- private byte[] scrollBuffer(byte[] data, int nAdjust)
boolean transmit(SSegment seg, long now)
seg
- segment to be sentnow
- current timestampvoid attemptSend(SendFlags sflags)
sflags
- void closedown(IOException e)
e
- exception to be propagatedvoid adjustMTU()
boolean isReceiveBufferFull()
void disableWindowScale()
void queueConnectMessage()
boolean parseOptions(byte[] data, int offset, int len)
data
- source bufferoffset
- source offsetlen
- byte countvoid applyOption(short kind, byte[] data, long len)
kind
- option typedata
- option's data bufferlen
- data lengthvoid applyWindowScaleOption(short scale_factor)
scale_factor
- void resizeSendBuffer(int new_size)
new_size
- void resizeReceiveBuffer(int new_size)
new_size
- int getM_snd_wnd()
public PseudoTcpState getState()
int getSendBufferSize()
int getRecvBufferSize()
public short getM_rwnd_scale()
public short getM_swnd_scale()
public Object getAckNotify()
long getConversationID()
void setConversationID(long convID)
Copyright © 2018. All rights reserved.