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

Seed node repo refactoring #2476

Merged
Merged
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
2 changes: 0 additions & 2 deletions core/src/main/java/bisq/core/CoreModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import bisq.core.dao.DaoModule;
import bisq.core.filter.FilterModule;
import bisq.core.network.p2p.seed.DefaultSeedNodeRepository;
import bisq.core.network.p2p.seed.SeedNodeAddressLookup;
import bisq.core.notifications.MobileMessageEncryption;
import bisq.core.notifications.MobileModel;
import bisq.core.notifications.MobileNotificationService;
Expand Down Expand Up @@ -99,7 +98,6 @@ protected void configure() {
bind(CorruptedDatabaseFilesHandler.class).in(Singleton.class);
bind(AvoidStandbyModeService.class).in(Singleton.class);

bind(SeedNodeAddressLookup.class).in(Singleton.class);
bind(SeedNodeRepository.class).to(DefaultSeedNodeRepository.class).in(Singleton.class);

File storageDir = new File(environment.getRequiredProperty(Storage.STORAGE_DIR));
Expand Down
9 changes: 3 additions & 6 deletions core/src/main/java/bisq/core/app/BisqEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import java.io.FileOutputStream;
import java.io.IOException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
Expand Down Expand Up @@ -192,7 +193,7 @@ public static boolean isDaoActivated(Environment environment) {

protected final String btcNodes, seedNodes, ignoreDevMsg, useDevPrivilegeKeys, useDevMode, useTorForBtc, rpcUser, rpcPassword,
rpcPort, rpcBlockNotificationPort, dumpBlockchainData, fullDaoNode,
myAddress, banList, dumpStatistics, maxMemory, socks5ProxyBtcAddress,
banList, dumpStatistics, maxMemory, socks5ProxyBtcAddress,
torRcFile, torRcOptions, externalTorControlPort, externalTorPassword, externalTorCookieFile,
socks5ProxyHttpAddress, useAllProvidedNodes, numConnectionForBtc, genesisTxId, genesisBlockHeight,
referralId, daoActivated, msgThrottlePerSec, msgThrottlePer10Sec, sendMsgThrottleTrigger, sendMsgThrottleSleep;
Expand Down Expand Up @@ -258,9 +259,6 @@ public BisqEnvironment(PropertySource commandLineProperties) {
(String) commandLineProperties.getProperty(NetworkOptionKeys.SEED_NODES_KEY) :
"";

myAddress = commandLineProperties.containsProperty(NetworkOptionKeys.MY_ADDRESS) ?
(String) commandLineProperties.getProperty(NetworkOptionKeys.MY_ADDRESS) :
"";
banList = commandLineProperties.containsProperty(NetworkOptionKeys.BAN_LIST) ?
(String) commandLineProperties.getProperty(NetworkOptionKeys.BAN_LIST) :
"";
Expand Down Expand Up @@ -355,7 +353,7 @@ public BisqEnvironment(PropertySource commandLineProperties) {
bannedPriceRelayNodes = !bannedPriceRelayNodesAsString.isEmpty() ? Arrays.asList(StringUtils.deleteWhitespace(bannedPriceRelayNodesAsString).split(",")) : null;

final String bannedSeedNodesAsString = getProperty(FilterManager.BANNED_SEED_NODES, "");
bannedSeedNodes = !bannedSeedNodesAsString.isEmpty() ? Arrays.asList(StringUtils.deleteWhitespace(bannedSeedNodesAsString).split(",")) : null;
bannedSeedNodes = !bannedSeedNodesAsString.isEmpty() ? Arrays.asList(StringUtils.deleteWhitespace(bannedSeedNodesAsString).split(",")) : new ArrayList<>();

final String bannedBtcNodesAsString = getProperty(FilterManager.BANNED_BTC_NODES, "");
bannedBtcNodes = !bannedBtcNodesAsString.isEmpty() ? Arrays.asList(StringUtils.deleteWhitespace(bannedBtcNodesAsString).split(",")) : null;
Expand Down Expand Up @@ -461,7 +459,6 @@ private PropertySource<?> defaultProperties() {
setProperty(CommonOptionKeys.USE_DEV_MODE, useDevMode);

setProperty(NetworkOptionKeys.SEED_NODES_KEY, seedNodes);
setProperty(NetworkOptionKeys.MY_ADDRESS, myAddress);
setProperty(NetworkOptionKeys.BAN_LIST, banList);
setProperty(NetworkOptionKeys.TOR_DIR, Paths.get(btcNetworkDir, "tor").toString());
setProperty(NetworkOptionKeys.NETWORK_ID, String.valueOf(baseCurrencyNetwork.ordinal()));
Expand Down
5 changes: 0 additions & 5 deletions core/src/main/java/bisq/core/app/BisqExecutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,6 @@ protected void customizeOptionParsing(OptionParser parser) {
.withRequiredArg()
.describedAs("host:port[,...]");

parser.accepts(NetworkOptionKeys.MY_ADDRESS,
"My own onion address (used for bootstrap nodes to exclude itself)")
.withRequiredArg()
.describedAs("host:port");

parser.accepts(NetworkOptionKeys.BAN_LIST,
"Nodes to exclude from network connections.")
.withRequiredArg()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import bisq.core.dao.DaoModule;
import bisq.core.filter.FilterModule;
import bisq.core.network.p2p.seed.DefaultSeedNodeRepository;
import bisq.core.network.p2p.seed.SeedNodeAddressLookup;
import bisq.core.offer.OfferModule;
import bisq.core.proto.network.CoreNetworkProtoResolver;
import bisq.core.proto.persistable.CorePersistenceProtoResolver;
Expand Down Expand Up @@ -77,7 +76,6 @@ protected void configure() {
bind(BridgeAddressProvider.class).to(Preferences.class).in(Singleton.class);
bind(TorSetup.class).in(Singleton.class);

bind(SeedNodeAddressLookup.class).in(Singleton.class);
bind(SeedNodeRepository.class).to(DefaultSeedNodeRepository.class).in(Singleton.class);

File storageDir = new File(environment.getRequiredProperty(Storage.STORAGE_DIR));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,80 @@

package bisq.core.network.p2p.seed;

import bisq.core.app.BisqEnvironment;

import bisq.network.NetworkOptionKeys;
import bisq.network.p2p.NodeAddress;
import bisq.network.p2p.seed.SeedNodeRepository;

import javax.inject.Inject;
import javax.inject.Named;

import java.util.Set;
import java.util.stream.Stream;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class DefaultSeedNodeRepository implements SeedNodeRepository {
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

private final Set<NodeAddress> seedNodeAddresses;
private final Set<NodeAddress> torSeedNodeAddresses;
private final Set<NodeAddress> localhostSeedNodeAddresses;
import javax.annotation.Nullable;

public class DefaultSeedNodeRepository implements SeedNodeRepository {
private static final Pattern pattern = Pattern.compile("^([a-z0-9]+\\.onion:\\d+)");
private static final String ENDING = ".seednodes";
private static final Collection<NodeAddress> cache = new HashSet<>();
private final BisqEnvironment bisqEnvironment;
private final String seedNodes;

@Inject
public DefaultSeedNodeRepository(SeedNodeAddressLookup lookup) {
this.seedNodeAddresses = lookup.resolveNodeAddresses();
this.torSeedNodeAddresses = DefaultSeedNodeAddresses.DEFAULT_TOR_SEED_NODE_ADDRESSES;
this.localhostSeedNodeAddresses = DefaultSeedNodeAddresses.DEFAULT_LOCALHOST_SEED_NODE_ADDRESSES;
public DefaultSeedNodeRepository(BisqEnvironment environment,
@Nullable @Named(NetworkOptionKeys.SEED_NODES_KEY) String seedNodes) {
bisqEnvironment = environment;
this.seedNodes = seedNodes;
}

@Override
public Set<NodeAddress> getSeedNodeAddresses() {
return seedNodeAddresses;
}
private void reload() {

// see if there are any seed nodes configured manually
if(seedNodes != null && !seedNodes.isEmpty()) {
cache.clear();
Arrays.stream(seedNodes.split(",")).forEach(s -> cache.add(new NodeAddress(s)));

@Override
public String getOperator(NodeAddress nodeAddress) {
switch (nodeAddress.getFullAddress()) {
case "5quyxpxheyvzmb2d.onion:8000":
return "@miker";
case "ef5qnzx6znifo3df.onion:8000":
return "@manfredkarrer";
case "s67qglwhkgkyvr74.onion:8000":
return "@emzy";
case "jhgcy2won7xnslrb.onion:8000":
return "@manfredkarrer";
case "3f3cu2yw7u457ztq.onion:8000":
return "@manfredkarrer";
case "723ljisnynbtdohi.onion:8000":
return "@manfredkarrer";
case "rm7b56wbrcczpjvl.onion:8000":
return "@manfredkarrer";
case "fl3mmribyxgrv63c.onion:8000":
return "@manfredkarrer";
default:
return "Undefined";
return;
}

// else, we fetch the seed nodes from our resources
final InputStream fileInputStream = DefaultSeedNodeRepository.class.getClassLoader().getResourceAsStream(BisqEnvironment.getBaseCurrencyNetwork().name().toLowerCase() + ENDING);
final BufferedReader seedNodeFile = new BufferedReader(new InputStreamReader(fileInputStream));

// only clear if we have a fresh data source (otherwise, an exception would prevent us from getting here)
cache.clear();

// refill the cache
seedNodeFile.lines().forEach(s -> {
final Matcher matcher = pattern.matcher(s);
if(matcher.find())
cache.add(new NodeAddress(matcher.group(1)));
});

// filter
cache.removeAll(bisqEnvironment.getBannedSeedNodes().stream().map(s -> new NodeAddress(s)).collect(Collectors.toSet()));
}

public Collection<NodeAddress> getSeedNodeAddresses() {
if(cache.isEmpty())
reload();

return cache;
}

@Override
public boolean isSeedNode(NodeAddress nodeAddress) {
return Stream.concat(localhostSeedNodeAddresses.stream(), torSeedNodeAddresses.stream())
.anyMatch(e -> e.equals(nodeAddress));
if(cache.isEmpty())
reload();
return cache.contains(nodeAddress);
}
}

This file was deleted.

Loading