Skip to content
Permalink
Browse files

Revert 2473067

Seed nodes do not connect to correct network. The PR needs to be better
tested and fixed.
  • Loading branch information...
ManfredKarrer committed Feb 27, 2019
1 parent 740c112 commit a9ee15d9f60b52d0c5e2e3a9cc24e9be82a8b407
Showing with 589 additions and 171 deletions.
  1. +2 −0 core/src/main/java/bisq/core/CoreModule.java
  2. +1 −2 core/src/main/java/bisq/core/app/BisqEnvironment.java
  3. +2 −0 core/src/main/java/bisq/core/app/misc/ModuleForAppWithP2p.java
  4. +97 −0 core/src/main/java/bisq/core/network/p2p/seed/DefaultSeedNodeAddresses.java
  5. +38 −66 core/src/main/java/bisq/core/network/p2p/seed/DefaultSeedNodeRepository.java
  6. +45 −0 core/src/main/java/bisq/core/network/p2p/seed/ImmutableSetDecorator.java
  7. +106 −0 core/src/main/java/bisq/core/network/p2p/seed/SeedNodeAddressLookup.java
  8. +67 −0 core/src/main/java/bisq/core/network/p2p/seed/SeedNodeAddresses.java
  9. +0 −5 core/src/main/resources/btc_dao_testnet.seednodes
  10. +0 −9 core/src/main/resources/btc_mainnet.seednodes
  11. +0 −10 core/src/main/resources/btc_regtest.seednodes
  12. +0 −2 core/src/main/resources/btc_testnet.seednodes
  13. +0 −48 core/src/test/java/bisq/core/network/p2p/seed/DefaultSeedNodeRepositoryTest.java
  14. +65 −0 core/src/test/java/bisq/core/network/p2p/seed/ImmutableSetDecoratorTest.java
  15. +55 −0 core/src/test/java/bisq/core/network/p2p/seed/SeedNodeAddressLookupTest.java
  16. +102 −0 core/src/test/java/bisq/core/network/p2p/seed/SeedNodeAddressesTest.java
  17. +0 −9 core/src/test/resources/mainnet.seednodes
  18. +0 −10 core/src/test/resources/regtest.seednodes
  19. +0 −7 core/src/test/resources/testnet.seednodes
  20. +5 −1 monitor/src/main/java/bisq/monitor/metric/P2PNetworkLoad.java
  21. +4 −2 p2p/src/main/java/bisq/network/p2p/seed/SeedNodeRepository.java
@@ -30,6 +30,7 @@
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;
@@ -98,6 +99,7 @@ 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));
@@ -57,7 +57,6 @@
import java.io.FileOutputStream;
import java.io.IOException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
@@ -346,7 +345,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(",")) : new ArrayList<>();
bannedSeedNodes = !bannedSeedNodesAsString.isEmpty() ? Arrays.asList(StringUtils.deleteWhitespace(bannedSeedNodesAsString).split(",")) : null;

final String bannedBtcNodesAsString = getProperty(FilterManager.BANNED_BTC_NODES, "");
bannedBtcNodes = !bannedBtcNodesAsString.isEmpty() ? Arrays.asList(StringUtils.deleteWhitespace(bannedBtcNodesAsString).split(",")) : null;
@@ -26,6 +26,7 @@
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;
@@ -76,6 +77,7 @@ 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));
@@ -0,0 +1,97 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.network.p2p.seed;

import bisq.network.p2p.NodeAddress;

import com.google.common.collect.ImmutableSet;

import java.util.Set;

