mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 01:41:11 +01:00
Add NetworkFilter, remove BanList
This commit is contained in:
parent
9dfcc01acd
commit
3cf6c60354
@ -21,6 +21,7 @@ import bisq.core.alert.AlertModule;
|
||||
import bisq.core.btc.BitcoinModule;
|
||||
import bisq.core.dao.DaoModule;
|
||||
import bisq.core.filter.FilterModule;
|
||||
import bisq.core.network.CoreNetworkFilter;
|
||||
import bisq.core.network.p2p.seed.DefaultSeedNodeRepository;
|
||||
import bisq.core.offer.OfferModule;
|
||||
import bisq.core.presentation.CorePresentationModule;
|
||||
@ -35,6 +36,7 @@ import bisq.core.util.coin.ImmutableCoinFormatter;
|
||||
import bisq.network.crypto.EncryptionServiceModule;
|
||||
import bisq.network.p2p.P2PModule;
|
||||
import bisq.network.p2p.network.BridgeAddressProvider;
|
||||
import bisq.network.p2p.network.NetworkFilter;
|
||||
import bisq.network.p2p.seed.SeedNodeRepository;
|
||||
|
||||
import bisq.common.app.AppModule;
|
||||
@ -44,6 +46,8 @@ import bisq.common.crypto.PubKeyRingProvider;
|
||||
import bisq.common.proto.network.NetworkProtoResolver;
|
||||
import bisq.common.proto.persistable.PersistenceProtoResolver;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static bisq.common.config.Config.*;
|
||||
@ -62,6 +66,7 @@ public class CoreModule extends AppModule {
|
||||
bind(BridgeAddressProvider.class).to(Preferences.class);
|
||||
|
||||
bind(SeedNodeRepository.class).to(DefaultSeedNodeRepository.class);
|
||||
bind(NetworkFilter.class).to(CoreNetworkFilter.class).in(Singleton.class);
|
||||
|
||||
bind(File.class).annotatedWith(named(STORAGE_DIR)).toInstance(config.storageDir);
|
||||
|
||||
|
@ -22,6 +22,7 @@ import bisq.core.app.TorSetup;
|
||||
import bisq.core.btc.BitcoinModule;
|
||||
import bisq.core.dao.DaoModule;
|
||||
import bisq.core.filter.FilterModule;
|
||||
import bisq.core.network.CoreNetworkFilter;
|
||||
import bisq.core.network.p2p.seed.DefaultSeedNodeRepository;
|
||||
import bisq.core.offer.OfferModule;
|
||||
import bisq.core.proto.network.CoreNetworkProtoResolver;
|
||||
@ -33,6 +34,7 @@ import bisq.core.user.User;
|
||||
import bisq.network.crypto.EncryptionServiceModule;
|
||||
import bisq.network.p2p.P2PModule;
|
||||
import bisq.network.p2p.network.BridgeAddressProvider;
|
||||
import bisq.network.p2p.network.NetworkFilter;
|
||||
import bisq.network.p2p.seed.SeedNodeRepository;
|
||||
|
||||
import bisq.common.ClockWatcher;
|
||||
@ -73,6 +75,7 @@ public class ModuleForAppWithP2p extends AppModule {
|
||||
bind(TorSetup.class).in(Singleton.class);
|
||||
|
||||
bind(SeedNodeRepository.class).to(DefaultSeedNodeRepository.class).in(Singleton.class);
|
||||
bind(NetworkFilter.class).to(CoreNetworkFilter.class).in(Singleton.class);
|
||||
|
||||
bind(File.class).annotatedWith(named(STORAGE_DIR)).toInstance(config.storageDir);
|
||||
bind(File.class).annotatedWith(named(KEY_STORAGE_DIR)).toInstance(config.keyStorageDir);
|
||||
|
@ -19,6 +19,7 @@ package bisq.core.filter;
|
||||
|
||||
import bisq.core.btc.nodes.BtcNodes;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.network.CoreNetworkFilter;
|
||||
import bisq.core.payment.payload.PaymentAccountPayload;
|
||||
import bisq.core.payment.payload.PaymentMethod;
|
||||
import bisq.core.provider.ProvidersRepository;
|
||||
@ -96,6 +97,7 @@ public class FilterManager {
|
||||
private final Preferences preferences;
|
||||
private final ConfigFileEditor configFileEditor;
|
||||
private final ProvidersRepository providersRepository;
|
||||
private final CoreNetworkFilter coreNetworkFilter;
|
||||
private final boolean ignoreDevMsg;
|
||||
private final ObjectProperty<Filter> filterProperty = new SimpleObjectProperty<>();
|
||||
private final List<Listener> listeners = new CopyOnWriteArrayList<>();
|
||||
@ -115,6 +117,7 @@ public class FilterManager {
|
||||
Preferences preferences,
|
||||
Config config,
|
||||
ProvidersRepository providersRepository,
|
||||
CoreNetworkFilter coreNetworkFilter,
|
||||
@Named(Config.IGNORE_DEV_MSG) boolean ignoreDevMsg,
|
||||
@Named(Config.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys) {
|
||||
this.p2PService = p2PService;
|
||||
@ -123,6 +126,7 @@ public class FilterManager {
|
||||
this.preferences = preferences;
|
||||
this.configFileEditor = new ConfigFileEditor(config.configFile);
|
||||
this.providersRepository = providersRepository;
|
||||
this.coreNetworkFilter = coreNetworkFilter;
|
||||
this.ignoreDevMsg = ignoreDevMsg;
|
||||
|
||||
publicKeys = useDevPrivilegeKeys ?
|
||||
|
@ -15,37 +15,35 @@
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.network.p2p.peers;
|
||||
package bisq.core.network;
|
||||
|
||||
import bisq.network.p2p.NodeAddress;
|
||||
import bisq.network.p2p.network.NetworkFilter;
|
||||
|
||||
import bisq.common.config.Config;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Set;
|
||||
|
||||
public class BanList {
|
||||
private static List<NodeAddress> list = new ArrayList<>();
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
public static void add(NodeAddress onionAddress) {
|
||||
list.add(onionAddress);
|
||||
}
|
||||
|
||||
public static boolean isBanned(NodeAddress nodeAddress) {
|
||||
return list.contains(nodeAddress);
|
||||
}
|
||||
@Slf4j
|
||||
public class CoreNetworkFilter implements NetworkFilter {
|
||||
private final Set<NodeAddress> bannedPeersFromOptions = new HashSet<>();
|
||||
|
||||
/**
|
||||
* @param banList List of banned peers from program argument
|
||||
*/
|
||||
@Inject
|
||||
public BanList(@Named(Config.BAN_LIST) List<String> banList) {
|
||||
if (!banList.isEmpty())
|
||||
BanList.list = banList.stream().map(NodeAddress::new).collect(Collectors.toList());
|
||||
public CoreNetworkFilter(@Named(Config.BAN_LIST) List<String> banList) {
|
||||
banList.stream().map(NodeAddress::new).forEach(bannedPeersFromOptions::add);
|
||||
}
|
||||
|
||||
public boolean isPeerBanned(NodeAddress nodeAddress) {
|
||||
return bannedPeersFromOptions.contains(nodeAddress);
|
||||
}
|
||||
}
|
@ -25,6 +25,8 @@ import bisq.core.proto.CoreProtoResolver;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
public class UserPayloadModelVOTest {
|
||||
@ -64,7 +66,8 @@ public class UserPayloadModelVOTest {
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
Lists.newArrayList()));
|
||||
Lists.newArrayList(),
|
||||
new HashSet<>()));
|
||||
|
||||
vo.setRegisteredArbitrator(ArbitratorTest.getArbitratorMock());
|
||||
vo.setRegisteredMediator(MediatorTest.getMediatorMock());
|
||||
|
@ -26,6 +26,7 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.primitives.Longs;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
@ -123,6 +124,7 @@ public class FeeReceiverSelectorTest {
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
Lists.newArrayList());
|
||||
Lists.newArrayList(),
|
||||
new HashSet<>());
|
||||
}
|
||||
}
|
||||
|
@ -257,6 +257,7 @@ public class InventoryMonitor implements SetupListener {
|
||||
CoreNetworkProtoResolver networkProtoResolver = new CoreNetworkProtoResolver(Clock.systemDefaultZone());
|
||||
return new NetworkNodeProvider(networkProtoResolver,
|
||||
ArrayList::new,
|
||||
null,
|
||||
useLocalhostForP2P,
|
||||
9999,
|
||||
torDir,
|
||||
|
@ -116,7 +116,7 @@ public class P2PNetworkLoad extends Metric implements MessageListener, SetupList
|
||||
// start the network node
|
||||
networkNode = new TorNetworkNode(Integer.parseInt(configuration.getProperty(TOR_PROXY_PORT, "9053")),
|
||||
new CoreNetworkProtoResolver(Clock.systemDefaultZone()), false,
|
||||
new AvailableTor(Monitor.TOR_WORKING_DIR, torHiddenServiceDir.getName()));
|
||||
new AvailableTor(Monitor.TOR_WORKING_DIR, torHiddenServiceDir.getName()), null);
|
||||
networkNode.start(this);
|
||||
|
||||
// wait for the HS to be published
|
||||
|
@ -155,7 +155,7 @@ public abstract class P2PSeedNodeSnapshotBase extends Metric implements MessageL
|
||||
// start the network node
|
||||
final NetworkNode networkNode = new TorNetworkNode(Integer.parseInt(configuration.getProperty(TOR_PROXY_PORT, "9054")),
|
||||
new CoreNetworkProtoResolver(Clock.systemDefaultZone()), false,
|
||||
new AvailableTor(Monitor.TOR_WORKING_DIR, "unused"));
|
||||
new AvailableTor(Monitor.TOR_WORKING_DIR, "unused"), null);
|
||||
// we do not need to start the networkNode, as we do not need the HS
|
||||
//networkNode.start(this);
|
||||
|
||||
|
@ -19,6 +19,7 @@ package bisq.network.p2p;
|
||||
|
||||
import bisq.network.p2p.network.BridgeAddressProvider;
|
||||
import bisq.network.p2p.network.LocalhostNetworkNode;
|
||||
import bisq.network.p2p.network.NetworkFilter;
|
||||
import bisq.network.p2p.network.NetworkNode;
|
||||
import bisq.network.p2p.network.NewTor;
|
||||
import bisq.network.p2p.network.RunningTor;
|
||||
@ -27,10 +28,9 @@ import bisq.network.p2p.network.TorNetworkNode;
|
||||
import bisq.common.config.Config;
|
||||
import bisq.common.proto.network.NetworkProtoResolver;
|
||||
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Named;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@ -43,6 +43,7 @@ public class NetworkNodeProvider implements Provider<NetworkNode> {
|
||||
@Inject
|
||||
public NetworkNodeProvider(NetworkProtoResolver networkProtoResolver,
|
||||
BridgeAddressProvider bridgeAddressProvider,
|
||||
@Nullable NetworkFilter networkFilter,
|
||||
@Named(Config.USE_LOCALHOST_FOR_P2P) boolean useLocalhostForP2P,
|
||||
@Named(Config.NODE_PORT) int port,
|
||||
@Named(Config.TOR_DIR) File torDir,
|
||||
@ -52,13 +53,14 @@ public class NetworkNodeProvider implements Provider<NetworkNode> {
|
||||
@Named(Config.TOR_CONTROL_PASSWORD) String password,
|
||||
@Nullable @Named(Config.TOR_CONTROL_COOKIE_FILE) File cookieFile,
|
||||
@Named(Config.TOR_STREAM_ISOLATION) boolean streamIsolation,
|
||||
@Named(Config.TOR_CONTROL_USE_SAFE_COOKIE_AUTH) boolean useSafeCookieAuthentication ) {
|
||||
@Named(Config.TOR_CONTROL_USE_SAFE_COOKIE_AUTH) boolean useSafeCookieAuthentication) {
|
||||
networkNode = useLocalhostForP2P ?
|
||||
new LocalhostNetworkNode(port, networkProtoResolver) :
|
||||
new LocalhostNetworkNode(port, networkProtoResolver, networkFilter) :
|
||||
new TorNetworkNode(port, networkProtoResolver, streamIsolation,
|
||||
controlPort != Config.UNSPECIFIED_PORT ?
|
||||
new RunningTor(torDir, controlPort, password, cookieFile, useSafeCookieAuthentication) :
|
||||
new NewTor(torDir, torrcFile, torrcOptions, bridgeAddressProvider.getBridgeAddresses()));
|
||||
new NewTor(torDir, torrcFile, torrcOptions, bridgeAddressProvider.getBridgeAddresses()),
|
||||
networkFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,7 +22,6 @@ import bisq.network.http.HttpClient;
|
||||
import bisq.network.http.HttpClientImpl;
|
||||
import bisq.network.p2p.network.Connection;
|
||||
import bisq.network.p2p.network.NetworkNode;
|
||||
import bisq.network.p2p.peers.BanList;
|
||||
import bisq.network.p2p.peers.Broadcaster;
|
||||
import bisq.network.p2p.peers.PeerManager;
|
||||
import bisq.network.p2p.peers.getdata.RequestDataManager;
|
||||
@ -68,7 +67,6 @@ public class P2PModule extends AppModule {
|
||||
bind(PeerExchangeManager.class).in(Singleton.class);
|
||||
bind(KeepAliveManager.class).in(Singleton.class);
|
||||
bind(Broadcaster.class).in(Singleton.class);
|
||||
bind(BanList.class).in(Singleton.class);
|
||||
bind(NetworkNode.class).toProvider(NetworkNodeProvider.class).in(Singleton.class);
|
||||
bind(Socks5ProxyProvider.class).in(Singleton.class);
|
||||
bind(HttpClient.class).to(HttpClientImpl.class);
|
||||
|
@ -24,7 +24,6 @@ import bisq.network.p2p.NodeAddress;
|
||||
import bisq.network.p2p.PrefixedSealedAndSignedMessage;
|
||||
import bisq.network.p2p.SendersNodeAddressMessage;
|
||||
import bisq.network.p2p.SupportedCapabilitiesMessage;
|
||||
import bisq.network.p2p.peers.BanList;
|
||||
import bisq.network.p2p.peers.getdata.messages.GetDataRequest;
|
||||
import bisq.network.p2p.peers.getdata.messages.GetDataResponse;
|
||||
import bisq.network.p2p.peers.keepalive.messages.KeepAliveMessage;
|
||||
@ -141,6 +140,8 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
|
||||
private final Socket socket;
|
||||
// private final MessageListener messageListener;
|
||||
private final ConnectionListener connectionListener;
|
||||
@Nullable
|
||||
private final NetworkFilter networkFilter;
|
||||
@Getter
|
||||
private final String uid;
|
||||
private final ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(runnable -> new Thread(runnable, "Connection.java executor-service"));
|
||||
@ -184,9 +185,11 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
|
||||
MessageListener messageListener,
|
||||
ConnectionListener connectionListener,
|
||||
@Nullable NodeAddress peersNodeAddress,
|
||||
NetworkProtoResolver networkProtoResolver) {
|
||||
NetworkProtoResolver networkProtoResolver,
|
||||
@Nullable NetworkFilter networkFilter) {
|
||||
this.socket = socket;
|
||||
this.connectionListener = connectionListener;
|
||||
this.networkFilter = networkFilter;
|
||||
uid = UUID.randomUUID().toString();
|
||||
statistic = new Statistic();
|
||||
|
||||
@ -209,9 +212,12 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
|
||||
// We create a thread for handling inputStream data
|
||||
singleThreadExecutor.submit(this);
|
||||
|
||||
if (peersNodeAddress != null)
|
||||
if (peersNodeAddress != null) {
|
||||
setPeersNodeAddress(peersNodeAddress);
|
||||
|
||||
if (networkFilter != null && networkFilter.isPeerBanned(peersNodeAddress)) {
|
||||
reportInvalidRequest(RuleViolation.PEER_BANNED);
|
||||
}
|
||||
}
|
||||
UserThread.execute(() -> connectionListener.onConnection(this));
|
||||
} catch (Throwable e) {
|
||||
handleException(e);
|
||||
@ -484,13 +490,9 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
|
||||
}
|
||||
|
||||
peersNodeAddressProperty.set(peerNodeAddress);
|
||||
|
||||
if (BanList.isBanned(peerNodeAddress)) {
|
||||
log.warn("We detected a connection to a banned peer. We will close that connection. (setPeersNodeAddress)");
|
||||
reportInvalidRequest(RuleViolation.PEER_BANNED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -881,6 +883,10 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
|
||||
// We check for a banned peer inside setPeersNodeAddress() and shut down if banned.
|
||||
setPeersNodeAddress(senderNodeAddress);
|
||||
}
|
||||
|
||||
if (networkFilter != null && networkFilter.isPeerBanned(senderNodeAddress)) {
|
||||
reportInvalidRequest(RuleViolation.PEER_BANNED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,11 +21,14 @@ import bisq.common.proto.network.NetworkProtoResolver;
|
||||
|
||||
import java.net.Socket;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class InboundConnection extends Connection {
|
||||
public InboundConnection(Socket socket,
|
||||
MessageListener messageListener,
|
||||
ConnectionListener connectionListener,
|
||||
NetworkProtoResolver networkProtoResolver) {
|
||||
super(socket, messageListener, connectionListener, null, networkProtoResolver);
|
||||
NetworkProtoResolver networkProtoResolver,
|
||||
@Nullable NetworkFilter networkFilter) {
|
||||
super(socket, messageListener, connectionListener, null, networkProtoResolver, networkFilter);
|
||||
}
|
||||
}
|
||||
|
@ -54,8 +54,10 @@ public class LocalhostNetworkNode extends NetworkNode {
|
||||
// Constructor
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public LocalhostNetworkNode(int port, NetworkProtoResolver networkProtoResolver) {
|
||||
super(port, networkProtoResolver);
|
||||
public LocalhostNetworkNode(int port,
|
||||
NetworkProtoResolver networkProtoResolver,
|
||||
@Nullable NetworkFilter networkFilter) {
|
||||
super(port, networkProtoResolver, networkFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.network.p2p.network;
|
||||
|
||||
import bisq.network.p2p.NodeAddress;
|
||||
|
||||
public interface NetworkFilter {
|
||||
boolean isPeerBanned(NodeAddress nodeAddress);
|
||||
}
|
@ -69,6 +69,8 @@ public abstract class NetworkNode implements MessageListener {
|
||||
|
||||
final int servicePort;
|
||||
private final NetworkProtoResolver networkProtoResolver;
|
||||
@Nullable
|
||||
private final NetworkFilter networkFilter;
|
||||
|
||||
private final CopyOnWriteArraySet<InboundConnection> inBoundConnections = new CopyOnWriteArraySet<>();
|
||||
private final CopyOnWriteArraySet<MessageListener> messageListeners = new CopyOnWriteArraySet<>();
|
||||
@ -87,9 +89,12 @@ public abstract class NetworkNode implements MessageListener {
|
||||
// Constructor
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NetworkNode(int servicePort, NetworkProtoResolver networkProtoResolver) {
|
||||
NetworkNode(int servicePort,
|
||||
NetworkProtoResolver networkProtoResolver,
|
||||
@Nullable NetworkFilter networkFilter) {
|
||||
this.servicePort = servicePort;
|
||||
this.networkProtoResolver = networkProtoResolver;
|
||||
this.networkFilter = networkFilter;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -190,7 +195,8 @@ public abstract class NetworkNode implements MessageListener {
|
||||
NetworkNode.this,
|
||||
connectionListener,
|
||||
peersNodeAddress,
|
||||
networkProtoResolver);
|
||||
networkProtoResolver,
|
||||
networkFilter);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" +
|
||||
@ -457,7 +463,8 @@ public abstract class NetworkNode implements MessageListener {
|
||||
server = new Server(serverSocket,
|
||||
NetworkNode.this,
|
||||
connectionListener,
|
||||
networkProtoResolver);
|
||||
networkProtoResolver,
|
||||
networkFilter);
|
||||
executorService.submit(server);
|
||||
}
|
||||
|
||||
|
@ -23,12 +23,15 @@ import bisq.common.proto.network.NetworkProtoResolver;
|
||||
|
||||
import java.net.Socket;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class OutboundConnection extends Connection {
|
||||
public OutboundConnection(Socket socket,
|
||||
MessageListener messageListener,
|
||||
ConnectionListener connectionListener,
|
||||
NodeAddress peersNodeAddress,
|
||||
NetworkProtoResolver networkProtoResolver) {
|
||||
super(socket, messageListener, connectionListener, peersNodeAddress, networkProtoResolver);
|
||||
NetworkProtoResolver networkProtoResolver,
|
||||
@Nullable NetworkFilter networkFilter) {
|
||||
super(socket, messageListener, connectionListener, peersNodeAddress, networkProtoResolver, networkFilter);
|
||||
}
|
||||
}
|
||||
|
@ -31,12 +31,16 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
// Runs in UserThread
|
||||
class Server implements Runnable {
|
||||
private static final Logger log = LoggerFactory.getLogger(Server.class);
|
||||
|
||||
private final MessageListener messageListener;
|
||||
private final ConnectionListener connectionListener;
|
||||
@Nullable
|
||||
private final NetworkFilter networkFilter;
|
||||
|
||||
// accessed from different threads
|
||||
private final ServerSocket serverSocket;
|
||||
@ -48,11 +52,13 @@ class Server implements Runnable {
|
||||
public Server(ServerSocket serverSocket,
|
||||
MessageListener messageListener,
|
||||
ConnectionListener connectionListener,
|
||||
NetworkProtoResolver networkProtoResolver) {
|
||||
NetworkProtoResolver networkProtoResolver,
|
||||
@Nullable NetworkFilter networkFilter) {
|
||||
this.networkProtoResolver = networkProtoResolver;
|
||||
this.serverSocket = serverSocket;
|
||||
this.messageListener = messageListener;
|
||||
this.connectionListener = connectionListener;
|
||||
this.networkFilter = networkFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -69,7 +75,8 @@ class Server implements Runnable {
|
||||
InboundConnection connection = new InboundConnection(socket,
|
||||
messageListener,
|
||||
connectionListener,
|
||||
networkProtoResolver);
|
||||
networkProtoResolver,
|
||||
networkFilter);
|
||||
|
||||
log.debug("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" +
|
||||
"Server created new inbound connection:"
|
||||
|
@ -87,9 +87,12 @@ public class TorNetworkNode extends NetworkNode {
|
||||
// Constructor
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public TorNetworkNode(int servicePort, NetworkProtoResolver networkProtoResolver, boolean useStreamIsolation,
|
||||
TorMode torMode) {
|
||||
super(servicePort, networkProtoResolver);
|
||||
public TorNetworkNode(int servicePort,
|
||||
NetworkProtoResolver networkProtoResolver,
|
||||
boolean useStreamIsolation,
|
||||
TorMode torMode,
|
||||
@Nullable NetworkFilter networkFilter) {
|
||||
super(servicePort, networkProtoResolver, networkFilter);
|
||||
this.torMode = torMode;
|
||||
this.streamIsolation = useStreamIsolation;
|
||||
createExecutorService();
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
package bisq.network.p2p;
|
||||
|
||||
import bisq.network.p2p.peers.BanList;
|
||||
|
||||
import bisq.common.UserThread;
|
||||
import bisq.common.app.Log;
|
||||
import bisq.common.app.Version;
|
||||
@ -137,10 +135,11 @@ public class DummySeedNode {
|
||||
checkArgument(arg.contains(":") && arg.split(":").length > 1 && arg.split(":")[1].length() > 3,
|
||||
"Wrong program argument " + arg);
|
||||
List<String> list = Arrays.asList(arg.split(","));
|
||||
Set<NodeAddress> bannedPeers = new HashSet<>();
|
||||
list.forEach(e -> {
|
||||
checkArgument(e.contains(":") && e.split(":").length == 2 && e.split(":")[1].length() == 4,
|
||||
"Wrong program argument " + e);
|
||||
BanList.add(new NodeAddress(e));
|
||||
bannedPeers.add(new NodeAddress(e));
|
||||
});
|
||||
log.debug("From processArgs: ignoreList=" + list);
|
||||
} else if (arg.startsWith(HELP)) {
|
||||
|
@ -38,13 +38,10 @@ import org.junit.Test;
|
||||
public class LocalhostNetworkNodeTest {
|
||||
private static final Logger log = LoggerFactory.getLogger(LocalhostNetworkNodeTest.class);
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testMessage() throws InterruptedException, IOException {
|
||||
CountDownLatch msgLatch = new CountDownLatch(2);
|
||||
LocalhostNetworkNode node1 = new LocalhostNetworkNode(9001, TestUtils.getNetworkProtoResolver());
|
||||
LocalhostNetworkNode node1 = new LocalhostNetworkNode(9001, TestUtils.getNetworkProtoResolver(), null);
|
||||
node1.addMessageListener((message, connection) -> {
|
||||
log.debug("onMessage node1 " + message);
|
||||
msgLatch.countDown();
|
||||
@ -72,7 +69,7 @@ public class LocalhostNetworkNodeTest {
|
||||
}
|
||||
});
|
||||
|
||||
LocalhostNetworkNode node2 = new LocalhostNetworkNode(9002, TestUtils.getNetworkProtoResolver());
|
||||
LocalhostNetworkNode node2 = new LocalhostNetworkNode(9002, TestUtils.getNetworkProtoResolver(), null);
|
||||
node2.addMessageListener((message, connection) -> {
|
||||
log.debug("onMessage node2 " + message);
|
||||
msgLatch.countDown();
|
||||
|
@ -27,6 +27,7 @@ import com.google.common.util.concurrent.SettableFuture;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
@ -49,13 +50,12 @@ public class TorNetworkNodeTest {
|
||||
private CountDownLatch latch;
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testTorNodeBeforeSecondReady() throws InterruptedException, IOException {
|
||||
latch = new CountDownLatch(1);
|
||||
int port = 9001;
|
||||
TorNetworkNode node1 = new TorNetworkNode(port, TestUtils.getNetworkProtoResolver(), false,
|
||||
new NewTor(new File("torNode_" + port), null, "", new ArrayList<String>()));
|
||||
new NewTor(new File("torNode_" + port), null, "", new ArrayList<String>()), null);
|
||||
node1.start(new SetupListener() {
|
||||
@Override
|
||||
public void onTorNodeReady() {
|
||||
@ -82,7 +82,7 @@ public class TorNetworkNodeTest {
|
||||
latch = new CountDownLatch(1);
|
||||
int port2 = 9002;
|
||||
TorNetworkNode node2 = new TorNetworkNode(port2, TestUtils.getNetworkProtoResolver(), false,
|
||||
new NewTor(new File("torNode_" + port), null, "", new ArrayList<String>()));
|
||||
new NewTor(new File("torNode_" + port), null, "", new ArrayList<String>()), null);
|
||||
node2.start(new SetupListener() {
|
||||
@Override
|
||||
public void onTorNodeReady() {
|
||||
@ -140,7 +140,7 @@ public class TorNetworkNodeTest {
|
||||
latch = new CountDownLatch(2);
|
||||
int port = 9001;
|
||||
TorNetworkNode node1 = new TorNetworkNode(port, TestUtils.getNetworkProtoResolver(), false,
|
||||
new NewTor(new File("torNode_" + port), null, "", new ArrayList<String>()));
|
||||
new NewTor(new File("torNode_" + port), null, "", new ArrayList<String>()), null);
|
||||
node1.start(new SetupListener() {
|
||||
@Override
|
||||
public void onTorNodeReady() {
|
||||
@ -166,7 +166,7 @@ public class TorNetworkNodeTest {
|
||||
|
||||
int port2 = 9002;
|
||||
TorNetworkNode node2 = new TorNetworkNode(port2, TestUtils.getNetworkProtoResolver(), false,
|
||||
new NewTor(new File("torNode_" + port), null, "", new ArrayList<String>()));
|
||||
new NewTor(new File("torNode_" + port), null, "", new ArrayList<String>()), null);
|
||||
node2.start(new SetupListener() {
|
||||
@Override
|
||||
public void onTorNodeReady() {
|
||||
|
Loading…
Reference in New Issue
Block a user