Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to select "Splinter" instances #1073

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ deploy
.vscode
.vim/*
*/.factorypath
node_modules/
package.json
package-lock.json
41 changes: 39 additions & 2 deletions common/src/main/java/haveno/common/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public class Config {
public static final String BTC_FEE_INFO = "bitcoinFeeInfo";
public static final String BYPASS_MEMPOOL_VALIDATION = "bypassMempoolValidation";
public static final String PASSWORD_REQUIRED = "passwordRequired";
public static final String PUB_KEYS_LIST = "pubKeyList";
public static final String DEV_PRIV_LIST = "devPrivilegeKeyList";
public static final String MAKER_FEE = "makerFee";
public static final String TAKER_FEE = "takerFee";

// Default values for certain options
public static final int UNSPECIFIED_PORT = -1;
Expand Down Expand Up @@ -203,6 +207,12 @@ public enum UseTorForXmr {
public final boolean bypassMempoolValidation;
public final boolean passwordRequired;

// Options supported only within the config file (unless i screw up the implementation)
public final List<String> pubKeyList;
public final List<String> devPrivilegeKeyList;
public final float makerFee;
public final float takerFee;

// Properties derived from options but not exposed as options themselves
public final File torDir;
public final File walletDir;
Expand Down Expand Up @@ -612,8 +622,32 @@ public Config(String defaultAppName, File defaultUserDataDir, String... args) {
.withRequiredArg()
.ofType(boolean.class)
.defaultsTo(false);
ArgumentAcceptingOptionSpec<String> pubKeyListOpt =
parser.accepts(PUB_KEYS_LIST,
"List of public keys for the accepted splinter")
.withRequiredArg()
.ofType(String.class)
.withValuesSeparatedBy(',')
.describedAs("key[,...]");
ArgumentAcceptingOptionSpec<String> devPrivilegeKeyListOpt =
parser.accepts(DEV_PRIV_LIST,
"List of privileged dev keys for the accepted splinter")
.withRequiredArg()
.ofType(String.class)
.withValuesSeparatedBy(',')
.describedAs("key[,...]");
ArgumentAcceptingOptionSpec<Float> makerFeeOpt =
parser.accepts(MAKER_FEE, "Maker fee for the accepted splinter")
.withRequiredArg()
.ofType(Float.class)
.defaultsTo(0.0015f);
ArgumentAcceptingOptionSpec<Float> takerFeeOpt =
parser.accepts(TAKER_FEE, "Taker fee for the accepted splinter")
.withRequiredArg()
.ofType(Float.class)
.defaultsTo(0.0075f);

try {
try {
CompositeOptionSet options = new CompositeOptionSet();

// Parse command line options
Expand Down Expand Up @@ -717,7 +751,10 @@ public Config(String defaultAppName, File defaultUserDataDir, String... args) {
this.useAllProvidedNodes = options.valueOf(useAllProvidedNodesOpt);
this.userAgent = options.valueOf(userAgentOpt);
this.numConnectionsForBtc = options.valueOf(numConnectionsForBtcOpt);

this.pubKeyList = options.valuesOf(pubKeyListOpt);
this.devPrivilegeKeyList = options.valuesOf(devPrivilegeKeyListOpt);
this.makerFee = options.valueOf(makerFeeOpt);
this.takerFee = options.valueOf(takerFeeOpt);
this.apiPassword = options.valueOf(apiPasswordOpt);
this.apiPort = options.valueOf(apiPortOpt);
this.preventPeriodicShutdownAtSeedNode = options.valueOf(preventPeriodicShutdownAtSeedNodeOpt);
Expand Down
8 changes: 6 additions & 2 deletions core/src/main/java/haveno/core/alert/AlertManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import haveno.common.app.DevEnv;
import haveno.common.config.Config;
import haveno.common.crypto.KeyRing;
import haveno.core.user.Preferences;
import haveno.core.user.User;
import haveno.network.p2p.P2PService;
import haveno.network.p2p.storage.HashMapChangedListener;
Expand All @@ -44,6 +45,7 @@
public class AlertManager {
private static final Logger log = LoggerFactory.getLogger(AlertManager.class);

private final Preferences preferences;
private final P2PService p2PService;
private final KeyRing keyRing;
private final User user;
Expand All @@ -58,11 +60,13 @@ public class AlertManager {
///////////////////////////////////////////////////////////////////////////////////////////

@Inject
public AlertManager(P2PService p2PService,
public AlertManager(Preferences preferences,
P2PService p2PService,
KeyRing keyRing,
User user,
@Named(Config.IGNORE_DEV_MSG) boolean ignoreDevMsg,
@Named(Config.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys) {
this.preferences = preferences;
this.p2PService = p2PService;
this.keyRing = keyRing;
this.user = user;
Expand Down Expand Up @@ -109,7 +113,7 @@ protected List<String> getPubKeyList() {
"026c581ad773d987e6bd10785ac7f7e0e64864aedeb8bce5af37046de812a37854",
"025b058c9f2c60d839669dbfa5578cf5a8117d60e6b70e2f0946f8a691273c6a36");
case XMR_MAINNET:
return List.of();
return preferences.getPubKeyList();
default:
throw new RuntimeException("Unhandled base currency network: " + Config.baseCurrencyNetwork());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import haveno.common.crypto.KeyRing;
import haveno.common.crypto.PubKeyRing;
import haveno.common.proto.network.NetworkEnvelope;
import haveno.core.user.Preferences;
import haveno.network.p2p.DecryptedMessageWithPubKey;
import haveno.network.p2p.NodeAddress;
import haveno.network.p2p.P2PService;
Expand Down Expand Up @@ -59,6 +60,7 @@
public class PrivateNotificationManager implements MessageListener {
private static final Logger log = LoggerFactory.getLogger(PrivateNotificationManager.class);

private final Preferences preferences;
private final P2PService p2PService;
private final MailboxMessageService mailboxMessageService;
private final KeyRing keyRing;
Expand All @@ -77,12 +79,14 @@ public class PrivateNotificationManager implements MessageListener {
///////////////////////////////////////////////////////////////////////////////////////////

@Inject
public PrivateNotificationManager(P2PService p2PService,
public PrivateNotificationManager(Preferences preferences,
P2PService p2PService,
NetworkNode networkNode,
MailboxMessageService mailboxMessageService,
KeyRing keyRing,
@Named(Config.IGNORE_DEV_MSG) boolean ignoreDevMsg,
@Named(Config.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys) {
this.preferences = preferences;
this.p2PService = p2PService;
this.networkNode = networkNode;
this.mailboxMessageService = mailboxMessageService;
Expand All @@ -108,7 +112,8 @@ protected List<String> getPubKeyList() {
"026c581ad773d987e6bd10785ac7f7e0e64864aedeb8bce5af37046de812a37854",
"025b058c9f2c60d839669dbfa5578cf5a8117d60e6b70e2f0946f8a691273c6a36");
case XMR_MAINNET:
return List.of();
return preferences.getPubKeyList();
//preland: add pubkey info
default:
throw new RuntimeException("Unhandled base currency network: " + Config.baseCurrencyNetwork());
}
Expand Down
23 changes: 20 additions & 3 deletions core/src/main/java/haveno/core/app/HavenoSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public class HavenoSetup {
private final StringProperty topErrorMsg = new SimpleStringProperty();
@Setter
@Nullable
private Consumer<Runnable> displayTacHandler;
private Consumer<Runnable> displayTacHandler, displaySplinterManagerHandler;
@Setter
@Nullable
private Consumer<String> chainFileLockedExceptionHandler,
Expand All @@ -154,7 +154,7 @@ public class HavenoSetup {
rejectedTxErrorMessageHandler;
@Setter
@Nullable
private Consumer<Boolean> displayTorNetworkSettingsHandler;
private Consumer<Boolean> displayTorNetworkSettingsHandler;//, displaySplinterManagerHandler;
@Setter
@Nullable
private Runnable showFirstPopupIfResyncSPVRequestedHandler;
Expand Down Expand Up @@ -307,10 +307,11 @@ public void start() {
}

persistHavenoVersion();
maybeShowTac(this::step2);
maybeShowTac(this::showSplinterManager);
}

private void step2() {
//showSplinterManager();
readMapsFromResources(this::step3);
checkForCorrectOSArchitecture();
checkOSXVersion();
Expand Down Expand Up @@ -341,6 +342,22 @@ private void step4() {
// Sub tasks
///////////////////////////////////////////////////////////////////////////////////////////

private void showSplinterManager() {
//todo: fix the if statement after debugging is done
if (Config.baseCurrencyNetwork() == BaseCurrencyNetwork.XMR_MAINNET) {
if (displaySplinterManagerHandler != null){
displaySplinterManagerHandler.accept(() -> {
log.info("wearehere.jpg");
log.info(preferences.getPubKeyList().toString());
step2();
});
log.info("bioz");
} else {log.info("we aresoback.json");}
} else {
step2();
}
//displaySplinterManagerHandler.accept(true);
}
private void maybeShowTac(Runnable nextStep) {
if (!preferences.isTacAcceptedV120() && !DevEnv.isDevMode()) {
if (displayTacHandler != null)
Expand Down
16 changes: 10 additions & 6 deletions core/src/main/java/haveno/core/filter/FilterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public interface Listener {
private final boolean ignoreDevMsg;
private final ObjectProperty<Filter> filterProperty = new SimpleObjectProperty<>();
private final List<Listener> listeners = new CopyOnWriteArrayList<>();
private final List<String> publicKeys;
private List<String> publicKeys;
private ECKey filterSigningKey;
private final Set<Filter> invalidFilters = new HashSet<>();
private Consumer<String> filterWarningHandler;
Expand Down Expand Up @@ -115,11 +115,10 @@ public FilterManager(P2PService p2PService,
this.ignoreDevMsg = ignoreDevMsg;

publicKeys = useDevPrivilegeKeys ?
Collections.singletonList(DevEnv.DEV_PRIVILEGE_PUB_KEY) :
List.of("0358d47858acdc41910325fce266571540681ef83a0d6fedce312bef9810793a27",
"029340c3e7d4bb0f9e651b5f590b434fecb6175aeaa57145c7804ff05d210e534f",
"034dc7530bf66ffd9580aa98031ea9a18ac2d269f7c56c0e71eca06105b9ed69f9");

Collections.singletonList(DevEnv.DEV_PRIVILEGE_PUB_KEY) : preferences.getPubKeyList();
// List.of("0358d47858acdc41910325fce266571540681ef83a0d6fedce312bef9810793a27",
// "029340c3e7d4bb0f9e651b5f590b434fecb6175aeaa57145c7804ff05d210e534f",
// "034dc7530bf66ffd9580aa98031ea9a18ac2d269f7c56c0e71eca06105b9ed69f9");
banFilter.setBannedNodePredicate(this::isNodeAddressBannedFromNetwork);
}

Expand Down Expand Up @@ -590,6 +589,11 @@ private boolean isFilterPublicKeyInList(Filter filter) {
}

private boolean isPublicKeyInList(String pubKeyAsHex) {
if(publicKeys.isEmpty()){
publicKeys = preferences.getPubKeyList();
//updatePrefs(); //todo: this could loop indefinitely; fix
}

boolean isPublicKeyInList = publicKeys.contains(pubKeyAsHex);
if (!isPublicKeyInList) {
log.info("pubKeyAsHex is not part of our pub key list (expected case for pre v1.3.9 filter). pubKeyAsHex={}, publicKeys={}", pubKeyAsHex, publicKeys);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.inject.Inject;
import com.google.inject.Singleton;
import haveno.common.config.Config;
import haveno.core.user.Preferences;
import haveno.network.p2p.NodeAddress;
import haveno.network.p2p.seed.SeedNodeRepository;
import java.io.BufferedReader;
Expand All @@ -44,10 +45,12 @@ public class DefaultSeedNodeRepository implements SeedNodeRepository {
private static final String ENDING = ".seednodes";
private final Collection<NodeAddress> cache = new HashSet<>();
private final Config config;
private final Preferences preferences;

@Inject
public DefaultSeedNodeRepository(Config config) {
public DefaultSeedNodeRepository(Config config, Preferences preferences) {
this.config = config;
this.preferences = preferences;
}

private void reload() {
Expand All @@ -59,6 +62,13 @@ private void reload() {

return;
}
//if not, see if there are seed nodes defined at initialization, and use those
if(!preferences.getSeedNodeList().isEmpty()) {
cache.clear();
preferences.getSeedNodeList().forEach(s -> cache.add(new NodeAddress(s)));

return;
}

cache.clear();
List<NodeAddress> result = getSeedNodeAddressesFromPropertyFile(config.baseCurrencyNetwork.name().toLowerCase());
Expand Down Expand Up @@ -114,7 +124,11 @@ public Collection<NodeAddress> getSeedNodeAddresses() {

return cache;
}

public void reloadFromPrefs() {
reload();
log.info("ghastly.");
log.info(cache.toString());
}
@Override
public boolean isSeedNode(NodeAddress nodeAddress) {
if (cache.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import haveno.common.handlers.ResultHandler;
import haveno.common.util.Utilities;
import haveno.core.filter.FilterManager;
import haveno.core.user.Preferences;
import haveno.core.user.User;
import haveno.network.p2p.BootstrapListener;
import haveno.network.p2p.NodeAddress;
Expand Down Expand Up @@ -63,7 +64,7 @@ public abstract class DisputeAgentManager<T extends DisputeAgent> {
protected static final long RETRY_REPUBLISH_SEC = 5;
protected static final long REPEATED_REPUBLISH_AT_STARTUP_SEC = 60;

protected final List<String> publicKeys;
protected List<String> publicKeys;

///////////////////////////////////////////////////////////////////////////////////////////
// Instance fields
Expand All @@ -76,16 +77,18 @@ public abstract class DisputeAgentManager<T extends DisputeAgent> {
protected final ObservableMap<NodeAddress, T> observableMap = FXCollections.observableHashMap();
protected List<T> persistedAcceptedDisputeAgents;
protected Timer republishTimer, retryRepublishTimer;

protected final Preferences preferences;

///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////

public DisputeAgentManager(KeyRing keyRing,
public DisputeAgentManager(Preferences preferences,
KeyRing keyRing,
DisputeAgentService<T> disputeAgentService,
User user,
FilterManager filterManager) {
this.preferences = preferences;
this.keyRing = keyRing;
this.disputeAgentService = disputeAgentService;
this.user = user;
Expand Down Expand Up @@ -162,6 +165,12 @@ public void onDataReceived() {
updateMap();
}

public void updatePrefs() {
log.info("updateprefs");
publicKeys = getPubKeyList();
log.info(publicKeys.toString());
updateMap();
}
public void shutDown() {
stopRepublishTimer();
stopRetryRepublishTimer();
Expand All @@ -187,10 +196,13 @@ public void updateMap() {
log.info("We got the DEV_PRIVILEGE_PUB_KEY in our list of publicKeys. RegistrationPubKey={}, nodeAddress={}",
Utilities.bytesAsHexString(e.getRegistrationPubKey()),
e.getNodeAddress().getFullAddress());
else
else{
log.info(DevEnv.DEV_PRIVILEGE_PUB_KEY);
log.info(pubKeyAsHex);
log.warn("We got an disputeAgent which is not in our list of publicKeys. RegistrationPubKey={}, nodeAddress={}",
Utilities.bytesAsHexString(e.getRegistrationPubKey()),
e.getNodeAddress().getFullAddress());
}
}
final boolean isSigValid = verifySignature(e.getPubKeyRing().getSignaturePubKey(),
e.getRegistrationPubKey(),
Expand Down Expand Up @@ -262,6 +274,10 @@ public ECKey getRegistrationKey(String privKeyBigIntString) {
}

public boolean isPublicKeyInList(String pubKeyAsHex) {
log.info(publicKeys.toString());
if(publicKeys.isEmpty()){
updatePrefs(); //todo: this could loop indefinitely; fix
}
return publicKeys.contains(pubKeyAsHex);
}

Expand Down
Loading
Loading