You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2009/11/16 23:15:56 UTC
svn commit: r881006 - in
/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd: SshClient.java
SshServer.java common/AbstractFactoryManager.java
server/command/ScpCommand.java
Author: gnodet
Date: Mon Nov 16 22:15:56 2009
New Revision: 881006
URL: http://svn.apache.org/viewvc?rev=881006&view=rev
Log:
SSHD-58: better support for subclassing ScpCommand and SshServer
Modified:
mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshClient.java
mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java
mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/AbstractFactoryManager.java
mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java
Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshClient.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshClient.java?rev=881006&r1=881005&r2=881006&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshClient.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshClient.java Mon Nov 16 22:15:56 2009
@@ -117,8 +117,8 @@
*/
public class SshClient extends AbstractFactoryManager {
- private IoConnector connector;
- private SessionFactory sessionFactory;
+ protected IoConnector connector;
+ protected SessionFactory sessionFactory;
public SshClient() {
}
Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java?rev=881006&r1=881005&r2=881006&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java Mon Nov 16 22:15:56 2009
@@ -30,6 +30,9 @@
import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.session.IoSession;
+import org.apache.mina.core.session.IoSessionConfig;
+import org.apache.mina.transport.socket.DefaultSocketSessionConfig;
+import org.apache.mina.transport.socket.SocketSessionConfig;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.apache.sshd.common.*;
import org.apache.sshd.common.cipher.AES128CBC;
@@ -88,16 +91,18 @@
*/
public class SshServer extends AbstractFactoryManager implements ServerFactoryManager {
- private IoAcceptor acceptor;
- private int port;
- private boolean reuseAddress = true;
- private List<NamedFactory<UserAuth>> userAuthFactories;
- private Factory<Command> shellFactory;
- private SessionFactory sessionFactory;
- private CommandFactory commandFactory;
- private List<NamedFactory<Command>> subsystemFactories;
- private PasswordAuthenticator passwordAuthenticator;
- private PublickeyAuthenticator publickeyAuthenticator;
+ protected IoAcceptor acceptor;
+ protected int port;
+ protected int backlog = 50;
+ protected boolean reuseAddress = true;
+ protected IoSessionConfig sessionConfig;
+ protected List<NamedFactory<UserAuth>> userAuthFactories;
+ protected Factory<Command> shellFactory;
+ protected SessionFactory sessionFactory;
+ protected CommandFactory commandFactory;
+ protected List<NamedFactory<Command>> subsystemFactories;
+ protected PasswordAuthenticator passwordAuthenticator;
+ protected PublickeyAuthenticator publickeyAuthenticator;
public SshServer() {
}
@@ -123,6 +128,22 @@
this.reuseAddress = reuseAddress;
}
+ public int getBacklog() {
+ return backlog;
+ }
+
+ public void setBacklog(int backlog) {
+ this.backlog = backlog;
+ }
+
+ public IoSessionConfig getSessionConfig() {
+ return sessionConfig;
+ }
+
+ public void setSessionConfig(IoSessionConfig sessionConfig) {
+ this.sessionConfig = sessionConfig;
+ }
+
public List<NamedFactory<UserAuth>> getUserAuthFactories() {
return userAuthFactories;
}
@@ -216,13 +237,12 @@
*/
public void start() throws IOException {
checkConfig();
- acceptor = new NioSocketAcceptor();
-
- ((NioSocketAcceptor) acceptor).setReuseAddress(reuseAddress);
+ acceptor = createAcceptor();
+ configure(acceptor);
SessionFactory handler = sessionFactory;
if (handler == null) {
- handler = new SessionFactory();
+ handler = createSessionFactory();
}
handler.setServer(this);
acceptor.setHandler(handler);
@@ -260,6 +280,24 @@
acceptor = null;
}
+ protected IoAcceptor createAcceptor() {
+ return new NioSocketAcceptor();
+ }
+
+ protected void configure(IoAcceptor acceptor) {
+ if (acceptor instanceof NioSocketAcceptor) {
+ ((NioSocketAcceptor) acceptor).setReuseAddress(reuseAddress);
+ ((NioSocketAcceptor) acceptor).setBacklog(backlog);
+ }
+ if (sessionConfig != null) {
+ acceptor.getSessionConfig().setAll(sessionConfig);
+ }
+ }
+
+ protected SessionFactory createSessionFactory() {
+ return new SessionFactory();
+ }
+
public static SshServer setUpDefaultServer() {
SshServer sshd = new SshServer();
// DHG14 uses 2048 bits key which are not supported by the default JCE provider
Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/AbstractFactoryManager.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/AbstractFactoryManager.java?rev=881006&r1=881005&r2=881006&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/AbstractFactoryManager.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/AbstractFactoryManager.java Mon Nov 16 22:15:56 2009
@@ -36,16 +36,16 @@
private final Logger log = LoggerFactory.getLogger(getClass());
- private Map<String,String> properties = new HashMap<String,String>();
- private List<NamedFactory<KeyExchange>> keyExchangeFactories;
- private List<NamedFactory<Cipher>> cipherFactories;
- private List<NamedFactory<Compression>> compressionFactories;
- private List<NamedFactory<Mac>> macFactories;
- private List<NamedFactory<Signature>> signatureFactories;
- private Factory<Random> randomFactory;
- private KeyPairProvider keyPairProvider;
- private String version;
- private List<NamedFactory<Channel>> channelFactories;
+ protected Map<String,String> properties = new HashMap<String,String>();
+ protected List<NamedFactory<KeyExchange>> keyExchangeFactories;
+ protected List<NamedFactory<Cipher>> cipherFactories;
+ protected List<NamedFactory<Compression>> compressionFactories;
+ protected List<NamedFactory<Mac>> macFactories;
+ protected List<NamedFactory<Signature>> signatureFactories;
+ protected Factory<Random> randomFactory;
+ protected KeyPairProvider keyPairProvider;
+ protected String version;
+ protected List<NamedFactory<Channel>> channelFactories;
protected AbstractFactoryManager() {
loadVersion();
Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java?rev=881006&r1=881005&r2=881006&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java Mon Nov 16 22:15:56 2009
@@ -43,21 +43,21 @@
*/
public class ScpCommand implements Command, Runnable {
- private static final Logger log = LoggerFactory.getLogger(ScpCommand.class);
- private static final int OK = 0;
- private static final int ERROR = 2;
-
- private boolean optR;
- private boolean optT;
- private boolean optF;
- private boolean optV;
- private boolean optP;
- private File root;
- private InputStream in;
- private OutputStream out;
- private OutputStream err;
- private ExitCallback callback;
- private IOException error;
+ protected static final Logger log = LoggerFactory.getLogger(ScpCommand.class);
+ protected static final int OK = 0;
+ protected static final int ERROR = 2;
+
+ protected boolean optR;
+ protected boolean optT;
+ protected boolean optF;
+ protected boolean optV;
+ protected boolean optP;
+ protected File root;
+ protected InputStream in;
+ protected OutputStream out;
+ protected OutputStream err;
+ protected ExitCallback callback;
+ protected IOException error;
public ScpCommand(String[] args) {
if (log.isDebugEnabled()) {
@@ -171,7 +171,7 @@
}
}
- private void writeDir(String header, File path) throws IOException {
+ protected void writeDir(String header, File path) throws IOException {
if (log.isDebugEnabled()) {
log.debug("Writing dir {}", path);
}
@@ -216,7 +216,7 @@
}
- private void writeFile(String header, File path) throws IOException {
+ protected void writeFile(String header, File path) throws IOException {
if (log.isDebugEnabled()) {
log.debug("Writing file {}", path);
}
@@ -260,7 +260,7 @@
readAck();
}
- private String readLine() throws IOException {
+ protected String readLine() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (;;) {
int c = in.read();
@@ -274,7 +274,7 @@
}
}
- private void readFile(File path) throws IOException {
+ protected void readFile(File path) throws IOException {
if (log.isDebugEnabled()) {
log.debug("Reading file {}", path);
}
@@ -307,7 +307,7 @@
readAck();
}
- private void readDir(File path) throws IOException {
+ protected void readDir(File path) throws IOException {
if (log.isDebugEnabled()) {
log.debug("Reading directory {}", path);
}
@@ -336,12 +336,12 @@
readAck();
}
- private void ack() throws IOException {
+ protected void ack() throws IOException {
out.write(0);
out.flush();
}
- private void readAck() throws IOException {
+ protected void readAck() throws IOException {
int c = in.read();
switch (c) {
case 0: