Changes to Pseudo Tcp:
- fixes bug with connect packet and disabled window scaling - disables window scaling by default - adds isConnected method in PseudoTcpSocket
This commit is contained in:
parent
40e8c691e1
commit
0ee1c41582
@ -330,7 +330,7 @@ public class PseudoTCPBase
|
|||||||
|
|
||||||
m_use_nagling = true;
|
m_use_nagling = true;
|
||||||
m_ack_delay = DEF_ACK_DELAY;
|
m_ack_delay = DEF_ACK_DELAY;
|
||||||
m_support_wnd_scale = true;
|
m_support_wnd_scale = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -343,7 +343,7 @@ public class PseudoTCPBase
|
|||||||
if (m_state != PseudoTcpState.TCP_LISTEN)
|
if (m_state != PseudoTcpState.TCP_LISTEN)
|
||||||
{
|
{
|
||||||
//m_error = PseudoTcpError.EINVAL;
|
//m_error = PseudoTcpError.EINVAL;
|
||||||
throw new IOException("Invalid socket state");
|
throw new IOException("Invalid socket state: "+m_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_state = PseudoTcpState.TCP_SYN_SENT;
|
m_state = PseudoTcpState.TCP_SYN_SENT;
|
||||||
@ -1050,7 +1050,10 @@ public class PseudoTCPBase
|
|||||||
bConnect = true;
|
bConnect = true;
|
||||||
|
|
||||||
// TCP options are in the remainder of the payload after CTL_CONNECT.
|
// TCP options are in the remainder of the payload after CTL_CONNECT.
|
||||||
parseOptions(seg.data, 1, seg.len - 1);
|
if(!parseOptions(seg.data, 1, seg.len - 1))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_state == PseudoTcpState.TCP_LISTEN)
|
if (m_state == PseudoTcpState.TCP_LISTEN)
|
||||||
{
|
{
|
||||||
@ -1855,14 +1858,19 @@ public class PseudoTCPBase
|
|||||||
*/
|
*/
|
||||||
void queueConnectMessage()
|
void queueConnectMessage()
|
||||||
{
|
{
|
||||||
byte[] buff = new byte[4];
|
byte[] buff = null;
|
||||||
buff[0] = CTL_CONNECT & 0xFF;
|
|
||||||
if (m_support_wnd_scale)
|
if (m_support_wnd_scale)
|
||||||
{
|
{
|
||||||
|
buff = new byte[4];
|
||||||
buff[1] = TCP_OPT_WND_SCALE & 0xFF;
|
buff[1] = TCP_OPT_WND_SCALE & 0xFF;
|
||||||
buff[2] = 1;
|
buff[2] = 1;
|
||||||
buff[3] = (byte) (m_rwnd_scale & 0xFF);
|
buff[3] = (byte) (m_rwnd_scale & 0xFF);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buff = new byte[1];
|
||||||
|
}
|
||||||
|
buff[0] = CTL_CONNECT & 0xFF;
|
||||||
m_snd_wnd = buff.length;
|
m_snd_wnd = buff.length;
|
||||||
queue(buff, 0, buff.length, true);
|
queue(buff, 0, buff.length, true);
|
||||||
}
|
}
|
||||||
@ -1873,8 +1881,9 @@ public class PseudoTCPBase
|
|||||||
* @param data source buffer
|
* @param data source buffer
|
||||||
* @param offset source offset
|
* @param offset source offset
|
||||||
* @param len byte count
|
* @param len byte count
|
||||||
|
* @return true if options were properly parsed
|
||||||
*/
|
*/
|
||||||
void parseOptions(byte[] data, int offset, int len)
|
boolean parseOptions(byte[] data, int offset, int len)
|
||||||
{
|
{
|
||||||
List<Short> options_specified = new ArrayList<Short>();
|
List<Short> options_specified = new ArrayList<Short>();
|
||||||
|
|
||||||
@ -1917,8 +1926,10 @@ public class PseudoTCPBase
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger.log(Level.SEVERE, "Invalid option length received.");
|
logger.log(Level.SEVERE,
|
||||||
return;
|
"Invalid option length received: "+opt_len
|
||||||
|
+" data len: "+buf.remaining());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
options_specified.add(kind);
|
options_specified.add(kind);
|
||||||
}
|
}
|
||||||
@ -1934,6 +1945,7 @@ public class PseudoTCPBase
|
|||||||
m_swnd_scale = 0;
|
m_swnd_scale = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -126,6 +126,18 @@ public class PseudoTcpSocket extends Socket
|
|||||||
return getState() == PseudoTcpState.TCP_ESTABLISHED;
|
return getState() == PseudoTcpState.TCP_ESTABLISHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return true if socket is connected or is trying to connect
|
||||||
|
*/
|
||||||
|
public boolean isConnecting()
|
||||||
|
{
|
||||||
|
PseudoTcpState currentState = getState();
|
||||||
|
return currentState == PseudoTcpState.TCP_ESTABLISHED
|
||||||
|
|| currentState == PseudoTcpState.TCP_SYN_RECEIVED
|
||||||
|
|| currentState == PseudoTcpState.TCP_SYN_SENT;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isClosed()
|
public boolean isClosed()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -624,6 +624,7 @@ class PseudoTcpSocketImpl
|
|||||||
logger.log(Level.WARNING,
|
logger.log(Level.WARNING,
|
||||||
"Ignoring packet from " + packet.getAddress()
|
"Ignoring packet from " + packet.getAddress()
|
||||||
+ ":" + packet.getPort() + " should be: " + remoteAddr);
|
+ ":" + packet.getPort() + " should be: " + remoteAddr);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
synchronized (pseudoTcp)
|
synchronized (pseudoTcp)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user