mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-08 00:00:54 +03:00
extract makeInetSocketAddress (by hostname) in SocketClient (#509)
to allow overriding with InetSocketAddress.createUnresolved for use with proxy Co-authored-by: Jeroen van Erp <jeroen@hierynomus.com>
This commit is contained in:
@@ -53,6 +53,10 @@ public abstract class SocketClient {
|
|||||||
this.defaultPort = defaultPort;
|
this.defaultPort = defaultPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected InetSocketAddress makeInetSocketAddress(String hostname, int port) {
|
||||||
|
return new InetSocketAddress(hostname, port);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to a host via a proxy.
|
* Connect to a host via a proxy.
|
||||||
* @param hostname The host name to connect to.
|
* @param hostname The host name to connect to.
|
||||||
@@ -83,7 +87,7 @@ public abstract class SocketClient {
|
|||||||
} else {
|
} else {
|
||||||
socket = new Socket(proxy);
|
socket = new Socket(proxy);
|
||||||
}
|
}
|
||||||
socket.connect(new InetSocketAddress(hostname, port), connectTimeout);
|
socket.connect(makeInetSocketAddress(hostname, port), connectTimeout);
|
||||||
onConnect();
|
onConnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +135,7 @@ public abstract class SocketClient {
|
|||||||
this.hostname = hostname;
|
this.hostname = hostname;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
socket = socketFactory.createSocket();
|
socket = socketFactory.createSocket();
|
||||||
socket.connect(new InetSocketAddress(hostname, port), connectTimeout);
|
socket.connect(makeInetSocketAddress(hostname, port), connectTimeout);
|
||||||
onConnect();
|
onConnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,7 +148,7 @@ public abstract class SocketClient {
|
|||||||
this.port = port;
|
this.port = port;
|
||||||
socket = socketFactory.createSocket();
|
socket = socketFactory.createSocket();
|
||||||
socket.bind(new InetSocketAddress(localAddr, localPort));
|
socket.bind(new InetSocketAddress(localAddr, localPort));
|
||||||
socket.connect(new InetSocketAddress(hostname, port), connectTimeout);
|
socket.connect(makeInetSocketAddress(hostname, port), connectTimeout);
|
||||||
onConnect();
|
onConnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user