class DefaultSeedNodeAddresses {
// Addresses are used if the last digit of their port match the network id:
// - mainnet use port ends in 0
// - testnet use port ends in 1
// - regtest use port ends in 2
public static final Set<NodeAddress> DEFAULT_LOCALHOST_SEED_NODE_ADDRESSES = ImmutableSet.of(
// BTC
// mainnet
new NodeAddress("localhost:2000"),
new NodeAddress("localhost:3000"),
new NodeAddress("localhost:4000"),

// testnet
new NodeAddress("localhost:2001"),
new NodeAddress("localhost:3001"),
new NodeAddress("localhost:4001"),

// regtest
new NodeAddress("localhost:2002"),
new NodeAddress("localhost:3002")
/* new NodeAddress("localhost:4002"),*/
);

// Addresses are used if their port match the network id:
// - mainnet uses port 8000
// - testnet uses port 8001
// - regtest uses port 8002
public static final Set<NodeAddress> DEFAULT_TOR_SEED_NODE_ADDRESSES = ImmutableSet.of(
// BTC mainnet
new NodeAddress("5quyxpxheyvzmb2d.onion:8000"), // @miker
new NodeAddress("s67qglwhkgkyvr74.onion:8000"), // @emzy
new NodeAddress("ef5qnzx6znifo3df.onion:8000"), // @manfredkarrer
new NodeAddress("jhgcy2won7xnslrb.onion:8000"), // @manfredkarrer
new NodeAddress("3f3cu2yw7u457ztq.onion:8000"), // @manfredkarrer
new NodeAddress("723ljisnynbtdohi.onion:8000"), // @manfredkarrer
new NodeAddress("rm7b56wbrcczpjvl.onion:8000"), // @manfredkarrer
new NodeAddress("fl3mmribyxgrv63c.onion:8000"), // @manfredkarrer

// local dev
// new NodeAddress("joehwtpe7ijnz4df.onion:8000"),
// new NodeAddress("uqxi3zrpobhtoes6.onion:8000"),

// BTC testnet
// new NodeAddress("vjkh4ykq7x5skdlt.onion:8001"), // local dev test
//new NodeAddress("fjr5w4eckjghqtnu.onion:8001"), // testnet seed 1
/* new NodeAddress("74w2sttlo4qk6go3.onion:8001"), // testnet seed 2
new NodeAddress("jmc5ajqvtnzqaggm.onion:8001"), // testnet seed 3
new NodeAddress("3d56s6acbi3vk52v.onion:8001"), // testnet seed 4*/

// BTC regtest
// For development you need to change that to your local onion addresses
// 1. Run a seed node with prog args: --bitcoinNetwork=regtest --nodePort=8002 --myAddress=rxdkppp3vicnbgqt:8002 --appName=bisq_seed_node_rxdkppp3vicnbgqt.onion_8002
// 2. Find your local onion address in bisq_seed_node_rxdkppp3vicnbgqt.onion_8002/regtest/tor/hiddenservice/hostname
// 3. Shut down the seed node
// 4. Rename the directory with your local onion address
// 5. Edit here your found onion address (new NodeAddress("YOUR_ONION.onion:8002")
new NodeAddress("rxdkppp3vicnbgqt.onion:8002"),
new NodeAddress("4ie52dse64kaarxw.onion:8002"),

// DAO TESTNET (server side regtest dedicated for DAO testing)
new NodeAddress("fjr5w4eckjghqtnu.onion:8003"), // testnet seed 1
new NodeAddress("74w2sttlo4qk6go3.onion:8003"), // testnet seed 2
new NodeAddress("jmc5ajqvtnzqaggm.onion:8003"), // testnet seed 3
new NodeAddress("3d56s6acbi3vk52v.onion:8003") // testnet seed 4

// explorer
// new NodeAddress("gtif46mfxirv533z.onion:8003")
);

private DefaultSeedNodeAddresses() {
}
}
@@ -17,87 +17,59 @@

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.net.URL;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;

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;

import javax.annotation.Nullable;
import java.util.Set;
import java.util.stream.Stream;

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;

private final Set<NodeAddress> seedNodeAddresses;
private final Set<NodeAddress> torSeedNodeAddresses;
private final Set<NodeAddress> localhostSeedNodeAddresses;

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

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)));

return;
}

// else, we fetch the seed nodes from our resources
try {
// read appropriate file
final URL file = DefaultSeedNodeRepository.class.getClassLoader().getResource(BisqEnvironment.getBaseCurrencyNetwork().name().toLowerCase() + ENDING);
final BufferedReader seedNodeFile = new BufferedReader(new FileReader(file.getFile()));

// 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()));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
@Override
public Set<NodeAddress> getSeedNodeAddresses() {
return seedNodeAddresses;
}

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

return cache;
@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";
}
}

@Override
public boolean isSeedNode(NodeAddress nodeAddress) {
if(cache.isEmpty())
reload();
return cache.contains(nodeAddress);
return Stream.concat(localhostSeedNodeAddresses.stream(), torSeedNodeAddresses.stream())
.anyMatch(e -> e.equals(nodeAddress));
}
}
@@ -0,0 +1,45 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.network.p2p.seed;

import com.google.common.collect.ImmutableSet;

import java.util.AbstractSet;
import java.util.Iterator;
import java.util.Set;

import org.jetbrains.annotations.NotNull;

class ImmutableSetDecorator<T> extends AbstractSet<T> {
private final Set<T> delegate;

public ImmutableSetDecorator(Set<T> delegate) {
this.delegate = ImmutableSet.copyOf(delegate);
}

@NotNull
@Override
public Iterator<T> iterator() {
return delegate.iterator();
}

@Override
public int size() {
return delegate.size();
}
}

2 comments on commit a9ee15d

@freimair

This comment has been minimized.

Copy link
Member

replied Feb 28, 2019

I tried everything I can think of and I cannot reproduce the issue you have faced.

So it seems like finding the issue is up to you.

@freimair

This comment has been minimized.

Copy link
Member

replied Feb 28, 2019

nevermind: #2476

shame on me

Please sign in to comment.
You can’t perform that action at this time.