Skip to content

Commit

Permalink
Merge pull request #249 from btdex/feat/dynamic-remote-resources
Browse files Browse the repository at this point in the history
feat: added remote resources, i.e. pools, nodes
  • Loading branch information
jjos2372 committed Sep 22, 2023
2 parents 1a46707 + 90a2bb0 commit d6d30bf
Show file tree
Hide file tree
Showing 6 changed files with 365 additions and 241 deletions.
22 changes: 11 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
id 'org.gradle.crypto.checksum' version '1.2.0'
id 'com.palantir.git-version' version '0.12.2'
id 'io.spring.dependency-management' version '1.0.1.RELEASE' //for logging - log4j

id "de.undercouch.download" version "1.2"
}

Expand All @@ -29,18 +29,18 @@ dependencies {
implementation 'com.github.signum-network:signumj:abd8563d73'
implementation 'com.github.signum-network:signum-smartj:89e2f28bb3'

implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'io.reactivex.rxjava2:rxjava:2.2.15'
implementation 'com.squareup.okhttp3:okhttp:4.4.0'

implementation 'com.github.jiconfont:jiconfont-swing:1.0.0'
//implementation 'com.github.jiconfont:jiconfont-font_awesome:4.7.0.1'
implementation 'com.github.meisenla:jiconfont-font_awesome:8be36e8ba9'

implementation 'com.github.jjos2372:java-sdk:4739af9c11'

implementation 'com.github.sealedtx:bitcoin-cash-converter:1.0'

//implementation 'net.java.dev.jna:jna-platform:5.7.0'
//implementation 'net.java.dev.jna:jna:5.7.0'

Expand All @@ -49,7 +49,7 @@ dependencies {
implementation 'com.github.jjos2372:Darcula:3b47831130' // this one is compatible with Java16
//implementation 'com.formdev:flatlaf:1.5'
//implementation 'com.formdev:flatlaf-intellij-themes:1.5'

implementation 'com.dorkbox:SystemTray:3.17'

implementation 'org.apache.commons:commons-text:1.8'
Expand All @@ -65,9 +65,9 @@ dependencies {
implementation 'fr.marcwrobel:jbanking:1.0'

implementation 'com.github.jjos2372:ledger4j:06fb465b5a'

implementation 'org.nanohttpd:nanohttpd:2.3.1'

implementation 'com.github.stellar:java-stellar-sdk:0.32.0'

//logging
Expand Down Expand Up @@ -133,7 +133,7 @@ createExe {
copyright = 'BTDEX'
companyName = 'https://btdex.trade'
textVersion = details.lastTag

bundledJrePath = "./jre"
bundledJre64Bit = false

Expand Down Expand Up @@ -197,7 +197,7 @@ unzipLinuxJDK.dependsOn downloadLinuxJDK
task makeDeb(type: Deb) {
dependsOn shadowJar
dependsOn unzipLinuxJDK

maintainer 'btdex.trade'
license 'GPL-3+'
version details.lastTag.substring(1)
Expand All @@ -209,7 +209,7 @@ task makeDeb(type: Deb) {
from('dist/copyright'){
into '/usr/share/doc/btdex'
}

from("dist/jdk/${jdkVersion}-linux_x64/jre"){
into '/opt/btdex/jre'
}
Expand Down
58 changes: 38 additions & 20 deletions src/main/java/btdex/core/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,44 @@

public class Constants {

public static final String NODE_LIST_TESTNET[] = {
"https://europe3.testnet.signum.network",
"http://localhost:6876",
};

public static final String NODE_LIST[] = {
"https://us-east.signum.network",
"https://europe.signum.network",
"https://us-central.signum.network",
"https://europe1.signum.network",
"https://europe2.signum.network",
"https://europe3.signum.network",
"https://brazil.signum.network",
"https://latam.signum.network",
"https://singapore.signum.network",
BT.NODE_BURSTCOIN_RO,
"https://canada.signum.network",
"https://australia.signum.network",
"http://localhost:8125",
};
public static final String REMOTE_NODE_RESOURCES_URL = "https://signum-network.github.io/public-resources";

public static final String[] NODE_LIST_TESTNET = {
"https://europe3.testnet.signum.network",
"http://localhost:6876",
};

public static final String[] NODE_LIST = {
"https://us-east.signum.network",
"https://europe.signum.network",
"https://us-central.signum.network",
"https://europe1.signum.network",
"https://europe2.signum.network",
"https://europe3.signum.network",
"https://brazil.signum.network",
"https://latam.signum.network",
"https://singapore.signum.network",
"https://ru.signum.network",
BT.NODE_BURSTCOIN_RO,
"https://canada.signum.network",
"https://australia.signum.network",
"http://localhost:8125",
};

public static final String[] POOL_LIST = {
"https://pool.signumcoin.ro",
"https://signapool.notallmine.net",
"http://pool.btfg.space",
"http://signa.voiplanparty.com:8124",
"http://signumpool.de:8080",
"http://burst.e4pool.com",
"http://opensignumpool.ddns.net:8126",
};

public static final String[] POOL_LIST_TESTNET = {
"https://t-pool.notallmine.net",
"http://localhost:8000"
};

public static final String PROP_LANG = "lang";
public static final String PROP_NODE = "node";
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/btdex/core/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class Globals {
private NodeService NS;
public static final SignumCrypto BC = SignumCrypto.getInstance();

public static final RemoteSignumResources SIGNUM_RESOURCES = RemoteSignumResources.getInstance();

static String confFile = Constants.DEF_CONF_FILE;
private Properties conf = new Properties();

Expand Down Expand Up @@ -118,12 +120,18 @@ public Globals() {
String nodeAutomatic = conf.getProperty(Constants.PROP_NODE_AUTO, "true");
String nodeAddress = conf.getProperty(Constants.PROP_NODE, "");
ArrayList<String> nodeList = new ArrayList<>();
if(nodeAddress.length() > 0) {
if(!nodeAddress.isEmpty()) {
// the stored node always goes to the list as first
nodeList.add(nodeAddress);
}
if("true".equals(nodeAutomatic)) {
nodeList.addAll(Arrays.asList(isTestnet() ? Constants.NODE_LIST_TESTNET : Constants.NODE_LIST));

RemoteSignumResources remoteResources = RemoteSignumResources
.getInstance()
.loadNodeLists()
.loadPoolLists();

if ("true".equals(nodeAutomatic)) {
nodeList.addAll(isTestnet() ? remoteResources.testNetNodes() : remoteResources.mainNetNodes());
}

setNodeList(nodeList);
Expand Down
111 changes: 111 additions & 0 deletions src/main/java/btdex/core/RemoteSignumResources.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package btdex.core;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class RemoteSignumResources {
static RemoteSignumResources instance;

private final String baseURL = Constants.REMOTE_NODE_RESOURCES_URL;
private final OkHttpClient httpClient = new OkHttpClient();

private Set<String> testnetNodes = new HashSet<>();
private Set<String> mainnetNodes = new HashSet<>();
private Set<String> testnetPools = new HashSet<>();
private Set<String> mainnetPools = new HashSet<>();

private Logger logger;

public static RemoteSignumResources getInstance() {
if (instance == null)
instance = new RemoteSignumResources();
return instance;
}

private RemoteSignumResources() {
this.logger = LogManager.getLogger();
}

public RemoteSignumResources loadNodeLists() throws IOException {
try {
logger.debug("Fetching remote node list from {}...", this.baseURL);
Request request = new Request
.Builder()
.url(this.baseURL + "/nodes.json")
.addHeader("Accept", "application/json")
.build();
Response response = this.httpClient.newCall(request).execute();

assert response.code() == 200;
assert response.body() != null;

String body = response.body().string();
JsonObject json = JsonParser.parseString(body).getAsJsonObject();
json.get("mainnet").getAsJsonArray().forEach(node -> {
this.mainnetNodes.add(node.getAsJsonObject().get("url").getAsString());
});
json.get("testnet").getAsJsonArray().forEach(node -> {
this.testnetNodes.add(node.getAsJsonObject().get("url").getAsString());
});
}catch(Exception e){
logger.error(e);
logger.debug("Loading Remote node list failed. Using constant fallbacks");
this.mainnetNodes.addAll(Arrays.asList(Constants.NODE_LIST));
this.testnetNodes.addAll(Arrays.asList(Constants.NODE_LIST_TESTNET));
}
return this;
}
public RemoteSignumResources loadPoolLists() throws IOException {
try {
logger.debug("Fetching remote pool list from {}...", this.baseURL);
Request request = new Request
.Builder()
.url(this.baseURL + "/pools.json")
.addHeader("Accept", "application/json")
.build();
Response response = this.httpClient.newCall(request).execute();

assert response.code() == 200;
assert response.body() != null;

String body = response.body().string();
JsonObject json = JsonParser.parseString(body).getAsJsonObject();
json.get("mainnet").getAsJsonArray().forEach(node -> {
this.mainnetPools.add(node.getAsJsonObject().get("url").getAsString());
});
json.get("testnet").getAsJsonArray().forEach(node -> {
this.testnetPools.add(node.getAsJsonObject().get("url").getAsString());
});
}catch(Exception e){
logger.error(e);
logger.debug("Loading Remote pool list failed. Using constant fallbacks");
this.mainnetPools.addAll(Arrays.asList(Constants.POOL_LIST));
this.testnetPools.addAll(Arrays.asList(Constants.POOL_LIST_TESTNET));
}
return this;
}

public Set<String> testNetNodes() {
return this.testnetNodes;
}
public Set<String> mainNetNodes() {
return this.mainnetNodes;
}

public Set<String> testNetPools() {
return this.testnetPools;
}
public Set<String> mainNetPools() {
return this.mainnetPools;
}
}
Loading

1 comment on commit d6d30bf

@pir8radio
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjos2372 can we get a beta build release of this?

Please sign in to comment.