Commit 1d9d80db authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent a9f6d80b
...@@ -3,30 +3,55 @@ package org.telegram; ...@@ -3,30 +3,55 @@ package org.telegram;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log; import android.util.Log;
import android.view.View;
import android.widget.EditText; import android.widget.EditText;
import org.telegram.io.Proxy;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.tgnet.ConnectionsManager; import org.telegram.tgnet.ConnectionsManager;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.Subscriber; import rx.Subscriber;
import rx.schedulers.Schedulers; import rx.functions.Action1;
import rx.subjects.PublishSubject;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
EditText editText; EditText editText;
ConnectionsManager connectionsManager; ConnectionsManager connectionsManager;
private int value = 0;
private PublishSubject<Integer> subject ;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ConnectionsManager.setProxySettings("NewProxy.dynu.net",9969,"00000000000000000000000000000000");
getSubject().subscribe(new Subscriber<Integer>() {
@Override
public void onCompleted() {
Log.e("Tag","onCompleted");
}
@Override
public void onError(Throwable e) {
Log.e("Tag","onError");
}
@Override
public void onNext(Integer integer) {
Log.e("Tag","rxvalue :"+integer);
}
});
setValue(15);
}
});
...@@ -34,8 +59,27 @@ public class MainActivity extends AppCompatActivity { ...@@ -34,8 +59,27 @@ public class MainActivity extends AppCompatActivity {
} }
private PublishSubject<Integer> getSubject()
{
subject=PublishSubject.create();
return subject;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
if (subject !=null)
{
subject.onNext(value);
subject.onCompleted();
}
}
} }
package org.telegram.io;
/**
* Created by Ahmad Nemati on 2/1/19.
*/
public interface Caller {
void status(int status);
}
...@@ -38,7 +38,7 @@ public class Proxy { ...@@ -38,7 +38,7 @@ public class Proxy {
private String updatedAt; private String updatedAt;
@SerializedName("ping") @SerializedName("ping")
@Expose @Expose
private long ping = 0; private long ping = -1;
@SerializedName("messageId") @SerializedName("messageId")
@Expose @Expose
...@@ -47,6 +47,8 @@ public class Proxy { ...@@ -47,6 +47,8 @@ public class Proxy {
@Expose @Expose
private int retry ; private int retry ;
private Boolean connect=false;
public int getId() { public int getId() {
return id; return id;
} }
...@@ -144,5 +146,12 @@ public class Proxy { ...@@ -144,5 +146,12 @@ public class Proxy {
} }
public Boolean getConnect() {
return connect;
}
public void setConnect(Boolean connect) {
this.connect = connect;
}
} }
...@@ -8,7 +8,6 @@ import android.util.Log; ...@@ -8,7 +8,6 @@ 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;
...@@ -98,35 +97,35 @@ public class SocketService extends Service implements Emitter.Listener { ...@@ -98,35 +97,35 @@ public class SocketService extends Service implements Emitter.Listener {
return Observable.create(subscriber -> { return Observable.create(subscriber -> {
ConnectionsManager.setCaller(status -> {
Log.e("Proxy Connect", "IP :" + proxy.getIp());
proxy.setConnect(true);
subscriber.onNext(proxy);
subscriber.onCompleted();
});
ConnectionsManager.setProxySettings(proxy.getIp(), proxy.getPort(), proxy.getSecret()); ConnectionsManager.setProxySettings(proxy.getIp(), proxy.getPort(), proxy.getSecret());
connectionsManager.checkProxy(proxy.getIp(), proxy.getPort(), proxy.getSecret()
, time -> {
proxy.setPing(time == -1 ? 0 : time);
subscriber.onNext(proxy);
subscriber.onCompleted();
});
});
});
} }
public void initCheckProxy(List<Proxy> proxyList) { public void initCheckProxy(List<Proxy> proxyList) {
Observable.from(proxyList) Observable.from(proxyList)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.newThread())
.concatMap(proxy -> getPingServerObservable(proxy) .concatMap(proxy -> getPingServerObservable(proxy)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.newThread())
.timeout(10, TimeUnit.SECONDS) .timeout(5, TimeUnit.SECONDS)
.onErrorResumeNext(t -> .onErrorResumeNext(throwable -> {
ConnectionsManager.setCaller(null);
{ proxy.setConnect(false);
proxy.setPing(0);
return Observable.just(proxy); return Observable.just(proxy);
})) }))
.toList() .toList()
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<List<Proxy>>() { .subscribe(new Subscriber<List<Proxy>>() {
...@@ -146,25 +145,19 @@ public class SocketService extends Service implements Emitter.Listener { ...@@ -146,25 +145,19 @@ public class SocketService extends Service implements Emitter.Listener {
int n = 0; int n = 0;
for (Proxy proxy : proxyList) { for (Proxy proxy : proxyList) {
if (proxy.getPing() > 0) if (proxy.getConnect())
w++; w++;
else else
n++; n++;
} }
if (w == 0) {
Log.e("Status :", "Try Stop");
SingletonSocket.getInstance().getSocket().disconnect();
stopSelf();
return;
}
work = false; work = false;
Log.e("Status Result :", "Task Check Finished for " + proxyList.size() + " Ips And " + w + " Ips Work and " + n + " IPS not work"); Log.e("Status Result :", "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);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -3,13 +3,14 @@ package org.telegram.tgnet; ...@@ -3,13 +3,14 @@ package org.telegram.tgnet;
import android.util.Log; import android.util.Log;
public class ConnectionsManager { import org.telegram.io.Caller;
public class ConnectionsManager {
private int currentAccount = 0; private int currentAccount = 0;
private static volatile ConnectionsManager[] Instance = new ConnectionsManager[3];
public static Caller caller = null;
public ConnectionsManager() { public ConnectionsManager() {
...@@ -19,7 +20,7 @@ public class ConnectionsManager { ...@@ -19,7 +20,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) {
return native_checkProxy(currentAccount, address, port, "", "", secret, requestTimeDelegate); return native_checkProxy(currentAccount, address, port, "", "", secret, requestTimeDelegate);
} }
...@@ -138,7 +139,22 @@ public class ConnectionsManager { ...@@ -138,7 +139,22 @@ public class ConnectionsManager {
} }
public static void onConnectionStateChanged(final int state, final int currentAccount) { public static void onConnectionStateChanged(final int state, final int currentAccount) {
if (state == 3) {
Log.e("Ip Status Must", String.valueOf(state));
if (caller != null) {
caller.status(state);
} else {
Log.e("Ip Caller", "Null");
}
}
}
public static void setCaller(Caller clr) {
caller = clr;
} }
public static void onLogout(final int currentAccount) { public static void onLogout(final int currentAccount) {
......
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