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

init

parent 257d1e51
......@@ -39,6 +39,7 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.5'
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.6'
compile 'com.jakewharton:process-phoenix:2.0.0'
}
......
......@@ -43,8 +43,9 @@ public class Proxy {
@SerializedName("messageId")
@Expose
private String messageId;
private int retry = 0;
@SerializedName("retry")
@Expose
private int retry ;
public int getId() {
return id;
......
......@@ -8,6 +8,7 @@ import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jakewharton.processphoenix.ProcessPhoenix;
import org.telegram.io.Constants;
import org.telegram.io.CryptLib;
......@@ -25,6 +26,7 @@ import javax.crypto.NoSuchPaddingException;
import io.socket.emitter.Emitter;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
......@@ -70,12 +72,10 @@ public class SocketService extends Service implements Emitter.Listener {
@Override
public void call(Object... args) {
if (args.length == 0) return;
if (work) {
Log.e("Ping", "Reject Worker is work!");
return;
}
Log.e("Received from server", String.valueOf(args.length));
if (args.length == 0 || work) return;
Log.e("Ping from server Size", String.valueOf(args.length));
String chiper = String.valueOf(args[0]);
try {
......@@ -101,7 +101,7 @@ public class SocketService extends Service implements Emitter.Listener {
ConnectionsManager.setProxySettings(proxy.getIp(), proxy.getPort(), proxy.getSecret());
connectionsManager.checkProxy(proxy.getIp(), proxy.getPort(), proxy.getSecret()
, time -> {
proxy.setPing(time);
proxy.setPing(time == -1 ? 0 : time);
subscriber.onNext(proxy);
subscriber.onCompleted();
});
......@@ -110,6 +110,8 @@ public class SocketService extends Service implements Emitter.Listener {
}
public void initCheckProxy(List<Proxy> proxyList) {
......@@ -118,31 +120,19 @@ public class SocketService extends Service implements Emitter.Listener {
.subscribeOn(Schedulers.io())
.concatMap(proxy -> getPingServerObservable(proxy)
.subscribeOn(Schedulers.io())
.timeout(5, TimeUnit.SECONDS)
.timeout(10, TimeUnit.SECONDS)
.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()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<List<Proxy>>() {
@Override
public void onCompleted() {
work = false;
//Log.e("Ping", "Done");
}
@Override
......@@ -152,8 +142,22 @@ public class SocketService extends Service implements Emitter.Listener {
@Override
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;
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 {
String cipherText = cryptLib.encryptPlainTextWithRandomIV(gson.toJson(proxyList), key);
SingletonSocket.getInstance().getSocket().emit("checkping", cipherText);
......@@ -167,4 +171,5 @@ public class SocketService extends Service implements Emitter.Listener {
}
}
......@@ -6,6 +6,8 @@ import android.util.Log;
public class ConnectionsManager {
private int currentAccount = 0;
private static volatile ConnectionsManager[] Instance = new ConnectionsManager[3];
......@@ -19,9 +21,7 @@ public class ConnectionsManager {
public long checkProxy(String address, int port, String secret, RequestTimeDelegate requestTimeDelegate) {
long l = native_checkProxy(currentAccount, address, port, "", "", secret, requestTimeDelegate);
Log.e("Here", String.valueOf(l));
return l;
return native_checkProxy(currentAccount, address, port, "", "", secret, requestTimeDelegate);
}
......
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