Commit ab2ed827 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 5a1e826f
......@@ -4,6 +4,9 @@ repositories {
mavenCentral()
google()
jcenter()
maven {
url "https://jitpack.io"
}
}
configurations {
......@@ -40,6 +43,7 @@ dependencies {
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.6'
compile 'com.jakewharton:process-phoenix:2.0.0'
compile 'com.github.stealthcopter:AndroidNetworkTools:0.4.0'
}
......
......@@ -2,16 +2,24 @@ package org.telegram;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.stealthcopter.networktools.Ping;
import com.stealthcopter.networktools.ping.PingResult;
import com.stealthcopter.networktools.ping.PingStats;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
......
......@@ -6,4 +6,5 @@ package org.telegram.io;
public class Constants {
public static final String CHAT_SERVER_URL = "http://3.123.1.22:3000";
public static final String GET_JSON_FOR_PING = "ping";
public static final String GET_JSON_FOR_PING_Amazon = "pingAmazon";
}
......@@ -50,6 +50,15 @@ public class Proxy {
@SerializedName("type")
@Expose
private String type ;
@SerializedName("alias")
@Expose
private String alias ;
@SerializedName("aliasId")
@Expose
private String aliasId ;
@SerializedName("instance")
@Expose
private String instance ;
private Boolean connect=false;
......
......@@ -8,6 +8,9 @@ import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.stealthcopter.networktools.Ping;
import com.stealthcopter.networktools.ping.PingResult;
import com.stealthcopter.networktools.ping.PingStats;
import org.telegram.io.Constants;
import org.telegram.io.CryptLib;
......@@ -38,6 +41,7 @@ public class SocketService extends Service implements Emitter.Listener {
private static final String key = "6*sN_rZxHD4!X$=T";
ConnectionsManager connectionsManager;
Boolean work = false;
Boolean workAmazon = false;
@Override
......@@ -53,6 +57,7 @@ public class SocketService extends Service implements Emitter.Listener {
e.printStackTrace();
}
SingletonSocket.getInstance().getSocket().on(Constants.GET_JSON_FOR_PING, this);
SingletonSocket.getInstance().getSocket().on(Constants.GET_JSON_FOR_PING_Amazon, new PingAmazon());
SingletonSocket.getInstance().getSocket().connect();
}
......@@ -110,6 +115,36 @@ public class SocketService extends Service implements Emitter.Listener {
});
}
public Observable<Proxy> getPingAmazonServerObservable(Proxy proxy) {
return Observable.create(subscriber -> {
Ping.onAddress(proxy.getIp()).setTimeOutMillis(1000).setTimes(10).doPing(new Ping.PingListener() {
@Override
public void onResult(PingResult pingResult) {
}
@Override
public void onFinished(PingStats pingStats) {
if (pingStats.getPacketsLost() >=5)
proxy.setConnect(false);
else
proxy.setConnect(true);
subscriber.onNext(proxy);
subscriber.onCompleted();
}
@Override
public void onError(Exception e) {
}
});
});
}
public void initCheckProxy(List<Proxy> proxyList) {
......@@ -156,8 +191,59 @@ public class SocketService extends Service implements Emitter.Listener {
Log.e("Status Result :", "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);
String cipherText = cryptLib.encryptPlainTextWithRandomIV(gson.toJson(proxyList), key);
SingletonSocket.getInstance().getSocket().emit("checkping", cipherText);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public void initCheckAmazonProxy(List<Proxy> proxyList) {
Observable.from(proxyList)
.subscribeOn(Schedulers.newThread())
.concatMap(proxy -> getPingAmazonServerObservable(proxy)
.subscribeOn(Schedulers.newThread()))
.toList()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<List<Proxy>>() {
@Override
public void onCompleted() {
workAmazon = false;
}
@Override
public void onError(Throwable e) {
workAmazon = false;
}
@Override
public void onNext(List<Proxy> proxyList) {
int w = 0;
int n = 0;
for (Proxy proxy : proxyList) {
if (proxy.getConnect())
w++;
else
n++;
}
work = false;
Log.e("Status Amazon Result :", "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("checkAmazonPing", cipherText);
} catch (Exception e) {
e.printStackTrace();
......@@ -168,5 +254,26 @@ public class SocketService extends Service implements Emitter.Listener {
}
private class PingAmazon implements Emitter.Listener {
@Override
public void call(Object... args) {
if (args.length == 0 || workAmazon) return;
String chiper = String.valueOf(args[0]);
try {
String decrypt = cryptLib.decryptCipherTextWithRandomIV(chiper, key);
List<Proxy> proxyList = gson.fromJson(decrypt, new TypeToken<List<Proxy>>() {
}.getType());
proxyList = Utils.removeDuplicator(proxyList);
workAmazon = true;
initCheckAmazonProxy(proxyList);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
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