use of com.github.jh3nd3rs0n.jargyle.common.net.Host in project jargyle by jh3nd3rs0n.
the class SocksServerTest method testGetHostForChangingConfiguration.
@Test
public void testGetHostForChangingConfiguration() throws IOException {
ModifiableConfiguration configuration = ModifiableConfiguration.newInstance();
SocksServer socksServer = new SocksServer(configuration);
try {
socksServer.start();
configuration.addSetting(GeneralSettingSpecConstants.HOST.newSetting(Host.newInstance("127.0.0.1")));
Host expectedHost = GeneralSettingSpecConstants.HOST.getDefaultSetting().getValue();
Host actualHost = socksServer.getHost();
assertEquals(expectedHost, actualHost);
} finally {
if (!socksServer.getState().equals(SocksServer.State.STOPPED)) {
socksServer.stop();
}
}
}
use of com.github.jh3nd3rs0n.jargyle.common.net.Host in project jargyle by jh3nd3rs0n.
the class ConnectCommandWorker method newServerFacingSocket.
private Socket newServerFacingSocket() throws IOException {
Socks5Reply socks5Rep = null;
HostResolver hostResolver = this.netObjectFactory.newHostResolver();
Socket serverFacingSocket = null;
int connectTimeout = this.settings.getLastValue(Socks5SettingSpecConstants.SOCKS5_ON_CONNECT_SERVER_FACING_CONNECT_TIMEOUT).intValue();
if (this.settings.getLastValue(Socks5SettingSpecConstants.SOCKS5_ON_CONNECT_PREPARE_SERVER_FACING_SOCKET)) {
serverFacingSocket = netObjectFactory.newSocket();
if (!this.configureServerFacingSocket(serverFacingSocket)) {
return null;
}
try {
serverFacingSocket.connect(new InetSocketAddress(hostResolver.resolve(this.desiredDestinationAddress), this.desiredDestinationPort), connectTimeout);
} catch (UnknownHostException e) {
LOGGER.error(ObjectLogMessageHelper.objectLogMessage(this, "Error in connecting the server-facing socket"), e);
socks5Rep = Socks5Reply.newFailureInstance(Reply.HOST_UNREACHABLE);
this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
return null;
}
} else {
Host bindHost = this.settings.getLastValue(Socks5SettingSpecConstants.SOCKS5_ON_CONNECT_SERVER_FACING_BIND_HOST);
InetAddress bindInetAddress = bindHost.toInetAddress();
try {
serverFacingSocket = this.netObjectFactory.newSocket(this.desiredDestinationAddress, this.desiredDestinationPort, bindInetAddress, 0);
} catch (UnknownHostException e) {
LOGGER.error(ObjectLogMessageHelper.objectLogMessage(this, "Error in creating the server-facing socket"), e);
socks5Rep = Socks5Reply.newFailureInstance(Reply.HOST_UNREACHABLE);
this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
return null;
}
}
return serverFacingSocket;
}
use of com.github.jh3nd3rs0n.jargyle.common.net.Host in project jargyle by jh3nd3rs0n.
the class ConnectCommandWorker method configureServerFacingSocket.
private boolean configureServerFacingSocket(final Socket serverFacingSocket) {
SocketSettings socketSettings = this.settings.getLastValue(Socks5SettingSpecConstants.SOCKS5_ON_CONNECT_SERVER_FACING_SOCKET_SETTINGS);
Host bindHost = this.settings.getLastValue(Socks5SettingSpecConstants.SOCKS5_ON_CONNECT_SERVER_FACING_BIND_HOST);
InetAddress bindInetAddress = bindHost.toInetAddress();
try {
socketSettings.applyTo(serverFacingSocket);
serverFacingSocket.bind(new InetSocketAddress(bindInetAddress, 0));
} catch (SocketException e) {
LOGGER.error(ObjectLogMessageHelper.objectLogMessage(this, "Error in setting the server-facing socket"), e);
Socks5Reply socks5Rep = Socks5Reply.newFailureInstance(Reply.GENERAL_SOCKS_SERVER_FAILURE);
this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
return false;
} catch (IOException e) {
LOGGER.error(ObjectLogMessageHelper.objectLogMessage(this, "Error in binding the server-facing socket"), e);
Socks5Reply socks5Rep = Socks5Reply.newFailureInstance(Reply.GENERAL_SOCKS_SERVER_FAILURE);
this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
return false;
}
return true;
}
use of com.github.jh3nd3rs0n.jargyle.common.net.Host in project jargyle by jh3nd3rs0n.
the class UdpAssociateCommandWorker method newClientFacingDatagramSocket.
private DatagramSocket newClientFacingDatagramSocket() {
Host bindHost = this.settings.getLastValue(Socks5SettingSpecConstants.SOCKS5_ON_UDP_ASSOCIATE_CLIENT_FACING_BIND_HOST);
InetAddress bindInetAddress = bindHost.toInetAddress();
DatagramSocket clientFacingDatagramSock = null;
try {
clientFacingDatagramSock = new DatagramSocket(new InetSocketAddress(bindInetAddress, 0));
} catch (SocketException e) {
LOGGER.error(ObjectLogMessageHelper.objectLogMessage(this, "Error in creating the client-facing UDP socket"), e);
Socks5Reply socks5Rep = Socks5Reply.newFailureInstance(Reply.GENERAL_SOCKS_SERVER_FAILURE);
this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
return null;
}
return clientFacingDatagramSock;
}
use of com.github.jh3nd3rs0n.jargyle.common.net.Host in project jargyle by jh3nd3rs0n.
the class UdpAssociateCommandWorker method newPeerFacingDatagramSocket.
private DatagramSocket newPeerFacingDatagramSocket() {
Host bindHost = this.settings.getLastValue(Socks5SettingSpecConstants.SOCKS5_ON_UDP_ASSOCIATE_PEER_FACING_BIND_HOST);
InetAddress bindInetAddress = bindHost.toInetAddress();
DatagramSocket peerFacingDatagramSock = null;
try {
peerFacingDatagramSock = this.netObjectFactory.newDatagramSocket(new InetSocketAddress(bindInetAddress, 0));
} catch (SocketException e) {
LOGGER.error(ObjectLogMessageHelper.objectLogMessage(this, "Error in creating the peer-facing UDP socket"), e);
Socks5Reply socks5Rep = Socks5Reply.newFailureInstance(Reply.GENERAL_SOCKS_SERVER_FAILURE);
this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
return null;
}
return peerFacingDatagramSock;
}
Aggregations