Skip to content

Commit

Permalink
增加对量子计算机的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
chinashiyu authored Oct 27, 2022
1 parent bf46757 commit cc80ffc
Show file tree
Hide file tree
Showing 23 changed files with 478 additions and 388 deletions.
Binary file modified bin/press/gfw/Client.class
Binary file not shown.
Binary file modified bin/press/gfw/ClientThread.class
Binary file not shown.
Binary file modified bin/press/gfw/Config.class
Binary file not shown.
Binary file modified bin/press/gfw/DecryptForwardThread.class
Binary file not shown.
Binary file modified bin/press/gfw/Encrypt.class
Binary file not shown.
Binary file modified bin/press/gfw/EncryptForwardThread.class
Binary file not shown.
Binary file modified bin/press/gfw/PointThread.class
Binary file not shown.
Binary file modified bin/press/gfw/Server.class
Binary file not shown.
Binary file modified bin/press/gfw/ServerThread.class
Binary file not shown.
Binary file modified bin/press/gfw/Windows$ButtonListener.class
Binary file not shown.
Binary file modified bin/press/gfw/Windows$TrayListener.class
Binary file not shown.
Binary file modified bin/press/gfw/Windows$WindowsListener.class
Binary file not shown.
Binary file modified bin/press/gfw/Windows.class
Binary file not shown.
18 changes: 11 additions & 7 deletions src/press/gfw/Client.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
*
*
* GFW.Press
* Copyright (C) 2016 chinashiyu ( [email protected] ; http://gfw.press )
*
Expand All @@ -15,7 +15,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
**/
package press.gfw;

Expand All @@ -26,11 +26,12 @@
import java.sql.Timestamp;

import javax.crypto.SecretKey;
import javax.net.ServerSocketFactory;

/**
*
*
* GFW.Press客户端
*
*
* @author chinashiyu ( [email protected] ; http://gfw.press )
*
*/
Expand Down Expand Up @@ -164,7 +165,7 @@ public synchronized void kill() {

/**
* 打印信息
*
*
* @param o
*/
@SuppressWarnings("unused")
Expand All @@ -178,9 +179,11 @@ private void log(Object o) {

/**
* 启动客户端
*
*
* @return
*/
@Override
@SuppressWarnings("preview")
public void run() {

if (serverHost == null || (serverHost = serverHost.trim()).length() == 0 || serverPort == 0 || listenPort == 0 || key == null) {
Expand All @@ -197,7 +200,7 @@ public void run() {

try {

listenSocket = new ServerSocket(listenPort);
listenSocket = ServerSocketFactory.getDefault().createServerSocket(listenPort);

} catch (IOException ex) {

Expand Down Expand Up @@ -259,6 +262,7 @@ public void run() {

ClientThread clientThread = new ClientThread(agentSocket, serverHost, serverPort, key);

// startVirtualThread(clientThread);
clientThread.start();

}
Expand Down
122 changes: 84 additions & 38 deletions src/press/gfw/ClientThread.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
*
*
* GFW.Press
* Copyright (C) 2016 chinashiyu ( [email protected] ; http://gfw.press )
*
Expand All @@ -15,22 +15,25 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
**/
package press.gfw;

import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.sql.Timestamp;

import javax.crypto.SecretKey;
import javax.net.SocketFactory;

/**
*
*
* GFW.Press客户端线程
*
*
* @author chinashiyu ( [email protected] ; http://gfw.press )
*
*/
Expand All @@ -46,7 +49,15 @@ public class ClientThread extends PointThread {

private Socket serverSocket = null;

private boolean forwarding = false;
private int overN = 0;

private InputStream agentIn = null;

private OutputStream agentOut = null;

private InputStream serverIn = null;

OutputStream serverOut = null;

public ClientThread(Socket agentSocket, String serverHost, int serverPort, SecretKey key) {

Expand All @@ -61,68 +72,104 @@ public ClientThread(Socket agentSocket, String serverHost, int serverPort, Secre
}

/**
* 打印信息
*
* @param o
* 暂停
*
* @param m
*/
private void log(Object o) {
private void _sleep(long m) {

String time = (new Timestamp(System.currentTimeMillis())).toString().substring(0, 19);
try {

System.out.println("[" + time + "] " + o.toString());
sleep(m);

} catch (InterruptedException ie) {

}

}

/**
* 关闭所有连接,此线程及转发子线程调用
*/
public synchronized void over() {
private void close() {

try {
close(agentIn);

serverSocket.close();
close(serverOut);

} catch (Exception e) {
close(serverIn);

}
close(agentOut);

try {
close(agentSocket);

agentSocket.close();
close(serverSocket);

}

} catch (Exception e) {
private void close(Closeable o) {

if (o == null) {

return;

}

if (forwarding) {
try {

o.close();

forwarding = false;
} catch (IOException e) {

}

}

/**
* 启动客户端与服务器之间的转发线程,并对数据进行加密及解密
* 打印信息
*
* @param o
*/
public void run() {
private void log(Object o) {

String time = (new Timestamp(System.currentTimeMillis())).toString().substring(0, 19);

System.out.println("[" + time + "] " + o.toString());

}

@Override
public synchronized void over() {

overN++;

if (overN < 2) {

return;

}

InputStream agentIn = null;
_sleep(OVER_TIMEOUT);

OutputStream agentOut = null;
close();

InputStream serverIn = null;
}

OutputStream serverOut = null;
/**
* 启动客户端与服务器之间的转发线程,并对数据进行加密及解密
*/
@Override
@SuppressWarnings("preview")
public void run() {

try {

// 连接服务器
serverSocket = new Socket(serverHost, serverPort);
serverSocket = SocketFactory.getDefault().createSocket();
serverSocket.connect(new InetSocketAddress(serverHost, serverPort), CONN_TIMEOUT);

serverSocket.setSoTimeout(SOCK_TIMEOUT);
agentSocket.setSoTimeout(SOCK_TIMEOUT);

// 设置3分钟超时
serverSocket.setSoTimeout(180000);
agentSocket.setSoTimeout(180000);
serverSocket.setTcpNoDelay(true);
agentSocket.setTcpNoDelay(true);

// 打开 keep-alive
serverSocket.setKeepAlive(true);
Expand All @@ -139,19 +186,18 @@ public void run() {

log("连接服务器出错:" + serverHost + ":" + serverPort);

over();
close();

return;

}

// 开始转发
forwarding = true;

EncryptForwardThread forwardServer = new EncryptForwardThread(this, agentIn, serverOut, key);
// startVirtualThread(forwardServer);
forwardServer.start();

DecryptForwardThread forwardAgent = new DecryptForwardThread(this, serverIn, agentOut, key);
// startVirtualThread(forwardAgent);
forwardAgent.start();

}
Expand Down
28 changes: 14 additions & 14 deletions src/press/gfw/Config.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
*
*
* GFW.Press
* Copyright (C) 2016 chinashiyu ( [email protected] ; http://gfw.press )
*
Expand All @@ -15,7 +15,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
**/
package press.gfw;

Expand All @@ -33,7 +33,7 @@

/**
* GFW.Press配置文件管理
*
*
* @author chinashiyu ( [email protected] ; http://gfw.press )
*
*/
Expand Down Expand Up @@ -71,7 +71,7 @@ public Config() {

/**
* 获取客户端配置文件
*
*
* @return
*/
public JSONObject getClientConfig() {
Expand All @@ -82,7 +82,7 @@ public JSONObject getClientConfig() {

/**
* 字符串转JSON对象
*
*
* @param data
* @return
*/
Expand Down Expand Up @@ -114,7 +114,7 @@ public JSONObject getJSON(String data) {

/**
* 获取服务器配置
*
*
* @return
*/
public JSONObject getServerConfig() {
Expand Down Expand Up @@ -151,11 +151,11 @@ public Hashtable<String, String> getUser() {

}

Hashtable<String, String> users = new Hashtable<String, String>(lines.length);
Hashtable<String, String> users = new Hashtable<>(lines.length);

for (int i = 0; i < lines.length; i++) {
for (String line : lines) {

String[] cols = lines[i].trim().split(" ");
String[] cols = line.trim().split(" ");

if (cols == null || cols.length < 2 || !(cols[0] = cols[0].trim()).matches("\\d+") || (cols[cols.length - 1] = cols[cols.length - 1].trim()).length() < 8) {

Expand All @@ -173,7 +173,7 @@ public Hashtable<String, String> getUser() {

/**
* 打印信息
*
*
* @param o
*/
private void log(Object o) {
Expand All @@ -186,7 +186,7 @@ private void log(Object o) {

/**
* 读文件内容
*
*
* @param file
* @return
*/
Expand Down Expand Up @@ -268,7 +268,7 @@ public String read(File file) {

/**
* 保存内容到文件
*
*
* @param file
* @param text
* @return
Expand Down Expand Up @@ -317,7 +317,7 @@ public boolean save(File file, String text) {

/**
* 保存客户端配置文件
*
*
* @param json
* @return
*/
Expand Down Expand Up @@ -348,7 +348,7 @@ public boolean saveClientConfig(JSONObject json) {

/**
* 保存服务器配置文件
*
*
* @param json
* @return
*/
Expand Down
Loading

0 comments on commit cc80ffc

Please sign in to comment.