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

Persist and republish mailbox messages #5072

Merged
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
0656a52
Refactor: Move mailbox related classed to mailbox package. Make const…
chimp1984 Jan 10, 2021
73cfe0b
Make some methods default
chimp1984 Jan 10, 2021
a28a2f5
Move mailbox related code from P2PService to MailboxMessageService
chimp1984 Jan 10, 2021
d470d73
Remove getMailBoxMessages from P2PService and use MailboxMessageServi…
chimp1984 Jan 10, 2021
ee3f158
Remove addDecryptedMailboxListener from P2PService and use MailboxMes…
chimp1984 Jan 10, 2021
33703c2
Remove removePrivateNotification from P2PService and use MailboxMessa…
chimp1984 Jan 10, 2021
b8fc7f3
Remove sendEncryptedMailboxMessage from P2PService and use MailboxMes…
chimp1984 Jan 10, 2021
4fc35a7
Cleanups
chimp1984 Jan 10, 2021
4c7b560
Add new methods, make decryptedMessageWithPubKey nullable
chimp1984 Jan 10, 2021
504fb2e
Refactor: Rename
chimp1984 Jan 10, 2021
cf8c93d
Filter expired entries at startup
chimp1984 Jan 10, 2021
79363e7
Refactor: Rename
chimp1984 Jan 10, 2021
63a0117
Remove nullable return value from decryptProtectedMailboxStorageEntry
chimp1984 Jan 11, 2021
5245c20
Add filter for isMine at getMyMailBoxMessages
chimp1984 Jan 11, 2021
bfbc657
Remove old code
chimp1984 Jan 11, 2021
6146362
Add onRemoved method to remove mailbox entries once a remove message …
chimp1984 Jan 11, 2021
32f8874
Persist map for removed mailbox messages (AddOncePayload more generally)
chimp1984 Jan 11, 2021
75e547f
Refactor: move classes to persistence package
chimp1984 Jan 11, 2021
e69a3f6
Refactor: rename method
chimp1984 Jan 11, 2021
1886b4e
Set addressPrefixHash to empty bytes.
chimp1984 Jan 11, 2021
5ba7d78
Add RemovedPayloadsStorageService
chimp1984 Jan 11, 2021
41a92ea
Refactor: Rename class
chimp1984 Jan 11, 2021
9edad02
Use a hashset for listeners
chimp1984 Jan 11, 2021
de131c8
Use MailboxItem value at mailboxItemsByUid instead of a list:
chimp1984 Jan 11, 2021
a3b2aad
Refactor: move class to new utils package
chimp1984 Jan 11, 2021
026858d
Refactor: move duplicated method
chimp1984 Jan 11, 2021
873b557
Add logs
chimp1984 Jan 11, 2021
7a2501e
Set uid inside constructor
chimp1984 Jan 11, 2021
35ef3b8
Add support for TTL defined by payload message so we can use
chimp1984 Jan 11, 2021
659fe15
Add comment
chimp1984 Jan 11, 2021
320e5f1
Refactor: Rename method
chimp1984 Jan 11, 2021
a54813a
Increase timout for BroadcastHandler to 120 sec
chimp1984 Jan 12, 2021
8e0181e
Add republishExistingProtectedMailboxStorageEntry method
chimp1984 Jan 12, 2021
e933bfd
Add temp. ignore to a failing test.
chimp1984 Jan 12, 2021
8d866d5
Improve logs, rename methods, variables
chimp1984 Jan 12, 2021
a9802e6
Refactor: return early
chimp1984 Jan 12, 2021
d39a697
Fix wrong delay, increase timeout
chimp1984 Jan 12, 2021
b4ab8a4
Fix incorrect comparison at RemovedPayloadsService.readPersisted
chimp1984 Jan 12, 2021
337ea89
Add program argument flag republishMailboxEntries
chimp1984 Jan 12, 2021
32aeda7
Add null check
chimp1984 Jan 12, 2021
3875bd8
Add removeMailboxMsg with MailboxMessage as argument
chimp1984 Jan 12, 2021
0f08794
Remove unneeded wrapping of tradeMessage into DecryptedMessageWithPubKey
chimp1984 Jan 12, 2021
bffe2b8
Store PrivateNotificationMessage instead of DecryptedMessageWithPubKey
chimp1984 Jan 12, 2021
f536aba
Refactor handling of removeMailboxMsg
chimp1984 Jan 12, 2021
456ce70
Refactor: rename dispatchMessage to onSupportMessage (no functionalit…
chimp1984 Jan 12, 2021
2235c4f
Use removeMailboxMsg method with MailboxMessage as param type
chimp1984 Jan 12, 2021
575196c
Refactor handleDecryptedMessageWithPubKey to use MailboxMessage
chimp1984 Jan 12, 2021
5cdae86
Refactor: rename method to make it more explicit that its only used f…
chimp1984 Jan 12, 2021
d353140
Refactor: rename getMyDecryptedMessages method to make it more explicit
chimp1984 Jan 12, 2021
c229c3f
Refactor handling of DecryptedMessageWithPubKey
chimp1984 Jan 12, 2021
008fb3b
Inline isMyMessage methods
chimp1984 Jan 12, 2021
5c429bb
Add containsKey check
chimp1984 Jan 12, 2021
4c003cd
Clone reportedPeers to avoid ConcurrentModificationExceptions
chimp1984 Jan 12, 2021
46f6026
Remove outdated code
chimp1984 Jan 12, 2021
470230c
Add TradeMailboxMessage and use a TTL of 15 days
chimp1984 Jan 12, 2021
2b05ed5
Let MailboxMessage extend ExpirablePayload:
chimp1984 Jan 12, 2021
364a7f5
Add toString
chimp1984 Jan 12, 2021
a21d79a
Refactor: rename
chimp1984 Jan 12, 2021
3e69ede
Remove comment
chimp1984 Jan 12, 2021
3834785
Bugfix: Add processing of SendersNodeAddressMessage to
chimp1984 Jan 12, 2021
36657f5
Use TradeMailboxMessage as type for getMessage in SendMailboxMessageTask
chimp1984 Jan 12, 2021
c12e239
Refactor: rename method
chimp1984 Jan 12, 2021
2fb3bba
Use MailboxMessage as param type in sendEncryptedMailboxMessage
chimp1984 Jan 12, 2021
d434cb3
Sort persisted mail box messages by age and limit total number.
chimp1984 Jan 13, 2021
541f367
Dont log filter content if a filter got updated
chimp1984 Jan 14, 2021
7ba5ab5
Change prio for mailboxMessageList persitence
chimp1984 Jan 14, 2021
5d13fdc
Return early
chimp1984 Jan 15, 2021
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
10 changes: 10 additions & 0 deletions common/src/main/java/bisq/common/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public class Config {
public static final String API_PASSWORD = "apiPassword";
public static final String API_PORT = "apiPort";
public static final String PREVENT_PERIODIC_SHUTDOWN_AT_SEED_NODE = "preventPeriodicShutdownAtSeedNode";
public static final String REPUBLISH_MAILBOX_ENTRIES = "republishMailboxEntries";

// Default values for certain options
public static final int UNSPECIFIED_PORT = -1;
Expand Down Expand Up @@ -207,6 +208,7 @@ public class Config {
public final String apiPassword;
public final int apiPort;
public final boolean preventPeriodicShutdownAtSeedNode;
public final boolean republishMailboxEntries;

// Properties derived from options but not exposed as options themselves
public final File torDir;
Expand Down Expand Up @@ -648,6 +650,13 @@ public Config(String defaultAppName, File defaultUserDataDir, String... args) {
.ofType(boolean.class)
.defaultsTo(false);

ArgumentAcceptingOptionSpec<Boolean> republishMailboxEntriesOpt =
parser.accepts(REPUBLISH_MAILBOX_ENTRIES,
"Republish mailbox messages at startup")
.withRequiredArg()
.ofType(boolean.class)
.defaultsTo(false);

try {
CompositeOptionSet options = new CompositeOptionSet();

Expand Down Expand Up @@ -764,6 +773,7 @@ public Config(String defaultAppName, File defaultUserDataDir, String... args) {
this.apiPassword = options.valueOf(apiPasswordOpt);
this.apiPort = options.valueOf(apiPortOpt);
this.preventPeriodicShutdownAtSeedNode = options.valueOf(preventPeriodicShutdownAtSeedNodeOpt);
this.republishMailboxEntries = options.valueOf(republishMailboxEntriesOpt);
} catch (OptionException ex) {
throw new ConfigException("problem parsing option '%s': %s",
ex.options().get(0),
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/bisq/core/alert/Alert.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
@ToString
@Slf4j
public final class Alert implements ProtectedStoragePayload, ExpirablePayload {
public static final long TTL = TimeUnit.DAYS.toMillis(90);

private final String message;
private final boolean isUpdateInfo;
private final String version;
Expand Down Expand Up @@ -131,7 +133,7 @@ public static Alert fromProto(protobuf.Alert proto) {

@Override
public long getTTL() {
return TimeUnit.DAYS.toMillis(90);
return TTL;
}

public void setSigAndPubKey(String signatureAsBase64, PublicKey ownerPubKey) {
Expand Down
27 changes: 19 additions & 8 deletions core/src/main/java/bisq/core/alert/PrivateNotificationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import bisq.network.p2p.NodeAddress;
import bisq.network.p2p.P2PService;
import bisq.network.p2p.SendMailboxMessageListener;
import bisq.network.p2p.mailbox.MailboxMessageService;

import bisq.common.app.DevEnv;
import bisq.common.config.Config;
Expand Down Expand Up @@ -49,20 +50,24 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;

import static org.bitcoinj.core.Utils.HEX;

public class PrivateNotificationManager {
private static final Logger log = LoggerFactory.getLogger(PrivateNotificationManager.class);

private final P2PService p2PService;
private final MailboxMessageService mailboxMessageService;
private final KeyRing keyRing;
private final ObjectProperty<PrivateNotificationPayload> privateNotificationMessageProperty = new SimpleObjectProperty<>();

// Pub key for developer global privateNotification message
private final String pubKeyAsHex;

private ECKey privateNotificationSigningKey;
private DecryptedMessageWithPubKey decryptedMessageWithPubKey;
@Nullable
private PrivateNotificationMessage privateNotificationMessage;


///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -71,26 +76,27 @@ public class PrivateNotificationManager {

@Inject
public PrivateNotificationManager(P2PService p2PService,
MailboxMessageService mailboxMessageService,
KeyRing keyRing,
@Named(Config.IGNORE_DEV_MSG) boolean ignoreDevMsg,
@Named(Config.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys) {
this.p2PService = p2PService;
this.mailboxMessageService = mailboxMessageService;
this.keyRing = keyRing;

if (!ignoreDevMsg) {
this.p2PService.addDecryptedDirectMessageListener(this::handleMessage);
this.p2PService.addDecryptedMailboxListener(this::handleMessage);
this.mailboxMessageService.addDecryptedMailboxListener(this::handleMessage);
}
pubKeyAsHex = useDevPrivilegeKeys ?
DevEnv.DEV_PRIVILEGE_PUB_KEY :
"02ba7c5de295adfe57b60029f3637a2c6b1d0e969a8aaefb9e0ddc3a7963f26925";
}

private void handleMessage(DecryptedMessageWithPubKey decryptedMessageWithPubKey, NodeAddress senderNodeAddress) {
this.decryptedMessageWithPubKey = decryptedMessageWithPubKey;
NetworkEnvelope networkEnvelope = decryptedMessageWithPubKey.getNetworkEnvelope();
if (networkEnvelope instanceof PrivateNotificationMessage) {
PrivateNotificationMessage privateNotificationMessage = (PrivateNotificationMessage) networkEnvelope;
privateNotificationMessage = (PrivateNotificationMessage) networkEnvelope;
log.info("Received PrivateNotificationMessage from {} with uid={}",
senderNodeAddress, privateNotificationMessage.getUid());
if (privateNotificationMessage.getSenderNodeAddress().equals(senderNodeAddress)) {
Expand All @@ -112,8 +118,11 @@ public ReadOnlyObjectProperty<PrivateNotificationPayload> privateNotificationPro
return privateNotificationMessageProperty;
}

public boolean sendPrivateNotificationMessageIfKeyIsValid(PrivateNotificationPayload privateNotification, PubKeyRing pubKeyRing, NodeAddress peersNodeAddress,
String privKeyString, SendMailboxMessageListener sendMailboxMessageListener) {
public boolean sendPrivateNotificationMessageIfKeyIsValid(PrivateNotificationPayload privateNotification,
PubKeyRing pubKeyRing,
NodeAddress peersNodeAddress,
String privKeyString,
SendMailboxMessageListener sendMailboxMessageListener) {
boolean isKeyValid = isKeyValid(privKeyString);
if (isKeyValid) {
signAndAddSignatureToPrivateNotificationMessage(privateNotification);
Expand All @@ -123,7 +132,7 @@ public boolean sendPrivateNotificationMessageIfKeyIsValid(PrivateNotificationPay
UUID.randomUUID().toString());
log.info("Send {} to peer {}. uid={}",
message.getClass().getSimpleName(), peersNodeAddress, message.getUid());
p2PService.sendEncryptedMailboxMessage(peersNodeAddress,
mailboxMessageService.sendEncryptedMailboxMessage(peersNodeAddress,
pubKeyRing,
message,
sendMailboxMessageListener);
Expand All @@ -133,7 +142,9 @@ public boolean sendPrivateNotificationMessageIfKeyIsValid(PrivateNotificationPay
}

public void removePrivateNotification() {
p2PService.removeMailboxMsg(decryptedMessageWithPubKey);
if (privateNotificationMessage != null) {
mailboxMessageService.removeMailboxMsg(privateNotificationMessage);
}
}

private boolean isKeyValid(String privKeyString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

package bisq.core.alert;

import bisq.network.p2p.MailboxMessage;
import bisq.network.p2p.NodeAddress;
import bisq.network.p2p.mailbox.MailboxMessage;

import bisq.common.app.Version;
import bisq.common.proto.network.NetworkEnvelope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
public class TempProposalPayload implements ProcessOncePersistableNetworkPayload, ProtectedStoragePayload,
ExpirablePayload, PersistablePayload {
// We keep data 2 months to be safe if we increase durations of cycle. Also give a bit more resilience in case
// of any issues with the append-only data store
public static final long TTL = TimeUnit.DAYS.toMillis(60);

protected final Proposal proposal;
protected final byte[] ownerPubKeyEncoded;
Expand Down Expand Up @@ -124,8 +127,6 @@ public PublicKey getOwnerPubKey() {

@Override
public long getTTL() {
// We keep data 2 months to be safe if we increase durations of cycle. Also give a bit more resilience in case
// of any issues with the append-only data store
return TimeUnit.DAYS.toMillis(60);
return TTL;
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/dao/node/full/RpcService.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ void setup(ResultHandler resultHandler, Consumer<Throwable> errorHandler) {
nodeConfig.setProperty("node.bitcoind.rpc.port", Integer.toString(rpcPort));
nodeConfig.setProperty("node.bitcoind.notification.block.port", Integer.toString(rpcBlockPort));
nodeConfig.setProperty("node.bitcoind.notification.block.host", rpcBlockHost);
nodeConfig.setProperty("node.bitcoind.notification.alert.port", Integer.toString(bisq.network.p2p.Utils.findFreeSystemPort()));
nodeConfig.setProperty("node.bitcoind.notification.wallet.port", Integer.toString(bisq.network.p2p.Utils.findFreeSystemPort()));
nodeConfig.setProperty("node.bitcoind.notification.alert.port", Integer.toString(bisq.network.utils.Utils.findFreeSystemPort()));
nodeConfig.setProperty("node.bitcoind.notification.wallet.port", Integer.toString(bisq.network.utils.Utils.findFreeSystemPort()));

nodeConfig.setProperty("node.bitcoind.http.auth_scheme", "Basic");
BtcdClientImpl client = new BtcdClientImpl(httpProvider, nodeConfig);
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/bisq/core/filter/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
@Slf4j
@Value
public final class Filter implements ProtectedStoragePayload, ExpirablePayload {
public static final long TTL = TimeUnit.DAYS.toMillis(180);

private final List<String> bannedOfferIds;
private final List<String> nodeAddressesBannedFromTrading;
private final List<String> bannedAutoConfExplorers;
Expand Down Expand Up @@ -361,7 +363,7 @@ public static Filter fromProto(protobuf.Filter proto) {

@Override
public long getTTL() {
return TimeUnit.DAYS.toMillis(180);
return TTL;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

@Slf4j
public class GetInventoryRequester implements MessageListener, ConnectionListener {
private final static int TIMEOUT_SEC = 90;
private final static int TIMEOUT_SEC = 180;

private final NetworkNode networkNode;
private final NodeAddress nodeAddress;
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/bisq/core/offer/OfferPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
@Getter
@Slf4j
public final class OfferPayload implements ProtectedStoragePayload, ExpirablePayload, RequiresOwnerIsOnlinePayload {
public static final long TTL = TimeUnit.MINUTES.toMillis(9);

///////////////////////////////////////////////////////////////////////////////////////////
// Enum
Expand Down Expand Up @@ -373,7 +374,7 @@ public static OfferPayload fromProto(protobuf.OfferPayload proto) {

@Override
public long getTTL() {
return TimeUnit.MINUTES.toMillis(9);
return TTL;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@
import bisq.core.user.PreferencesPayload;
import bisq.core.user.UserPayload;

import bisq.network.p2p.MailboxMessageList;
import bisq.network.p2p.mailbox.IgnoredMailboxMap;
import bisq.network.p2p.mailbox.MailboxMessageList;
import bisq.network.p2p.peers.peerexchange.PeerList;
import bisq.network.p2p.storage.persistence.RemovedPayloadsMap;
import bisq.network.p2p.storage.persistence.SequenceNumberMap;

import bisq.common.proto.ProtobufferRuntimeException;
Expand Down Expand Up @@ -135,6 +136,8 @@ public PersistableEnvelope fromProto(protobuf.PersistableEnvelope proto) {
return MailboxMessageList.fromProto(proto.getMailboxMessageList(), networkProtoResolver);
case IGNORED_MAILBOX_MAP:
return IgnoredMailboxMap.fromProto(proto.getIgnoredMailboxMap());
case REMOVED_PAYLOADS_MAP:
return RemovedPayloadsMap.fromProto(proto.getRemovedPayloadsMap());
default:
throw new ProtobufferRuntimeException("Unknown proto message case(PB.PersistableEnvelope). " +
"messageCase=" + proto.getMessageCase() + "; proto raw data=" + proto.toString());
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/bisq/core/setup/CorePersistedDataHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
import bisq.core.user.Preferences;
import bisq.core.user.User;

import bisq.network.p2p.P2PService;
import bisq.network.p2p.mailbox.IgnoredMailboxService;
import bisq.network.p2p.mailbox.MailboxMessageService;
import bisq.network.p2p.peers.PeerManager;
import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.persistence.RemovedPayloadsService;

import bisq.common.config.Config;
import bisq.common.proto.persistable.PersistedDataHost;
Expand Down Expand Up @@ -68,8 +69,9 @@ public static List<PersistedDataHost> getPersistedDataHosts(Injector injector) {
persistedDataHosts.add(injector.getInstance(RefundDisputeListService.class));
persistedDataHosts.add(injector.getInstance(P2PDataStorage.class));
persistedDataHosts.add(injector.getInstance(PeerManager.class));
persistedDataHosts.add(injector.getInstance(P2PService.class));
persistedDataHosts.add(injector.getInstance(MailboxMessageService.class));
persistedDataHosts.add(injector.getInstance(IgnoredMailboxService.class));
persistedDataHosts.add(injector.getInstance(RemovedPayloadsService.class));

if (injector.getInstance(Config.class).daoActivated) {
persistedDataHosts.add(injector.getInstance(BallotListService.class));
Expand Down
31 changes: 17 additions & 14 deletions core/src/main/java/bisq/core/support/SupportManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import bisq.network.p2p.NodeAddress;
import bisq.network.p2p.P2PService;
import bisq.network.p2p.SendMailboxMessageListener;
import bisq.network.p2p.mailbox.MailboxMessageService;

import bisq.common.Timer;
import bisq.common.UserThread;
Expand All @@ -49,6 +50,7 @@ public abstract class SupportManager {
protected final Map<String, Timer> delayMsgMap = new HashMap<>();
private final CopyOnWriteArraySet<DecryptedMessageWithPubKey> decryptedMailboxMessageWithPubKeys = new CopyOnWriteArraySet<>();
private final CopyOnWriteArraySet<DecryptedMessageWithPubKey> decryptedDirectMessageWithPubKeys = new CopyOnWriteArraySet<>();
protected final MailboxMessageService mailboxMessageService;
private boolean allServicesInitialized;


Expand All @@ -58,6 +60,8 @@ public abstract class SupportManager {

public SupportManager(P2PService p2PService, WalletsSetup walletsSetup) {
this.p2PService = p2PService;
mailboxMessageService = p2PService.getMailboxMessageService();

this.walletsSetup = walletsSetup;

// We get first the message handler called then the onBootstrapped
Expand All @@ -67,7 +71,7 @@ public SupportManager(P2PService p2PService, WalletsSetup walletsSetup) {
decryptedDirectMessageWithPubKeys.add(decryptedMessageWithPubKey);
tryApplyMessages();
});
p2PService.addDecryptedMailboxListener((decryptedMessageWithPubKey, senderAddress) -> {
mailboxMessageService.addDecryptedMailboxListener((decryptedMessageWithPubKey, senderAddress) -> {
// As decryptedMailboxMessageWithPubKeys is a CopyOnWriteArraySet we do not need to check if it was
// already stored
decryptedMailboxMessageWithPubKeys.add(decryptedMessageWithPubKey);
Expand All @@ -80,7 +84,7 @@ public SupportManager(P2PService p2PService, WalletsSetup walletsSetup) {
// Abstract methods
///////////////////////////////////////////////////////////////////////////////////////////

protected abstract void dispatchMessage(SupportMessage networkEnvelope);
protected abstract void onSupportMessage(SupportMessage networkEnvelope);

public abstract NodeAddress getPeerNodeAddress(ChatMessage message);

Expand Down Expand Up @@ -155,8 +159,7 @@ protected void onChatMessage(ChatMessage chatMessage) {
sendAckMessage(chatMessage, receiverPubKeyRing, true, null);
}

private void onAckMessage(AckMessage ackMessage,
@Nullable DecryptedMessageWithPubKey decryptedMessageWithPubKey) {
private void onAckMessage(AckMessage ackMessage) {
if (ackMessage.getSourceType() == getAckMessageSourceType()) {
if (ackMessage.isSuccess()) {
log.info("Received AckMessage for {} with tradeId {} and uid {}",
Expand All @@ -175,9 +178,6 @@ private void onAckMessage(AckMessage ackMessage,
msg.setAckError(ackMessage.getErrorMessage());
});
requestPersistence();

if (decryptedMessageWithPubKey != null)
p2PService.removeMailboxMsg(decryptedMessageWithPubKey);
}
}

Expand All @@ -195,7 +195,7 @@ public ChatMessage sendChatMessage(ChatMessage message) {
log.info("Send {} to peer {}. tradeId={}, uid={}",
message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid());

p2PService.sendEncryptedMailboxMessage(peersNodeAddress,
mailboxMessageService.sendEncryptedMailboxMessage(peersNodeAddress,
receiverPubKeyRing,
message,
new SendMailboxMessageListener() {
Expand Down Expand Up @@ -243,7 +243,7 @@ protected void sendAckMessage(SupportMessage supportMessage, PubKeyRing peersPub
final NodeAddress peersNodeAddress = supportMessage.getSenderNodeAddress();
log.info("Send AckMessage for {} to peer {}. tradeId={}, uid={}",
ackMessage.getSourceMsgClassName(), peersNodeAddress, tradeId, uid);
p2PService.sendEncryptedMailboxMessage(
mailboxMessageService.sendEncryptedMailboxMessage(
peersNodeAddress,
peersPubKeyRing,
ackMessage,
Expand Down Expand Up @@ -302,9 +302,9 @@ private void applyMessages() {
decryptedDirectMessageWithPubKeys.forEach(decryptedMessageWithPubKey -> {
NetworkEnvelope networkEnvelope = decryptedMessageWithPubKey.getNetworkEnvelope();
if (networkEnvelope instanceof SupportMessage) {
dispatchMessage((SupportMessage) networkEnvelope);
onSupportMessage((SupportMessage) networkEnvelope);
} else if (networkEnvelope instanceof AckMessage) {
onAckMessage((AckMessage) networkEnvelope, null);
onAckMessage((AckMessage) networkEnvelope);
}
});
decryptedDirectMessageWithPubKeys.clear();
Expand All @@ -313,10 +313,13 @@ private void applyMessages() {
NetworkEnvelope networkEnvelope = decryptedMessageWithPubKey.getNetworkEnvelope();
log.debug("decryptedMessageWithPubKey.message " + networkEnvelope);
if (networkEnvelope instanceof SupportMessage) {
dispatchMessage((SupportMessage) networkEnvelope);
p2PService.removeMailboxMsg(decryptedMessageWithPubKey);
SupportMessage supportMessage = (SupportMessage) networkEnvelope;
onSupportMessage(supportMessage);
mailboxMessageService.removeMailboxMsg(supportMessage);
} else if (networkEnvelope instanceof AckMessage) {
onAckMessage((AckMessage) networkEnvelope, decryptedMessageWithPubKey);
AckMessage ackMessage = (AckMessage) networkEnvelope;
onAckMessage(ackMessage);
mailboxMessageService.removeMailboxMsg(ackMessage);
}
});
decryptedMailboxMessageWithPubKeys.clear();
Expand Down
Loading