Closed imwcc closed 4 years ago
Link to issues 274 支持 ping 所有的代理服务器,并且显示各个当前网络到服务器的延迟.
Hi @wongsyrone Could you help to review this PR?
Thank you very much.
OK. I requested reviews from @oasiscifr and @TchaikovDriver as well.
In fact, I prefer to Tcping instead of the plain Ping, as we use TCP instead of ICMP.
In fact, I prefer to Tcping instead of the plain Ping, as we use TCP instead of ICMP.
refer to https://github.com/stealthcopter/AndroidNetworkTools
Ping Uses the native ping binary if available on the device (some devices come without it) and falls back to a TCP request on port 7 (echo request) if not.
// Synchronously
PingResult pingResult = Ping.onAddress("192.168.0.1").setTimeOutMillis(1000).doPing();
// Asynchronously
Ping.onAddress("192.168.0.1").setTimeOutMillis(1000).setTimes(5).doPing(new Ping.PingListener() {
@Override
public void onResult(PingResult pingResult) {
...
}
});
Note: If we do have to fall back to using TCP port 7 (the java way) to detect devices we will find significantly less than with the native ping binary. If this is an issue you could consider adding a ping binary to your application or device so that it is always available.
Note: If you want a more advanced portscanner you should consider compiling nmap into your project and using that instead.
In fact, I prefer to Tcping instead of the plain Ping, as we use TCP instead of ICMP.
A month ago, I tried to test the latency by measuring a TLS handshake but failed, every handshake ended in timeout. I think I should review Computer Network :(
Hi @TchaikovDriver re-work done. Please help to review it. thank you.
Memory leak will not cause any crash, just occupy some memory. In this circumstance, the callback is held by the data manager, in the meantime, the callback refers the presenter and persenter refers the views, all the stuff will not be recycled as long as the test is not finished. With the help of weak reference, at least the presenter and views will not leak.
Arvin notifications@github.com 于 2020年9月11日周五 下午6:00写道:
@imwcc commented on this pull request.
In app/src/main/java/io/github/trojan_gfw/igniter/servers/presenter/ServerListPresenter.java https://github.com/trojan-gfw/igniter/pull/293#discussion_r486939572:
@@ -206,6 +212,30 @@ public void gotoScanQRCode() { mView.gotoScanQRCode(); }
- @Override
- public void pingAllProxyServer(List
configList) { - for (TrojanConfig config : configList) {
- mDataManager.pingTrojanConfigServer(config, new ServerListDataSource.PingCallback() {
Hi @TchaikovDriver https://github.com/TchaikovDriver If still a strong reference to ServerListPresenter. I have a question, Could you help me? scene:
If the mDataManager work thread has a long time IO work on the background. This time, click the back key to destroy the ServerListActivity. the mDataManager call back to UI thread ServerListActivity. No crash. no error logs.
Could help to explain it?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/trojan-gfw/igniter/pull/293#discussion_r486939572, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBIRSAVPLWKAVNVBGGOHKDSFHYMXANCNFSM4RGZ5HTA .
Memory leak will not cause any crash, just occupy some memory. In this circumstance, the callback is held by the data manager, in the meantime, the callback refers the presenter and persenter refers the views, all the stuff will not be recycled as long as the test is not finished. With the help of weak reference, at least the presenter and views will not leak. Arvin notifications@github.com 于 2020年9月11日周五 下午6:00写道: … @.**** commented on this pull request. ------------------------------ In app/src/main/java/io/github/trojan_gfw/igniter/servers/presenter/ServerListPresenter.java <#293 (comment)>: > @@ -206,6 +212,30 @@ public void gotoScanQRCode() { mView.gotoScanQRCode(); } + @override + public void pingAllProxyServer(List
configList) { + for (TrojanConfig config : configList) { + mDataManager.pingTrojanConfigServer(config, new ServerListDataSource.PingCallback() { Hi @TchaikovDriver https://github.com/TchaikovDriver If still a strong reference to ServerListPresenter. I have a question, Could you help me? scene: If the mDataManager work thread has a long time IO work on the background. This time, click the back key to destroy the ServerListActivity. the mDataManager call back to UI thread ServerListActivity. No crash. no error logs. Could help to explain it? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#293 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBIRSAVPLWKAVNVBGGOHKDSFHYMXANCNFSM4RGZ5HTA .
In Chinese? 感谢回答, 英语描述没有描述清晰
`public class SecondActivity extends Activity {
private static final String TAG = "SecondActivity";
private Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
TextView textView = this.findViewById(R.id.textView);
new Thread(new Runnable() {
@Override
public void run() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
Log.d(TAG, "test text");
textView.setText("test String");
}
}, 5000);
}
}).start();
handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
}
};
this.workthread();
}
@WorkerThread
private void workthread(){
Log.d(TAG,"workthread");
}
@Override
protected void onResume() {
Log.d(TAG,"onResume");
super.onResume();
}
@Override
protected void onStop() {
Log.d(TAG,"onStop");
super.onStop();
}
@Override
protected void onDestroy() {
Log.d(TAG,"onDestroy");
super.onDestroy();
}
}` Log: 2020-08-18 10:41:45.752 2615-2615/arvin.split_screen1 D/SecondActivity: onStop 2020-08-18 10:41:45.754 2615-2615/arvin.split_screen1 D/SecondActivity: onDestroy 2020-08-18 10:41:47.465 2615-2615/arvin.split_screen1 D/SecondActivity: test text
从log 来看, Activity已经destory, update UI 没有Error, 没有worning. 觉得奇怪.
Memory leak will not cause any crash, just occupy some memory. In this circumstance, the callback is held by the data manager, in the meantime, the callback refers the presenter and persenter refers the views, all the stuff will not be recycled as long as the test is not finished. With the help of weak reference, at least the presenter and views will not leak. Arvin notifications@github.com 于 2020年9月11日周五 下午6:00写道: … @.**** commented on this pull request. ------------------------------ In app/src/main/java/io/github/trojan_gfw/igniter/servers/presenter/ServerListPresenter.java <#293 (comment)>: > @@ -206,6 +212,30 @@ public void gotoScanQRCode() { mView.gotoScanQRCode(); } + @override + public void pingAllProxyServer(List configList) { + for (TrojanConfig config : configList) { + mDataManager.pingTrojanConfigServer(config, new ServerListDataSource.PingCallback() { Hi @TchaikovDriver https://github.com/TchaikovDriver If still a strong reference to ServerListPresenter. I have a question, Could you help me? scene: If the mDataManager work thread has a long time IO work on the background. This time, click the back key to destroy the ServerListActivity. the mDataManager call back to UI thread ServerListActivity. No crash. no error logs. Could help to explain it? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#293 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBIRSAVPLWKAVNVBGGOHKDSFHYMXANCNFSM4RGZ5HTA .
In Chinese? 感谢回答, 英语描述没有描述清晰
`public class SecondActivity extends Activity {
private static final String TAG = "SecondActivity"; private Handler handler; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); TextView textView = this.findViewById(R.id.textView); new Thread(new Runnable() { @Override public void run() { handler.postDelayed(new Runnable() { @Override public void run() { Log.d(TAG, "test text"); textView.setText("test String"); } }, 5000); } }).start(); handler = new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); } }; this.workthread(); } @WorkerThread private void workthread(){ Log.d(TAG,"workthread"); } @Override protected void onResume() { Log.d(TAG,"onResume"); super.onResume(); } @Override protected void onStop() { Log.d(TAG,"onStop"); super.onStop(); } @Override protected void onDestroy() { Log.d(TAG,"onDestroy"); super.onDestroy(); }
}` Log: 2020-08-18 10:41:45.752 2615-2615/arvin.split_screen1 D/SecondActivity: onStop 2020-08-18 10:41:45.754 2615-2615/arvin.split_screen1 D/SecondActivity: onDestroy 2020-08-18 10:41:47.465 2615-2615/arvin.split_screen1 D/SecondActivity: test text
从log 来看, Activity已经destory, update UI 没有Error, 没有worning. 觉得奇怪.
一般情况下内存泄漏是不会抛出异常的,内存泄漏以后dump一下内存能看到Activity实例仍然存在,仅仅会导致应用的内存占用变大。
在我们这个场景下,测试ping的线程持有了Callback,Callback作为Presenter的非静态内部类持有Presenter的实例,而Presenter又持有了View,也就是Fragment,Fragment自然也持有了Activity,所以只要ping测试没执行完,上面提到的一系列引用都没法被GC回收。
要解决这个问题,有两个方案,第一个是你在DataManager里创建一个测试ping的线程,在退出页面的时候通过Presenter去interrupt这个线程,线程被中止了,Callback不再被引用了,就没有内存泄漏的问题;另一个方案是Callback持有Presenter的弱引用(参考SubscribeCallback
),这样的话,View和Presenter都能被回收,只是Callback仍然会被持有一段时间直至ping线程执行完毕。
Memory leak will not cause any crash, just occupy some memory. In this circumstance, the callback is held by the data manager, in the meantime, the callback refers the presenter and persenter refers the views, all the stuff will not be recycled as long as the test is not finished. With the help of weak reference, at least the presenter and views will not leak. Arvin notifications@github.com 于 2020年9月11日周五 下午6:00写道: … @.**** commented on this pull request. ------------------------------ In app/src/main/java/io/github/trojan_gfw/igniter/servers/presenter/ServerListPresenter.java <#293 (comment)>: > @@ -206,6 +212,30 @@ public void gotoScanQRCode() { mView.gotoScanQRCode(); } + @override + public void pingAllProxyServer(List configList) { + for (TrojanConfig config : configList) { + mDataManager.pingTrojanConfigServer(config, new ServerListDataSource.PingCallback() { Hi @TchaikovDriver https://github.com/TchaikovDriver If still a strong reference to ServerListPresenter. I have a question, Could you help me? scene: If the mDataManager work thread has a long time IO work on the background. This time, click the back key to destroy the ServerListActivity. the mDataManager call back to UI thread ServerListActivity. No crash. no error logs. Could help to explain it? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#293 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBIRSAVPLWKAVNVBGGOHKDSFHYMXANCNFSM4RGZ5HTA .
In Chinese? 感谢回答, 英语描述没有描述清晰 `public class SecondActivity extends Activity {
private static final String TAG = "SecondActivity"; private Handler handler; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); TextView textView = this.findViewById(R.id.textView); new Thread(new Runnable() { @Override public void run() { handler.postDelayed(new Runnable() { @Override public void run() { Log.d(TAG, "test text"); textView.setText("test String"); } }, 5000); } }).start(); handler = new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); } }; this.workthread(); } @WorkerThread private void workthread(){ Log.d(TAG,"workthread"); } @Override protected void onResume() { Log.d(TAG,"onResume"); super.onResume(); } @Override protected void onStop() { Log.d(TAG,"onStop"); super.onStop(); } @Override protected void onDestroy() { Log.d(TAG,"onDestroy"); super.onDestroy(); }
}` Log: 2020-08-18 10:41:45.752 2615-2615/arvin.split_screen1 D/SecondActivity: onStop 2020-08-18 10:41:45.754 2615-2615/arvin.split_screen1 D/SecondActivity: onDestroy 2020-08-18 10:41:47.465 2615-2615/arvin.split_screen1 D/SecondActivity: test text 从log 来看, Activity已经destory, update UI 没有Error, 没有worning. 觉得奇怪.
一般情况下内存泄漏是不会抛出异常的,内存泄漏以后dump一下内存能看到Activity实例仍然存在,仅仅会导致应用的内存占用变大。 在我们这个场景下,测试ping的线程持有了Callback,Callback作为Presenter的非静态内部类持有Presenter的实例,而Presenter又持有了View,也就是Fragment,Fragment自然也持有了Activity,所以只要ping测试没执行完,上面提到的一系列引用都没法被GC回收。 要解决这个问题,有两个方案,第一个是你在DataManager里创建一个测试ping的线程,在退出页面的时候通过Presenter去interrupt这个线程,线程被中止了,Callback不再被引用了,就没有内存泄漏的问题;另一个方案是Callback持有Presenter的弱引用(参考
SubscribeCallback
),这样的话,View和Presenter都能被回收,只是Callback仍然会被持有一段时间直至ping线程执行完毕。
Thank you. Callback 回来, Presenter 还能调用API更新UI, 虽然UI已经destroy, Android还是比较宽容.
Hi @TchaikovDriver 谢谢你的review. 刚的内存问题已经修好了. 对于异步问题, 这是一个良好的习惯.
@wongsyrone LGTM
Thanks. Merged.
Test all proxy server ping delay times.
Signed-off-by: Arvin arvinxwang@gmail.com