Skip to content

Commit

Permalink
fix remote nodes connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Mas7erMind committed Mar 7, 2024
1 parent c8aa227 commit fad1567
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 26 deletions.
19 changes: 9 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ android {
defaultConfig {
applicationId "io.scalaproject.vault"
buildToolsVersion = '34.0.0'
compileSdk 33
compileSdk 34
minSdkVersion 21
targetSdkVersion 33
versionCode 13
versionName "1.1.2"
targetSdkVersion 34
versionCode 14
versionName "1.1.3"

testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
externalNativeBuild {
Expand Down Expand Up @@ -115,16 +115,15 @@ android {
}

dependencies {
//noinspection GradleDependency
implementation 'com.google.android.material:material:1.0.0' // keep version 1.0.0 as it fixes a bug with Material Button

implementation 'com.google.android.material:material:1.11.0' // keep version 1.0.0 as it fixes a bug with Material Button
implementation "com.android.support:support-v4"
implementation "com.android.support:recyclerview-v7"
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
//noinspection GradleDependency
implementation 'com.google.android.material:material:1.1.0' // keep version 1.1.0 as it fixes a bug with Material Button
//noinspection GradleDependency
implementation 'androidx.appcompat:appcompat:1.1.0' // keep version 1.1.0 as it fixes a bug with Material Button

implementation 'com.google.android.material:material:1.11.0' // keep version 1.1.0 as it fixes a bug with Material Button
implementation 'androidx.appcompat:appcompat:1.6.1' // keep version 1.1.0 as it fixes a bug with Material Button
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

implementation 'me.dm7.barcodescanner:zxing:1.9.8'
Expand Down
29 changes: 14 additions & 15 deletions app/src/main/java/io/scalaproject/vault/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ public class LoginActivity extends BaseActivity
// to the IPNS gateway as well.
static private final String IPNS_NAME = "node-list.scala.network";
static private final String[] NODES_REPOSITORY_IPNS_GATEWAYS = {
"https://dweb.link/ipns/",
"https://cloudflare-ipfs.com/ipns/",
"https://ipfs.io/ipns/",
"https://gateway.ipfs.io/ipns/",
"https://cloudflare-ipfs.com/ipns/"
"https://dweb.link/ipns/"
};

static private final String DEFAULT_NODE = "{\n" +
Expand Down Expand Up @@ -249,21 +249,20 @@ public void loadDefaultNodes() {

String jsonString = "";

// Load Pools data from IPFS gateways
for (String strNodeURLDir : NODES_REPOSITORY_IPNS_GATEWAYS) {
String strNodeURL = strNodeURLDir + IPNS_NAME;
if(Helper.isURLReachable(strNodeURL)) {
jsonString = Helper.fetchJSON(strNodeURL);
if (!jsonString.isEmpty())
break;
}
}
// Load Pools data from the GitHub repository by default
if(Helper.isURLReachable(DEFAULT_NODES_REPOSITORY))
jsonString = Helper.fetchJSON(DEFAULT_NODES_REPOSITORY);

// If IPFS is not available or is blocked by firewalls, use GitHub raw file
// If GitHub file is not available or is blocked by firewalls, use IPFS
if(jsonString.isEmpty()) {
// Load Pools data from repository
if(Helper.isURLReachable(DEFAULT_NODES_REPOSITORY))
jsonString = Helper.fetchJSON(DEFAULT_NODES_REPOSITORY);
for (String strNodeURLDir : NODES_REPOSITORY_IPNS_GATEWAYS) {
String strNodeURL = strNodeURLDir + IPNS_NAME;
if(Helper.isURLReachable(strNodeURL)) {
jsonString = Helper.fetchJSON(strNodeURL);
if (!jsonString.isEmpty())
break;
}
}
}

// None of the URL can be reached. Load default data but don't cache it.
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/io/scalaproject/vault/NodeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@ private void complete() {
nodesAdapter.allowClick(true);

selectedNodeView = rvNodes.getChildAt(0);;
selectedNode = nodesAdapter.getNodes().get(0);
if(!nodesAdapter.getNodes().isEmpty())
selectedNode = nodesAdapter.getNodes().get(0);
setItemNodeLayout(selectedNodeView, true);

Config.write(Config.CONFIG_KEY_USER_SELECTED_NODE, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public void onCreate() {
super.onCreate();
SharedPreferences preferences = getSharedPreferences(getPackageName() + "_preferences", MODE_PRIVATE);
Config.initialize(preferences);

/*if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree());
}*/
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/io/scalaproject/vault/util/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,10 @@ static public boolean isURLReachable(String strURL) {
try {
URL url = new URL(strURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setReadTimeout(2000);
return connection.getResponseCode() == 200;
} catch (java.net.SocketTimeoutException e) {
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
Expand Down

0 comments on commit fad1567

Please sign in to comment.