fix bug when clicking abort

This commit is contained in:
sirjonasxx 2020-05-01 05:54:28 +02:00
parent c9bdcdd5b3
commit 59a0adac82
3 changed files with 17 additions and 7 deletions

View File

@ -140,7 +140,7 @@ public class NormalProxyProvider extends ProxyProvider {
} }
clearAllProxies(); clearAllProxies();
stateSetter.setState(HState.NOT_CONNECTED); super.abort();
} }
@Override @Override

View File

@ -23,13 +23,15 @@ public abstract class ProxyProvider {
protected final HStateSetter stateSetter; protected final HStateSetter stateSetter;
protected final HConnection hConnection; protected final HConnection hConnection;
private Semaphore abortSemaphore = null;
public ProxyProvider(HProxySetter proxySetter, HStateSetter stateSetter, HConnection hConnection){ public ProxyProvider(HProxySetter proxySetter, HStateSetter stateSetter, HConnection hConnection){
this.proxySetter = proxySetter; this.proxySetter = proxySetter;
this.stateSetter = stateSetter; this.stateSetter = stateSetter;
this.hConnection = hConnection; this.hConnection = hConnection;
} }
protected void startProxyThread(Socket client, Socket server, HProxy proxy) throws InterruptedException, UnknownHostException, IOException { protected void startProxyThread(Socket client, Socket server, HProxy proxy) throws IOException, InterruptedException {
final boolean[] datastream = new boolean[1]; final boolean[] datastream = new boolean[1];
server.setTcpNoDelay(true); server.setTcpNoDelay(true);
client.setTcpNoDelay(true); client.setTcpNoDelay(true);
@ -41,22 +43,22 @@ public abstract class ProxyProvider {
IncomingPacketHandler incomingHandler = new IncomingPacketHandler(client.getOutputStream(), hConnection.getTrafficObservables()); IncomingPacketHandler incomingHandler = new IncomingPacketHandler(client.getOutputStream(), hConnection.getTrafficObservables());
rc4Obtainer.setPacketHandlers(outgoingHandler, incomingHandler); rc4Obtainer.setPacketHandlers(outgoingHandler, incomingHandler);
Semaphore abort = new Semaphore(0);
outgoingHandler.addOnDatastreamConfirmedListener(hotelVersion -> { outgoingHandler.addOnDatastreamConfirmedListener(hotelVersion -> {
incomingHandler.setAsDataStream(); incomingHandler.setAsDataStream();
proxy.verifyProxy(incomingHandler, outgoingHandler, hotelVersion); proxy.verifyProxy(incomingHandler, outgoingHandler, hotelVersion);
proxySetter.setProxy(proxy); proxySetter.setProxy(proxy);
datastream[0] = true; datastream[0] = true;
abortSemaphore = abort;
onConnect(); onConnect();
}); });
Semaphore abort = new Semaphore(0);
handleInputStream(client, outgoingHandler, abort); handleInputStream(client, outgoingHandler, abort);
handleInputStream(server, incomingHandler, abort); handleInputStream(server, incomingHandler, abort);
// abort can be acquired as soon as one of the sockets is closed // abort can be acquired as soon as one of the sockets is closed
abort.acquire(); abort.acquire();
try { try {
if (!server.isClosed()) server.close(); if (!server.isClosed()) server.close();
if (!client.isClosed()) client.close(); if (!client.isClosed()) client.close();
@ -89,13 +91,21 @@ public abstract class ProxyProvider {
public abstract void start() throws IOException; public abstract void start() throws IOException;
public abstract void abort(); public void abort() {
if (abortSemaphore != null) {
abortSemaphore.release();
}
else {
stateSetter.setState(HState.NOT_CONNECTED);
}
}
protected void onConnect() { protected void onConnect() {
stateSetter.setState(HState.CONNECTED); stateSetter.setState(HState.CONNECTED);
} }
protected void onConnectEnd() { protected void onConnectEnd() {
proxySetter.setProxy(null); proxySetter.setProxy(null);
abortSemaphore = null;
stateSetter.setState(HState.NOT_CONNECTED); stateSetter.setState(HState.NOT_CONNECTED);
} }

View File

@ -123,7 +123,7 @@ public class RawIpProxyProvider extends ProxyProvider {
hasMapped = false; hasMapped = false;
} }
tryCloseProxy(); tryCloseProxy();
stateSetter.setState(HState.NOT_CONNECTED); super.abort();
} }
@Override @Override