Java中的域名前置代理,赢得';“得不到”;拉法;工作委托书

Java中的域名前置代理,赢得';“得不到”;拉法;工作委托书,java,sockets,proxy,Java,Sockets,Proxy,我目前正在从事一个项目,该项目使用了一种称为“领域前沿”的技术。简而言之:它通过加密连接将互联网流量发送到CDN(在本例中为Google),然后CDN将此信息传回代理。这样你就可以绕过审查(只要CDN没有被屏蔽),因为真正的目的地对观察者来说是未知的。(要了解更多关于域名前置的信息,这里是原文)许多应用程序(如Signal和Tor)已经使用了这种技术,但是没有一个通用的代理,它只是通过Google将tcp套接字代理到另一端。我决定继续这方面的工作,它几乎完成了:HTTP编码部分和谷歌服务器上的代

我目前正在从事一个项目,该项目使用了一种称为“领域前沿”的技术。简而言之:它通过加密连接将互联网流量发送到CDN(在本例中为Google),然后CDN将此信息传回代理。这样你就可以绕过审查(只要CDN没有被屏蔽),因为真正的目的地对观察者来说是未知的。(要了解更多关于域名前置的信息,这里是原文)许多应用程序(如Signal和Tor)已经使用了这种技术,但是没有一个通用的代理,它只是通过Google将tcp套接字代理到另一端。我决定继续这方面的工作,它几乎完成了:HTTP编码部分和谷歌服务器上的代码正在工作。唯一的问题是真正的代理部分。 这是代理的结构: 源-->客户端代理-->[Google]-->服务器代理-->目标

与普通代理的区别在于HTTP是一种基于请求的协议,因此不能像普通代理那样进行异步操作。我的设置是每100毫秒从客户端向服务器发出一次请求,将客户端接收到的字节发送到服务器。服务器从目标读取字节并将其发送回客户端。然后,服务器和客户端都将接收到的字节写入原始套接字,另一个往返将在100ms后开始

这是我到这一点的代码(我只粘贴了相关部分,此代码还不是域前置): 客户:

服务器:

try {
            Socket destination = new Socket("192.168.0.150", 22);
            BufferedReader destinationIn = new BufferedReader(new InputStreamReader(destination.getInputStream()));
            PrintWriter destinationOut = new PrintWriter(destination.getOutputStream(), false);
            ServerSocket server = new ServerSocket(8081);
            while(true) {
                Socket clientSocket = server.accept();
                BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), false);
                System.out.println("received new connection from client");

                //read what client has for destination
                char[] buffer = new char[15000];
                int bytesRead = 0;
                while((bytesRead = in.read(buffer)) == -1) {
                    System.out.println("didn't receive any bytes from client");
                    Thread.sleep(20);
                }
                byte[] bytesToSend = Arrays.copyOfRange(new String(buffer).getBytes(), 0, bytesRead);
                if(bytesToSend[0] == (byte) 1) {
                    destinationOut.print(bytesToSend);
                    destinationOut.flush();
                    System.out.println("Sent to destination: " + new String(bytesToSend));
                } else {
                    System.out.println("Client has nothing for destination");
                }

                //read what distination has for client
                System.out.println("start reading destination socket");
                System.out.println("available: " + destination.getInputStream().available());
                buffer = new char[15000];
                if(destination.getInputStream().available() != 0) {
                    bytesRead = destinationIn.read(buffer);
                    bytesToSend = new byte[bytesRead];
                    bytesToSend = Arrays.copyOfRange(new String(buffer).getBytes(), 0, bytesRead);
                    out.print("1");
                    out.print(new String(bytesToSend));
                    out.flush();
                    System.out.println("Sent to client: " + new String(bytesToSend) + " bytesRead: " + bytesRead);
                } else {
                    out.print((byte) 0);
                    out.flush();
                    System.out.println("Sent to client: nothing");
                }
                out.close();
                in.close();
                clientSocket.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
当我运行此代码连接到SSH服务器时,SSH客户端冻结,代理服务器似乎不再响应代理客户端

我真的希望有人能帮我,如果你需要额外的信息,请告诉我!:)

try {
            Socket destination = new Socket("192.168.0.150", 22);
            BufferedReader destinationIn = new BufferedReader(new InputStreamReader(destination.getInputStream()));
            PrintWriter destinationOut = new PrintWriter(destination.getOutputStream(), false);
            ServerSocket server = new ServerSocket(8081);
            while(true) {
                Socket clientSocket = server.accept();
                BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), false);
                System.out.println("received new connection from client");

                //read what client has for destination
                char[] buffer = new char[15000];
                int bytesRead = 0;
                while((bytesRead = in.read(buffer)) == -1) {
                    System.out.println("didn't receive any bytes from client");
                    Thread.sleep(20);
                }
                byte[] bytesToSend = Arrays.copyOfRange(new String(buffer).getBytes(), 0, bytesRead);
                if(bytesToSend[0] == (byte) 1) {
                    destinationOut.print(bytesToSend);
                    destinationOut.flush();
                    System.out.println("Sent to destination: " + new String(bytesToSend));
                } else {
                    System.out.println("Client has nothing for destination");
                }

                //read what distination has for client
                System.out.println("start reading destination socket");
                System.out.println("available: " + destination.getInputStream().available());
                buffer = new char[15000];
                if(destination.getInputStream().available() != 0) {
                    bytesRead = destinationIn.read(buffer);
                    bytesToSend = new byte[bytesRead];
                    bytesToSend = Arrays.copyOfRange(new String(buffer).getBytes(), 0, bytesRead);
                    out.print("1");
                    out.print(new String(bytesToSend));
                    out.flush();
                    System.out.println("Sent to client: " + new String(bytesToSend) + " bytesRead: " + bytesRead);
                } else {
                    out.print((byte) 0);
                    out.flush();
                    System.out.println("Sent to client: nothing");
                }
                out.close();
                in.close();
                clientSocket.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }