Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make window size a long, as it can be upto (2^32 - 1)

Fix for #57
  • Loading branch information...
commit ee0707284643499e5a54c0bd9b622bc50d1f487e 1 parent d38bbbc
@shikhar shikhar authored
View
12 src/main/java/net/schmizz/sshj/connection/channel/AbstractChannel.java
@@ -116,9 +116,9 @@ protected AbstractChannel(Connection conn, String type) {
close = new Event<ConnectionException>("chan#" + id + " / " + "close", ConnectionException.chainer, lock);
}
- protected void init(int recipient, int remoteWinSize, int remoteMaxPacketSize) {
+ protected void init(int recipient, long remoteWinSize, long remoteMaxPacketSize) {
this.recipient = recipient;
- rwin = new Window.Remote(remoteWinSize, remoteMaxPacketSize);
+ rwin = new Window.Remote(remoteWinSize, (int) Math.min(remoteMaxPacketSize, Integer.MAX_VALUE));
@hierynomus Owner

Shouldn't the maxPacketSIze also be a long?

@shikhar
shikhar added a note

Technically yes... however a max packet size of even MAX_INT (2 gigabytes!) would be ridiculous.

But yes I think it would be better to move the ceiling on this to the place where it is used (ChannelOutputStream), and in fact lower it to a saner value -- don't want to allocate 2 gigabyte buffers

Thanks Jeroen :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
out = new ChannelOutputStream(this, trans, rwin);
log.info("Initialized - {}", this);
}
@@ -144,7 +144,7 @@ public int getLocalMaxPacketSize() {
}
@Override
- public int getLocalWinSize() {
+ public long getLocalWinSize() {
return lwin.getSize();
}
@@ -164,7 +164,7 @@ public int getRemoteMaxPacketSize() {
}
@Override
- public int getRemoteWinSize() {
+ public long getRemoteWinSize() {
return rwin.getSize();
}
@@ -315,9 +315,9 @@ private void gotChannelRequest(SSHPacket buf)
private void gotWindowAdjustment(SSHPacket buf)
throws ConnectionException {
- final int howMuch;
+ final long howMuch;
try {
- howMuch = buf.readUInt32AsInt();
+ howMuch = buf.readUInt32();
} catch (Buffer.BufferException be) {
throw new ConnectionException(be);
}
View
4 src/main/java/net/schmizz/sshj/connection/channel/Channel.java
@@ -99,7 +99,7 @@ void close()
int getLocalMaxPacketSize();
/** @return the current local window size. */
- int getLocalWinSize();
+ long getLocalWinSize();
/** @return an {@code OutputStream} for this channel. */
OutputStream getOutputStream();
@@ -111,7 +111,7 @@ void close()
int getRemoteMaxPacketSize();
/** @return the current remote window size. */
- int getRemoteWinSize();
+ long getRemoteWinSize();
/** @return the channel type identifier. */
String getType();
View
2  src/main/java/net/schmizz/sshj/connection/channel/ChannelInputStream.java
@@ -159,7 +159,7 @@ public void receive(byte[] data, int offset, int len)
private void checkWindow()
throws TransportException {
synchronized (win) {
- final int adjustment = win.neededAdjustment();
+ final long adjustment = win.neededAdjustment();
if (adjustment > 0) {
log.info("Sending SSH_MSG_CHANNEL_WINDOW_ADJUST to #{} for {} bytes", chan.getRecipient(), adjustment);
trans.write(new SSHPacket(Message.CHANNEL_WINDOW_ADJUST)
View
6 src/main/java/net/schmizz/sshj/connection/channel/ChannelOutputStream.java
@@ -97,12 +97,12 @@ void flush()
throws TransportException, ConnectionException {
flush(packet.wpos() - dataOffset);
}
-
+
void flush(int bufferSize)
throws TransportException, ConnectionException {
while (bufferSize > 0) {
- int remoteWindowSize = win.getSize();
+ long remoteWindowSize = win.getSize();
if (remoteWindowSize == 0)
remoteWindowSize = win.awaitExpansion(remoteWindowSize);
@@ -110,7 +110,7 @@ void flush(int bufferSize)
// a) how much data we have
// b) the max packet size
// c) what the current window size will allow
- final int writeNow = Math.min(bufferSize, Math.min(win.getMaxPacketSize(), remoteWindowSize));
+ final int writeNow = Math.min(bufferSize, (int) Math.min(win.getMaxPacketSize(), remoteWindowSize));
packet.wpos(headerOffset);
packet.putMessageID(Message.CHANNEL_DATA);
View
24 src/main/java/net/schmizz/sshj/connection/channel/Window.java
@@ -28,14 +28,14 @@
protected final int maxPacketSize;
- protected int size;
+ protected long size;
- public Window(int initialWinSize, int maxPacketSize) {
+ public Window(long initialWinSize, int maxPacketSize) {
size = initialWinSize;
this.maxPacketSize = maxPacketSize;
}
- public void expand(int inc) {
+ public void expand(long inc) {
synchronized (lock) {
size += inc;
log.debug("Increasing by {} up to {}", inc, size);
@@ -47,13 +47,13 @@ public int getMaxPacketSize() {
return maxPacketSize;
}
- public int getSize() {
+ public long getSize() {
synchronized (lock) {
return size;
}
}
- public void consume(int dec)
+ public void consume(long dec)
throws ConnectionException {
synchronized (lock) {
size -= dec;
@@ -72,11 +72,11 @@ public String toString() {
public static final class Remote
extends Window {
- public Remote(int initialWinSize, int maxPacketSize) {
+ public Remote(long initialWinSize, int maxPacketSize) {
super(initialWinSize, maxPacketSize);
}
- public int awaitExpansion(int was)
+ public long awaitExpansion(long was)
throws ConnectionException {
synchronized (lock) {
while (size <= was) {
@@ -91,7 +91,7 @@ public int awaitExpansion(int was)
}
}
- public void consume(int howMuch) {
+ public void consume(long howMuch) {
try {
super.consume(howMuch);
} catch (ConnectionException e) { // It's a bug if we consume more than remote allowed
@@ -105,16 +105,16 @@ public void consume(int howMuch) {
public static final class Local
extends Window {
- private final int initialSize;
- private final int threshold;
+ private final long initialSize;
+ private final long threshold;
- public Local(int initialWinSize, int maxPacketSize) {
+ public Local(long initialWinSize, int maxPacketSize) {
super(initialWinSize, maxPacketSize);
this.initialSize = initialWinSize;
threshold = Math.min(maxPacketSize * 20, initialSize / 4);
}
- public int neededAdjustment() {
+ public long neededAdjustment() {
synchronized (lock) {
return (size <= threshold) ? (initialSize - size) : 0;
}
View
2  src/main/java/net/schmizz/sshj/connection/channel/direct/AbstractDirectChannel.java
@@ -71,7 +71,7 @@ public void open()
private void gotOpenConfirmation(SSHPacket buf)
throws ConnectionException {
try {
- init(buf.readUInt32AsInt(), buf.readUInt32AsInt(), buf.readUInt32AsInt());
+ init(buf.readUInt32AsInt(), buf.readUInt32(), buf.readUInt32());
} catch (Buffer.BufferException be) {
throw new ConnectionException(be);
}
View
5 src/main/java/net/schmizz/sshj/connection/channel/forwarded/AbstractForwardedChannel.java
@@ -54,8 +54,9 @@
* First 2 args are standard; the others can be parsed from a CHANNEL_OPEN packet.
*/
- protected AbstractForwardedChannel(Connection conn, String type, int recipient, int remoteWinSize,
- int remoteMaxPacketSize, String origIP, int origPort) {
+ protected AbstractForwardedChannel(Connection conn, String type,
+ int recipient, long remoteWinSize, long remoteMaxPacketSize,
+ String origIP, int origPort) {
super(conn, type);
this.origIP = origIP;
this.origPort = origPort;
View
5 src/main/java/net/schmizz/sshj/connection/channel/forwarded/RemotePortForwarder.java
@@ -127,7 +127,8 @@ public String toString() {
private final Forward fwd;
- public ForwardedTCPIPChannel(Connection conn, int recipient, int remoteWinSize, int remoteMaxPacketSize,
+ public ForwardedTCPIPChannel(Connection conn,
+ int recipient, long remoteWinSize, long remoteMaxPacketSize,
Forward fwd, String origIP, int origPort) {
super(conn, TYPE, recipient, remoteWinSize, remoteMaxPacketSize, origIP, origPort);
this.fwd = fwd;
@@ -217,7 +218,7 @@ public void handleOpen(SSHPacket buf)
throws ConnectionException, TransportException {
final ForwardedTCPIPChannel chan;
try {
- chan = new ForwardedTCPIPChannel(conn, buf.readUInt32AsInt(), buf.readUInt32AsInt(), buf.readUInt32AsInt(),
+ chan = new ForwardedTCPIPChannel(conn, buf.readUInt32AsInt(), buf.readUInt32(), buf.readUInt32(),
new Forward(buf.readString(), buf.readUInt32AsInt()),
buf.readString(), buf.readUInt32AsInt());
} catch (Buffer.BufferException be) {
View
8 src/main/java/net/schmizz/sshj/connection/channel/forwarded/X11Forwarder.java
@@ -34,8 +34,9 @@
public static final String TYPE = "x11";
- public X11Channel(Connection conn, int recipient, int remoteWinSize, int remoteMaxPacketSize, String origIP,
- int origPort) {
+ public X11Channel(Connection conn,
+ int recipient, long remoteWinSize, long remoteMaxPacketSize,
+ String origIP, int origPort) {
super(conn, TYPE, recipient, remoteWinSize, remoteMaxPacketSize, origIP, origPort);
}
@@ -58,8 +59,7 @@ public void handleOpen(SSHPacket buf)
throws ConnectionException, TransportException {
try {
callListener(listener, new X11Channel(conn,
- buf.readUInt32AsInt(),
- buf.readUInt32AsInt(), buf.readUInt32AsInt(),
+ buf.readUInt32AsInt(), buf.readUInt32(), buf.readUInt32(),
buf.readString(), buf.readUInt32AsInt()));
} catch (Buffer.BufferException be) {
throw new ConnectionException(be);
Please sign in to comment.
Something went wrong with that request. Please try again.