Search in sources :

Example 6 with Method

use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Method in project jargyle by jh3nd3rs0n.

the class Socks5HostResolver method resolve.

@Override
public InetAddress resolve(final String host) throws IOException {
    if (host == null) {
        return InetAddress.getLoopbackAddress();
    }
    Properties properties = this.socks5Client.getProperties();
    AddressType addressType = AddressType.valueForString(host);
    if (!addressType.equals(AddressType.DOMAINNAME) || !properties.getValue(Socks5PropertySpecConstants.SOCKS5_RESOLVE_USE_RESOLVE_COMMAND).booleanValue()) {
        return InetAddress.getByName(host);
    }
    Socket socket = this.socks5Client.newInternalSocket();
    this.socks5Client.configureInternalSocket(socket);
    Socket sock = this.socks5Client.getConnectedInternalSocket(socket, true);
    Method method = this.socks5Client.negotiateMethod(sock);
    MethodEncapsulation methodEncapsulation = this.socks5Client.doMethodSubnegotiation(method, sock);
    Socket sck = methodEncapsulation.getSocket();
    Socks5Request socks5Req = Socks5Request.newInstance(Command.RESOLVE, host, 0);
    this.socks5Client.sendSocks5Request(socks5Req, sck);
    Socks5Reply socks5Rep = null;
    try {
        socks5Rep = this.socks5Client.receiveSocks5Reply(sck);
    } catch (FailureSocks5ReplyException e) {
        Reply reply = e.getFailureSocks5Reply().getReply();
        if (reply.equals(Reply.HOST_UNREACHABLE)) {
            throw new UnknownHostException(host);
        } else {
            throw e;
        }
    }
    InetAddress inetAddress = InetAddress.getByName(socks5Rep.getServerBoundAddress());
    return InetAddress.getByAddress(host, inetAddress.getAddress());
}
Also used : MethodEncapsulation(com.github.jh3nd3rs0n.jargyle.transport.socks5.MethodEncapsulation) Socks5Request(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request) UnknownHostException(java.net.UnknownHostException) Socks5Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply) Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply) Socks5Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply) Method(com.github.jh3nd3rs0n.jargyle.transport.socks5.Method) Properties(com.github.jh3nd3rs0n.jargyle.client.Properties) AddressType(com.github.jh3nd3rs0n.jargyle.transport.socks5.AddressType) InetAddress(java.net.InetAddress) Socket(java.net.Socket)

Aggregations

Method (com.github.jh3nd3rs0n.jargyle.transport.socks5.Method)4 IOException (java.io.IOException)4 ClientMethodSelectionMessage (com.github.jh3nd3rs0n.jargyle.transport.socks5.ClientMethodSelectionMessage)2 MethodEncapsulation (com.github.jh3nd3rs0n.jargyle.transport.socks5.MethodEncapsulation)2 Methods (com.github.jh3nd3rs0n.jargyle.transport.socks5.Methods)2 ServerMethodSelectionMessage (com.github.jh3nd3rs0n.jargyle.transport.socks5.ServerMethodSelectionMessage)2 Socks5Request (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request)2 InputStream (java.io.InputStream)2 UncheckedIOException (java.io.UncheckedIOException)2 Socket (java.net.Socket)2 Properties (com.github.jh3nd3rs0n.jargyle.client.Properties)1 Route (com.github.jh3nd3rs0n.jargyle.server.Route)1 WorkerContext (com.github.jh3nd3rs0n.jargyle.server.WorkerContext)1 Socks5RequestRoutingRule (com.github.jh3nd3rs0n.jargyle.server.rules.impl.Socks5RequestRoutingRule)1 AddressType (com.github.jh3nd3rs0n.jargyle.transport.socks5.AddressType)1 Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply)1 Socks5Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply)1 JsonParser (com.google.api.client.json.JsonParser)1 FixedHeaderProvider (com.google.api.gax.rpc.FixedHeaderProvider)1 StorageObject (com.google.api.services.storage.model.StorageObject)1