From 3e13a0f2262a2f1ca4182a299099edcee4c4f83e Mon Sep 17 00:00:00 2001 From: Sergey Rozhnov Date: Thu, 15 Feb 2018 15:19:51 +0400 Subject: [PATCH] Extracted default addresses into a separate class --- .../CoreSeedNodeRepositoryFactory.java | 83 +----------------- .../core/network/CoreSeedNodesRepository.java | 7 +- .../core/network/DefaultNodeAddresses.java | 84 +++++++++++++++++++ .../io/bisq/core/network/NodeAddresses.java | 2 +- 4 files changed, 91 insertions(+), 85 deletions(-) create mode 100644 core/src/main/java/io/bisq/core/network/DefaultNodeAddresses.java diff --git a/core/src/main/java/io/bisq/core/network/CoreSeedNodeRepositoryFactory.java b/core/src/main/java/io/bisq/core/network/CoreSeedNodeRepositoryFactory.java index 25f6d795b2..4823bf34ad 100644 --- a/core/src/main/java/io/bisq/core/network/CoreSeedNodeRepositoryFactory.java +++ b/core/src/main/java/io/bisq/core/network/CoreSeedNodeRepositoryFactory.java @@ -1,6 +1,5 @@ package io.bisq.core.network; -import com.google.common.collect.ImmutableSet; import com.google.inject.name.Named; import io.bisq.core.app.BisqEnvironment; import io.bisq.network.NetworkOptionKeys; @@ -14,86 +13,12 @@ import java.util.HashSet; import java.util.Optional; import java.util.Set; +import static io.bisq.core.network.DefaultNodeAddresses.DEFAULT_LOCALHOST_SEED_NODE_ADDRESSES; +import static io.bisq.core.network.DefaultNodeAddresses.DEFAULT_TOR_SEED_NODE_ADDRESSES; + class CoreSeedNodeRepositoryFactory { private static final Logger log = LoggerFactory.getLogger(CoreSeedNodeRepositoryFactory.class); - // 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 - private static final Set 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"),*/ - - // LTC - // mainnet - new NodeAddress("localhost:2003"), - - // regtest - new NodeAddress("localhost:2005"), - - // DOGE regtest - new NodeAddress("localhost:2008"), - - // DASH regtest - new NodeAddress("localhost:2011") - ); - - // Addresses are used if their port match the network id: - // - mainnet uses port 8000 - // - testnet uses port 8001 - // - regtest uses port 8002 - private static final Set 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("nbphlanpgbei4okt.onion:8001"), - // new NodeAddress("vjkh4ykq7x5skdlt.onion:8001"), // dev test - - // 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"), - - // LTC mainnet - new NodeAddress("acyvotgewx46pebw.onion:8003"), - new NodeAddress("pklgy3vdfn3obkur.onion:8003"), - - // DASH mainnet - new NodeAddress("toeu5ikb27ydscxt.onion:8009"), - new NodeAddress("ae4yvaivhnekkhqf.onion:8009") - ); - - CoreSeedNodesRepository create(BisqEnvironment environment, @Named(NetworkOptionKeys.USE_LOCALHOST_FOR_P2P) boolean useLocalhostForP2P, @Named(NetworkOptionKeys.NETWORK_ID) int networkId, @@ -104,7 +29,7 @@ class CoreSeedNodeRepositoryFactory { Set delegate = useLocalhostForP2P ? DEFAULT_LOCALHOST_SEED_NODE_ADDRESSES : DEFAULT_TOR_SEED_NODE_ADDRESSES; - nodeAddresses = NodeAddresses.createFromSet(delegate, networkId); + nodeAddresses = NodeAddresses.fromSet(delegate, networkId); } Set bannedHosts = getBannedHosts(environment); diff --git a/core/src/main/java/io/bisq/core/network/CoreSeedNodesRepository.java b/core/src/main/java/io/bisq/core/network/CoreSeedNodesRepository.java index c9624daec1..cc3372be33 100644 --- a/core/src/main/java/io/bisq/core/network/CoreSeedNodesRepository.java +++ b/core/src/main/java/io/bisq/core/network/CoreSeedNodesRepository.java @@ -11,6 +11,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import javax.annotation.Nullable; +import javax.annotation.concurrent.NotThreadSafe; import javax.inject.Inject; import java.util.Arrays; import java.util.List; @@ -19,6 +20,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; @Slf4j +@NotThreadSafe public class CoreSeedNodesRepository implements SeedNodesRepository { @Getter @@ -55,11 +57,6 @@ public class CoreSeedNodesRepository implements SeedNodesRepository { log.warn("We received banned seed nodes={}, seedNodeAddresses={}", bannedNodes, seedNodeAddresses); } - public CoreSeedNodesRepository(Set seedNodeAddresses) { - this.seedNodeAddresses = seedNodeAddresses; - - } - public String getOperator(NodeAddress nodeAddress) { switch (nodeAddress.getFullAddress()) { case "5quyxpxheyvzmb2d.onion:8000": diff --git a/core/src/main/java/io/bisq/core/network/DefaultNodeAddresses.java b/core/src/main/java/io/bisq/core/network/DefaultNodeAddresses.java new file mode 100644 index 0000000000..9d7fd807e2 --- /dev/null +++ b/core/src/main/java/io/bisq/core/network/DefaultNodeAddresses.java @@ -0,0 +1,84 @@ +package io.bisq.core.network; + +import com.google.common.collect.ImmutableSet; +import io.bisq.network.p2p.NodeAddress; + +import java.util.Set; + +class DefaultNodeAddresses { + // 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 + static final Set 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"),*/ + + // LTC + // mainnet + new NodeAddress("localhost:2003"), + + // regtest + new NodeAddress("localhost:2005"), + + // DOGE regtest + new NodeAddress("localhost:2008"), + + // DASH regtest + new NodeAddress("localhost:2011") + ); + + // Addresses are used if their port match the network id: + // - mainnet uses port 8000 + // - testnet uses port 8001 + // - regtest uses port 8002 + static final Set 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("nbphlanpgbei4okt.onion:8001"), + // new NodeAddress("vjkh4ykq7x5skdlt.onion:8001"), // dev test + + // 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"), + + // LTC mainnet + new NodeAddress("acyvotgewx46pebw.onion:8003"), + new NodeAddress("pklgy3vdfn3obkur.onion:8003"), + + // DASH mainnet + new NodeAddress("toeu5ikb27ydscxt.onion:8009"), + new NodeAddress("ae4yvaivhnekkhqf.onion:8009") + ); +} diff --git a/core/src/main/java/io/bisq/core/network/NodeAddresses.java b/core/src/main/java/io/bisq/core/network/NodeAddresses.java index f7534a7bb7..586e5364f7 100644 --- a/core/src/main/java/io/bisq/core/network/NodeAddresses.java +++ b/core/src/main/java/io/bisq/core/network/NodeAddresses.java @@ -27,7 +27,7 @@ class NodeAddresses { return new NodeAddresses(addresses); } - static NodeAddresses createFromSet(Set addresses, int networkId) { + static NodeAddresses fromSet(Set addresses, int networkId) { Set delegate = addresses.stream() .filter(address -> isAddressFromNetwork(address, networkId)) .collect(Collectors.toSet());