Commit b05fa4ca authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 95485955
......@@ -18,22 +18,7 @@ dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
compileOnly 'org.checkerframework:checker-qual:2.5.0'
compileOnly 'org.checkerframework:checker-compat-qual:2.5.0'
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-messaging:17.3.0'
implementation 'com.google.firebase:firebase-config:16.0.0'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-vision:15.0.2'
implementation 'com.google.android.gms:play-services-wallet:16.0.0'
implementation 'com.google.android.gms:play-services-wearable:15.0.1'
implementation 'com.android.support:support-core-ui:28.0.0-rc01'
implementation 'com.android.support:support-compat:28.0.0-rc01'
implementation 'com.android.support:support-core-utils:28.0.0-rc01'
implementation 'com.android.support:support-v13:28.0.0-rc01'
implementation 'com.android.support:palette-v7:28.0.0-rc01'
implementation 'com.android.support:exifinterface:28.0.0-rc01'
implementation 'net.hockeyapp.android:HockeySDK:5.1.0'
implementation 'com.googlecode.mp4parser:isoparser:1.0.6'
implementation 'com.stripe:stripe-android:2.0.2'
implementation ('io.socket:socket.io-client:1.0.0') {
// excluding org.json which is provided by Android
exclude group: 'org.json', module: 'json'
......@@ -51,7 +36,7 @@ android {
compileSdkVersion 28
buildToolsVersion '28.0.2'
defaultConfig.applicationId = "org.telegram.messenger"
defaultConfig.applicationId = "org.telegram.hetzner"
......
......@@ -23,7 +23,13 @@ public class MainActivity extends AppCompatActivity {
}
@Override
protected void onResume() {
super.onResume();
startService(new Intent(this, SocketService.class));
}
}
......@@ -4,7 +4,9 @@ package org.telegram.io;
* Created by Ahmad Nemati on 1/17/19.
*/
public class Constants {
public static final String CHAT_SERVER_URL = "http://3.123.1.22:3000";
public static final String CHAT_SERVER_URL = "http://116.202.97.73:3000";
public static final String GET_JSON_FOR_PING = "ping";
public static final String WAKE_UP = "wakeup";
public static final String TYPE = "hetzner";
public static final String GET_JSON_FOR_PING_Amazon = "pingAmazon";
}
package org.telegram.io;
/**
* Created by Ahmad Nemati on 2019-10-22.
*/
public class Counter {
private String ip;
private int count=0;
public Counter(String ip, int count) {
this.ip = ip;
this.count = count;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public void setCountPlus() {
this.count++;
}
}
......@@ -60,6 +60,10 @@ public class Proxy {
@Expose
private String instance ;
@SerializedName("ipdate")
@Expose
private String ipdate ;
private long dur=0;
private Boolean connect=false;
......@@ -174,11 +178,32 @@ public class Proxy {
return type;
}
public String getAlias() {
return alias;
}
public String getAliasId() {
return aliasId;
}
public String getInstance() {
return instance;
}
public long getDur() {
return dur;
}
public void setDur(long dur) {
this.dur = dur;
}
public String getIpdate() {
return ipdate;
}
public void setIpdate(String ipdate) {
this.ipdate = ipdate;
}
}
......@@ -25,7 +25,7 @@ public class SingletonSocket {
opts.forceNew = true;
opts.reconnection = true;
opts.secure = true;
opts.query="type=Ping";
opts.query="type="+Constants.TYPE;
mSocket = IO.socket(Constants.CHAT_SERVER_URL,opts);
} catch (URISyntaxException e) {
......
......@@ -14,6 +14,11 @@ import android.content.Intent;
import org.telegram.io.SingletonSocket;
import org.telegram.service.SocketService;
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.tgnet.RequestDelegate;
import org.telegram.tgnet.TLObject;
import org.telegram.tgnet.TLRPC;
import static org.telegram.tgnet.ConnectionsManager.RequestFlagFailOnServerErrors;
public class ApplicationLoader extends Application {
......@@ -29,6 +34,12 @@ public class ApplicationLoader extends Application {
startService(new Intent(this, SocketService.class));
ConnectionsManager.native_setJava(false);
// ConnectionsManager.setProxySettings("78.46.148.22", 443, "00000000000000000000000000000000");
}
......
......@@ -10,16 +10,15 @@ import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.telegram.io.Constants;
import org.telegram.io.Counter;
import org.telegram.io.CryptLib;
import org.telegram.io.Proxy;
import org.telegram.io.SingletonSocket;
import org.telegram.io.Utils;
import org.telegram.tgnet.ConnectionsManager;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
......@@ -42,6 +41,7 @@ public class SocketService extends Service implements Emitter.Listener {
ConnectionsManager connectionsManager;
Boolean work = false;
Boolean workAmazon = false;
private List<Counter> counters = new ArrayList<>();
@Override
......@@ -56,12 +56,23 @@ public class SocketService extends Service implements Emitter.Listener {
} catch (NoSuchPaddingException e) {
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().on(Constants.WAKE_UP, args -> {
if (work) return;
needSendProxy();
});
SingletonSocket.getInstance().getSocket().connect();
}
private void needSendProxy() {
SingletonSocket.getInstance().getSocket().emit("need", "");
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
......@@ -79,7 +90,7 @@ public class SocketService extends Service implements Emitter.Listener {
if (args.length == 0 || work) return;
Log.e("Ping from server Size", String.valueOf(args.length));
Log.e("Proxy from server Size", String.valueOf(args.length));
String chiper = String.valueOf(args[0]);
try {
......@@ -102,16 +113,16 @@ public class SocketService extends Service implements Emitter.Listener {
return Observable.create(subscriber -> {
if (proxy.getType().equals("especial")) {
proxy.setConnect(true);
subscriber.onNext(proxy);
subscriber.onCompleted();
}
// if (getCounter(proxy.getIp()) > 2) {
// subscriber.onError(null);
// subscriber.onCompleted();
// return;
// }
long startTime = System.nanoTime();
ConnectionsManager.defaultIp = proxy.getIp();
ConnectionsManager.setCaller(status -> {
Log.e("Proxy Connect", "IP :" + proxy.getIp());
Log.e("Proxy Connect", "IP ***Work*** :" + proxy.getIp() + " " + Constants.TYPE);
addCounter(proxy.getIp(), true);
long endTime = System.nanoTime();
long duration = (endTime - startTime) / 1000000 - 120;
proxy.setDur(duration);
......@@ -126,112 +137,78 @@ public class SocketService extends Service implements Emitter.Listener {
});
}
public Observable<Proxy> getPingAmazonServerObservable(Proxy proxy) {
private Boolean addCounter(String ip, Boolean work) {
for (int i = 0; i < counters.size(); i++) {
if (counters.get(i).getIp().equals(ip)) {
return Observable.create(subscriber -> {
try {
Process process = Runtime.getRuntime().exec("ping -c 7 " + proxy.getIp());
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String log = "";
String line;
while ((line = bufferedReader.readLine()) != null) {
if (!line.contains("received"))
continue;
log = line;
if (work) {
counters.get(i).setCount(0);
return true;
} else {
counters.get(i).setCountPlus();
return counters.get(i).getCount() <= 5;
}
}
String[] res = log.split(",");
int packetRes = Integer.parseInt(res[1].replace("received", "").trim());
if (packetRes <= 2)
proxy.setConnect(false);
else
proxy.setConnect(true);
subscriber.onNext(proxy);
subscriber.onCompleted();
}
} catch (IOException e) {
Log.e("Amazon Error", "Error");
proxy.setConnect(true);
subscriber.onNext(proxy);
subscriber.onCompleted();
Counter counter = new Counter(ip, work ? 0 : 1);
}
counters.add(counter);
return true;
});
}
private int getCounter(String ip) {
public void initCheckProxy(List<Proxy> proxyList) {
for (int i = 0; i < counters.size(); i++) {
if (counters.get(i).getIp().equals(ip)) {
Observable.from(proxyList)
.subscribeOn(Schedulers.newThread())
.concatMap(proxy -> getPingServerObservable(proxy)
.subscribeOn(Schedulers.newThread())
.timeout(5, TimeUnit.SECONDS)
.onErrorResumeNext(throwable -> {
ConnectionsManager.setCaller(null);
proxy.setConnect(false);
return Observable.just(proxy);
}))
return counters.get(i).getCount();
}
.toList()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<List<Proxy>>() {
@Override
public void onCompleted() {
work = false;
}
@Override
public void onError(Throwable e) {
work = false;
}
@Override
public void onNext(List<Proxy> proxyList) {
int w = 0;
int n = 0;
Counter counter = new Counter(ip, 0);
counters.add(counter);
for (Proxy proxy : proxyList) {
if (proxy.getConnect())
w++;
else
n++;
}
return 0;
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);
} catch (Exception e) {
e.printStackTrace();
}
}
});
public void initCheckProxy(List<Proxy> proxyList) {
Observable.from(proxyList)
.subscribeOn(Schedulers.newThread())
.concatMap(proxy -> getPingServerObservable(proxy)
.subscribeOn(Schedulers.newThread())
.timeout(10, TimeUnit.SECONDS)
.onErrorResumeNext(throwable -> {
ConnectionsManager.setCaller(null);
if (!addCounter(proxy.getIp(), false)) {
proxy.setConnect(false);
Log.e("Proxy Connect", "IP Not Work :" + proxy.getIp() + " " + Constants.TYPE);
} else {
proxy.setConnect(true);
Log.e("Proxy Connect", "IP So So :" + proxy.getIp() + " " + Constants.TYPE);
}
public void initCheckAmazonProxy(List<Proxy> proxyList) {
return Observable.just(proxy);
Observable.from(proxyList)
.subscribeOn(Schedulers.newThread())
.flatMap(proxy -> getPingAmazonServerObservable(proxy)
.subscribeOn(Schedulers.newThread()))
}))
.toList()
......@@ -239,63 +216,49 @@ public class SocketService extends Service implements Emitter.Listener {
.subscribe(new Subscriber<List<Proxy>>() {
@Override
public void onCompleted() {
workAmazon = false;
work = false;
}
@Override
public void onError(Throwable e) {
workAmazon = false;
work = false;
}
@Override
public void onNext(List<Proxy> proxyList) {
int w = 0;
int n = 0;
List<Proxy> notWork = new ArrayList<>();
for (Proxy proxy : proxyList) {
if (proxy.getConnect())
w++;
else
else {
notWork.add(proxy);
n++;
Log.e("Status", proxy.getInstance());
}
}
work = false;
Log.e("Status Amazon Result :", "Task Check Finished for " + proxyList.size() + " Ips And " + w + " Ips Work and " + n + " IPS not work");
work = false;
Log.e("Status Proxy Result :", "Task Check Finished for " + proxyList.size() + " Ips And " + w + " Ips Work and " + n + " IPS not work" + " " + Constants.TYPE);
if (notWork.size() != 0) {
try {
String cipherText = cryptLib.encryptPlainTextWithRandomIV(gson.toJson(proxyList), key);
SingletonSocket.getInstance().getSocket().emit("checkAmazonPing", cipherText);
String cipherText = cryptLib.encryptPlainTextWithRandomIV(gson.toJson(notWork), key);
SingletonSocket.getInstance().getSocket().emit("checkping", cipherText);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
});
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();
}
}
}
}
......@@ -24,7 +24,7 @@ public abstract class AbstractSerializedData {
public abstract void writeDouble(double d);
public abstract void writeByteBuffer(NativeByteBuffer buffer);
public abstract int readInt32(boolean exception);
......@@ -40,7 +40,7 @@ public abstract class AbstractSerializedData {
public abstract byte[] readByteArray(boolean exception);
public abstract NativeByteBuffer readByteBuffer(boolean exception);
public abstract double readDouble(boolean exception);
......
......@@ -5,12 +5,15 @@ import android.util.Log;
import org.telegram.io.Caller;
import java.util.concurrent.atomic.AtomicInteger;
public class ConnectionsManager {
private int currentAccount = 0;
public static Caller caller = null;
public static String defaultIp = "127.0.0.1";
public ConnectionsManager() {
......@@ -100,6 +103,14 @@ public class ConnectionsManager {
return false;
}
public final static int RequestFlagEnableUnauthorized = 1;
public final static int RequestFlagFailOnServerErrors = 2;
public final static int RequestFlagCanCompress = 4;
public final static int RequestFlagWithoutLogin = 8;
public final static int RequestFlagTryDifferentDc = 16;
public final static int RequestFlagForceDownload = 32;
public final static int RequestFlagInvokeAfter = 64;
public final static int RequestFlagNeedQuickAck = 128;
public void setAppPaused(final boolean value, final boolean byScreenState) {
......@@ -114,6 +125,54 @@ public class ConnectionsManager {
}
public final static int DEFAULT_DATACENTER_ID = Integer.MAX_VALUE;
public final static int ConnectionTypeGeneric = 1;
public static int sendRequest() {
final TLRPC.TL_auth_signIn req = new TLRPC.TL_auth_signIn();
req.phone_number = "9371455245";
req.phone_code = "98";
req.phone_code_hash = "0";
return sendRequest(req, new RequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
}
}, null, null, ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin, DEFAULT_DATACENTER_ID, ConnectionTypeGeneric, true);
}
public static int sendRequest(final TLObject object, final RequestDelegate onComplete, final QuickAckDelegate onQuickAck, final WriteToSocketDelegate onWriteToSocket, final int flags, final int datacenterId, final int connetionType, final boolean immediate) {
String ip = defaultIp;
AtomicInteger lastRequestToken = new AtomicInteger(1);
final int requestToken = lastRequestToken.getAndIncrement();
try {
NativeByteBuffer buffer = new NativeByteBuffer(object.getObjectSize());
object.serializeToStream(buffer);
object.freeResources();
native_sendRequest(0, buffer.address, (response, errorCode, errorText, networkType) -> {
if (defaultIp.equals(ip))
{
if (caller != null) {
caller.status(0);
} else {
Log.e("Ip Caller", "Null");
}
}
}, onQuickAck, onWriteToSocket, flags, datacenterId, connetionType, immediate, requestToken);
} catch (Exception e) {
// FileLog.e(e);
}
return requestToken;
}
public static int getCurrentNetworkType() {
return 0;
......@@ -140,12 +199,8 @@ 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");
}
// Log.e("Ip Status Must", String.valueOf(state));
sendRequest();
}
......
/*
* This is the source code of Telegram for Android v. 3.x.x.
* This is the source code of Telegram for Android v. 5.x.x.
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Nikolai Kudashov, 2013-2017.
* Copyright Nikolai Kudashov, 2013-2018.
*/
package org.telegram.tgnet;
public class TLObject {
public int networkType;
public boolean disableFree = false;
private static final ThreadLocal<NativeByteBuffer> sizeCalculator = new ThreadLocal<NativeByteBuffer>() {
@Override
protected NativeByteBuffer initialValue() {
return new NativeByteBuffer(true);
}
};
public TLObject() {
......@@ -21,11 +28,22 @@ public class TLObject {
}
public void serializeToStream(AbstractSerializedData stream) {
}
public TLObject deserializeResponse(AbstractSerializedData stream, int constructor, boolean exception) {
return null;
}
public void freeResources() {
}
public int getObjectSize() {
NativeByteBuffer byteBuffer = sizeCalculator.get();
byteBuffer.rewind();
serializeToStream(sizeCalculator.get());
return byteBuffer.length();
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="AppName">Telegram</string>
<string name="AppNameBeta">Telegram Beta</string>
<string name="AppNameBeta">hetzner</string>
<string name="LanguageName">English</string>
<string name="English">English</string>
<string name="LanguageNameInEnglish">English</string>
......
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