You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2016/02/26 17:46:58 UTC
[1/4] mina-sshd git commit: Fixed ScpFileOpener resolution hierarchy
Repository: mina-sshd
Updated Branches:
refs/heads/master ce0582baa -> fa205ccbc
Fixed ScpFileOpener resolution hierarchy
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/346f8727
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/346f8727
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/346f8727
Branch: refs/heads/master
Commit: 346f8727e49f6b968d617ed196eec7ead14a412a
Parents: ce0582b
Author: Lyor Goldstein <ly...@gmail.com>
Authored: Fri Feb 26 18:45:16 2016 +0200
Committer: Lyor Goldstein <ly...@gmail.com>
Committed: Fri Feb 26 18:45:16 2016 +0200
----------------------------------------------------------------------
.../sshd/client/ClientFactoryManager.java | 2 ++
.../java/org/apache/sshd/client/SshClient.java | 13 +++++++
.../sshd/client/scp/DefaultScpClient.java | 2 +-
.../sshd/client/scp/ScpClientCreator.java | 17 ++-------
.../client/session/AbstractClientSession.java | 14 ++++++--
.../apache/sshd/common/scp/ScpFileOpener.java | 2 +-
.../sshd/common/scp/ScpFileOpenerHolder.java | 37 ++++++++++++++++++++
.../sshd/server/scp/ScpCommandFactory.java | 22 +++++-------
.../org/apache/sshd/client/scp/ScpTest.java | 2 +-
9 files changed, 77 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/346f8727/sshd-core/src/main/java/org/apache/sshd/client/ClientFactoryManager.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/ClientFactoryManager.java b/sshd-core/src/main/java/org/apache/sshd/client/ClientFactoryManager.java
index def207b..e4e873f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/ClientFactoryManager.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/ClientFactoryManager.java
@@ -23,6 +23,7 @@ import org.apache.sshd.client.config.keys.ClientIdentityLoader;
import org.apache.sshd.client.session.ClientProxyConnectorHolder;
import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.config.keys.FilePasswordProvider;
+import org.apache.sshd.common.scp.ScpFileOpenerHolder;
/**
* The <code>ClientFactoryManager</code> enable the retrieval of additional
@@ -32,6 +33,7 @@ import org.apache.sshd.common.config.keys.FilePasswordProvider;
*/
public interface ClientFactoryManager
extends FactoryManager,
+ ScpFileOpenerHolder,
ClientProxyConnectorHolder,
ClientAuthenticationManager {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/346f8727/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
index c357cc1..9388a1f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
@@ -113,6 +113,7 @@ import org.apache.sshd.common.keyprovider.AbstractFileKeyPairProvider;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
import org.apache.sshd.common.mac.BuiltinMacs;
import org.apache.sshd.common.mac.Mac;
+import org.apache.sshd.common.scp.ScpFileOpener;
import org.apache.sshd.common.session.helpers.AbstractSession;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.OsUtils;
@@ -215,6 +216,8 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
private ClientIdentityLoader clientIdentityLoader;
private FilePasswordProvider filePasswordProvider;
private PasswordIdentityProvider passwordIdentityProvider;
+ private ScpFileOpener scpOpener;
+
private final List<Object> identities = new CopyOnWriteArrayList<>();
private final AuthenticationIdentitiesProvider identitiesProvider;
@@ -241,6 +244,16 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
}
@Override
+ public ScpFileOpener getScpFileOpener() {
+ return scpOpener;
+ }
+
+ @Override
+ public void setScpFileOpener(ScpFileOpener opener) {
+ scpOpener = opener;
+ }
+
+ @Override
public ServerKeyVerifier getServerKeyVerifier() {
return serverKeyVerifier;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/346f8727/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java
index e184f76..7b950a7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java
@@ -61,9 +61,9 @@ public class DefaultScpClient extends AbstractScpClient {
*/
public static final String SCP_PORT_OPTION = "-P";
- protected final ClientSession clientSession;
protected final ScpFileOpener opener;
protected final ScpTransferEventListener listener;
+ private final ClientSession clientSession;
public DefaultScpClient(ClientSession clientSession, ScpFileOpener fileOpener, ScpTransferEventListener eventListener) {
this.clientSession = ValidateUtils.checkNotNull(clientSession, "No client session");
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/346f8727/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClientCreator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClientCreator.java b/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClientCreator.java
index cfe598e..37fea18 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClientCreator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClientCreator.java
@@ -20,12 +20,13 @@
package org.apache.sshd.client.scp;
import org.apache.sshd.common.scp.ScpFileOpener;
+import org.apache.sshd.common.scp.ScpFileOpenerHolder;
import org.apache.sshd.common.scp.ScpTransferEventListener;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public interface ScpClientCreator {
+public interface ScpClientCreator extends ScpFileOpenerHolder {
/**
* Create an SCP client from this session.
*
@@ -74,20 +75,6 @@ public interface ScpClientCreator {
ScpClient createScpClient(ScpFileOpener opener, ScpTransferEventListener listener);
/**
- * @return The last {@link ScpFileOpener} set via call
- * to {@link #setScpFileOpener(ScpFileOpener)}
- */
- ScpFileOpener getScpFileOpener();
-
- /**
- * @param opener The default {@link ScpFileOpener} to use - if {@code null}
- * then a default opener is used
- * @see #createScpClient(ScpFileOpener)
- * @see #createScpClient(ScpFileOpener, ScpTransferEventListener)
- */
- void setScpFileOpener(ScpFileOpener opener);
-
- /**
* @return The last {@link ScpTransferEventListener} set via
* {@link #setScpTransferEventListener(ScpTransferEventListener)}
*/
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/346f8727/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java b/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
index 382865b..cef2703 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
@@ -197,7 +197,9 @@ public abstract class AbstractClientSession extends AbstractSession implements C
identities.add(kp);
if (log.isDebugEnabled()) {
- log.debug("addPublicKeyIdentity({}) {}", this, KeyUtils.getFingerPrint(kp.getPublic()));
+ PublicKey key = kp.getPublic();
+ log.debug("addPublicKeyIdentity({}) {}-{}",
+ this, KeyUtils.getKeyType(key), KeyUtils.getFingerPrint(key));
}
}
@@ -302,7 +304,7 @@ public abstract class AbstractClientSession extends AbstractSession implements C
@Override
public ScpFileOpener getScpFileOpener() {
- return scpOpener;
+ return resolveEffectiveProvider(ScpFileOpener.class, scpOpener, getFactoryManager().getScpFileOpener());
}
@Override
@@ -355,6 +357,14 @@ public abstract class AbstractClientSession extends AbstractSession implements C
try {
client.negotiateVersion(selector);
} catch (IOException | RuntimeException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("createSftpClient({}) failed ({}) to negotiate version: {}",
+ this, e.getClass().getSimpleName(), e.getMessage());
+ }
+ if (log.isTraceEnabled()) {
+ log.trace("createSftpClient(" + this + ") version negotiation failure details", e);
+ }
+
client.close();
throw e;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/346f8727/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpFileOpener.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpFileOpener.java b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpFileOpener.java
index e2db9b8..887d649 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpFileOpener.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpFileOpener.java
@@ -47,7 +47,7 @@ public interface ScpFileOpener {
InputStream openRead(Session session, Path file, OpenOption... options) throws IOException;
/**
- * Create an input stream to read from a file
+ * Create an output stream to write to a file
*
* @param session The {@link Session} requesting the access
* @param file The requested local file {@link Path}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/346f8727/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpFileOpenerHolder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpFileOpenerHolder.java b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpFileOpenerHolder.java
new file mode 100644
index 0000000..b492129
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpFileOpenerHolder.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sshd.common.scp;
+
+/**
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public interface ScpFileOpenerHolder {
+ /**
+ * @return The last {@link ScpFileOpener} set via call
+ * to {@link #setScpFileOpener(ScpFileOpener)}
+ */
+ ScpFileOpener getScpFileOpener();
+
+ /**
+ * @param opener The default {@link ScpFileOpener} to use - if {@code null}
+ * then a default opener is used
+ */
+ void setScpFileOpener(ScpFileOpener opener);
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/346f8727/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommandFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommandFactory.java b/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommandFactory.java
index 1f52ea4..d515046 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommandFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommandFactory.java
@@ -23,6 +23,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ExecutorService;
import org.apache.sshd.common.scp.ScpFileOpener;
+import org.apache.sshd.common.scp.ScpFileOpenerHolder;
import org.apache.sshd.common.scp.ScpHelper;
import org.apache.sshd.common.scp.ScpTransferEventListener;
import org.apache.sshd.common.util.EventListenerUtils;
@@ -39,7 +40,7 @@ import org.apache.sshd.server.CommandFactory;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
* @see ScpCommand
*/
-public class ScpCommandFactory implements CommandFactory, Cloneable, ExecutorServiceConfigurer {
+public class ScpCommandFactory implements ScpFileOpenerHolder, CommandFactory, Cloneable, ExecutorServiceConfigurer {
/**
* A useful {@link ObjectBuilder} for {@link ScpCommandFactory}
*/
@@ -51,7 +52,7 @@ public class ScpCommandFactory implements CommandFactory, Cloneable, ExecutorSer
}
public Builder withFileOpener(ScpFileOpener opener) {
- factory.setFileOpener(opener);
+ factory.setScpFileOpener(opener);
return this;
}
@@ -113,15 +114,13 @@ public class ScpCommandFactory implements CommandFactory, Cloneable, ExecutorSer
listenerProxy = EventListenerUtils.proxyWrapper(ScpTransferEventListener.class, getClass().getClassLoader(), listeners);
}
- public ScpFileOpener getFileOpener() {
+ @Override
+ public ScpFileOpener getScpFileOpener() {
return fileOpener;
}
- /**
- * @param fileOpener The {@link ScpFileOpener} to use - if {@code null}.
- * the a default opener is used
- */
- public void setFileOpener(ScpFileOpener fileOpener) {
+ @Override
+ public void setScpFileOpener(ScpFileOpener fileOpener) {
this.fileOpener = fileOpener;
}
@@ -161,11 +160,6 @@ public class ScpCommandFactory implements CommandFactory, Cloneable, ExecutorSer
return shutdownExecutor;
}
- /**
- * @param shutdown If {@code true} the {@link ExecutorService#shutdownNow()}
- * will be called when command terminates - unless it is the ad-hoc
- * service, which will be shutdown regardless
- */
@Override
public void setShutdownOnExit(boolean shutdown) {
shutdownExecutor = shutdown;
@@ -248,7 +242,7 @@ public class ScpCommandFactory implements CommandFactory, Cloneable, ExecutorSer
return new ScpCommand(command,
getExecutorService(), isShutdownOnExit(),
getSendBufferSize(), getReceiveBufferSize(),
- getFileOpener(), listenerProxy);
+ getScpFileOpener(), listenerProxy);
}
CommandFactory factory = getDelegateCommandFactory();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/346f8727/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java b/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
index b797680..5d16071 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
@@ -767,7 +767,7 @@ public class ScpTest extends BaseTestSupport {
ScpCommandFactory factory = (ScpCommandFactory) sshd.getCommandFactory();
TrackingFileOpener serverOpener = new TrackingFileOpener();
- factory.setFileOpener(serverOpener);
+ factory.setScpFileOpener(serverOpener);
try (SshClient client = setupTestClient()) {
client.start();
[3/4] mina-sshd git commit: Added some more documentation comments to
AbstractSession
Posted by lg...@apache.org.
Added some more documentation comments to AbstractSession
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/7f52ea81
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/7f52ea81
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/7f52ea81
Branch: refs/heads/master
Commit: 7f52ea81476cffdab8300b5c0471aa3099b7d7c4
Parents: dd38bc4
Author: Lyor Goldstein <ly...@gmail.com>
Authored: Fri Feb 26 18:46:58 2016 +0200
Committer: Lyor Goldstein <ly...@gmail.com>
Committed: Fri Feb 26 18:46:58 2016 +0200
----------------------------------------------------------------------
.../common/session/helpers/AbstractSession.java | 127 ++++++++++++++-----
1 file changed, 96 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/7f52ea81/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
index 384a99f..e7359b3 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
@@ -137,14 +137,14 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
protected final SessionListener sessionListenerProxy;
/**
- * Channel events listener
+ * Channel events listener container
*/
protected final Collection<ChannelListener> channelListeners = new CopyOnWriteArraySet<>();
protected final ChannelListener channelListenerProxy;
- //
- // Key exchange support
- //
+ /*
+ * Key exchange support
+ */
protected byte[] sessionId;
protected String serverVersion;
protected String clientVersion;
@@ -159,9 +159,9 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
protected final AtomicReference<KexState> kexState = new AtomicReference<>(KexState.UNKNOWN);
protected final AtomicReference<DefaultKeyExchangeFuture> kexFutureHolder = new AtomicReference<>(null);
- //
- // SSH packets encoding / decoding support
- //
+ /*
+ * SSH packets encoding / decoding support
+ */
protected Cipher outCipher;
protected Cipher inCipher;
protected int outCipherSize = 8;
@@ -186,9 +186,9 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
protected long idleTimeoutStart = System.currentTimeMillis();
protected final AtomicReference<TimeoutStatus> timeoutStatus = new AtomicReference<>(TimeoutStatus.NoTimeout);
- //
- // Rekeying
- //
+ /*
+ * Rekeying
+ */
protected final AtomicLong inPacketsCount = new AtomicLong(0L);
protected final AtomicLong outPacketsCount = new AtomicLong(0L);
protected final AtomicLong inBytesCount = new AtomicLong(0L);
@@ -216,8 +216,20 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
* The factory manager used to retrieve factories of Ciphers, Macs and other objects
*/
private final FactoryManager factoryManager;
+
+ /**
+ * The session specific properties
+ */
private final Map<String, Object> properties = new ConcurrentHashMap<>();
+
+ /**
+ * Used to wait for global requests result synchronous wait
+ */
private final AtomicReference<Object> requestResult = new AtomicReference<>();
+
+ /**
+ * Session specific attributes
+ */
private final Map<AttributeKey<?>, Object> attributes = new ConcurrentHashMap<>();
private ReservedSessionMessagesHandler reservedSessionMessagesHandler;
@@ -232,7 +244,6 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
super(ValidateUtils.checkNotNull(factoryManager, "No factory manager provided"));
this.isServer = isServer;
this.factoryManager = factoryManager;
- this.reservedSessionMessagesHandler = factoryManager.getReservedSessionMessagesHandler();
this.ioSession = ioSession;
this.decoderBuffer = new SessionWorkBuffer(this);
@@ -252,11 +263,12 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
/**
* Retrieve the session from the MINA session.
- * If the session has not been attached, an IllegalStateException
+ * If the session has not been attached, an {@link IllegalStateException}
* will be thrown
*
* @param ioSession the MINA session
* @return the session attached to the MINA session
+ * @see #getSession(IoSession, boolean)
*/
public static AbstractSession getSession(IoSession ioSession) {
return getSession(ioSession, false);
@@ -264,7 +276,7 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
/**
* Retrieve the session from the MINA session.
- * If the session has not been attached and allowNull is <code>false</code>,
+ * If the session has not been attached and <tt>allowNull</tt> is <code>false</code>,
* an {@link IllegalStateException} will be thrown, else a {@code null} will
* be returned
*
@@ -317,6 +329,12 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
return ioSession;
}
+ /**
+ * @param knownAddress Any externally set peer address - e.g., due to some
+ * proxy mechanism meta-data
+ * @return The external address if not {@code null} otherwise, the {@code IoSession}
+ * peer address
+ */
protected SocketAddress resolvePeerAddress(SocketAddress knownAddress) {
if (knownAddress != null) {
return knownAddress;
@@ -716,7 +734,7 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
synchronized (pendingPackets) {
if (!pendingPackets.isEmpty()) {
if (log.isDebugEnabled()) {
- log.debug("handleNewKeys({}) Dequeing pending packets", this);
+ log.debug("handleNewKeys({}) Dequeing {} pending packets", this, pendingPackets.size());
}
synchronized (encodeLock) {
PendingWriteFuture future;
@@ -727,6 +745,7 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
}
kexState.set(KexState.DONE);
}
+
synchronized (lock) {
lock.notifyAll();
}
@@ -897,6 +916,7 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
}
}
}
+
try {
return doWritePacket(buffer);
} finally {
@@ -1022,6 +1042,10 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
synchronized (requestResult) {
while (isOpen() && (maxWaitMillis > 0L) && (requestResult.get() == null)) {
+ if (log.isTraceEnabled()) {
+ log.trace("request({})[{}] remaining wait={}", this, request, maxWaitMillis);
+ }
+
long waitStart = System.nanoTime();
requestResult.wait(maxWaitMillis);
long waitEnd = System.nanoTime();
@@ -1415,6 +1439,7 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
log.debug("doReadIdentification({}) line='{}'", this, str);
}
+ // if this is a server then only one line is expected
if (server || str.startsWith("SSH-")) {
return str;
}
@@ -1501,7 +1526,7 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
* Receive the remote key exchange init message.
* The packet data is returned for later use.
*
- * @param buffer the buffer containing the key exchange init packet
+ * @param buffer the {@link Buffer} containing the key exchange init packet
* @param proposal the remote proposal to fill
* @return the packet data
*/
@@ -1674,10 +1699,12 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
inCompression = s2ccomp;
}
outCipherSize = outCipher.getIVSize();
+ // TODO add support for configurable compression level
outCompression.init(Compression.Type.Deflater, -1);
inCipherSize = inCipher.getIVSize();
inMacResult = new byte[inMac.getBlockSize()];
+ // TODO add support for configurable compression level
inCompression.init(Compression.Type.Inflater, -1);
// see https://tools.ietf.org/html/rfc4344#section-3.2
@@ -1772,9 +1799,9 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
}
/**
- * Send an unimplemented packet. This packet should contain the
- * sequence id of the unsupported packet: this number is assumed to
- * be the last packet received.
+ * Send a {@code SSH_MSG_UNIMPLEMENTED} packet. This packet should
+ * contain the sequence id of the unsupported packet: this number
+ * is assumed to be the last packet received.
*
* @return An {@link IoWriteFuture} that can be used to wait for packet write completion
* @throws IOException if an error occurred sending the packet
@@ -1871,6 +1898,12 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
return guess;
}
+ /**
+ * Indicates the reception of a {@code SSH_MSG_REQUEST_SUCCESS} message
+ *
+ * @param buffer The {@link Buffer} containing the message data
+ * @throws Exception If failed to handle the message
+ */
protected void requestSuccess(Buffer buffer) throws Exception {
// use a copy of the original data in case it is re-used on return
Buffer resultBuf = ByteArrayBuffer.getCompactClone(buffer.array(), buffer.rpos(), buffer.available());
@@ -1881,6 +1914,12 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
}
}
+ /**
+ * Indicates the reception of a {@code SSH_MSG_REQUEST_FAILURE} message
+ *
+ * @param buffer The {@link Buffer} containing the message data
+ * @throws Exception If failed to handle the message
+ */
protected void requestFailure(Buffer buffer) throws Exception {
synchronized (requestResult) {
requestResult.set(GenericUtils.NULL);
@@ -1930,7 +1969,8 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
@Override
public ReservedSessionMessagesHandler getReservedSessionMessagesHandler() {
- return reservedSessionMessagesHandler;
+ return resolveEffectiveProvider(ReservedSessionMessagesHandler.class,
+ reservedSessionMessagesHandler, getFactoryManager().getReservedSessionMessagesHandler());
}
@Override
@@ -1998,6 +2038,12 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
return channelListenerProxy;
}
+ /**
+ * Sends a session event to all currently registered session listeners
+ *
+ * @param event The event to send
+ * @throws IOException If any of the registered listeners threw an exception.
+ */
protected void sendSessionEvent(SessionListener.Event event) throws IOException {
SessionListener listener = getSessionListenerProxy();
try {
@@ -2027,25 +2073,40 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
return ValidateUtils.checkNotNull(kexFutureHolder.get(), "No current KEX future on state=%s", kexState.get());
}
- protected void checkRekey() throws IOException {
- if (isRekeyRequired()) {
- requestNewKeysExchange();
- }
+ /**
+ * Checks if a re-keying is required and if so initiates it
+ *
+ * @return A {@link KeyExchangeFuture} to wait for the initiated exchange
+ * or {@code null} if no need to re-key or an exchange is already in progress
+ * @throws IOException If failed to send the request
+ * @see #isRekeyRequired()
+ * @see #requestNewKeysExchange()
+ */
+ protected KeyExchangeFuture checkRekey() throws IOException {
+ return isRekeyRequired() ? requestNewKeysExchange() : null;
}
- protected void requestNewKeysExchange() throws IOException {
+ /**
+ * Initiates a new keys exchange if one not already in progress
+ *
+ * @return A {@link KeyExchangeFuture} to wait for the initiated exchange
+ * or {@code null} if an exchange is already in progress
+ * @throws IOException If failed to send the request
+ */
+ protected KeyExchangeFuture requestNewKeysExchange() throws IOException {
if (!kexState.compareAndSet(KexState.DONE, KexState.INIT)) {
if (log.isDebugEnabled()) {
log.debug("requestNewKeysExchange({}) KEX state not DONE: {}", this, kexState.get());
}
- return;
+ return null;
}
log.info("requestNewKeysExchange({}) Initiating key re-exchange", this);
sendKexInit();
- DefaultKeyExchangeFuture kexFuture = kexFutureHolder.getAndSet(new DefaultKeyExchangeFuture(null));
+ DefaultKeyExchangeFuture newFuture = new DefaultKeyExchangeFuture(null);
+ DefaultKeyExchangeFuture kexFuture = kexFutureHolder.getAndSet(newFuture);
if (kexFuture != null) {
synchronized (kexFuture) {
Object value = kexFuture.getValue();
@@ -2054,6 +2115,8 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
}
}
}
+
+ return newFuture;
}
protected boolean isRekeyRequired() {
@@ -2175,6 +2238,12 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
*/
protected abstract String resolveAvailableSignaturesProposal(FactoryManager manager);
+ /**
+ * Indicates the the key exchange is completed and the exchanged keys
+ * can now be verified - e.g., client can verify the server's key
+ *
+ * @throws IOException If validation failed
+ */
protected abstract void checkKeys() throws IOException;
protected void receiveKexInit(Buffer buffer) throws IOException {
@@ -2188,7 +2257,7 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
// returns the proposal argument
protected Map<KexProposalOption, String> mergeProposals(Map<KexProposalOption, String> current, Map<KexProposalOption, String> proposal) {
if (current == proposal) {
- return proposal; // debug breakpoint
+ return proposal; // nothing to merge
}
synchronized (current) {
@@ -2206,10 +2275,6 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
return proposal;
}
- protected void serviceAccept() throws IOException {
- // nothing
- }
-
/**
* Checks whether the session has timed out (both auth and idle timeouts are checked).
* If the session has timed out, a DISCONNECT message will be sent.
[2/4] mina-sshd git commit: Allow SftpVersionSelector to be null -
interpret it as if use whatever current version is reported
Posted by lg...@apache.org.
Allow SftpVersionSelector to be null - interpret it as if use whatever current version is reported
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/dd38bc4f
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/dd38bc4f
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/dd38bc4f
Branch: refs/heads/master
Commit: dd38bc4fdc4811a7bf47840516ceacddeb241e60
Parents: 346f872
Author: Lyor Goldstein <ly...@gmail.com>
Authored: Fri Feb 26 18:46:38 2016 +0200
Committer: Lyor Goldstein <ly...@gmail.com>
Committed: Fri Feb 26 18:46:38 2016 +0200
----------------------------------------------------------------------
.../subsystem/sftp/AbstractSftpClient.java | 128 ++++++++++---------
.../subsystem/sftp/DefaultSftpClient.java | 10 +-
.../client/subsystem/sftp/SftpFileSystem.java | 2 +-
.../subsystem/sftp/SftpFileSystemProvider.java | 2 +-
.../helpers/AbstractCheckFileExtension.java | 5 +-
.../helpers/AbstractMD5HashExtension.java | 8 +-
.../helpers/AbstractSftpClientExtension.java | 4 +-
7 files changed, 86 insertions(+), 73 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/dd38bc4f/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClient.java
index 16b9105..639d965 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClient.java
@@ -191,29 +191,31 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
}
/**
- * Sends the specified command, waits for the response and then invokes {@link #checkStatus(Buffer)}
+ * Sends the specified command, waits for the response and then invokes {@link #checkResponseStatus(int, Buffer)}
* @param cmd The command to send
* @param request The request {@link Buffer}
* @throws IOException If failed to send, receive or check the returned status
* @see #send(int, Buffer)
* @see #receive(int)
- * @see #checkStatus(Buffer)
+ * @see #checkResponseStatus(int, Buffer)
*/
- protected void checkStatus(int cmd, Buffer request) throws IOException {
+ protected void checkCommandStatus(int cmd, Buffer request) throws IOException {
int reqId = send(cmd, request);
Buffer response = receive(reqId);
- checkStatus(response);
+ checkResponseStatus(cmd, response);
}
/**
* Checks if the incoming response is an {@code SSH_FXP_STATUS} one,
* and if so whether the substatus is {@code SSH_FX_OK}.
+ *
+ * @param cmd The sent command opcode
* @param buffer The received response {@link Buffer}
* @throws IOException If response does not carry a status or carries
* a bad status code
- * @see #checkStatus(int, int, String, String)
+ * @see #checkResponseStatus(int, int, int, String, String)
*/
- protected void checkStatus(Buffer buffer) throws IOException {
+ protected void checkResponseStatus(int cmd, Buffer buffer) throws IOException {
int length = buffer.getInt();
int type = buffer.getUByte();
int id = buffer.getInt();
@@ -221,32 +223,34 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
int substatus = buffer.getInt();
String msg = buffer.getString();
String lang = buffer.getString();
- checkStatus(id, substatus, msg, lang);
+ checkResponseStatus(cmd, id, substatus, msg, lang);
} else {
handleUnexpectedPacket(SftpConstants.SSH_FXP_STATUS, id, type, length, buffer);
}
}
/**
+ * @param cmd The sent command opcode
* @param id The request id
* @param substatus The sub-status value
* @param msg The message
* @param lang The language
* @throws IOException if the sub-status is not {@code SSH_FX_OK}
- * @see #throwStatusException(int, int, String, String)
+ * @see #throwStatusException(int, int, int, String, String)
*/
- protected void checkStatus(int id, int substatus, String msg, String lang) throws IOException {
+ protected void checkResponseStatus(int cmd, int id, int substatus, String msg, String lang) throws IOException {
if (log.isTraceEnabled()) {
- log.trace("checkStatus({})[id={}] status={} lang={} msg={}",
- getClientChannel(), id, SftpConstants.getStatusName(substatus), lang, msg);
+ log.trace("checkStatus({})[id={}] cmd={} status={} lang={} msg={}",
+ getClientChannel(), id, SftpConstants.getCommandMessageName(cmd),
+ SftpConstants.getStatusName(substatus), lang, msg);
}
if (substatus != SftpConstants.SSH_FX_OK) {
- throwStatusException(id, substatus, msg, lang);
+ throwStatusException(cmd, id, substatus, msg, lang);
}
}
- protected void throwStatusException(int id, int substatus, String msg, String lang) throws IOException {
+ protected void throwStatusException(int cmd, int id, int substatus, String msg, String lang) throws IOException {
throw new SftpException(substatus, msg);
}
@@ -257,15 +261,15 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
* @throws IOException If failed to send/receive or process the response
* @see #send(int, Buffer)
* @see #receive(int)
- * @see #checkHandle(Buffer)
+ * @see #checkHandleResponse(int, Buffer)
*/
protected byte[] checkHandle(int cmd, Buffer request) throws IOException {
int reqId = send(cmd, request);
Buffer response = receive(reqId);
- return checkHandle(response);
+ return checkHandleResponse(cmd, response);
}
- protected byte[] checkHandle(Buffer buffer) throws IOException {
+ protected byte[] checkHandleResponse(int cmd, Buffer buffer) throws IOException {
int length = buffer.getInt();
int type = buffer.getUByte();
int id = buffer.getInt();
@@ -278,10 +282,11 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
String msg = buffer.getString();
String lang = buffer.getString();
if (log.isTraceEnabled()) {
- log.trace("checkHandle({})[id={}] - status: {} [{}] {}",
- getClientChannel(), id, SftpConstants.getStatusName(substatus), lang, msg);
+ log.trace("checkHandleResponse({})[id={}] {} - status: {} [{}] {}",
+ getClientChannel(), id, SftpConstants.getCommandMessageName(cmd),
+ SftpConstants.getStatusName(substatus), lang, msg);
}
- throwStatusException(id, substatus, msg, lang);
+ throwStatusException(cmd, id, substatus, msg, lang);
}
return handleUnexpectedHandlePacket(id, type, length, buffer);
@@ -300,15 +305,15 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
* @throws IOException If failed to send/receive or process the response
* @see #send(int, Buffer)
* @see #receive(int)
- * @see #checkAttributes(Buffer)
+ * @see #checkAttributesResponse(int, Buffer)
*/
protected Attributes checkAttributes(int cmd, Buffer request) throws IOException {
int reqId = send(cmd, request);
Buffer response = receive(reqId);
- return checkAttributes(response);
+ return checkAttributesResponse(cmd, response);
}
- protected Attributes checkAttributes(Buffer buffer) throws IOException {
+ protected Attributes checkAttributesResponse(int cmd, Buffer buffer) throws IOException {
int length = buffer.getInt();
int type = buffer.getUByte();
int id = buffer.getInt();
@@ -321,10 +326,11 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
String msg = buffer.getString();
String lang = buffer.getString();
if (log.isTraceEnabled()) {
- log.trace("checkAttributes()[id={}] - status: {} [{}] {}",
- getClientChannel(), id, SftpConstants.getStatusName(substatus), lang, msg);
+ log.trace("checkAttributes()[id={}] {} - status: {} [{}] {}",
+ getClientChannel(), id, SftpConstants.getCommandMessageName(cmd),
+ SftpConstants.getStatusName(substatus), lang, msg);
}
- throwStatusException(id, substatus, msg, lang);
+ throwStatusException(cmd, id, substatus, msg, lang);
}
return handleUnexpectedAttributesPacket(id, type, length, buffer);
@@ -346,15 +352,15 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
* @throws IOException If failed to send/receive or process the response
* @see #send(int, Buffer)
* @see #receive(int)
- * @see #checkOneName(Buffer)
+ * @see #checkOneNameResponse(int, Buffer)
*/
protected String checkOneName(int cmd, Buffer request) throws IOException {
int reqId = send(cmd, request);
Buffer response = receive(reqId);
- return checkOneName(response);
+ return checkOneNameResponse(cmd, response);
}
- protected String checkOneName(Buffer buffer) throws IOException {
+ protected String checkOneNameResponse(int cmd, Buffer buffer) throws IOException {
int length = buffer.getInt();
int type = buffer.getUByte();
int id = buffer.getInt();
@@ -374,8 +380,9 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
Boolean indicator = SftpHelper.getEndOfListIndicatorValue(buffer, version);
// TODO decide what to do if not-null and not TRUE
if (log.isTraceEnabled()) {
- log.trace("checkOneName({})[id={}] ({})[{}] eol={}: {}",
- getClientChannel(), id, name, longName, indicator, attrs);
+ log.trace("checkOneName({})[id={}] {} ({})[{}] eol={}: {}",
+ getClientChannel(), id, SftpConstants.getCommandMessageName(cmd),
+ name, longName, indicator, attrs);
}
return name;
}
@@ -385,11 +392,12 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
String msg = buffer.getString();
String lang = buffer.getString();
if (log.isTraceEnabled()) {
- log.trace("checkOneName({})[id={}] - status: {} [{}] {}",
- getClientChannel(), id, SftpConstants.getStatusName(substatus), lang, msg);
+ log.trace("checkOneName({})[id={}] {} status: {} [{}] {}",
+ getClientChannel(), id, SftpConstants.getCommandMessageName(cmd),
+ SftpConstants.getStatusName(substatus), lang, msg);
}
- throwStatusException(id, substatus, msg, lang);
+ throwStatusException(cmd, id, substatus, msg, lang);
}
return handleUnknownOneNamePacket(id, type, length, buffer);
@@ -714,7 +722,7 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
byte[] id = ValidateUtils.checkNotNull(handle, "No handle").getIdentifier();
Buffer buffer = new ByteArrayBuffer(id.length + Long.SIZE /* some extra fields */, false);
buffer.putBytes(id);
- checkStatus(SftpConstants.SSH_FXP_CLOSE, buffer);
+ checkCommandStatus(SftpConstants.SSH_FXP_CLOSE, buffer);
}
@Override
@@ -729,7 +737,7 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
Buffer buffer = new ByteArrayBuffer(path.length() + Long.SIZE /* some extra fields */, false);
buffer.putString(path);
- checkStatus(SftpConstants.SSH_FXP_REMOVE, buffer);
+ checkCommandStatus(SftpConstants.SSH_FXP_REMOVE, buffer);
}
@Override
@@ -768,7 +776,7 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
throw new UnsupportedOperationException("rename(" + oldPath + " => " + newPath + ")"
+ " - copy options can not be used with this SFTP version: " + options);
}
- checkStatus(SftpConstants.SSH_FXP_RENAME, buffer);
+ checkCommandStatus(SftpConstants.SSH_FXP_RENAME, buffer);
}
@Override // TODO make this a default method in Java 8
@@ -810,10 +818,10 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
}
int reqId = send(cmd, request);
Buffer response = receive(reqId);
- return checkData(response, dstOffset, dst, eofSignalled);
+ return checkDataResponse(cmd, response, dstOffset, dst, eofSignalled);
}
- protected int checkData(Buffer buffer, int dstoff, byte[] dst, AtomicReference<Boolean> eofSignalled) throws IOException {
+ protected int checkDataResponse(int cmd, Buffer buffer, int dstoff, byte[] dst, AtomicReference<Boolean> eofSignalled) throws IOException {
if (eofSignalled != null) {
eofSignalled.set(null);
}
@@ -826,8 +834,9 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
buffer.getRawBytes(dst, dstoff, len);
Boolean indicator = SftpHelper.getEndOfFileIndicatorValue(buffer, getVersion());
if (log.isTraceEnabled()) {
- log.trace("checkData({}][id={}] offset={}, len={}, EOF={}",
- getClientChannel(), id, dstoff, len, indicator);
+ log.trace("checkDataResponse({}][id={}] {} offset={}, len={}, EOF={}",
+ getClientChannel(), SftpConstants.getCommandMessageName(cmd),
+ id, dstoff, len, indicator);
}
if (eofSignalled != null) {
eofSignalled.set(indicator);
@@ -841,15 +850,16 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
String msg = buffer.getString();
String lang = buffer.getString();
if (log.isTraceEnabled()) {
- log.trace("checkData({})[id={}] - status: {} [{}] {}",
- getClientChannel(), id, SftpConstants.getStatusName(substatus), lang, msg);
+ log.trace("checkDataResponse({})[id={}] {} status: {} [{}] {}",
+ getClientChannel(), id, SftpConstants.getCommandMessageName(cmd),
+ SftpConstants.getStatusName(substatus), lang, msg);
}
if (substatus == SftpConstants.SSH_FX_EOF) {
return -1;
}
- throwStatusException(id, substatus, msg, lang);
+ throwStatusException(cmd, id, substatus, msg, lang);
}
return handleUnknownDataPacket(id, type, length, buffer);
@@ -886,7 +896,7 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
buffer.putBytes(id);
buffer.putLong(fileOffset);
buffer.putBytes(src, srcOffset, len);
- checkStatus(SftpConstants.SSH_FXP_WRITE, buffer);
+ checkCommandStatus(SftpConstants.SSH_FXP_WRITE, buffer);
}
@Override
@@ -908,7 +918,7 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
buffer.putByte((byte) 0);
}
- checkStatus(SftpConstants.SSH_FXP_MKDIR, buffer);
+ checkCommandStatus(SftpConstants.SSH_FXP_MKDIR, buffer);
}
@Override
@@ -923,7 +933,7 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
Buffer buffer = new ByteArrayBuffer(path.length() + Long.SIZE /* some extra fields */, false);
buffer.putString(path);
- checkStatus(SftpConstants.SSH_FXP_RMDIR, buffer);
+ checkCommandStatus(SftpConstants.SSH_FXP_RMDIR, buffer);
}
@Override
@@ -960,10 +970,10 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
byte[] id = handle.getIdentifier();
Buffer buffer = new ByteArrayBuffer(id.length + Byte.SIZE /* some extra fields */, false);
buffer.putBytes(id);
- return checkDir(receive(send(SftpConstants.SSH_FXP_READDIR, buffer)), eolIndicator);
+ return checkDirResponse(SftpConstants.SSH_FXP_READDIR, receive(send(SftpConstants.SSH_FXP_READDIR, buffer)), eolIndicator);
}
- protected List<DirEntry> checkDir(Buffer buffer, AtomicReference<Boolean> eolIndicator) throws IOException {
+ protected List<DirEntry> checkDirResponse(int cmd, Buffer buffer, AtomicReference<Boolean> eolIndicator) throws IOException {
if (eolIndicator != null) {
eolIndicator.set(null); // assume unknown
}
@@ -975,7 +985,7 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
int version = getVersion();
ClientChannel channel = getClientChannel();
if (log.isDebugEnabled()) {
- log.debug("checkDir({}}[id={}] reading {} entries", channel, id, len);
+ log.debug("checkDirResponse({}}[id={}] reading {} entries", channel, id, len);
}
List<DirEntry> entries = new ArrayList<DirEntry>(len);
for (int i = 0; i < len; i++) {
@@ -983,7 +993,7 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
String longName = (version == SftpConstants.SFTP_V3) ? buffer.getString() : null;
Attributes attrs = readAttributes(buffer);
if (log.isTraceEnabled()) {
- log.trace("checkDir({})[id={}][{}] ({})[{}]: {}",
+ log.trace("checkDirResponse({})[id={}][{}] ({})[{}]: {}",
channel, id, i, name, longName, attrs);
}
@@ -996,7 +1006,7 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
}
if (log.isDebugEnabled()) {
- log.debug("checkDir({}}[id={}] read count={}, eol={}", channel, entries.size(), indicator);
+ log.debug("checkDirResponse({}}[id={}] read count={}, eol={}", channel, entries.size(), indicator);
}
return entries;
}
@@ -1006,7 +1016,7 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
String msg = buffer.getString();
String lang = buffer.getString();
if (log.isTraceEnabled()) {
- log.trace("checkDir({})[id={}] - status: {} [{}] {}",
+ log.trace("checkDirResponse({})[id={}] - status: {} [{}] {}",
getClientChannel(), id, SftpConstants.getStatusName(substatus), lang, msg);
}
@@ -1014,7 +1024,7 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
return null;
}
- throwStatusException(id, substatus, msg, lang);
+ throwStatusException(cmd, id, substatus, msg, lang);
}
return handleUnknownDirListingPacket(id, type, length, buffer);
@@ -1109,7 +1119,7 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
Buffer buffer = new ByteArrayBuffer();
buffer.putString(path);
writeAttributes(buffer, attributes);
- checkStatus(SftpConstants.SSH_FXP_SETSTAT, buffer);
+ checkCommandStatus(SftpConstants.SSH_FXP_SETSTAT, buffer);
}
@Override
@@ -1125,7 +1135,7 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
Buffer buffer = new ByteArrayBuffer(id.length + (2 * Long.SIZE) /* some extras */, false);
buffer.putBytes(id);
writeAttributes(buffer, attributes);
- checkStatus(SftpConstants.SSH_FXP_FSETSTAT, buffer);
+ checkCommandStatus(SftpConstants.SSH_FXP_FSETSTAT, buffer);
}
@Override
@@ -1157,12 +1167,12 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
}
buffer.putString(targetPath);
buffer.putString(linkPath);
- checkStatus(SftpConstants.SSH_FXP_SYMLINK, buffer);
+ checkCommandStatus(SftpConstants.SSH_FXP_SYMLINK, buffer);
} else {
buffer.putString(targetPath);
buffer.putString(linkPath);
buffer.putBoolean(symbolic);
- checkStatus(SftpConstants.SSH_FXP_LINK, buffer);
+ checkCommandStatus(SftpConstants.SSH_FXP_LINK, buffer);
}
}
@@ -1183,7 +1193,7 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
buffer.putLong(offset);
buffer.putLong(length);
buffer.putInt(mask);
- checkStatus(SftpConstants.SSH_FXP_BLOCK, buffer);
+ checkCommandStatus(SftpConstants.SSH_FXP_BLOCK, buffer);
}
@Override
@@ -1201,7 +1211,7 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
buffer.putBytes(id);
buffer.putLong(offset);
buffer.putLong(length);
- checkStatus(SftpConstants.SSH_FXP_UNBLOCK, buffer);
+ checkCommandStatus(SftpConstants.SSH_FXP_UNBLOCK, buffer);
}
@Override
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/dd38bc4f/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/DefaultSftpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/DefaultSftpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/DefaultSftpClient.java
index b3bc7ee..049be14 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/DefaultSftpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/DefaultSftpClient.java
@@ -368,19 +368,23 @@ public class DefaultSftpClient extends AbstractSftpClient {
getClientChannel(), id, SftpConstants.getStatusName(substatus), lang, msg);
}
- throwStatusException(id, substatus, msg, lang);
+ throwStatusException(SftpConstants.SSH_FXP_INIT, id, substatus, msg, lang);
} else {
handleUnexpectedPacket(SftpConstants.SSH_FXP_VERSION, id, type, length, buffer);
}
}
/**
- * @param selector The {@link SftpVersionSelector} to use
+ * @param selector The {@link SftpVersionSelector} to use - ignored if {@code null}
* @return The selected version (may be same as current)
* @throws IOException If failed to negotiate
*/
public int negotiateVersion(SftpVersionSelector selector) throws IOException {
int current = getVersion();
+ if (selector == null) {
+ return current;
+ }
+
Set<Integer> available = GenericUtils.asSortedSet(Collections.singleton(current));
Map<String, ?> parsed = getParsedServerExtensions();
Collection<String> extensions = ParserUtils.supportedExtensions(parsed);
@@ -414,7 +418,7 @@ public class DefaultSftpClient extends AbstractSftpClient {
+ (Integer.SIZE / Byte.SIZE) + verVal.length(), false);
buffer.putString(SftpConstants.EXT_VERSION_SELECT);
buffer.putString(verVal);
- checkStatus(SftpConstants.SSH_FXP_EXTENDED, buffer);
+ checkCommandStatus(SftpConstants.SSH_FXP_EXTENDED, buffer);
versionHolder.set(selected);
return selected;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/dd38bc4f/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java
index 608246d..73e1750 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java
@@ -77,7 +77,7 @@ public class SftpFileSystem extends BaseFileSystem<SftpPath> implements ClientSe
super(provider);
this.id = id;
this.clientSession = ValidateUtils.checkNotNull(session, "No client session");
- this.selector = ValidateUtils.checkNotNull(selector, "No SFTP version selector provided");
+ this.selector = selector;
this.stores = Collections.unmodifiableList(Collections.<FileStore>singletonList(new SftpFileStore(id, this)));
this.pool = new LinkedBlockingQueue<>(PropertyResolverUtils.getIntProperty(session, POOL_SIZE_PROP, DEFAULT_POOL_SIZE));
try (SftpClient client = getClient()) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/dd38bc4f/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemProvider.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemProvider.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemProvider.java
index 8056631..a59d972 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemProvider.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemProvider.java
@@ -146,7 +146,7 @@ public class SftpFileSystemProvider extends FileSystemProvider {
public SftpFileSystemProvider(SshClient client, SftpVersionSelector selector) {
this.log = LoggerFactory.getLogger(getClass());
- this.selector = ValidateUtils.checkNotNull(selector, "No SFTP version selector provided");
+ this.selector = selector;
if (client == null) {
// TODO: make this configurable using system properties
client = SshClient.setUpDefaultClient();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/dd38bc4f/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtension.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtension.java
index 2ab6069..61fe34a 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtension.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtension.java
@@ -50,8 +50,8 @@ public abstract class AbstractCheckFileExtension extends AbstractSftpClientExten
if (log.isDebugEnabled()) {
log.debug("doGetHash({})[{}] - offset={}, length={}, block-size={}",
- getName(), (target instanceof CharSequence) ? target : BufferUtils.toHex(BufferUtils.EMPTY_HEX_SEPARATOR, (byte[]) target),
- offset, length, blockSize);
+ getName(), (target instanceof CharSequence) ? target : BufferUtils.toHex(BufferUtils.EMPTY_HEX_SEPARATOR, (byte[]) target),
+ offset, length, blockSize);
}
buffer = checkExtendedReplyBuffer(receive(sendExtendedCommand(buffer)));
@@ -73,5 +73,4 @@ public abstract class AbstractCheckFileExtension extends AbstractSftpClientExten
return new Pair<String, Collection<byte[]>>(algo, hashes);
}
-
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/dd38bc4f/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractMD5HashExtension.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractMD5HashExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractMD5HashExtension.java
index 482a1f0..62654dd 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractMD5HashExtension.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractMD5HashExtension.java
@@ -48,8 +48,8 @@ public abstract class AbstractMD5HashExtension extends AbstractSftpClientExtensi
if (log.isDebugEnabled()) {
log.debug("doGetHash({})[{}] - offset={}, length={}, quick-hash={}",
- opcode, (target instanceof CharSequence) ? target : BufferUtils.toHex(BufferUtils.EMPTY_HEX_SEPARATOR, (byte[]) target),
- offset, length, BufferUtils.toHex(':', quickHash));
+ opcode, (target instanceof CharSequence) ? target : BufferUtils.toHex(BufferUtils.EMPTY_HEX_SEPARATOR, (byte[]) target),
+ offset, length, BufferUtils.toHex(':', quickHash));
}
buffer = checkExtendedReplyBuffer(receive(sendExtendedCommand(buffer)));
@@ -65,8 +65,8 @@ public abstract class AbstractMD5HashExtension extends AbstractSftpClientExtensi
byte[] hashValue = buffer.getBytes();
if (log.isDebugEnabled()) {
log.debug("doGetHash({})[{}] - offset={}, length={}, quick-hash={} - result={}",
- opcode, target, offset, length,
- BufferUtils.toHex(':', quickHash), BufferUtils.toHex(':', hashValue));
+ opcode, target, offset, length,
+ BufferUtils.toHex(':', quickHash), BufferUtils.toHex(':', hashValue));
}
return hashValue;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/dd38bc4f/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractSftpClientExtension.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractSftpClientExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractSftpClientExtension.java
index 853332e..95697e7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractSftpClientExtension.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractSftpClientExtension.java
@@ -183,8 +183,8 @@ public abstract class AbstractSftpClientExtension extends AbstractLoggingBean im
String msg = buffer.getString();
String lang = buffer.getString();
if (log.isDebugEnabled()) {
- log.debug("checkStatus({}}[id={}] - status: {} [{}] {}",
- getName(), id, substatus, lang, msg);
+ log.debug("checkExtendedReplyBuffer({}}[id={}] - status: {} [{}] {}",
+ getName(), id, substatus, lang, msg);
}
if (substatus != SftpConstants.SSH_FX_OK) {
[4/4] mina-sshd git commit: Moved (unused)
AbstractServerSession#serviceAccept logic to
AbstractServerSession#handleServiceAccept
Posted by lg...@apache.org.
Moved (unused) AbstractServerSession#serviceAccept logic to AbstractServerSession#handleServiceAccept
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/fa205ccb
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/fa205ccb
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/fa205ccb
Branch: refs/heads/master
Commit: fa205ccbcfd8c98817b682d45424646cd1cd5dfc
Parents: 7f52ea8
Author: Lyor Goldstein <ly...@gmail.com>
Authored: Fri Feb 26 18:47:45 2016 +0200
Committer: Lyor Goldstein <ly...@gmail.com>
Committed: Fri Feb 26 18:47:45 2016 +0200
----------------------------------------------------------------------
.../org/apache/sshd/server/session/AbstractServerSession.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa205ccb/sshd-core/src/main/java/org/apache/sshd/server/session/AbstractServerSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/session/AbstractServerSession.java b/sshd-core/src/main/java/org/apache/sshd/server/session/AbstractServerSession.java
index 2c2bd01..1fa6996 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/session/AbstractServerSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/session/AbstractServerSession.java
@@ -186,9 +186,10 @@ public abstract class AbstractServerSession extends AbstractSession implements S
}
@Override
- protected void serviceAccept() throws IOException {
+ protected void handleServiceAccept(String serviceName, Buffer buffer) throws Exception {
+ super.handleServiceAccept(serviceName, buffer);
// TODO: can services be initiated by the server-side ?
- disconnect(SshConstants.SSH2_DISCONNECT_PROTOCOL_ERROR, "Unsupported packet: SSH_MSG_SERVICE_ACCEPT");
+ disconnect(SshConstants.SSH2_DISCONNECT_PROTOCOL_ERROR, "Unsupported packet: SSH_MSG_SERVICE_ACCEPT for " + serviceName);
}
@Override
@@ -302,7 +303,7 @@ public abstract class AbstractServerSession extends AbstractSession implements S
clientVersion = doReadIdentification(buffer, true);
if (GenericUtils.isEmpty(clientVersion)) {
buffer.rpos(rpos); // restore original buffer position
- return false;
+ return false; // more data required
}
if (log.isDebugEnabled()) {