testing i2p

This commit is contained in:
Adithya Abraham Philip 2015-06-13 06:14:03 +05:30
parent d3fbd4f062
commit 4651bb622d
2 changed files with 61 additions and 6 deletions

View File

@ -18,7 +18,11 @@
package org.sufficientlysecure.keychain.keyimport;
import com.squareup.okhttp.*;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import okio.BufferedSink;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.pgp.PgpHelper;
@ -47,6 +51,8 @@ import de.measite.minidns.Question;
import de.measite.minidns.Record;
import de.measite.minidns.record.SRV;
import javax.net.ssl.HttpsURLConnection;
public class HkpKeyserver extends Keyserver {
private static class HttpError extends Exception {
private static final long serialVersionUID = 1718783705229428893L;
@ -216,14 +222,14 @@ public class HkpKeyserver extends Keyserver {
private String query(String request, Proxy proxy) throws QueryFailedException, HttpError {
try {
tempIpTest(proxy);
URL url = new URL(getUrlPrefix() + mHost + ":" + mPort + request);
Log.d(Constants.TAG, "hkp keyserver query: " + url);
Log.d("PHILIP", "hkpKeyserver query(): " + proxy);
OkHttpClient client = getClient(url, proxy);
OkHttpClient client = getClient(new URL("https://www.eepsite.com"), proxy);
Response response = client.newCall(new Request.Builder().url(url).build()).execute();
tempIpTest(proxy);
String responseBody = response.body().string();// contains body both in case of success or failure
if (response.isSuccessful()) {
@ -238,7 +244,11 @@ public class HkpKeyserver extends Keyserver {
}
private void tempIpTest(Proxy proxy) throws IOException {
URL url = new URL("https://wtfismyip.com/text");
URL url = new URL("http://www.eepsite.com");
HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy);
connection.setConnectTimeout(100000);
connection.connect();
Log.e("Philip", connection.getResponseMessage()+" ");
Response response = getClient(url, proxy).newCall(new Request.Builder().url(url).build()).execute();
Log.e("PHILIP", "proxy Test: " + response.body().string());
}

View File

@ -28,6 +28,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import net.i2p.android.ui.I2PAndroidHelper;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.intents.OpenKeychainIntents;
@ -85,11 +86,16 @@ public class ImportKeysActivity extends BaseNfcActivity {
private Fragment mTopFragment;
private View mImportButton;
private I2PAndroidHelper mI2PHelper;
private boolean mI2PHelperBound;
private boolean mI2PProxyInitialized;
private Preferences.ProxyPrefs mProxyPrefs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mI2PHelper = new I2PAndroidHelper(this);
mProxyPrefs = Preferences.getPreferences(this).getProxyPrefs();
@ -317,7 +323,8 @@ public class ImportKeysActivity extends BaseNfcActivity {
* specified in user preferences
*/
private void startCloudFragment(Bundle savedInstanceState, String query, boolean disableQueryEdit, String keyserver) {
private void startCloudFragment(Bundle savedInstanceState, String query, boolean disableQueryEdit, String
keyserver) {
// However, if we're being restored from a previous state,
// then we don't need to do anything and should return or else
// we could end up with overlapping fragments.
@ -359,6 +366,13 @@ public class ImportKeysActivity extends BaseNfcActivity {
mListFragment.loadNew(loaderState, mProxyPrefs.parcelableProxy);
}
};
if (mProxyPrefs.category == Preferences.ProxyPrefs.Category.I2P) {
mI2PProxyInitialized = true;
if (mI2PHelperBound && !mI2PHelper.isI2PAndroidRunning()) {
mI2PHelper.requestI2PAndroidStart(this);
}
Log.e("Philip", "i2p: " + mI2PHelper.areTunnelsActive());
}
if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, mProxyPrefs, this)) {
mListFragment.loadNew(loaderState, mProxyPrefs.parcelableProxy);
}
@ -367,6 +381,16 @@ public class ImportKeysActivity extends BaseNfcActivity {
}
}
public boolean isProxyReady() {
if (!mI2PHelper.isI2PAndroidRunning()) {
return false;
} else if (!mI2PHelper.areTunnelsActive()) {
return false;
}
return true;
}
private void handleMessage(Message message) {
if (message.arg1 == ServiceProgressHandler.MessageStatus.OKAY.ordinal()) {
// get returned data bundle
@ -510,4 +534,25 @@ public class ImportKeysActivity extends BaseNfcActivity {
// either way, finish afterwards
finish();
}
@Override
protected void onStop() {
super.onStop();
mI2PHelper.unbind();
mI2PHelperBound = false;
}
@Override
protected void onStart() {
super.onStart();
// Try to bind to I2P Android
mI2PHelper.bind(new I2PAndroidHelper.Callback() {
@Override
public void onI2PAndroidBound() {
mI2PHelperBound = true;
if (mI2PProxyInitialized && !mI2PHelper.isI2PAndroidRunning())
mI2PHelper.requestI2PAndroidStart(ImportKeysActivity.this);
}
});
}
}