Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 62 additions & 11 deletions src/main/java/com/trilead/ssh2/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -564,29 +564,75 @@ private void close(Throwable t, boolean hard)

/**
* Same as
* @return see comments for the
* {@link #connect(ServerHostKeyVerifier, int, int) connect(ServerHostKeyVerifier, int, int)}
* method.
* @throws IOException on error
*/
* {@link #connect(ServerHostKeyVerifier, int, int, IpVersion) connect(null, 0, 0, IpVersion.IPV4_AND_IPV6)}.
*
* @return see comments for the
* {@link #connect(ServerHostKeyVerifier, int, int, IpVersion) connect(ServerHostKeyVerifier, int, int, IpVersion)}
* method.
* @throws IOException on error
*/
public synchronized ConnectionInfo connect() throws IOException
{
return connect(null, 0, 0);
return connect(null, 0, 0, IpVersion.IPV4_AND_IPV6);
}

/**
* Same as
* {@link #connect(ServerHostKeyVerifier, int, int) connect(verifier, 0, 0)}.
* {@link #connect(ServerHostKeyVerifier, int, int, IpVersion) connect(null, 0, 0, ipVersion)}.
*
* @return see comments for the
* {@link #connect(ServerHostKeyVerifier, int, int) connect(ServerHostKeyVerifier, int, int)}
* {@link #connect(ServerHostKeyVerifier, int, int, IpVersion) connect(ServerHostKeyVerifier, int, int, IpVersion)}
* method.
* @throws IOException
*/
public synchronized ConnectionInfo connect(IpVersion ipVersion) throws IOException
{
return connect(null, 0, 0, ipVersion);
}


/**
* Same as
* {@link #connect(ServerHostKeyVerifier, int, int, IpVersion) connect(verifier, 0, 0, IpVersion.IPV4_AND_IPV6)}.
*
* @return see comments for the
* {@link #connect(ServerHostKeyVerifier, int, int, IpVersion) connect(ServerHostKeyVerifier, int, int, IpVersion)}
* method.
* @param verifier the verifier
* @throws IOException on error
*/
public synchronized ConnectionInfo connect(ServerHostKeyVerifier verifier) throws IOException
{
return connect(verifier, 0, 0);
return connect(verifier, 0, 0, IpVersion.IPV4_AND_IPV6);
}

/**
* Same as
* {@link #connect(ServerHostKeyVerifier, int, int, IpVersion) connect(verifier, 0, 0, ipVersion)}.
*
* @return see comments for the
* {@link #connect(ServerHostKeyVerifier, int, int, IpVersion) connect(ServerHostKeyVerifier, int, int, IpVersion)}
* method.
* @throws IOException
*/
public synchronized ConnectionInfo connect(ServerHostKeyVerifier verifier, IpVersion ipVersion) throws IOException
{
return connect(verifier, 0, 0, ipVersion);
}

/**
* Same as
* {@link #connect(ServerHostKeyVerifier, int, int, IpVersion) connect(verifier, connectTimeout, kexTimeout, IpVersion.IPV4_AND_IPV6)}.
*
* @return see comments for the
* {@link #connect(ServerHostKeyVerifier, int, int, IpVersion) connect(ServerHostKeyVerifier, int, int, IpVersion)}
* method.
* @throws IOException
*/
public synchronized ConnectionInfo connect(ServerHostKeyVerifier verifier, int connectTimeout, int kexTimeout)
throws IOException
{
return connect(verifier, connectTimeout, kexTimeout, IpVersion.IPV4_AND_IPV6);
}

/**
Expand Down Expand Up @@ -648,6 +694,11 @@ public synchronized ConnectionInfo connect(ServerHostKeyVerifier verifier) throw
* but it will only have an effect after the
* <code>verifier</code> returns.
*
* @param ipVersion
* Specify whether the connection should be restricted to one of
* IPv4 or IPv6, with a default of allowing both. See
* {@link IpVersion}.
*
* @return A {@link ConnectionInfo} object containing the details of the
* established connection.
*
Expand All @@ -671,7 +722,7 @@ public synchronized ConnectionInfo connect(ServerHostKeyVerifier verifier) throw
* proxy is buggy and does not return a proper HTTP response,
* then a normal IOException is thrown instead.
*/
public synchronized ConnectionInfo connect(ServerHostKeyVerifier verifier, int connectTimeout, int kexTimeout)
public synchronized ConnectionInfo connect(ServerHostKeyVerifier verifier, int connectTimeout, int kexTimeout, IpVersion ipVersion)
throws IOException
{
final class TimeoutState
Expand Down Expand Up @@ -746,7 +797,7 @@ public void run()

try
{
tm.initialize(cryptoWishList, verifier, dhgexpara, connectTimeout, getOrCreateSecureRND(), proxyData);
tm.initialize(cryptoWishList, verifier, dhgexpara, connectTimeout, ipVersion, getOrCreateSecureRND(), proxyData);
}
catch (SocketTimeoutException se)
{
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/trilead/ssh2/IpVersion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

package com.trilead.ssh2;

/**
* Allow the caller to restrict the IP version of the connection to
* be established.
*/
public enum IpVersion {
IPV4_AND_IPV6,
IPV4_ONLY,
IPV6_ONLY
}
Loading
Loading