mirror of
https://codeberg.org/r4v3r23/mysu.git
synced 2024-11-30 01:23:16 +00:00
Add ability to enter a .b32.i2p address for a node to sync. Requires that user has set up their own SOCKS proxy in their I2P app
This commit is contained in:
parent
b66c81cedc
commit
c23879f3b6
4 changed files with 49 additions and 8 deletions
|
@ -230,6 +230,10 @@ public class Node {
|
||||||
return OnionHelper.isOnionHost(host);
|
return OnionHelper.isOnionHost(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isI2P() {
|
||||||
|
return OnionHelper.isI2PHost(host);
|
||||||
|
}
|
||||||
|
|
||||||
public String toNodeString() {
|
public String toNodeString() {
|
||||||
return toString();
|
return toString();
|
||||||
}
|
}
|
||||||
|
@ -240,7 +244,10 @@ public class Node {
|
||||||
if (!username.isEmpty() && !password.isEmpty()) {
|
if (!username.isEmpty() && !password.isEmpty()) {
|
||||||
sb.append(username).append(":").append(password).append("@");
|
sb.append(username).append(":").append(password).append("@");
|
||||||
}
|
}
|
||||||
sb.append(host).append(":").append(rpcPort);
|
sb.append(host);
|
||||||
|
if(!isI2P()) {
|
||||||
|
sb.append(":").append(rpcPort);
|
||||||
|
}
|
||||||
sb.append("/");
|
sb.append("/");
|
||||||
switch (networkType) {
|
switch (networkType) {
|
||||||
case NetworkType_Mainnet:
|
case NetworkType_Mainnet:
|
||||||
|
@ -263,6 +270,14 @@ public class Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAddress() {
|
public String getAddress() {
|
||||||
|
String port = "";
|
||||||
|
if(!isI2P()) {
|
||||||
|
port = ":" + rpcPort;
|
||||||
|
}
|
||||||
|
return getHost() + port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDaemonAddress() {
|
||||||
return getHost() + ":" + rpcPort;
|
return getHost() + ":" + rpcPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,10 +47,11 @@ public class AddNodeBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
addNodeButton.setOnClickListener(view1 -> {
|
addNodeButton.setOnClickListener(view1 -> {
|
||||||
String node = addressEditText.getText().toString();
|
String node = addressEditText.getText().toString();
|
||||||
String name = nodeNameEditText.getText().toString();
|
String name = nodeNameEditText.getText().toString();
|
||||||
if (node.contains(":") && !name.isEmpty()) {
|
try {
|
||||||
String[] nodeParts = node.split(":");
|
|
||||||
if (nodeParts.length == 2) {
|
if (node.contains(":") && !name.isEmpty()) {
|
||||||
try {
|
String[] nodeParts = node.split(":");
|
||||||
|
if (nodeParts.length == 2) {
|
||||||
String address = nodeParts[0];
|
String address = nodeParts[0];
|
||||||
int port = Integer.parseInt(nodeParts[1]);
|
int port = Integer.parseInt(nodeParts[1]);
|
||||||
String newNodeString = address + ":" + port + "/mainnet/" + name;
|
String newNodeString = address + ":" + port + "/mainnet/" + name;
|
||||||
|
@ -75,10 +76,31 @@ public class AddNodeBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
}
|
}
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException | JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
} else if(node.endsWith(".b32.i2p")) {
|
||||||
|
String newNodeString = node + "/mainnet/" + name;
|
||||||
|
String nodesArray = PrefService.getInstance().getString(Constants.PREF_CUSTOM_NODES, "[]");
|
||||||
|
JSONArray jsonArray = new JSONArray(nodesArray);
|
||||||
|
boolean exists = false;
|
||||||
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
|
String nodeString = jsonArray.getString(i);
|
||||||
|
if (nodeString.equals(newNodeString))
|
||||||
|
exists = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!exists) {
|
||||||
|
jsonArray.put(newNodeString);
|
||||||
|
}
|
||||||
|
|
||||||
|
PrefService.getInstance().edit().putString(Constants.PREF_CUSTOM_NODES, jsonArray.toString()).apply();
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onNodeAdded();
|
||||||
|
}
|
||||||
|
dismiss();
|
||||||
}
|
}
|
||||||
|
} catch (NumberFormatException | JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,7 +258,7 @@ public class WalletManager {
|
||||||
// this should not be called on the main thread as it connects to the node (and takes a long time)
|
// this should not be called on the main thread as it connects to the node (and takes a long time)
|
||||||
public void setDaemon(Node node) {
|
public void setDaemon(Node node) {
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
this.daemonAddress = node.getAddress();
|
this.daemonAddress = node.getDaemonAddress();
|
||||||
if (networkType != node.getNetworkType())
|
if (networkType != node.getNetworkType())
|
||||||
throw new IllegalArgumentException("network type does not match");
|
throw new IllegalArgumentException("network type does not match");
|
||||||
this.daemonUsername = node.getUsername();
|
this.daemonUsername = node.getUsername();
|
||||||
|
|
|
@ -21,4 +21,8 @@ public class OnionHelper {
|
||||||
public static boolean isOnionHost(String hostname) {
|
public static boolean isOnionHost(String hostname) {
|
||||||
return hostname.endsWith(".onion");
|
return hostname.endsWith(".onion");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isI2PHost(String hostname) {
|
||||||
|
return hostname.endsWith(".b32.i2p");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue