mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-10 07:30:05 -04:00
update p2p connection and message packages
remove inventor and monitor packages Co-authored-by: Alva Swanson <alvasw@protonmail.com> Co-authored-by: Alejandro García <117378669+alejandrogarcia83@users.noreply.github.com> Co-authored-by: jmacxx <47253594+jmacxx@users.noreply.github.com> Co-authored-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
parent
0f41c8d8b8
commit
e0db4528da
79 changed files with 1332 additions and 5327 deletions
|
@ -24,7 +24,7 @@ import haveno.common.proto.network.NetworkProtoResolver;
|
|||
import haveno.common.proto.persistable.PersistenceProtoResolver;
|
||||
import haveno.core.alert.AlertModule;
|
||||
import haveno.core.filter.FilterModule;
|
||||
import haveno.core.network.CoreNetworkFilter;
|
||||
import haveno.core.network.CoreBanFilter;
|
||||
import haveno.core.network.p2p.seed.DefaultSeedNodeRepository;
|
||||
import haveno.core.offer.OfferModule;
|
||||
import haveno.core.presentation.CorePresentationModule;
|
||||
|
@ -39,8 +39,8 @@ import haveno.core.xmr.MoneroConnectionModule;
|
|||
import haveno.core.xmr.MoneroModule;
|
||||
import haveno.network.crypto.EncryptionServiceModule;
|
||||
import haveno.network.p2p.P2PModule;
|
||||
import haveno.network.p2p.network.BanFilter;
|
||||
import haveno.network.p2p.network.BridgeAddressProvider;
|
||||
import haveno.network.p2p.network.NetworkFilter;
|
||||
import haveno.network.p2p.seed.SeedNodeRepository;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -66,7 +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(BanFilter.class).to(CoreBanFilter.class).in(Singleton.class);
|
||||
|
||||
bind(File.class).annotatedWith(named(STORAGE_DIR)).toInstance(config.storageDir);
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ import haveno.core.trade.statistics.TradeStatisticsManager;
|
|||
import haveno.core.user.User;
|
||||
import haveno.core.xmr.Balances;
|
||||
import haveno.network.p2p.P2PService;
|
||||
import haveno.network.p2p.mailbox.MailboxMessageService;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
@ -93,6 +94,7 @@ public class DomainInitialisation {
|
|||
private final User user;
|
||||
private final TriggerPriceService triggerPriceService;
|
||||
private final MempoolService mempoolService;
|
||||
private final MailboxMessageService mailboxMessageService;
|
||||
|
||||
@Inject
|
||||
public DomainInitialisation(ClockWatcher clockWatcher,
|
||||
|
@ -124,7 +126,8 @@ public class DomainInitialisation {
|
|||
MarketAlerts marketAlerts,
|
||||
User user,
|
||||
TriggerPriceService triggerPriceService,
|
||||
MempoolService mempoolService) {
|
||||
MempoolService mempoolService,
|
||||
MailboxMessageService mailboxMessageService) {
|
||||
this.clockWatcher = clockWatcher;
|
||||
this.arbitrationManager = arbitrationManager;
|
||||
this.mediationManager = mediationManager;
|
||||
|
@ -155,6 +158,7 @@ public class DomainInitialisation {
|
|||
this.user = user;
|
||||
this.triggerPriceService = triggerPriceService;
|
||||
this.mempoolService = mempoolService;
|
||||
this.mailboxMessageService = mailboxMessageService;
|
||||
}
|
||||
|
||||
public void initDomainServices(Consumer<String> rejectedTxErrorMessageHandler,
|
||||
|
@ -213,6 +217,8 @@ public class DomainInitialisation {
|
|||
triggerPriceService.onAllServicesInitialized();
|
||||
mempoolService.onAllServicesInitialized();
|
||||
|
||||
mailboxMessageService.onAllServicesInitialized();
|
||||
|
||||
if (revolutAccountsUpdateHandler != null && user.getPaymentAccountsAsObservable() != null) {
|
||||
revolutAccountsUpdateHandler.accept(user.getPaymentAccountsAsObservable().stream()
|
||||
.filter(paymentAccount -> paymentAccount instanceof RevolutAccount)
|
||||
|
|
|
@ -128,10 +128,6 @@ public class P2PNetworkSetup {
|
|||
closeConnectionReason, connection);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
}
|
||||
});
|
||||
|
||||
final BooleanProperty p2pNetworkInitialized = new SimpleBooleanProperty();
|
||||
|
|
|
@ -122,10 +122,6 @@ public class AppSetupWithP2P extends AppSetup {
|
|||
closeConnectionReason, connection);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
}
|
||||
});
|
||||
|
||||
final BooleanProperty p2pNetworkInitialized = new SimpleBooleanProperty();
|
||||
|
|
|
@ -28,7 +28,7 @@ import haveno.common.proto.persistable.PersistenceProtoResolver;
|
|||
import haveno.core.alert.AlertModule;
|
||||
import haveno.core.app.TorSetup;
|
||||
import haveno.core.filter.FilterModule;
|
||||
import haveno.core.network.CoreNetworkFilter;
|
||||
import haveno.core.network.CoreBanFilter;
|
||||
import haveno.core.network.p2p.seed.DefaultSeedNodeRepository;
|
||||
import haveno.core.offer.OfferModule;
|
||||
import haveno.core.proto.network.CoreNetworkProtoResolver;
|
||||
|
@ -40,8 +40,8 @@ import haveno.core.xmr.MoneroConnectionModule;
|
|||
import haveno.core.xmr.MoneroModule;
|
||||
import haveno.network.crypto.EncryptionServiceModule;
|
||||
import haveno.network.p2p.P2PModule;
|
||||
import haveno.network.p2p.network.BanFilter;
|
||||
import haveno.network.p2p.network.BridgeAddressProvider;
|
||||
import haveno.network.p2p.network.NetworkFilter;
|
||||
import haveno.network.p2p.seed.SeedNodeRepository;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -76,7 +76,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(BanFilter.class).to(CoreBanFilter.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);
|
||||
|
|
|
@ -32,7 +32,7 @@ import haveno.core.xmr.nodes.BtcNodes;
|
|||
import haveno.network.p2p.NodeAddress;
|
||||
import haveno.network.p2p.P2PService;
|
||||
import haveno.network.p2p.P2PServiceListener;
|
||||
import haveno.network.p2p.network.NetworkFilter;
|
||||
import haveno.network.p2p.network.BanFilter;
|
||||
import haveno.network.p2p.storage.HashMapChangedListener;
|
||||
import haveno.network.p2p.storage.payload.ProtectedStorageEntry;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
|
@ -49,6 +49,7 @@ import java.lang.reflect.Method;
|
|||
import java.math.BigInteger;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.PublicKey;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
@ -70,7 +71,6 @@ public class FilterManager {
|
|||
private static final String BANNED_SEED_NODES = "bannedSeedNodes";
|
||||
private static final String BANNED_BTC_NODES = "bannedBtcNodes";
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Listener
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -105,7 +105,7 @@ public class FilterManager {
|
|||
Preferences preferences,
|
||||
Config config,
|
||||
ProvidersRepository providersRepository,
|
||||
NetworkFilter networkFilter,
|
||||
BanFilter banFilter,
|
||||
@Named(Config.IGNORE_DEV_MSG) boolean ignoreDevMsg,
|
||||
@Named(Config.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys) {
|
||||
this.p2PService = p2PService;
|
||||
|
@ -122,7 +122,7 @@ public class FilterManager {
|
|||
"029340c3e7d4bb0f9e651b5f590b434fecb6175aeaa57145c7804ff05d210e534f",
|
||||
"034dc7530bf66ffd9580aa98031ea9a18ac2d269f7c56c0e71eca06105b9ed69f9");
|
||||
|
||||
networkFilter.setBannedNodeFunction(this::isNodeAddressBannedFromNetwork);
|
||||
banFilter.setBannedNodePredicate(this::isNodeAddressBannedFromNetwork);
|
||||
}
|
||||
|
||||
|
||||
|
@ -285,13 +285,18 @@ public class FilterManager {
|
|||
}
|
||||
|
||||
public void removeInvalidFilters(Filter filter, String privKeyString) {
|
||||
log.info("Remove invalid filter {}", filter);
|
||||
setFilterSigningKey(privKeyString);
|
||||
String signatureAsBase64 = getSignature(Filter.cloneWithoutSig(filter));
|
||||
Filter filterWithSig = Filter.cloneWithSig(filter, signatureAsBase64);
|
||||
boolean result = p2PService.removeData(filterWithSig);
|
||||
if (!result) {
|
||||
log.warn("Could not remove filter {}", filter);
|
||||
// We can only remove the filter if it's our own filter
|
||||
if (Arrays.equals(filter.getOwnerPubKey().getEncoded(), keyRing.getSignatureKeyPair().getPublic().getEncoded())) {
|
||||
log.info("Remove invalid filter {}", filter);
|
||||
setFilterSigningKey(privKeyString);
|
||||
String signatureAsBase64 = getSignature(Filter.cloneWithoutSig(filter));
|
||||
Filter filterWithSig = Filter.cloneWithSig(filter, signatureAsBase64);
|
||||
boolean result = p2PService.removeData(filterWithSig);
|
||||
if (!result) {
|
||||
log.warn("Could not remove filter {}", filter);
|
||||
}
|
||||
} else {
|
||||
log.info("The invalid filter is not our own, so we cannot remove it from the network");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -465,13 +470,13 @@ public class FilterManager {
|
|||
|
||||
if (currentFilter != null) {
|
||||
if (currentFilter.getCreationDate() > newFilter.getCreationDate()) {
|
||||
log.warn("We received a new filter from the network but the creation date is older than the " +
|
||||
log.info("We received a new filter from the network but the creation date is older than the " +
|
||||
"filter we have already. We ignore the new filter.");
|
||||
|
||||
addToInvalidFilters(newFilter);
|
||||
return;
|
||||
} else {
|
||||
log.warn("We received a new filter from the network and the creation date is newer than the " +
|
||||
log.info("We received a new filter from the network and the creation date is newer than the " +
|
||||
"filter we have already. We ignore the old filter.");
|
||||
addToInvalidFilters(currentFilter);
|
||||
}
|
||||
|
@ -522,7 +527,7 @@ public class FilterManager {
|
|||
|
||||
// We don't check for banned filter as we want to remove a banned filter anyway.
|
||||
|
||||
if (!filterProperty.get().equals(filter)) {
|
||||
if (filterProperty.get() != null && !filterProperty.get().equals(filter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ package haveno.core.network;
|
|||
|
||||
import haveno.common.config.Config;
|
||||
import haveno.network.p2p.NodeAddress;
|
||||
import haveno.network.p2p.network.NetworkFilter;
|
||||
import haveno.network.p2p.network.BanFilter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -27,29 +27,29 @@ import javax.inject.Named;
|
|||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@Slf4j
|
||||
public class CoreNetworkFilter implements NetworkFilter {
|
||||
public class CoreBanFilter implements BanFilter {
|
||||
private final Set<NodeAddress> bannedPeersFromOptions = new HashSet<>();
|
||||
private Function<NodeAddress, Boolean> bannedNodeFunction;
|
||||
private Predicate<NodeAddress> bannedNodePredicate;
|
||||
|
||||
/**
|
||||
* @param banList List of banned peers from program argument
|
||||
*/
|
||||
@Inject
|
||||
public CoreNetworkFilter(@Named(Config.BAN_LIST) List<String> banList) {
|
||||
public CoreBanFilter(@Named(Config.BAN_LIST) List<String> banList) {
|
||||
banList.stream().map(NodeAddress::new).forEach(bannedPeersFromOptions::add);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBannedNodeFunction(Function<NodeAddress, Boolean> bannedNodeFunction) {
|
||||
this.bannedNodeFunction = bannedNodeFunction;
|
||||
public void setBannedNodePredicate(Predicate<NodeAddress> bannedNodePredicate) {
|
||||
this.bannedNodePredicate = bannedNodePredicate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPeerBanned(NodeAddress nodeAddress) {
|
||||
return bannedPeersFromOptions.contains(nodeAddress) ||
|
||||
bannedNodeFunction != null && bannedNodeFunction.apply(nodeAddress);
|
||||
bannedNodePredicate != null && bannedNodePredicate.test(nodeAddress);
|
||||
}
|
||||
}
|
|
@ -112,8 +112,4 @@ public class GetInventoryRequester implements MessageListener, ConnectionListene
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -235,7 +235,7 @@ public final class OfferPayload implements ProtectedStoragePayload, ExpirablePay
|
|||
}
|
||||
|
||||
public byte[] getHash() {
|
||||
if (this.hash == null && this.offerFeeTxId != null) {
|
||||
if (this.hash == null) {
|
||||
// A proto message can be created only after the offerFeeTxId is
|
||||
// set to a non-null value; now is the time to cache the payload hash.
|
||||
this.hash = Hash.getSha256Hash(this.toProtoMessage().toByteArray());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue