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

init

parent a9f6d80b
......@@ -3,30 +3,55 @@ package org.telegram;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import org.telegram.io.Proxy;
import org.telegram.messenger.R;
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.schedulers.Schedulers;
import rx.functions.Action1;
import rx.subjects.PublishSubject;
public class MainActivity extends AppCompatActivity {
EditText editText;
ConnectionsManager connectionsManager;
private int value = 0;
private PublishSubject<Integer> subject ;
@Override
protected void onCreate(Bundle 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 {
}
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 {
private String updatedAt;
@SerializedName("ping")
@Expose
private long ping = 0;
private long ping = -1;
@SerializedName("messageId")
@Expose
......@@ -47,6 +47,8 @@ public class Proxy {
@Expose
private int retry ;
private Boolean connect=false;
public int getId() {
return id;
}
......@@ -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;
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;
......@@ -98,35 +97,35 @@ public class SocketService extends Service implements Emitter.Listener {
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.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) {
Observable.from(proxyList)
.subscribeOn(Schedulers.io())
.subscribeOn(Schedulers.newThread())
.concatMap(proxy -> getPingServerObservable(proxy)
.subscribeOn(Schedulers.io())
.timeout(10, TimeUnit.SECONDS)
.onErrorResumeNext(t ->
{
proxy.setPing(0);
.subscribeOn(Schedulers.newThread())
.timeout(5, TimeUnit.SECONDS)
.onErrorResumeNext(throwable -> {
ConnectionsManager.setCaller(null);
proxy.setConnect(false);
return Observable.just(proxy);
}))
.toList()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<List<Proxy>>() {
......@@ -146,25 +145,19 @@ public class SocketService extends Service implements Emitter.Listener {
int n = 0;
for (Proxy proxy : proxyList) {
if (proxy.getPing() > 0)
if (proxy.getConnect())
w++;
else
n++;
}
if (w == 0) {
Log.e("Status :", "Try Stop");
SingletonSocket.getInstance().getSocket().disconnect();
stopSelf();
return;
}
work = false;
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();
......
......@@ -3,13 +3,14 @@ package org.telegram.tgnet;
import android.util.Log;
public class ConnectionsManager {
import org.telegram.io.Caller;
public class ConnectionsManager {
private int currentAccount = 0;
private static volatile ConnectionsManager[] Instance = new ConnectionsManager[3];
public static Caller caller = null;
public 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);
}
......@@ -138,7 +139,22 @@ public class ConnectionsManager {
}
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) {
......
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