- rename *Protocol to *Impl

- not use Buffer in an interface (ConnectionImpl), use byte[]
This commit is contained in:
Shikhar Bhushan
2010-02-28 13:49:05 +01:00
parent c849b29cc1
commit b09729c623
11 changed files with 39 additions and 44 deletions

View File

@@ -42,7 +42,7 @@ import net.schmizz.sshj.common.SSHException;
import net.schmizz.sshj.common.SecurityUtils;
import net.schmizz.sshj.connection.Connection;
import net.schmizz.sshj.connection.ConnectionException;
import net.schmizz.sshj.connection.ConnectionProtocol;
import net.schmizz.sshj.connection.ConnectionImpl;
import net.schmizz.sshj.connection.channel.direct.LocalPortForwarder;
import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.connection.channel.direct.SessionChannel;
@@ -56,7 +56,7 @@ import net.schmizz.sshj.sftp.SFTPClient;
import net.schmizz.sshj.sftp.StatefulSFTPClient;
import net.schmizz.sshj.transport.Transport;
import net.schmizz.sshj.transport.TransportException;
import net.schmizz.sshj.transport.TransportProtocol;
import net.schmizz.sshj.transport.TransportImpl;
import net.schmizz.sshj.transport.compression.DelayedZlibCompression;
import net.schmizz.sshj.transport.compression.NoneCompression;
import net.schmizz.sshj.transport.compression.ZlibCompression;
@@ -64,7 +64,7 @@ import net.schmizz.sshj.transport.verification.HostKeyVerifier;
import net.schmizz.sshj.transport.verification.OpenSSHKnownHosts;
import net.schmizz.sshj.userauth.UserAuth;
import net.schmizz.sshj.userauth.UserAuthException;
import net.schmizz.sshj.userauth.UserAuthProtocol;
import net.schmizz.sshj.userauth.UserAuthImpl;
import net.schmizz.sshj.userauth.keyprovider.FileKeyProvider;
import net.schmizz.sshj.userauth.keyprovider.KeyPairWrapper;
import net.schmizz.sshj.userauth.keyprovider.KeyProvider;
@@ -143,7 +143,7 @@ public class SSHClient extends SocketClient implements SessionFactory {
protected final UserAuth auth;
/** {@code ssh-connection} service */
protected final ConnectionProtocol conn;
protected final ConnectionImpl conn;
/** Default constructor. Initializes this object using {@link DefaultConfig}. */
public SSHClient() {
@@ -157,9 +157,9 @@ public class SSHClient extends SocketClient implements SessionFactory {
*/
public SSHClient(Config config) {
super(DEFAULT_PORT);
this.trans = new TransportProtocol(config);
this.auth = new UserAuthProtocol(trans);
this.conn = new ConnectionProtocol(trans);
this.trans = new TransportImpl(config);
this.auth = new UserAuthImpl(trans);
this.conn = new ConnectionImpl(trans);
}
/**

View File

@@ -36,7 +36,6 @@
package net.schmizz.sshj.connection;
import net.schmizz.concurrent.Future;
import net.schmizz.sshj.common.Buffer;
import net.schmizz.sshj.common.SSHPacket;
import net.schmizz.sshj.connection.channel.Channel;
import net.schmizz.sshj.connection.channel.OpenFailException;
@@ -98,7 +97,7 @@ public interface Connection {
* @throws TransportException if there is an error sending the request
*/
public Future<SSHPacket, ConnectionException> sendGlobalRequest(String name, boolean wantReply,
Buffer.PlainBuffer specifics) throws TransportException;
byte[] specifics) throws TransportException;
/**
* Send a {@code SSH_MSG_OPEN_FAILURE} for specified {@code Reason} and {@code message}.

View File

@@ -18,7 +18,6 @@ package net.schmizz.sshj.connection;
import net.schmizz.concurrent.Future;
import net.schmizz.concurrent.FutureUtils;
import net.schmizz.sshj.AbstractService;
import net.schmizz.sshj.common.Buffer;
import net.schmizz.sshj.common.DisconnectReason;
import net.schmizz.sshj.common.ErrorNotifiable;
import net.schmizz.sshj.common.Message;
@@ -38,7 +37,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
/** {@link Connection} implementation. */
public class ConnectionProtocol extends AbstractService implements Connection {
public class ConnectionImpl extends AbstractService implements Connection {
private final Object internalSynchronizer = new Object();
@@ -58,7 +57,7 @@ public class ConnectionProtocol extends AbstractService implements Connection {
*
* @param trans transport layer
*/
public ConnectionProtocol(Transport trans) {
public ConnectionImpl(Transport trans) {
super("ssh-connection", trans);
}
@@ -175,13 +174,10 @@ public class ConnectionProtocol extends AbstractService implements Connection {
}
public Future<SSHPacket, ConnectionException> sendGlobalRequest(String name, boolean wantReply,
Buffer.PlainBuffer specifics) throws TransportException {
byte[] specifics) throws TransportException {
synchronized (globalReqFutures) {
log.info("Making global request for `{}`", name);
trans.write(new SSHPacket(Message.GLOBAL_REQUEST) //
.putString(name) //
.putBoolean(wantReply) //
.putBuffer(specifics)); //
trans.write(new SSHPacket(Message.GLOBAL_REQUEST).putString(name).putBoolean(wantReply).putRawBytes(specifics));
Future<SSHPacket, ConnectionException> future = null;
if (wantReply) {

View File

@@ -19,6 +19,7 @@ import net.schmizz.sshj.common.SSHException;
/** A factory interface for creating SSH {@link Session session channels}. */
public interface SessionFactory {
/**
* Opens a {@code session} channel. The returned {@link Session} instance allows {@link Session#exec(String)
* executing a remote command}, {@link Session#startSubsystem(String) starting a subsystem}, or {@link

View File

@@ -116,12 +116,12 @@ public class RemotePortForwarder extends AbstractForwardedChannelOpener {
return address.equals(other.address) && port == other.port;
}
/** Returns the address represented by this forward. */
/** @return the address represented by this forward. */
public String getAddress() {
return address;
}
/** Returns the port represented by this forward. */
/** @return the port represented by this forward. */
public int getPort() {
return port;
}
@@ -179,8 +179,8 @@ public class RemotePortForwarder extends AbstractForwardedChannelOpener {
*
* @return the {@link Forward} which was put into place on the remote host
*
* @throws net.schmizz.sshj.connection.ConnectionException
* if there is an error requesting the forwarding
* @throws ConnectionException if there is an error requesting the forwarding
* @throws TransportException
*/
public Forward bind(Forward forward, ConnectListener listener) throws ConnectionException, TransportException {
SSHPacket reply = req(PF_REQ, forward);
@@ -197,6 +197,7 @@ public class RemotePortForwarder extends AbstractForwardedChannelOpener {
* @param forward the forward which is being cancelled
*
* @throws ConnectionException if there is an error with the cancellation request
* @throws TransportException
*/
public void cancel(Forward forward) throws ConnectionException, TransportException {
try {
@@ -207,13 +208,12 @@ public class RemotePortForwarder extends AbstractForwardedChannelOpener {
}
protected SSHPacket req(String reqName, Forward forward) throws ConnectionException, TransportException {
return conn.sendGlobalRequest(PF_REQ, true, new Buffer.PlainBuffer() //
.putString(forward.address) //
.putInt(forward.port)) //
final byte[] specifics = new Buffer.PlainBuffer().putString(forward.address).putInt(forward.port).getCompactData();
return conn.sendGlobalRequest(reqName, true, specifics)
.get(conn.getTimeout(), TimeUnit.SECONDS);
}
/** Returns the active forwards. */
/** @return the active forwards. */
public Set<Forward> getActiveForwards() {
return listeners.keySet();
}
@@ -223,8 +223,8 @@ public class RemotePortForwarder extends AbstractForwardedChannelOpener {
* {@code ConnectListener} for that forward in a separate thread.
*/
public void handleOpen(SSHPacket buf) throws ConnectionException, TransportException {
ForwardedTCPIPChannel chan = new ForwardedTCPIPChannel(conn, buf.readInt(), buf.readInt(), buf.readInt(), //
new Forward(buf.readString(), buf.readInt()), //
final ForwardedTCPIPChannel chan = new ForwardedTCPIPChannel(conn, buf.readInt(), buf.readInt(), buf.readInt(),
new Forward(buf.readString(), buf.readInt()),
buf.readString(), buf.readInt());
if (listeners.containsKey(chan.getParentForward()))
callListener(listeners.get(chan.getParentForward()), chan);

View File

@@ -45,13 +45,13 @@ final class Heartbeater extends Thread {
private final Logger log = LoggerFactory.getLogger(getClass());
private final TransportProtocol trans;
private final TransportImpl trans;
private int interval;
private boolean started;
Heartbeater(TransportProtocol trans) {
Heartbeater(TransportImpl trans) {
this.trans = trans;
setName("heartbeater");
}

View File

@@ -68,7 +68,7 @@ final class KeyExchanger implements SSHPacketHandler, ErrorNotifiable {
private final Logger log = LoggerFactory.getLogger(getClass());
private final TransportProtocol transport;
private final TransportImpl transport;
/**
* {@link HostKeyVerifier#verify(String, int, java.security.PublicKey)} is invoked by {@link #verifyHost(PublicKey)}
@@ -95,10 +95,10 @@ final class KeyExchanger implements SSHPacketHandler, ErrorNotifiable {
private final Event<TransportException> done;
KeyExchanger(TransportProtocol trans) {
KeyExchanger(TransportImpl trans) {
this.transport = trans;
/*
* Use TransportProtocol's writeLock, since TransportProtocol.write() may wait on this event and the lock should
* Use TransportImpl's writeLock, since TransportImpl.write() may wait on this event and the lock should
* be released while waiting.
*/
this.done = new Event<TransportException>("kex done", TransportException.chainer, trans.getWriteLock());

View File

@@ -45,9 +45,9 @@ final class Reader extends Thread {
private final Logger log = LoggerFactory.getLogger(getClass());
private final TransportProtocol trans;
private final TransportImpl trans;
Reader(TransportProtocol trans) {
Reader(TransportImpl trans) {
this.trans = trans;
setName("reader");
}

View File

@@ -57,7 +57,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
/** A thread-safe {@link Transport} implementation. */
public final class TransportProtocol implements Transport {
public final class TransportImpl implements Transport {
private static final class NullService extends AbstractService {
NullService(Transport trans) {
@@ -121,7 +121,7 @@ public final class TransportProtocol implements Transport {
private final ReentrantLock writeLock = new ReentrantLock();
public TransportProtocol(Config config) {
public TransportImpl(Config config) {
this.config = config;
this.reader = new Reader(this);
this.heartbeater = new Heartbeater(this);

View File

@@ -216,27 +216,26 @@ public class OpenSSHKnownHosts implements HostKeyVerifier {
*
* @return {@code true} on successful verification or {@code false} on failure
*/
public boolean verify(String hostname, int port, PublicKey key) {
public boolean verify(final String hostname, final int port, final PublicKey key) {
KeyType type = KeyType.fromKey(key);
if (type == KeyType.UNKNOWN)
return false;
if (port != 22)
hostname = "[" + hostname + "]:" + port;
final String adjustedHostname = (port != 22) ? "[" + hostname + "]:" + port : hostname;
for (Entry e : entries)
try {
if (e.getType() == type && e.appliesTo(hostname))
if (e.getType() == type && e.appliesTo(adjustedHostname))
if (key.equals(e.getKey()))
return true;
else {
return hostKeyChangedAction(e, hostname, key);
return hostKeyChangedAction(e, adjustedHostname, key);
}
} catch (IOException ioe) {
log.error("Error with {}: {}", e, ioe);
return false;
}
return hostKeyUnverifiableAction(hostname, key);
return hostKeyUnverifiableAction(adjustedHostname, key);
}
protected boolean hostKeyUnverifiableAction(String hostname, PublicKey key) {

View File

@@ -54,7 +54,7 @@ import java.util.Set;
import java.util.concurrent.TimeUnit;
/** {@link UserAuth} implementation. */
public class UserAuthProtocol extends AbstractService implements UserAuth, AuthParams {
public class UserAuthImpl extends AbstractService implements UserAuth, AuthParams {
private final Set<String> allowed = new HashSet<String>();
@@ -72,7 +72,7 @@ public class UserAuthProtocol extends AbstractService implements UserAuth, AuthP
private volatile String banner;
private volatile boolean partialSuccess;
public UserAuthProtocol(Transport trans) {
public UserAuthImpl(Transport trans) {
super("ssh-userauth", trans);
}