wait for hostname
This commit is contained in:
parent
e776e12492
commit
3f384c060b
|
@ -137,6 +137,13 @@ public class OrbotMainActivity extends AppCompatActivity
|
||||||
|
|
||||||
private ArrayList<Bridge> alBridges = null;
|
private ArrayList<Bridge> alBridges = null;
|
||||||
|
|
||||||
|
private String[] mProjection = new String[]{
|
||||||
|
HSContentProvider.HiddenService._ID,
|
||||||
|
HSContentProvider.HiddenService.NAME,
|
||||||
|
HSContentProvider.HiddenService.DOMAIN,
|
||||||
|
HSContentProvider.HiddenService.PORT,
|
||||||
|
HSContentProvider.HiddenService.ONION_PORT};
|
||||||
|
|
||||||
//this is needed for backwards compat back to Android 2.3.*
|
//this is needed for backwards compat back to Android 2.3.*
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
public View onCreateView(View parent, String name, Context context, AttributeSet attrs)
|
public View onCreateView(View parent, String name, Context context, AttributeSet attrs)
|
||||||
|
@ -567,39 +574,69 @@ public class OrbotMainActivity extends AppCompatActivity
|
||||||
|
|
||||||
private void enableHiddenServicePort (String hsName, int hsPort, int hsRemotePort, boolean getGey) throws RemoteException, InterruptedException
|
private void enableHiddenServicePort (String hsName, int hsPort, int hsRemotePort, boolean getGey) throws RemoteException, InterruptedException
|
||||||
{
|
{
|
||||||
String onionHostname="";
|
String onionHostname = null;
|
||||||
String[] mProjection = new String[]{
|
|
||||||
HSContentProvider.HiddenService._ID,
|
final int mHsPort = hsPort;
|
||||||
HSContentProvider.HiddenService.NAME,
|
|
||||||
HSContentProvider.HiddenService.DOMAIN,
|
|
||||||
HSContentProvider.HiddenService.PORT,
|
|
||||||
HSContentProvider.HiddenService.ONION_PORT};
|
|
||||||
|
|
||||||
if(hsName == null)
|
if(hsName == null)
|
||||||
hsName = "hs"+hsPort;
|
hsName = "hs" + mHsPort;
|
||||||
|
|
||||||
if(hsRemotePort == -1)
|
if(hsRemotePort == -1)
|
||||||
hsRemotePort = hsPort;
|
hsRemotePort = mHsPort;
|
||||||
|
|
||||||
ContentValues fields = new ContentValues();
|
ContentValues fields = new ContentValues();
|
||||||
fields.put("name", hsName);
|
fields.put("name", hsName);
|
||||||
fields.put("port", hsPort);
|
fields.put("port", mHsPort);
|
||||||
fields.put("onion_port", hsRemotePort);
|
fields.put("onion_port", hsRemotePort);
|
||||||
|
|
||||||
ContentResolver cr = getContentResolver();
|
ContentResolver cr = getContentResolver();
|
||||||
Cursor row = cr.query(HSContentProvider.CONTENT_URI, mProjection, "port="+hsPort, null, null);
|
Cursor row = cr.query(HSContentProvider.CONTENT_URI, mProjection, "port=" + mHsPort, null, null);
|
||||||
|
|
||||||
if(row == null) {
|
if(row == null) {
|
||||||
cr.insert(HSContentProvider.CONTENT_URI, fields);
|
cr.insert(HSContentProvider.CONTENT_URI, fields);
|
||||||
} else {
|
} else {
|
||||||
onionHostname = row.getString(row.getColumnIndex(HSContentProvider.HiddenService.NAME));
|
onionHostname = row.getString(row.getColumnIndex(HSContentProvider.HiddenService.NAME));
|
||||||
cr.update(HSContentProvider.CONTENT_URI, fields, "port=" + hsPort, null);
|
cr.update(HSContentProvider.CONTENT_URI, fields, "port=" + mHsPort, null);
|
||||||
row.close();
|
row.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(onionHostname == null) {
|
||||||
|
|
||||||
requestTorRereadConfig();
|
requestTorRereadConfig();
|
||||||
|
|
||||||
// TODO: Wait for hostname
|
new Thread () {
|
||||||
|
|
||||||
|
public void run ()
|
||||||
|
{
|
||||||
|
String hostname = null;
|
||||||
|
|
||||||
|
while (hostname == null)
|
||||||
|
{
|
||||||
|
//we need to stop and start Tor
|
||||||
|
try {
|
||||||
|
Thread.sleep(3000); //wait three seconds
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Cursor onion = getContentResolver().query(HSContentProvider.CONTENT_URI, mProjection, "port=" + mHsPort, null, null);
|
||||||
|
if(onion != null) {
|
||||||
|
hostname = onion.getString(onion.getColumnIndex(HSContentProvider.HiddenService.NAME));
|
||||||
|
onion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Intent nResult = new Intent();
|
||||||
|
nResult.putExtra("hs_host", hostname);
|
||||||
|
// TODO: Add key
|
||||||
|
setResult(RESULT_OK, nResult);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Intent nResult = new Intent();
|
Intent nResult = new Intent();
|
||||||
nResult.putExtra("hs_host", onionHostname);
|
nResult.putExtra("hs_host", onionHostname);
|
||||||
// TODO: Add key
|
// TODO: Add key
|
||||||
|
|
Loading…
Reference in New Issue