diff --git a/src/main/java/net/schmizz/sshj/connection/channel/AbstractChannel.java b/src/main/java/net/schmizz/sshj/connection/channel/AbstractChannel.java index 63013c49..1c741f58 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/AbstractChannel.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/AbstractChannel.java @@ -116,9 +116,9 @@ public abstract class AbstractChannel close = new Event("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)); out = new ChannelOutputStream(this, trans, rwin); log.info("Initialized - {}", this); } @@ -144,7 +144,7 @@ public abstract class AbstractChannel } @Override - public int getLocalWinSize() { + public long getLocalWinSize() { return lwin.getSize(); } @@ -164,7 +164,7 @@ public abstract class AbstractChannel } @Override - public int getRemoteWinSize() { + public long getRemoteWinSize() { return rwin.getSize(); } @@ -315,9 +315,9 @@ public abstract class AbstractChannel 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); } diff --git a/src/main/java/net/schmizz/sshj/connection/channel/Channel.java b/src/main/java/net/schmizz/sshj/connection/channel/Channel.java index 8f9b8df1..4ed4f007 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/Channel.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/Channel.java @@ -99,7 +99,7 @@ public interface Channel 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 @@ public interface Channel int getRemoteMaxPacketSize(); /** @return the current remote window size. */ - int getRemoteWinSize(); + long getRemoteWinSize(); /** @return the channel type identifier. */ String getType(); diff --git a/src/main/java/net/schmizz/sshj/connection/channel/ChannelInputStream.java b/src/main/java/net/schmizz/sshj/connection/channel/ChannelInputStream.java index 054d8f50..43b7c7f2 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/ChannelInputStream.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/ChannelInputStream.java @@ -159,7 +159,7 @@ public final class ChannelInputStream 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) diff --git a/src/main/java/net/schmizz/sshj/connection/channel/ChannelOutputStream.java b/src/main/java/net/schmizz/sshj/connection/channel/ChannelOutputStream.java index be6f7e44..38c673aa 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/ChannelOutputStream.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/ChannelOutputStream.java @@ -97,12 +97,12 @@ public final class ChannelOutputStream 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 @@ public final class ChannelOutputStream // 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); diff --git a/src/main/java/net/schmizz/sshj/connection/channel/Window.java b/src/main/java/net/schmizz/sshj/connection/channel/Window.java index 23fac81b..44f6bfae 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/Window.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/Window.java @@ -28,14 +28,14 @@ public abstract class Window { 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 abstract class Window { 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 abstract class Window { 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 abstract class Window { } } - 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 abstract class Window { 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; } diff --git a/src/main/java/net/schmizz/sshj/connection/channel/direct/AbstractDirectChannel.java b/src/main/java/net/schmizz/sshj/connection/channel/direct/AbstractDirectChannel.java index d70f4a99..5e79889d 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/direct/AbstractDirectChannel.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/direct/AbstractDirectChannel.java @@ -71,7 +71,7 @@ public abstract class AbstractDirectChannel 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); } diff --git a/src/main/java/net/schmizz/sshj/connection/channel/forwarded/AbstractForwardedChannel.java b/src/main/java/net/schmizz/sshj/connection/channel/forwarded/AbstractForwardedChannel.java index 6168d96d..da8a3dcc 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/forwarded/AbstractForwardedChannel.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/forwarded/AbstractForwardedChannel.java @@ -54,8 +54,9 @@ public abstract class AbstractForwardedChannel * 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; diff --git a/src/main/java/net/schmizz/sshj/connection/channel/forwarded/RemotePortForwarder.java b/src/main/java/net/schmizz/sshj/connection/channel/forwarded/RemotePortForwarder.java index 61462e51..81182344 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/forwarded/RemotePortForwarder.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/forwarded/RemotePortForwarder.java @@ -127,7 +127,8 @@ public class RemotePortForwarder 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 class RemotePortForwarder 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) { diff --git a/src/main/java/net/schmizz/sshj/connection/channel/forwarded/X11Forwarder.java b/src/main/java/net/schmizz/sshj/connection/channel/forwarded/X11Forwarder.java index f6eef032..d2097a08 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/forwarded/X11Forwarder.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/forwarded/X11Forwarder.java @@ -34,8 +34,9 @@ public class X11Forwarder 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 class X11Forwarder 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);