-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf46757
commit cc80ffc
Showing
23 changed files
with
478 additions
and
388 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) | ||
* | ||
|
@@ -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; | ||
|
||
|
@@ -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 ) | ||
* | ||
*/ | ||
|
@@ -164,7 +165,7 @@ public synchronized void kill() { | |
|
||
/** | ||
* 打印信息 | ||
* | ||
* | ||
* @param o | ||
*/ | ||
@SuppressWarnings("unused") | ||
|
@@ -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) { | ||
|
@@ -197,7 +200,7 @@ public void run() { | |
|
||
try { | ||
|
||
listenSocket = new ServerSocket(listenPort); | ||
listenSocket = ServerSocketFactory.getDefault().createServerSocket(listenPort); | ||
|
||
} catch (IOException ex) { | ||
|
||
|
@@ -259,6 +262,7 @@ public void run() { | |
|
||
ClientThread clientThread = new ClientThread(agentSocket, serverHost, serverPort, key); | ||
|
||
// startVirtualThread(clientThread); | ||
clientThread.start(); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) | ||
* | ||
|
@@ -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 ) | ||
* | ||
*/ | ||
|
@@ -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) { | ||
|
||
|
@@ -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); | ||
|
@@ -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(); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) | ||
* | ||
|
@@ -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; | ||
|
||
|
@@ -33,7 +33,7 @@ | |
|
||
/** | ||
* GFW.Press配置文件管理 | ||
* | ||
* | ||
* @author chinashiyu ( [email protected] ; http://gfw.press ) | ||
* | ||
*/ | ||
|
@@ -71,7 +71,7 @@ public Config() { | |
|
||
/** | ||
* 获取客户端配置文件 | ||
* | ||
* | ||
* @return | ||
*/ | ||
public JSONObject getClientConfig() { | ||
|
@@ -82,7 +82,7 @@ public JSONObject getClientConfig() { | |
|
||
/** | ||
* 字符串转JSON对象 | ||
* | ||
* | ||
* @param data | ||
* @return | ||
*/ | ||
|
@@ -114,7 +114,7 @@ public JSONObject getJSON(String data) { | |
|
||
/** | ||
* 获取服务器配置 | ||
* | ||
* | ||
* @return | ||
*/ | ||
public JSONObject getServerConfig() { | ||
|
@@ -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) { | ||
|
||
|
@@ -173,7 +173,7 @@ public Hashtable<String, String> getUser() { | |
|
||
/** | ||
* 打印信息 | ||
* | ||
* | ||
* @param o | ||
*/ | ||
private void log(Object o) { | ||
|
@@ -186,7 +186,7 @@ private void log(Object o) { | |
|
||
/** | ||
* 读文件内容 | ||
* | ||
* | ||
* @param file | ||
* @return | ||
*/ | ||
|
@@ -268,7 +268,7 @@ public String read(File file) { | |
|
||
/** | ||
* 保存内容到文件 | ||
* | ||
* | ||
* @param file | ||
* @param text | ||
* @return | ||
|
@@ -317,7 +317,7 @@ public boolean save(File file, String text) { | |
|
||
/** | ||
* 保存客户端配置文件 | ||
* | ||
* | ||
* @param json | ||
* @return | ||
*/ | ||
|
@@ -348,7 +348,7 @@ public boolean saveClientConfig(JSONObject json) { | |
|
||
/** | ||
* 保存服务器配置文件 | ||
* | ||
* | ||
* @param json | ||
* @return | ||
*/ | ||
|
Oops, something went wrong.