Commit 2df7f3a1 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 257d1e51
...@@ -39,6 +39,7 @@ dependencies { ...@@ -39,6 +39,7 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.5' implementation 'com.google.code.gson:gson:2.8.5'
compile 'io.reactivex:rxandroid:1.2.1' compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.6' compile 'io.reactivex:rxjava:1.1.6'
compile 'com.jakewharton:process-phoenix:2.0.0'
} }
......
...@@ -43,8 +43,9 @@ public class Proxy { ...@@ -43,8 +43,9 @@ public class Proxy {
@SerializedName("messageId") @SerializedName("messageId")
@Expose @Expose
private String messageId; private String messageId;
@SerializedName("retry")
private int retry = 0; @Expose
private int retry ;
public int getId() { public int getId() {
return id; return id;
......
...@@ -8,6 +8,7 @@ import android.util.Log; ...@@ -8,6 +8,7 @@ import android.util.Log;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.jakewharton.processphoenix.ProcessPhoenix;
import org.telegram.io.Constants; import org.telegram.io.Constants;
import org.telegram.io.CryptLib; import org.telegram.io.CryptLib;
...@@ -25,6 +26,7 @@ import javax.crypto.NoSuchPaddingException; ...@@ -25,6 +26,7 @@ import javax.crypto.NoSuchPaddingException;
import io.socket.emitter.Emitter; import io.socket.emitter.Emitter;
import rx.Observable; import rx.Observable;
import rx.Subscriber; import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers; import rx.schedulers.Schedulers;
...@@ -70,12 +72,10 @@ public class SocketService extends Service implements Emitter.Listener { ...@@ -70,12 +72,10 @@ public class SocketService extends Service implements Emitter.Listener {
@Override @Override
public void call(Object... args) { public void call(Object... args) {
if (args.length == 0) return; if (args.length == 0 || work) return;
if (work) {
Log.e("Ping", "Reject Worker is work!");
return; Log.e("Ping from server Size", String.valueOf(args.length));
}
Log.e("Received from server", String.valueOf(args.length));
String chiper = String.valueOf(args[0]); String chiper = String.valueOf(args[0]);
try { try {
...@@ -101,7 +101,7 @@ public class SocketService extends Service implements Emitter.Listener { ...@@ -101,7 +101,7 @@ public class SocketService extends Service implements Emitter.Listener {
ConnectionsManager.setProxySettings(proxy.getIp(), proxy.getPort(), proxy.getSecret()); ConnectionsManager.setProxySettings(proxy.getIp(), proxy.getPort(), proxy.getSecret());
connectionsManager.checkProxy(proxy.getIp(), proxy.getPort(), proxy.getSecret() connectionsManager.checkProxy(proxy.getIp(), proxy.getPort(), proxy.getSecret()
, time -> { , time -> {
proxy.setPing(time); proxy.setPing(time == -1 ? 0 : time);
subscriber.onNext(proxy); subscriber.onNext(proxy);
subscriber.onCompleted(); subscriber.onCompleted();
}); });
...@@ -110,6 +110,8 @@ public class SocketService extends Service implements Emitter.Listener { ...@@ -110,6 +110,8 @@ public class SocketService extends Service implements Emitter.Listener {
} }
public void initCheckProxy(List<Proxy> proxyList) { public void initCheckProxy(List<Proxy> proxyList) {
...@@ -118,31 +120,19 @@ public class SocketService extends Service implements Emitter.Listener { ...@@ -118,31 +120,19 @@ public class SocketService extends Service implements Emitter.Listener {
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.concatMap(proxy -> getPingServerObservable(proxy) .concatMap(proxy -> getPingServerObservable(proxy)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.timeout(5, TimeUnit.SECONDS) .timeout(10, TimeUnit.SECONDS)
.onErrorResumeNext(t -> .onErrorResumeNext(t ->
{
if (proxy.getRetry() == 1) {
proxy.setPing(0);
return Observable.just(proxy);
}
Log.e("Ping","Try Retry");
proxy.setRetry(1);
return getPingServerObservable(proxy)
.subscribeOn(Schedulers.newThread())
.timeout(5, TimeUnit.SECONDS)
.onErrorResumeNext(throwable -> {
proxy.setPing(0);
return Observable.just(proxy);
});
{
proxy.setPing(0);
return Observable.just(proxy);
})) }))
.toList() .toList()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<List<Proxy>>() { .subscribe(new Subscriber<List<Proxy>>() {
@Override @Override
public void onCompleted() { public void onCompleted() {
work = false; work = false;
//Log.e("Ping", "Done");
} }
@Override @Override
...@@ -152,8 +142,22 @@ public class SocketService extends Service implements Emitter.Listener { ...@@ -152,8 +142,22 @@ public class SocketService extends Service implements Emitter.Listener {
@Override @Override
public void onNext(List<Proxy> proxyList) { public void onNext(List<Proxy> proxyList) {
int w = 0;
int n = 0;
Boolean needReset = true;
for (Proxy proxy : proxyList) {
if (proxy.getPing() > 0) {
needReset = false;
w++;
} else
n++;
}
if (needReset)
ProcessPhoenix.triggerRebirth(SocketService.this);
work = false; work = false;
Log.e("Ping", "Task Check Finished for " + proxyList.size() + " Ips"); Log.e("Ping", "Task Check Finished for " + proxyList.size() + " Ips And " + w + " Ips Work and " + n + " IPS not work");
try { try {
String cipherText = cryptLib.encryptPlainTextWithRandomIV(gson.toJson(proxyList), key); String cipherText = cryptLib.encryptPlainTextWithRandomIV(gson.toJson(proxyList), key);
SingletonSocket.getInstance().getSocket().emit("checkping", cipherText); SingletonSocket.getInstance().getSocket().emit("checkping", cipherText);
...@@ -167,4 +171,5 @@ public class SocketService extends Service implements Emitter.Listener { ...@@ -167,4 +171,5 @@ public class SocketService extends Service implements Emitter.Listener {
} }
} }
...@@ -6,6 +6,8 @@ import android.util.Log; ...@@ -6,6 +6,8 @@ import android.util.Log;
public class ConnectionsManager { public class ConnectionsManager {
private int currentAccount = 0; private int currentAccount = 0;
private static volatile ConnectionsManager[] Instance = new ConnectionsManager[3]; private static volatile ConnectionsManager[] Instance = new ConnectionsManager[3];
...@@ -19,9 +21,7 @@ public class ConnectionsManager { ...@@ -19,9 +21,7 @@ public class ConnectionsManager {
public long checkProxy(String address, int port, String secret, RequestTimeDelegate requestTimeDelegate) { public long checkProxy(String address, int port, String secret, RequestTimeDelegate requestTimeDelegate) {
long l = native_checkProxy(currentAccount, address, port, "", "", secret, requestTimeDelegate); return native_checkProxy(currentAccount, address, port, "", "", secret, requestTimeDelegate);
Log.e("Here", String.valueOf(l));
return l;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment