Merge branch 'DAO' into altcoins

This commit is contained in:
Manfred Karrer 2017-06-10 11:29:36 +02:00
commit f8c7149e68
95 changed files with 1104 additions and 571 deletions

View File

@ -32,8 +32,8 @@ import io.bisq.core.btc.BitcoinModule;
import io.bisq.core.dao.DaoModule;
import io.bisq.core.filter.FilterModule;
import io.bisq.core.offer.OfferModule;
import io.bisq.core.proto.CoreNetworkProtoResolver;
import io.bisq.core.proto.CoreDiskProtoResolver;
import io.bisq.core.proto.CoreNetworkProtoResolver;
import io.bisq.core.trade.TradeModule;
import io.bisq.core.user.Preferences;
import io.bisq.core.user.User;

View File

@ -1,14 +1,9 @@
package io.bisq.common.app;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Arrays;
public class Capabilities {
private static final Logger log = LoggerFactory.getLogger(Capabilities.class);
// We can define here special features the client is supporting.
// Useful for updates to new versions where a new data type would break backwards compatibility or to
// limit a node to certain behaviour and roles like the seed nodes.

View File

@ -1,25 +1,67 @@
/*
* 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 io.bisq.common.proto.network;
import com.google.protobuf.Message;
import io.bisq.common.Envelope;
import io.bisq.common.app.Version;
import io.bisq.generated.protobuffer.PB;
import lombok.EqualsAndHashCode;
/**
* Interface for the outside envelope object sent over the network.
*/
public interface NetworkEnvelope extends Envelope {
static PB.NetworkEnvelope.Builder getDefaultBuilder() {
return PB.NetworkEnvelope.newBuilder().setMessageVersion(Version.getP2PMessageVersion());
import static com.google.common.base.Preconditions.checkArgument;
@EqualsAndHashCode
public abstract class NetworkEnvelope implements Envelope {
protected final int messageVersion;
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
protected NetworkEnvelope(int messageVersion) {
this.messageVersion = messageVersion;
}
default int getMessageVersion() {
return Version.getP2PMessageVersion();
public PB.NetworkEnvelope.Builder getNetworkEnvelopeBuilder() {
return PB.NetworkEnvelope.newBuilder().setMessageVersion(messageVersion);
}
default Message toProtoMessage() {
return toProtoNetworkEnvelope();
@Override
public Message toProtoMessage() {
return getNetworkEnvelopeBuilder().build();
}
PB.NetworkEnvelope toProtoNetworkEnvelope();
}
// todo remove
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return getNetworkEnvelopeBuilder().build();
}
///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////
public int getMessageVersion() {
// -1 is used for the case that we use an envelope message as payload (mailbox)
// so we check only against 0 which is the default value if not set
checkArgument(messageVersion != 0, "messageVersion is not set (0).");
return messageVersion;
}
}

View File

@ -42,20 +42,19 @@ message NetworkEnvelope {
PublishDepositTxRequest publish_deposit_tx_request = 18;
DepositTxPublishedMessage deposit_tx_published_message = 19;
FiatTransferStartedMessage fiat_transfer_started_message = 20;
FinalizePayoutTxRequest finalize_payout_tx_request = 21;
PayoutTxPublishedMessage payout_tx_published_message = 22;
PayoutTxPublishedMessage payout_tx_published_message = 21;
OpenNewDisputeMessage open_new_dispute_message = 23;
PeerOpenedDisputeMessage peer_opened_dispute_message = 24;
DisputeCommunicationMessage dispute_communication_message = 25;
DisputeResultMessage dispute_result_message = 26;
PeerPublishedDisputePayoutTxMessage peer_published_dispute_payout_tx_message = 27;
OpenNewDisputeMessage open_new_dispute_message = 22;
PeerOpenedDisputeMessage peer_opened_dispute_message = 23;
DisputeCommunicationMessage dispute_communication_message = 24;
DisputeResultMessage dispute_result_message = 25;
PeerPublishedDisputePayoutTxMessage peer_published_dispute_payout_tx_message = 26;
PrivateNotificationMessage private_notification_message = 28;
PrivateNotificationMessage private_notification_message = 27;
GetBsqBlocksRequest get_bsq_blocks_request = 29;
GetBsqBlocksResponse get_bsq_blocks_response = 30;
NewBsqBlockBroadcastMessage new_bsq_block_broadcast_message = 31;
GetBsqBlocksRequest get_bsq_blocks_request = 28;
GetBsqBlocksResponse get_bsq_blocks_response = 29;
NewBsqBlockBroadcastMessage new_bsq_block_broadcast_message = 30;
}
}

View File

@ -76,9 +76,9 @@ public class PrivateNotificationManager {
private void handleMessage(DecryptedMessageWithPubKey decryptedMessageWithPubKey, NodeAddress senderNodeAddress) {
this.decryptedMessageWithPubKey = decryptedMessageWithPubKey;
NetworkEnvelope wireEnvelope = decryptedMessageWithPubKey.getWireEnvelope();
if (wireEnvelope instanceof PrivateNotificationMessage) {
PrivateNotificationMessage privateNotificationMessage = (PrivateNotificationMessage) wireEnvelope;
NetworkEnvelope networkEnvelop = decryptedMessageWithPubKey.getNetworkEnvelope();
if (networkEnvelop instanceof PrivateNotificationMessage) {
PrivateNotificationMessage privateNotificationMessage = (PrivateNotificationMessage) networkEnvelop;
log.trace("Received privateNotificationMessage: " + privateNotificationMessage);
if (privateNotificationMessage.getSenderNodeAddress().equals(senderNodeAddress)) {
final PrivateNotificationPayload privateNotification = privateNotificationMessage.getPrivateNotificationPayload();

View File

@ -1,13 +1,16 @@
package io.bisq.core.alert;
import io.bisq.common.app.Version;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.MailboxMessage;
import io.bisq.network.p2p.NodeAddress;
import lombok.EqualsAndHashCode;
import lombok.Value;
@EqualsAndHashCode(callSuper = true)
@Value
public class PrivateNotificationMessage implements MailboxMessage {
public class PrivateNotificationMessage extends NetworkEnvelope implements MailboxMessage {
private final PrivateNotificationPayload privateNotificationPayload;
private final NodeAddress senderNodeAddress;
private final String uid;
@ -15,6 +18,19 @@ public class PrivateNotificationMessage implements MailboxMessage {
public PrivateNotificationMessage(PrivateNotificationPayload privateNotificationPayload,
NodeAddress senderNodeAddress,
String uid) {
this(privateNotificationPayload, senderNodeAddress, uid, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private PrivateNotificationMessage(PrivateNotificationPayload privateNotificationPayload,
NodeAddress senderNodeAddress,
String uid,
int messageVersion) {
super(messageVersion);
this.privateNotificationPayload = privateNotificationPayload;
this.senderNodeAddress = senderNodeAddress;
this.uid = uid;
@ -22,7 +38,7 @@ public class PrivateNotificationMessage implements MailboxMessage {
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setPrivateNotificationMessage(PB.PrivateNotificationMessage.newBuilder()
.setPrivateNotificationPayload(privateNotificationPayload.toProtoMessage())
.setSenderNodeAddress(senderNodeAddress.toProtoMessage())
@ -30,9 +46,10 @@ public class PrivateNotificationMessage implements MailboxMessage {
.build();
}
public static PrivateNotificationMessage fromProto(PB.PrivateNotificationMessage proto) {
public static PrivateNotificationMessage fromProto(PB.PrivateNotificationMessage proto, int messageVersion) {
return new PrivateNotificationMessage(PrivateNotificationPayload.fromProto(proto.getPrivateNotificationPayload()),
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getUid());
proto.getUid(),
messageVersion);
}
}

View File

@ -52,9 +52,9 @@ public class SetupUtils {
keyRing.getSignatureKeyPair(), keyRing.getPubKeyRing().getEncryptionPubKey());
DecryptedDataTuple tuple = encryptionService.decryptHybridWithSignature(sealedAndSigned,
keyRing.getEncryptionKeyPair().getPrivate());
if (tuple.payload instanceof Ping &&
((Ping) tuple.payload).getNonce() == payload.getNonce() &&
((Ping) tuple.payload).getLastRoundTripTime() == payload.getLastRoundTripTime()) {
if (tuple.getNetworkEnvelope() instanceof Ping &&
((Ping) tuple.getNetworkEnvelope()).getNonce() == payload.getNonce() &&
((Ping) tuple.getNetworkEnvelope()).getLastRoundTripTime() == payload.getLastRoundTripTime()) {
log.debug("Crypto test succeeded");
if (Security.getProvider("BC") != null) {

View File

@ -218,7 +218,7 @@ public final class Dispute implements NetworkPayload {
proto.getIsSupportTicket());
dispute.disputeCommunicationMessages.addAll(proto.getDisputeCommunicationMessagesList().stream()
.map(DisputeCommunicationMessage::fromProto)
.map(DisputeCommunicationMessage::fromPayloadProto)
.collect(Collectors.toList()));
dispute.openingDate = proto.getOpeningDate();

View File

@ -83,6 +83,7 @@ public final class DisputeList implements PersistableEnvelope, PersistedDataHost
List<Dispute> list = proto.getDisputeList().stream()
.map(disputeProto -> Dispute.fromProto(disputeProto, coreProtoResolver))
.collect(Collectors.toList());
list.stream().forEach(e -> e.setStorage(storage));
return new DisputeList(storage, list);
}

View File

@ -175,18 +175,18 @@ public class DisputeManager implements PersistedDataHost {
private void applyMessages() {
decryptedDirectMessageWithPubKeys.forEach(decryptedMessageWithPubKey -> {
NetworkEnvelope wireEnvelope = decryptedMessageWithPubKey.getWireEnvelope();
log.debug("decryptedDirectMessageWithPubKeys.message " + wireEnvelope);
if (wireEnvelope instanceof DisputeMessage)
dispatchMessage((DisputeMessage) wireEnvelope);
NetworkEnvelope networkEnvelope = decryptedMessageWithPubKey.getNetworkEnvelope();
log.debug("decryptedDirectMessageWithPubKeys.message " + networkEnvelope);
if (networkEnvelope instanceof DisputeMessage)
dispatchMessage((DisputeMessage) networkEnvelope);
});
decryptedDirectMessageWithPubKeys.clear();
decryptedMailboxMessageWithPubKeys.forEach(decryptedMessageWithPubKey -> {
NetworkEnvelope wireEnvelope = decryptedMessageWithPubKey.getWireEnvelope();
log.debug("decryptedMessageWithPubKey.message " + wireEnvelope);
if (wireEnvelope instanceof DisputeMessage) {
dispatchMessage((DisputeMessage) wireEnvelope);
NetworkEnvelope networkEnvelope = decryptedMessageWithPubKey.getNetworkEnvelope();
log.debug("decryptedMessageWithPubKey.message " + networkEnvelope);
if (networkEnvelope instanceof DisputeMessage) {
dispatchMessage((DisputeMessage) networkEnvelope);
p2PService.removeEntryFromMailbox(decryptedMessageWithPubKey);
}
});

View File

@ -122,7 +122,7 @@ public final class DisputeResult implements NetworkPayload {
proto.getIdVerification(),
proto.getScreenCast(),
proto.getSummaryNotes(),
DisputeCommunicationMessage.fromProto(proto.getDisputeCommunicationMessage()),
DisputeCommunicationMessage.fromPayloadProto(proto.getDisputeCommunicationMessage()),
proto.getArbitratorSignature().toByteArray(),
proto.getBuyerPayoutAmount(),
proto.getSellerPayoutAmount(),

View File

@ -17,7 +17,7 @@
package io.bisq.core.arbitration.messages;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.common.app.Version;
import io.bisq.core.arbitration.Attachment;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.NodeAddress;
@ -62,7 +62,36 @@ public final class DisputeCommunicationMessage extends DisputeMessage {
boolean arrived,
boolean storedInMailbox,
String uid) {
super(uid);
this(tradeId,
traderId,
senderIsTrader,
message,
attachments,
senderNodeAddress,
date,
arrived,
storedInMailbox,
uid,
Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private DisputeCommunicationMessage(String tradeId,
int traderId,
boolean senderIsTrader,
String message,
@Nullable List<Attachment> attachments,
NodeAddress senderNodeAddress,
long date,
boolean arrived,
boolean storedInMailbox,
String uid,
int messageVersion) {
super(messageVersion, uid);
this.tradeId = tradeId;
this.traderId = traderId;
this.senderIsTrader = senderIsTrader;
@ -74,14 +103,9 @@ public final class DisputeCommunicationMessage extends DisputeMessage {
storedInMailboxProperty = new SimpleBooleanProperty(storedInMailbox);
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setDisputeCommunicationMessage(PB.DisputeCommunicationMessage.newBuilder()
.setTradeId(tradeId)
.setTraderId(traderId)
@ -98,7 +122,7 @@ public final class DisputeCommunicationMessage extends DisputeMessage {
.build();
}
public static DisputeCommunicationMessage fromProto(PB.DisputeCommunicationMessage proto) {
public static DisputeCommunicationMessage fromProto(PB.DisputeCommunicationMessage proto, int messageVersion) {
final DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(
proto.getTradeId(),
proto.getTraderId(),
@ -109,7 +133,29 @@ public final class DisputeCommunicationMessage extends DisputeMessage {
proto.getDate(),
proto.getArrived(),
proto.getStoredInMailbox(),
proto.getUid());
proto.getUid(),
messageVersion);
disputeCommunicationMessage.setSystemMessage(proto.getIsSystemMessage());
return disputeCommunicationMessage;
}
public static DisputeCommunicationMessage fromPayloadProto(PB.DisputeCommunicationMessage proto) {
// We have the case that an envelope got wrapped into a payload.
// We don't check the message version here as it was checked in the carrier envelope already (in connection class)
// Payloads dont have a message version and are also used for persistence
// We set the value to -1 to indicate it is set but irrelevant
final DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(
proto.getTradeId(),
proto.getTraderId(),
proto.getSenderIsTrader(),
proto.getMessage(),
new ArrayList<>(proto.getAttachmentsList().stream().map(Attachment::fromProto).collect(Collectors.toList())),
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getDate(),
proto.getArrived(),
proto.getStoredInMailbox(),
proto.getUid(),
-1);
disputeCommunicationMessage.setSystemMessage(proto.getIsSystemMessage());
return disputeCommunicationMessage;
}

View File

@ -17,20 +17,20 @@
package io.bisq.core.arbitration.messages;
import io.bisq.common.app.Version;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.network.p2p.MailboxMessage;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@ToString
@EqualsAndHashCode
@EqualsAndHashCode(callSuper = true)
@Getter
public abstract class DisputeMessage implements MailboxMessage {
protected final int messageVersion = Version.getP2PMessageVersion();
public abstract class DisputeMessage extends NetworkEnvelope implements MailboxMessage {
protected final String uid;
public DisputeMessage(String uid) {
public DisputeMessage(int messageVersion, String uid) {
super(messageVersion);
this.uid = uid;
}
}

View File

@ -17,7 +17,7 @@
package io.bisq.core.arbitration.messages;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.common.app.Version;
import io.bisq.core.arbitration.DisputeResult;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.NodeAddress;
@ -35,14 +35,29 @@ public final class DisputeResultMessage extends DisputeMessage {
public DisputeResultMessage(DisputeResult disputeResult,
NodeAddress senderNodeAddress,
String uid) {
super(uid);
this(disputeResult,
senderNodeAddress,
uid,
Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private DisputeResultMessage(DisputeResult disputeResult,
NodeAddress senderNodeAddress,
String uid,
int messageVersion) {
super(messageVersion, uid);
this.disputeResult = disputeResult;
this.senderNodeAddress = senderNodeAddress;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setDisputeResultMessage(PB.DisputeResultMessage.newBuilder()
.setDisputeResult(disputeResult.toProtoMessage())
.setSenderNodeAddress(senderNodeAddress.toProtoMessage())
@ -50,10 +65,11 @@ public final class DisputeResultMessage extends DisputeMessage {
.build();
}
public static DisputeResultMessage fromProto(PB.DisputeResultMessage proto) {
public static DisputeResultMessage fromProto(PB.DisputeResultMessage proto, int messageVersion) {
checkArgument(proto.hasDisputeResult(), "DisputeResult must be set");
return new DisputeResultMessage(DisputeResult.fromProto(proto.getDisputeResult()),
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getUid());
proto.getUid(),
messageVersion);
}
}

View File

@ -17,7 +17,7 @@
package io.bisq.core.arbitration.messages;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.common.app.Version;
import io.bisq.core.arbitration.Dispute;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.generated.protobuffer.PB;
@ -34,14 +34,29 @@ public final class OpenNewDisputeMessage extends DisputeMessage {
public OpenNewDisputeMessage(Dispute dispute,
NodeAddress senderNodeAddress,
String uid) {
super(uid);
this(dispute,
senderNodeAddress,
uid,
Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private OpenNewDisputeMessage(Dispute dispute,
NodeAddress senderNodeAddress,
String uid,
int messageVersion) {
super(messageVersion, uid);
this.dispute = dispute;
this.senderNodeAddress = senderNodeAddress;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setOpenNewDisputeMessage(PB.OpenNewDisputeMessage.newBuilder()
.setUid(uid)
.setDispute(dispute.toProtoMessage())
@ -49,9 +64,12 @@ public final class OpenNewDisputeMessage extends DisputeMessage {
.build();
}
public static OpenNewDisputeMessage fromProto(PB.OpenNewDisputeMessage proto, CoreProtoResolver coreProtoResolver) {
public static OpenNewDisputeMessage fromProto(PB.OpenNewDisputeMessage proto,
CoreProtoResolver coreProtoResolver,
int messageVersion) {
return new OpenNewDisputeMessage(Dispute.fromProto(proto.getDispute(), coreProtoResolver),
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getUid());
proto.getUid(),
messageVersion);
}
}

View File

@ -17,7 +17,7 @@
package io.bisq.core.arbitration.messages;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.common.app.Version;
import io.bisq.core.arbitration.Dispute;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.generated.protobuffer.PB;
@ -34,14 +34,29 @@ public final class PeerOpenedDisputeMessage extends DisputeMessage {
public PeerOpenedDisputeMessage(Dispute dispute,
NodeAddress senderNodeAddress,
String uid) {
super(uid);
this(dispute,
senderNodeAddress,
uid,
Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private PeerOpenedDisputeMessage(Dispute dispute,
NodeAddress senderNodeAddress,
String uid,
int messageVersion) {
super(messageVersion, uid);
this.dispute = dispute;
this.senderNodeAddress = senderNodeAddress;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setPeerOpenedDisputeMessage(PB.PeerOpenedDisputeMessage.newBuilder()
.setUid(uid)
.setDispute(dispute.toProtoMessage())
@ -49,9 +64,10 @@ public final class PeerOpenedDisputeMessage extends DisputeMessage {
.build();
}
public static PeerOpenedDisputeMessage fromProto(PB.PeerOpenedDisputeMessage proto, CoreProtoResolver coreProtoResolver) {
public static PeerOpenedDisputeMessage fromProto(PB.PeerOpenedDisputeMessage proto, CoreProtoResolver coreProtoResolver, int messageVersion) {
return new PeerOpenedDisputeMessage(Dispute.fromProto(proto.getDispute(), coreProtoResolver),
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getUid());
proto.getUid(),
messageVersion);
}
}

View File

@ -18,7 +18,7 @@
package io.bisq.core.arbitration.messages;
import com.google.protobuf.ByteString;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.common.app.Version;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.NodeAddress;
import lombok.EqualsAndHashCode;
@ -35,7 +35,24 @@ public final class PeerPublishedDisputePayoutTxMessage extends DisputeMessage {
String tradeId,
NodeAddress senderNodeAddress,
String uid) {
super(uid);
this(transaction,
tradeId,
senderNodeAddress,
uid,
Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private PeerPublishedDisputePayoutTxMessage(byte[] transaction,
String tradeId,
NodeAddress senderNodeAddress,
String uid,
int messageVersion) {
super(messageVersion, uid);
this.transaction = transaction;
this.tradeId = tradeId;
this.senderNodeAddress = senderNodeAddress;
@ -43,7 +60,7 @@ public final class PeerPublishedDisputePayoutTxMessage extends DisputeMessage {
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setPeerPublishedDisputePayoutTxMessage(PB.PeerPublishedDisputePayoutTxMessage.newBuilder()
.setTransaction(ByteString.copyFrom(transaction))
.setTradeId(tradeId)
@ -52,10 +69,11 @@ public final class PeerPublishedDisputePayoutTxMessage extends DisputeMessage {
.build();
}
public static PeerPublishedDisputePayoutTxMessage fromProto(PB.PeerPublishedDisputePayoutTxMessage proto) {
public static PeerPublishedDisputePayoutTxMessage fromProto(PB.PeerPublishedDisputePayoutTxMessage proto, int messageVersion) {
return new PeerPublishedDisputePayoutTxMessage(proto.getTransaction().toByteArray(),
proto.getTradeId(),
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getUid());
proto.getUid(),
messageVersion);
}
}

View File

@ -156,9 +156,9 @@ public class BsqFullNode extends BsqNode {
}
// TODO use handler class
private void onMessage(NetworkEnvelope wireEnvelope, Connection connection) {
if (wireEnvelope instanceof GetBsqBlocksRequest && connection.getPeersNodeAddressOptional().isPresent()) {
GetBsqBlocksRequest getBsqBlocksRequest = (GetBsqBlocksRequest) wireEnvelope;
private void onMessage(NetworkEnvelope networkEnvelop, Connection connection) {
if (networkEnvelop instanceof GetBsqBlocksRequest && connection.getPeersNodeAddressOptional().isPresent()) {
GetBsqBlocksRequest getBsqBlocksRequest = (GetBsqBlocksRequest) networkEnvelop;
final NodeAddress peersNodeAddress = connection.getPeersNodeAddressOptional().get();
log.info("Received getBsqBlocksRequest with data: {} from {}",
getBsqBlocksRequest.getFromBlockHeight(), peersNodeAddress);

View File

@ -134,9 +134,9 @@ public class BsqLiteNode extends BsqNode {
// so issue is on fullnode side...
byte[] pastRequests;
private void onMessage(NetworkEnvelope wireEnvelope, Connection connection) {
if (wireEnvelope instanceof GetBsqBlocksResponse && connection.getPeersNodeAddressOptional().isPresent()) {
GetBsqBlocksResponse getBsqBlocksResponse = (GetBsqBlocksResponse) wireEnvelope;
private void onMessage(NetworkEnvelope networkEnvelop, Connection connection) {
if (networkEnvelop instanceof GetBsqBlocksResponse && connection.getPeersNodeAddressOptional().isPresent()) {
GetBsqBlocksResponse getBsqBlocksResponse = (GetBsqBlocksResponse) networkEnvelop;
byte[] bsqBlocksBytes = getBsqBlocksResponse.getBsqBlocksBytes();
if (Arrays.equals(pastRequests, bsqBlocksBytes)) {
log.error("We got that message already. That should not happen.");
@ -161,8 +161,8 @@ public class BsqLiteNode extends BsqNode {
throwable.printStackTrace();
}
});
} else if (parseBlockchainComplete && wireEnvelope instanceof NewBsqBlockBroadcastMessage) {
NewBsqBlockBroadcastMessage newBsqBlockBroadcastMessage = (NewBsqBlockBroadcastMessage) wireEnvelope;
} else if (parseBlockchainComplete && networkEnvelop instanceof NewBsqBlockBroadcastMessage) {
NewBsqBlockBroadcastMessage newBsqBlockBroadcastMessage = (NewBsqBlockBroadcastMessage) networkEnvelop;
byte[] bsqBlockBytes = newBsqBlockBroadcastMessage.getBsqBlockBytes();
BsqBlock bsqBlock = Utilities.<BsqBlock>deserialize(bsqBlockBytes);
// Be safe and reset all mutable data in case the provider would not have done it

View File

@ -4,26 +4,37 @@ import io.bisq.common.app.Version;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.DirectMessage;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@EqualsAndHashCode(callSuper = true)
@Getter
public final class GetBsqBlocksRequest implements DirectMessage {
private final int messageVersion = Version.getP2PMessageVersion();
public final class GetBsqBlocksRequest extends NetworkEnvelope implements DirectMessage {
private final int fromBlockHeight;
public GetBsqBlocksRequest(int fromBlockHeight) {
this(fromBlockHeight, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private GetBsqBlocksRequest(int fromBlockHeight, int messageVersion) {
super(messageVersion);
this.fromBlockHeight = fromBlockHeight;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setGetBsqBlocksRequest(PB.GetBsqBlocksRequest.newBuilder()
.setFromBlockHeight(fromBlockHeight))
.build();
}
public static NetworkEnvelope fromProto(PB.GetBsqBlocksRequest proto) {
return new GetBsqBlocksRequest(proto.getFromBlockHeight());
public static NetworkEnvelope fromProto(PB.GetBsqBlocksRequest proto, int messageVersion) {
return new GetBsqBlocksRequest(proto.getFromBlockHeight(), messageVersion);
}
}

View File

@ -6,27 +6,37 @@ import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.DirectMessage;
import io.bisq.network.p2p.ExtendedDataSizePermission;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@EqualsAndHashCode(callSuper = true)
@Getter
public final class GetBsqBlocksResponse implements DirectMessage, ExtendedDataSizePermission {
private final int messageVersion = Version.getP2PMessageVersion();
public final class GetBsqBlocksResponse extends NetworkEnvelope implements DirectMessage, ExtendedDataSizePermission {
private final byte[] bsqBlocksBytes;
public GetBsqBlocksResponse(byte[] bsqBlocksBytes) {
this(bsqBlocksBytes, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private GetBsqBlocksResponse(byte[] bsqBlocksBytes, int messageVersion) {
super(messageVersion);
this.bsqBlocksBytes = bsqBlocksBytes;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setGetBsqBlocksResponse(PB.GetBsqBlocksResponse.newBuilder()
.setBsqBlocksBytes(ByteString.copyFrom(bsqBlocksBytes)))
.build();
}
public static NetworkEnvelope fromProto(PB.GetBsqBlocksResponse proto) {
return new GetBsqBlocksResponse(proto.getBsqBlocksBytes().toByteArray());
public static NetworkEnvelope fromProto(PB.GetBsqBlocksResponse proto, int messageVersion) {
return new GetBsqBlocksResponse(proto.getBsqBlocksBytes().toByteArray(), messageVersion);
}
}

View File

@ -5,28 +5,38 @@ import io.bisq.common.app.Version;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.storage.messages.BroadcastMessage;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@EqualsAndHashCode(callSuper = true)
@Getter
public final class NewBsqBlockBroadcastMessage extends BroadcastMessage {
private final int messageVersion = Version.getP2PMessageVersion();
private final byte[] bsqBlockBytes;
public NewBsqBlockBroadcastMessage(byte[] bsqBlockBytes) {
this(bsqBlockBytes, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private NewBsqBlockBroadcastMessage(byte[] bsqBlockBytes, int messageVersion) {
super(messageVersion);
this.bsqBlockBytes = bsqBlockBytes;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setNewBsqBlockBroadcastMessage(PB.NewBsqBlockBroadcastMessage.newBuilder()
.setBsqBlockBytes(ByteString.copyFrom(bsqBlockBytes)))
.build();
}
public static NetworkEnvelope fromProto(PB.NewBsqBlockBroadcastMessage proto) {
return new NewBsqBlockBroadcastMessage(proto.getBsqBlockBytes().toByteArray());
public static NetworkEnvelope fromProto(PB.NewBsqBlockBroadcastMessage proto, int messageVersion) {
return new NewBsqBlockBroadcastMessage(proto.getBsqBlockBytes().toByteArray(), messageVersion);
}
}

View File

@ -14,9 +14,8 @@ import io.bisq.network.p2p.network.CloseConnectionReason;
import io.bisq.network.p2p.network.Connection;
import io.bisq.network.p2p.network.MessageListener;
import io.bisq.network.p2p.network.NetworkNode;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
@ -25,9 +24,8 @@ import java.util.function.Consumer;
import static com.google.common.base.Preconditions.checkArgument;
@Slf4j
class RequestBsqBlocksHandler implements MessageListener {
private static final Logger log = LoggerFactory.getLogger(RequestBsqBlocksHandler.class);
private static final long TIME_OUT_SEC = 40;
private NodeAddress peersNodeAddress;
private Consumer<List<BsqBlock>> blockListHandler;
@ -122,13 +120,13 @@ class RequestBsqBlocksHandler implements MessageListener {
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void onMessage(NetworkEnvelope wireEnvelope, Connection connection) {
public void onMessage(NetworkEnvelope networkEnvelop, Connection connection) {
if (connection.getPeersNodeAddressOptional().isPresent() &&
connection.getPeersNodeAddressOptional().get().equals(peersNodeAddress)) {
if (wireEnvelope instanceof GetBsqBlocksResponse) {
Log.traceCall(wireEnvelope.toString() + "\n\tconnection=" + connection);
if (networkEnvelop instanceof GetBsqBlocksResponse) {
Log.traceCall(networkEnvelop.toString() + "\n\tconnection=" + connection);
if (!stopped) {
GetBsqBlocksResponse getBsqBlocksResponse = (GetBsqBlocksResponse) wireEnvelope;
GetBsqBlocksResponse getBsqBlocksResponse = (GetBsqBlocksResponse) networkEnvelop;
stopTimeoutTimer();
checkArgument(connection.getPeersNodeAddressOptional().isPresent(),
"RequestDataHandler.onMessage: connection.getPeersNodeAddressOptional() must be present " +

View File

@ -218,7 +218,6 @@ public final class OfferPayload implements StoragePayload, RequiresOwnerIsOnline
this.extraDataMap = extraDataMap;
this.protocolVersion = protocolVersion;
}
//38
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER

View File

@ -200,9 +200,9 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
// Handler for incoming offer availability requests
// We get an encrypted message but don't do the signature check as we don't know the peer yet.
// A basic sig check is in done also at decryption time
NetworkEnvelope wireEnvelope = decryptedMessageWithPubKey.getWireEnvelope();
if (wireEnvelope instanceof OfferAvailabilityRequest)
handleOfferAvailabilityRequest((OfferAvailabilityRequest) wireEnvelope, peerNodeAddress);
NetworkEnvelope networkEnvelop = decryptedMessageWithPubKey.getNetworkEnvelope();
if (networkEnvelop instanceof OfferAvailabilityRequest)
handleOfferAvailabilityRequest((OfferAvailabilityRequest) networkEnvelop, peerNodeAddress);
}

View File

@ -57,14 +57,14 @@ public class OfferAvailabilityProtocol {
this.errorMessageHandler = errorMessageHandler;
decryptedDirectMessageListener = (decryptedMessageWithPubKey, peersNodeAddress) -> {
NetworkEnvelope wireEnvelope = decryptedMessageWithPubKey.getWireEnvelope();
if (wireEnvelope instanceof OfferMessage) {
OfferMessage offerMessage = (OfferMessage) wireEnvelope;
NetworkEnvelope networkEnvelop = decryptedMessageWithPubKey.getNetworkEnvelope();
if (networkEnvelop instanceof OfferMessage) {
OfferMessage offerMessage = (OfferMessage) networkEnvelop;
Validator.nonEmptyStringOf(offerMessage.offerId);
if (wireEnvelope instanceof OfferAvailabilityResponse
if (networkEnvelop instanceof OfferAvailabilityResponse
&& model.offer.getId().equals(offerMessage.offerId)) {
log.trace("handle OfferAvailabilityResponse = " + wireEnvelope.getClass().getSimpleName() + " from " + peersNodeAddress);
handle((OfferAvailabilityResponse) wireEnvelope);
log.trace("handle OfferAvailabilityResponse = " + networkEnvelop.getClass().getSimpleName() + " from " + peersNodeAddress);
handle((OfferAvailabilityResponse) networkEnvelop);
}
}
};

View File

@ -18,8 +18,8 @@
package io.bisq.core.offer.messages;
import io.bisq.common.app.Capabilities;
import io.bisq.common.app.Version;
import io.bisq.common.crypto.PubKeyRing;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.SupportedCapabilitiesMessage;
import lombok.EqualsAndHashCode;
@ -39,14 +39,26 @@ public final class OfferAvailabilityRequest extends OfferMessage implements Supp
public OfferAvailabilityRequest(String offerId,
PubKeyRing pubKeyRing,
long takersTradePrice) {
super(offerId);
this(offerId, pubKeyRing, takersTradePrice, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private OfferAvailabilityRequest(String offerId,
PubKeyRing pubKeyRing,
long takersTradePrice,
int messageVersion) {
super(messageVersion, offerId);
this.pubKeyRing = pubKeyRing;
this.takersTradePrice = takersTradePrice;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setOfferAvailabilityRequest(PB.OfferAvailabilityRequest.newBuilder()
.setOfferId(offerId)
.setPubKeyRing(pubKeyRing.toProtoMessage())
@ -55,9 +67,10 @@ public final class OfferAvailabilityRequest extends OfferMessage implements Supp
.build();
}
public static OfferAvailabilityRequest fromProto(PB.OfferAvailabilityRequest proto) {
public static OfferAvailabilityRequest fromProto(PB.OfferAvailabilityRequest proto, int messageVersion) {
return new OfferAvailabilityRequest(proto.getOfferId(),
PubKeyRing.fromProto(proto.getPubKeyRing()),
proto.getTakersTradePrice());
proto.getTakersTradePrice(),
messageVersion);
}
}

View File

@ -19,8 +19,8 @@ package io.bisq.core.offer.messages;
import io.bisq.common.app.Capabilities;
import io.bisq.common.app.Version;
import io.bisq.common.proto.ProtoUtil;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.core.offer.AvailabilityResult;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.SupportedCapabilitiesMessage;
@ -38,13 +38,22 @@ public final class OfferAvailabilityResponse extends OfferMessage implements Sup
private final ArrayList<Integer> supportedCapabilities = Capabilities.getCapabilities();
public OfferAvailabilityResponse(String offerId, AvailabilityResult availabilityResult) {
super(offerId);
this(offerId, availabilityResult, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private OfferAvailabilityResponse(String offerId, AvailabilityResult availabilityResult, int messageVersion) {
super(messageVersion, offerId);
this.availabilityResult = availabilityResult;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setOfferAvailabilityResponse(PB.OfferAvailabilityResponse.newBuilder()
.setOfferId(offerId)
.setAvailabilityResult(PB.AvailabilityResult.valueOf(availabilityResult.name()))
@ -52,8 +61,9 @@ public final class OfferAvailabilityResponse extends OfferMessage implements Sup
.build();
}
public static OfferAvailabilityResponse fromProto(PB.OfferAvailabilityResponse proto) {
public static OfferAvailabilityResponse fromProto(PB.OfferAvailabilityResponse proto, int messageVersion) {
return new OfferAvailabilityResponse(proto.getOfferId(),
ProtoUtil.enumFromProto(AvailabilityResult.class, proto.getAvailabilityResult().name()));
ProtoUtil.enumFromProto(AvailabilityResult.class, proto.getAvailabilityResult().name()),
messageVersion);
}
}

View File

@ -17,30 +17,20 @@
package io.bisq.core.offer.messages;
import io.bisq.common.app.Version;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.network.p2p.DirectMessage;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import javax.annotation.concurrent.Immutable;
@Immutable
public abstract class OfferMessage implements DirectMessage {
private final int messageVersion = Version.getP2PMessageVersion();
@EqualsAndHashCode(callSuper = true)
@Getter
@ToString
public abstract class OfferMessage extends NetworkEnvelope implements DirectMessage {
public final String offerId;
OfferMessage(String offerId) {
protected OfferMessage(int messageVersion, String offerId) {
super(messageVersion);
this.offerId = offerId;
}
@Override
public int getMessageVersion() {
return messageVersion;
}
@Override
public String toString() {
return "OfferMessage{" +
"messageVersion=" + messageVersion +
", offerId='" + offerId + '\'' +
'}';
}
}

View File

@ -51,75 +51,74 @@ public class CoreNetworkProtoResolver extends CoreProtoResolver implements Netwo
@Override
public NetworkEnvelope fromProto(PB.NetworkEnvelope proto) {
if (proto != null) {
final int messageVersion = proto.getMessageVersion();
switch (proto.getMessageCase()) {
case PRELIMINARY_GET_DATA_REQUEST:
return PreliminaryGetDataRequest.fromProto(proto.getPreliminaryGetDataRequest());
return PreliminaryGetDataRequest.fromProto(proto.getPreliminaryGetDataRequest(), messageVersion);
case GET_DATA_RESPONSE:
return GetDataResponse.fromProto(proto.getGetDataResponse(), this);
return GetDataResponse.fromProto(proto.getGetDataResponse(), this, messageVersion);
case GET_UPDATED_DATA_REQUEST:
return GetUpdatedDataRequest.fromProto(proto.getGetUpdatedDataRequest());
return GetUpdatedDataRequest.fromProto(proto.getGetUpdatedDataRequest(), messageVersion);
case GET_PEERS_REQUEST:
return GetPeersRequest.fromProto(proto.getGetPeersRequest());
return GetPeersRequest.fromProto(proto.getGetPeersRequest(), messageVersion);
case GET_PEERS_RESPONSE:
return GetPeersResponse.fromProto(proto.getGetPeersResponse());
return GetPeersResponse.fromProto(proto.getGetPeersResponse(), messageVersion);
case PING:
return Ping.fromProto(proto.getPing());
return Ping.fromProto(proto.getPing(), messageVersion);
case PONG:
return Pong.fromProto(proto.getPong());
return Pong.fromProto(proto.getPong(), messageVersion);
case OFFER_AVAILABILITY_REQUEST:
return OfferAvailabilityRequest.fromProto(proto.getOfferAvailabilityRequest());
return OfferAvailabilityRequest.fromProto(proto.getOfferAvailabilityRequest(), messageVersion);
case OFFER_AVAILABILITY_RESPONSE:
return OfferAvailabilityResponse.fromProto(proto.getOfferAvailabilityResponse());
return OfferAvailabilityResponse.fromProto(proto.getOfferAvailabilityResponse(), messageVersion);
case REFRESH_OFFER_MESSAGE:
return RefreshOfferMessage.fromProto(proto.getRefreshOfferMessage());
return RefreshOfferMessage.fromProto(proto.getRefreshOfferMessage(), messageVersion);
case ADD_DATA_MESSAGE:
return AddDataMessage.fromProto(proto.getAddDataMessage(), this);
return AddDataMessage.fromProto(proto.getAddDataMessage(), this, messageVersion);
case REMOVE_DATA_MESSAGE:
return RemoveDataMessage.fromProto(proto.getRemoveDataMessage(), this);
return RemoveDataMessage.fromProto(proto.getRemoveDataMessage(), this, messageVersion);
case REMOVE_MAILBOX_DATA_MESSAGE:
return RemoveMailboxDataMessage.fromProto(proto.getRemoveMailboxDataMessage(), this);
return RemoveMailboxDataMessage.fromProto(proto.getRemoveMailboxDataMessage(), this, messageVersion);
case CLOSE_CONNECTION_MESSAGE:
return CloseConnectionMessage.fromProto(proto.getCloseConnectionMessage());
return CloseConnectionMessage.fromProto(proto.getCloseConnectionMessage(), messageVersion);
case PREFIXED_SEALED_AND_SIGNED_MESSAGE:
return PrefixedSealedAndSignedMessage.fromProto(proto.getPrefixedSealedAndSignedMessage());
return PrefixedSealedAndSignedMessage.fromProto(proto.getPrefixedSealedAndSignedMessage(), messageVersion);
case PAY_DEPOSIT_REQUEST:
return PayDepositRequest.fromProto(proto.getPayDepositRequest(), this);
return PayDepositRequest.fromProto(proto.getPayDepositRequest(), this, messageVersion);
case DEPOSIT_TX_PUBLISHED_MESSAGE:
return DepositTxPublishedMessage.fromProto(proto.getDepositTxPublishedMessage());
return DepositTxPublishedMessage.fromProto(proto.getDepositTxPublishedMessage(), messageVersion);
case PUBLISH_DEPOSIT_TX_REQUEST:
return PublishDepositTxRequest.fromProto(proto.getPublishDepositTxRequest(), this);
return PublishDepositTxRequest.fromProto(proto.getPublishDepositTxRequest(), this, messageVersion);
case FIAT_TRANSFER_STARTED_MESSAGE:
return FiatTransferStartedMessage.fromProto(proto.getFiatTransferStartedMessage());
case FINALIZE_PAYOUT_TX_REQUEST:
return FinalizePayoutTxRequest.fromProto(proto.getFinalizePayoutTxRequest());
return FiatTransferStartedMessage.fromProto(proto.getFiatTransferStartedMessage(), messageVersion);
case PAYOUT_TX_PUBLISHED_MESSAGE:
return PayoutTxPublishedMessage.fromProto(proto.getPayoutTxPublishedMessage());
return PayoutTxPublishedMessage.fromProto(proto.getPayoutTxPublishedMessage(), messageVersion);
case OPEN_NEW_DISPUTE_MESSAGE:
return OpenNewDisputeMessage.fromProto(proto.getOpenNewDisputeMessage(), this);
return OpenNewDisputeMessage.fromProto(proto.getOpenNewDisputeMessage(), this, messageVersion);
case PEER_OPENED_DISPUTE_MESSAGE:
return PeerOpenedDisputeMessage.fromProto(proto.getPeerOpenedDisputeMessage(), this);
return PeerOpenedDisputeMessage.fromProto(proto.getPeerOpenedDisputeMessage(), this, messageVersion);
case DISPUTE_COMMUNICATION_MESSAGE:
return DisputeCommunicationMessage.fromProto(proto.getDisputeCommunicationMessage());
return DisputeCommunicationMessage.fromProto(proto.getDisputeCommunicationMessage(), messageVersion);
case DISPUTE_RESULT_MESSAGE:
return DisputeResultMessage.fromProto(proto.getDisputeResultMessage());
return DisputeResultMessage.fromProto(proto.getDisputeResultMessage(), messageVersion);
case PEER_PUBLISHED_DISPUTE_PAYOUT_TX_MESSAGE:
return PeerPublishedDisputePayoutTxMessage.fromProto(proto.getPeerPublishedDisputePayoutTxMessage());
return PeerPublishedDisputePayoutTxMessage.fromProto(proto.getPeerPublishedDisputePayoutTxMessage(), messageVersion);
case PRIVATE_NOTIFICATION_MESSAGE:
return PrivateNotificationMessage.fromProto(proto.getPrivateNotificationMessage());
return PrivateNotificationMessage.fromProto(proto.getPrivateNotificationMessage(), messageVersion);
case GET_BSQ_BLOCKS_REQUEST:
return GetBsqBlocksRequest.fromProto(proto.getGetBsqBlocksRequest());
return GetBsqBlocksRequest.fromProto(proto.getGetBsqBlocksRequest(), messageVersion);
case GET_BSQ_BLOCKS_RESPONSE:
return GetBsqBlocksResponse.fromProto(proto.getGetBsqBlocksResponse());
return GetBsqBlocksResponse.fromProto(proto.getGetBsqBlocksResponse(), messageVersion);
case NEW_BSQ_BLOCK_BROADCAST_MESSAGE:
return NewBsqBlockBroadcastMessage.fromProto(proto.getNewBsqBlockBroadcastMessage());
return NewBsqBlockBroadcastMessage.fromProto(proto.getNewBsqBlockBroadcastMessage(), messageVersion);
default:
throw new ProtobufferException("Unknown proto message case (PB.NetworkEnvelope). messageCase=" + proto.getMessageCase());

View File

@ -13,9 +13,8 @@ import io.bisq.core.btc.wallet.BtcWalletService;
import io.bisq.core.dao.blockchain.parse.BsqChainState;
import io.bisq.core.dao.compensation.CompensationRequestPayload;
import io.bisq.core.dao.vote.VoteItemsList;
import io.bisq.core.offer.OpenOffer;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.core.trade.*;
import io.bisq.core.trade.TradableList;
import io.bisq.core.trade.statistics.TradeStatisticsList;
import io.bisq.core.user.PreferencesPayload;
import io.bisq.core.user.UserPayload;
@ -89,26 +88,4 @@ public class CorePersistenceProtoResolver extends CoreProtoResolver implements P
throw new ProtobufferException("PB.PersistableEnvelope is null");
}
}
public Tradable fromProto(PB.Tradable proto, Storage<TradableList<SellerAsMakerTrade>> storage) {
if (proto != null) {
switch (proto.getMessageCase()) {
case OPEN_OFFER:
return OpenOffer.fromProto(proto.getOpenOffer());
case BUYER_AS_MAKER_TRADE:
return BuyerAsMakerTrade.fromProto(proto.getBuyerAsMakerTrade(), storage, btcWalletService.get(), this);
case BUYER_AS_TAKER_TRADE:
return BuyerAsTakerTrade.fromProto(proto.getBuyerAsTakerTrade(), storage, btcWalletService.get(), this);
case SELLER_AS_MAKER_TRADE:
return SellerAsMakerTrade.fromProto(proto.getSellerAsMakerTrade(), storage, btcWalletService.get(), this);
case SELLER_AS_TAKER_TRADE:
return SellerAsTakerTrade.fromProto(proto.getSellerAsTakerTrade(), storage, btcWalletService.get(), this);
default:
throw new ProtobufferException("Unknown proto message case(PB.Tradable). messageCase=" + proto.getMessageCase());
}
} else {
log.error("PersistableEnvelope.fromProto: PB.Tradable is null");
throw new ProtobufferException("PB.Tradable is null");
}
}
}

View File

@ -41,7 +41,7 @@ public class FeeService {
private static final Logger log = LoggerFactory.getLogger(FeeService.class);
public static final long MIN_TX_FEE = 40; // satoshi/byte
public static final long MAX_TX_FEE = 500;
public static final long MAX_TX_FEE = 1000;
public static final long DEFAULT_TX_FEE = 150;
private static final long MIN_MAKER_FEE_IN_BTC = 10_000;

View File

@ -136,12 +136,12 @@ public class TradeManager implements PersistedDataHost {
p2PService.addDecryptedDirectMessageListener(new DecryptedDirectMessageListener() {
@Override
public void onDirectMessage(DecryptedMessageWithPubKey decryptedMessageWithPubKey, NodeAddress peerNodeAddress) {
NetworkEnvelope wireEnvelope = decryptedMessageWithPubKey.getWireEnvelope();
NetworkEnvelope networkEnvelop = decryptedMessageWithPubKey.getNetworkEnvelope();
// Handler for incoming initial network_messages from taker
if (wireEnvelope instanceof PayDepositRequest) {
log.trace("Received PayDepositRequest: " + wireEnvelope);
handleInitialTakeOfferRequest((PayDepositRequest) wireEnvelope, peerNodeAddress);
if (networkEnvelop instanceof PayDepositRequest) {
log.trace("Received PayDepositRequest: " + networkEnvelop);
handleInitialTakeOfferRequest((PayDepositRequest) networkEnvelop, peerNodeAddress);
}
}
});
@ -152,10 +152,10 @@ public class TradeManager implements PersistedDataHost {
public void onMailboxMessageAdded(DecryptedMessageWithPubKey decryptedMessageWithPubKey, NodeAddress senderNodeAddress) {
log.debug("onMailboxMessageAdded decryptedMessageWithPubKey: " + decryptedMessageWithPubKey);
log.trace("onMailboxMessageAdded senderAddress: " + senderNodeAddress);
NetworkEnvelope wireEnvelope = decryptedMessageWithPubKey.getWireEnvelope();
if (wireEnvelope instanceof TradeMessage) {
log.trace("Received TradeMessage: " + wireEnvelope);
String tradeId = ((TradeMessage) wireEnvelope).getTradeId();
NetworkEnvelope networkEnvelop = decryptedMessageWithPubKey.getNetworkEnvelope();
if (networkEnvelop instanceof TradeMessage) {
log.trace("Received TradeMessage: " + networkEnvelop);
String tradeId = ((TradeMessage) networkEnvelop).getTradeId();
Optional<Trade> tradeOptional = tradableList.stream().filter(e -> e.getId().equals(tradeId)).findAny();
// The mailbox message will be removed inside the tasks after they are processed successfully
if (tradeOptional.isPresent())

View File

@ -18,7 +18,8 @@
package io.bisq.core.trade.messages;
import com.google.protobuf.ByteString;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.common.app.Version;
import io.bisq.common.util.Utilities;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.MailboxMessage;
import io.bisq.network.p2p.NodeAddress;
@ -36,15 +37,32 @@ public final class DepositTxPublishedMessage extends TradeMessage implements Mai
byte[] depositTx,
NodeAddress senderNodeAddress,
String uid) {
super(tradeId);
this(tradeId,
depositTx,
senderNodeAddress,
uid,
Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private DepositTxPublishedMessage(String tradeId,
byte[] depositTx,
NodeAddress senderNodeAddress,
String uid,
int messageVersion) {
super(messageVersion, tradeId);
this.depositTx = depositTx;
this.senderNodeAddress = senderNodeAddress;
this.uid = uid;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setDepositTxPublishedMessage(PB.DepositTxPublishedMessage.newBuilder()
.setTradeId(tradeId)
.setDepositTx(ByteString.copyFrom(depositTx))
@ -53,10 +71,21 @@ public final class DepositTxPublishedMessage extends TradeMessage implements Mai
.build();
}
public static DepositTxPublishedMessage fromProto(PB.DepositTxPublishedMessage proto) {
public static DepositTxPublishedMessage fromProto(PB.DepositTxPublishedMessage proto, int messageVersion) {
return new DepositTxPublishedMessage(proto.getTradeId(),
proto.getDepositTx().toByteArray(),
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getUid());
proto.getUid(),
messageVersion);
}
@Override
public String toString() {
return "DepositTxPublishedMessage{" +
"\n depositTx=" + Utilities.bytesAsHexString(depositTx) +
",\n senderNodeAddress=" + senderNodeAddress +
",\n uid='" + uid + '\'' +
"\n} " + super.toString();
}
}

View File

@ -18,7 +18,8 @@
package io.bisq.core.trade.messages;
import com.google.protobuf.ByteString;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.common.app.Version;
import io.bisq.common.util.Utilities;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.MailboxMessage;
import io.bisq.network.p2p.NodeAddress;
@ -38,7 +39,26 @@ public final class FiatTransferStartedMessage extends TradeMessage implements Ma
NodeAddress senderNodeAddress,
byte[] buyerSignature,
String uid) {
super(tradeId);
this(tradeId,
buyerPayoutAddress,
senderNodeAddress,
buyerSignature,
uid,
Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private FiatTransferStartedMessage(String tradeId,
String buyerPayoutAddress,
NodeAddress senderNodeAddress,
byte[] buyerSignature,
String uid,
int messageVersion) {
super(messageVersion, tradeId);
this.buyerPayoutAddress = buyerPayoutAddress;
this.senderNodeAddress = senderNodeAddress;
this.buyerSignature = buyerSignature;
@ -47,7 +67,7 @@ public final class FiatTransferStartedMessage extends TradeMessage implements Ma
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setFiatTransferStartedMessage(PB.FiatTransferStartedMessage.newBuilder()
.setTradeId(tradeId)
.setBuyerPayoutAddress(buyerPayoutAddress)
@ -57,12 +77,23 @@ public final class FiatTransferStartedMessage extends TradeMessage implements Ma
.build();
}
public static FiatTransferStartedMessage fromProto(PB.FiatTransferStartedMessage proto) {
public static FiatTransferStartedMessage fromProto(PB.FiatTransferStartedMessage proto, int messageVersion) {
return new FiatTransferStartedMessage(proto.getTradeId(),
proto.getBuyerPayoutAddress(),
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getBuyerSignature().toByteArray(),
proto.getUid()
);
proto.getUid(),
messageVersion);
}
@Override
public String toString() {
return "FiatTransferStartedMessage{" +
"\n buyerPayoutAddress='" + buyerPayoutAddress + '\'' +
",\n senderNodeAddress=" + senderNodeAddress +
",\n uid='" + uid + '\'' +
",\n buyerSignature=" + Utilities.bytesAsHexString(buyerSignature) +
"\n} " + super.toString();
}
}

View File

@ -1,66 +0,0 @@
/*
* 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 io.bisq.core.trade.messages;
import com.google.protobuf.ByteString;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.MailboxMessage;
import io.bisq.network.p2p.NodeAddress;
import lombok.EqualsAndHashCode;
import lombok.Value;
@EqualsAndHashCode(callSuper = true)
@Value
public final class FinalizePayoutTxRequest extends TradeMessage implements MailboxMessage {
private final byte[] sellerSignature;
private final String sellerPayoutAddress;
private final NodeAddress senderNodeAddress;
private final String uid;
public FinalizePayoutTxRequest(String tradeId,
byte[] sellerSignature,
String sellerPayoutAddress,
NodeAddress senderNodeAddress,
String uid) {
super(tradeId);
this.sellerSignature = sellerSignature;
this.sellerPayoutAddress = sellerPayoutAddress;
this.senderNodeAddress = senderNodeAddress;
this.uid = uid;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
.setFinalizePayoutTxRequest(PB.FinalizePayoutTxRequest.newBuilder()
.setTradeId(tradeId)
.setSellerSignature(ByteString.copyFrom(sellerSignature))
.setSellerPayoutAddress(sellerPayoutAddress)
.setSenderNodeAddress(senderNodeAddress.toProtoMessage())
.setUid(uid)).build();
}
public static FinalizePayoutTxRequest fromProto(PB.FinalizePayoutTxRequest proto) {
return new FinalizePayoutTxRequest(proto.getTradeId(),
proto.getSellerSignature().toByteArray(),
proto.getSellerPayoutAddress(),
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getUid());
}
}

View File

@ -20,7 +20,7 @@ package io.bisq.core.trade.messages;
import com.google.protobuf.ByteString;
import io.bisq.common.crypto.PubKeyRing;
import io.bisq.common.proto.ProtoUtil;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.common.util.Utilities;
import io.bisq.core.btc.data.RawTransactionInput;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.proto.CoreProtoResolver;
@ -80,8 +80,9 @@ public final class PayDepositRequest extends TradeMessage {
List<NodeAddress> acceptedMediatorNodeAddresses,
NodeAddress arbitratorNodeAddress,
NodeAddress mediatorNodeAddress,
String uid) {
super(tradeId);
String uid,
int messageVersion) {
super(messageVersion, tradeId);
this.senderNodeAddress = senderNodeAddress;
this.tradeAmount = tradeAmount;
this.tradePrice = tradePrice;
@ -104,6 +105,11 @@ public final class PayDepositRequest extends TradeMessage {
this.uid = uid;
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
PB.PayDepositRequest.Builder builder = PB.PayDepositRequest.newBuilder()
@ -131,10 +137,10 @@ public final class PayDepositRequest extends TradeMessage {
.setMediatorNodeAddress(mediatorNodeAddress.toProtoMessage())
.setUid(uid);
Optional.ofNullable(changeOutputAddress).ifPresent(builder::setChangeOutputAddress);
return NetworkEnvelope.getDefaultBuilder().setPayDepositRequest(builder).build();
return getNetworkEnvelopeBuilder().setPayDepositRequest(builder).build();
}
public static PayDepositRequest fromProto(PB.PayDepositRequest proto, CoreProtoResolver coreProtoResolver) {
public static PayDepositRequest fromProto(PB.PayDepositRequest proto, CoreProtoResolver coreProtoResolver, int messageVersion) {
List<RawTransactionInput> rawTransactionInputs = proto.getRawTransactionInputsList().stream()
.map(rawTransactionInput -> new RawTransactionInput(rawTransactionInput.getIndex(),
rawTransactionInput.getParentTransaction().toByteArray(), rawTransactionInput.getValue()))
@ -164,6 +170,34 @@ public final class PayDepositRequest extends TradeMessage {
acceptedMediatorNodeAddresses,
NodeAddress.fromProto(proto.getArbitratorNodeAddress()),
NodeAddress.fromProto(proto.getMediatorNodeAddress()),
proto.getUid());
proto.getUid(),
messageVersion);
}
@Override
public String toString() {
return "PayDepositRequest{" +
"\n senderNodeAddress=" + senderNodeAddress +
",\n tradeAmount=" + tradeAmount +
",\n tradePrice=" + tradePrice +
",\n txFee=" + txFee +
",\n takerFee=" + takerFee +
",\n isCurrencyForTakerFeeBtc=" + isCurrencyForTakerFeeBtc +
",\n rawTransactionInputs=" + rawTransactionInputs +
",\n changeOutputValue=" + changeOutputValue +
",\n changeOutputAddress='" + changeOutputAddress + '\'' +
",\n takerMultiSigPubKey=" + Utilities.bytesAsHexString(takerMultiSigPubKey) +
",\n takerPayoutAddressString='" + takerPayoutAddressString + '\'' +
",\n takerPubKeyRing=" + takerPubKeyRing +
",\n takerPaymentAccountPayload=" + takerPaymentAccountPayload +
",\n takerAccountId='" + takerAccountId + '\'' +
",\n takerFeeTxId='" + takerFeeTxId + '\'' +
",\n acceptedArbitratorNodeAddresses=" + acceptedArbitratorNodeAddresses +
",\n acceptedMediatorNodeAddresses=" + acceptedMediatorNodeAddresses +
",\n arbitratorNodeAddress=" + arbitratorNodeAddress +
",\n mediatorNodeAddress=" + mediatorNodeAddress +
",\n uid='" + uid + '\'' +
"\n} " + super.toString();
}
}

View File

@ -18,7 +18,9 @@
package io.bisq.core.trade.messages;
import com.google.protobuf.ByteString;
import io.bisq.common.app.Version;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.common.util.Utilities;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.MailboxMessage;
import io.bisq.network.p2p.NodeAddress;
@ -36,7 +38,24 @@ public final class PayoutTxPublishedMessage extends TradeMessage implements Mail
byte[] payoutTx,
NodeAddress senderNodeAddress,
String uid) {
super(tradeId);
this(tradeId,
payoutTx,
senderNodeAddress,
uid,
Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private PayoutTxPublishedMessage(String tradeId,
byte[] payoutTx,
NodeAddress senderNodeAddress,
String uid,
int messageVersion) {
super(messageVersion, tradeId);
this.payoutTx = payoutTx;
this.senderNodeAddress = senderNodeAddress;
this.uid = uid;
@ -44,7 +63,7 @@ public final class PayoutTxPublishedMessage extends TradeMessage implements Mail
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setPayoutTxPublishedMessage(PB.PayoutTxPublishedMessage.newBuilder()
.setTradeId(tradeId)
.setPayoutTx(ByteString.copyFrom(payoutTx))
@ -53,10 +72,20 @@ public final class PayoutTxPublishedMessage extends TradeMessage implements Mail
.build();
}
public static NetworkEnvelope fromProto(PB.PayoutTxPublishedMessage proto) {
public static NetworkEnvelope fromProto(PB.PayoutTxPublishedMessage proto, int messageVersion) {
return new PayoutTxPublishedMessage(proto.getTradeId(),
proto.getPayoutTx().toByteArray(),
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getUid());
proto.getUid(),
messageVersion);
}
@Override
public String toString() {
return "PayoutTxPublishedMessage{" +
"\n payoutTx=" + Utilities.bytesAsHexString(payoutTx) +
",\n senderNodeAddress=" + senderNodeAddress +
",\n uid='" + uid + '\'' +
"\n} " + super.toString();
}
}

View File

@ -18,7 +18,8 @@
package io.bisq.core.trade.messages;
import com.google.protobuf.ByteString;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.common.app.Version;
import io.bisq.common.util.Utilities;
import io.bisq.core.btc.data.RawTransactionInput;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.proto.CoreProtoResolver;
@ -60,7 +61,38 @@ public final class PublishDepositTxRequest extends TradeMessage implements Mailb
List<RawTransactionInput> makerInputs,
NodeAddress senderNodeAddress,
String uid) {
super(tradeId);
this(tradeId,
makerPaymentAccountPayload,
makerAccountId,
makerMultiSigPubKey,
makerContractAsJson,
makerContractSignature,
makerPayoutAddressString,
preparedDepositTx,
makerInputs,
senderNodeAddress,
uid,
Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private PublishDepositTxRequest(String tradeId,
PaymentAccountPayload makerPaymentAccountPayload,
String makerAccountId,
byte[] makerMultiSigPubKey,
String makerContractAsJson,
String makerContractSignature,
String makerPayoutAddressString,
byte[] preparedDepositTx,
List<RawTransactionInput> makerInputs,
NodeAddress senderNodeAddress,
String uid,
int messageVersion) {
super(messageVersion, tradeId);
this.makerPaymentAccountPayload = makerPaymentAccountPayload;
this.makerAccountId = makerAccountId;
this.makerMultiSigPubKey = makerMultiSigPubKey;
@ -75,7 +107,7 @@ public final class PublishDepositTxRequest extends TradeMessage implements Mailb
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setPublishDepositTxRequest(PB.PublishDepositTxRequest.newBuilder()
.setTradeId(tradeId)
.setMakerPaymentAccountPayload((PB.PaymentAccountPayload) makerPaymentAccountPayload.toProtoMessage())
@ -91,7 +123,7 @@ public final class PublishDepositTxRequest extends TradeMessage implements Mailb
.build();
}
public static PublishDepositTxRequest fromProto(PB.PublishDepositTxRequest proto, CoreProtoResolver coreProtoResolver) {
public static PublishDepositTxRequest fromProto(PB.PublishDepositTxRequest proto, CoreProtoResolver coreProtoResolver, int messageVersion) {
List<RawTransactionInput> makerInputs = proto.getMakerInputsList().stream()
.map(RawTransactionInput::fromProto)
.collect(Collectors.toList());
@ -106,6 +138,24 @@ public final class PublishDepositTxRequest extends TradeMessage implements Mailb
proto.getPreparedDepositTx().toByteArray(),
makerInputs,
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getUid());
proto.getUid(),
messageVersion);
}
@Override
public String toString() {
return "PublishDepositTxRequest{" +
"\n makerPaymentAccountPayload=" + makerPaymentAccountPayload +
",\n makerAccountId='" + makerAccountId + '\'' +
",\n makerMultiSigPubKey=" + Utilities.bytesAsHexString(makerMultiSigPubKey) +
",\n makerContractAsJson='" + makerContractAsJson + '\'' +
",\n makerContractSignature='" + makerContractSignature + '\'' +
",\n makerPayoutAddressString='" + makerPayoutAddressString + '\'' +
",\n preparedDepositTx=" + Utilities.bytesAsHexString(preparedDepositTx) +
",\n makerInputs=" + makerInputs +
",\n senderNodeAddress=" + senderNodeAddress +
",\n uid='" + uid + '\'' +
"\n} " + super.toString();
}
}

View File

@ -17,21 +17,21 @@
package io.bisq.core.trade.messages;
import io.bisq.common.app.Version;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.network.p2p.DirectMessage;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@EqualsAndHashCode
@ToString
@EqualsAndHashCode(callSuper = true)
@Getter
public abstract class TradeMessage implements DirectMessage {
protected final int messageVersion = Version.getP2PMessageVersion();
@ToString
public abstract class TradeMessage extends NetworkEnvelope implements DirectMessage {
protected final String tradeId;
protected TradeMessage(String tradeId) {
protected TradeMessage(int messageVersion, String tradeId) {
super(messageVersion);
this.tradeId = tradeId;
}
}

View File

@ -77,18 +77,18 @@ public class BuyerAsMakerProtocol extends TradeProtocol implements BuyerProtocol
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void doApplyMailboxMessage(NetworkEnvelope wireEnvelope, Trade trade) {
public void doApplyMailboxMessage(NetworkEnvelope networkEnvelop, Trade trade) {
this.trade = trade;
if (wireEnvelope instanceof MailboxMessage) {
MailboxMessage mailboxMessage = (MailboxMessage) wireEnvelope;
if (networkEnvelop instanceof MailboxMessage) {
MailboxMessage mailboxMessage = (MailboxMessage) networkEnvelop;
NodeAddress peerNodeAddress = mailboxMessage.getSenderNodeAddress();
if (wireEnvelope instanceof DepositTxPublishedMessage)
handle((DepositTxPublishedMessage) wireEnvelope, peerNodeAddress);
else if (wireEnvelope instanceof PayoutTxPublishedMessage)
handle((PayoutTxPublishedMessage) wireEnvelope, peerNodeAddress);
if (networkEnvelop instanceof DepositTxPublishedMessage)
handle((DepositTxPublishedMessage) networkEnvelop, peerNodeAddress);
else if (networkEnvelop instanceof PayoutTxPublishedMessage)
handle((PayoutTxPublishedMessage) networkEnvelop, peerNodeAddress);
else
log.error("We received an unhandled MailboxMessage" + wireEnvelope.toString());
log.error("We received an unhandled MailboxMessage" + networkEnvelop.toString());
}
}

View File

@ -69,15 +69,15 @@ public class BuyerAsTakerProtocol extends TradeProtocol implements BuyerProtocol
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void doApplyMailboxMessage(NetworkEnvelope wireEnvelope, Trade trade) {
public void doApplyMailboxMessage(NetworkEnvelope networkEnvelop, Trade trade) {
this.trade = trade;
final NodeAddress senderNodeAddress = ((MailboxMessage) wireEnvelope).getSenderNodeAddress();
if (wireEnvelope instanceof PublishDepositTxRequest)
handle((PublishDepositTxRequest) wireEnvelope, senderNodeAddress);
else if (wireEnvelope instanceof PayoutTxPublishedMessage) {
handle((PayoutTxPublishedMessage) wireEnvelope, senderNodeAddress);
final NodeAddress senderNodeAddress = ((MailboxMessage) networkEnvelop).getSenderNodeAddress();
if (networkEnvelop instanceof PublishDepositTxRequest)
handle((PublishDepositTxRequest) networkEnvelop, senderNodeAddress);
else if (networkEnvelop instanceof PayoutTxPublishedMessage) {
handle((PayoutTxPublishedMessage) networkEnvelop, senderNodeAddress);
} else
log.error("We received an unhandled MailboxMessage" + wireEnvelope.toString());
log.error("We received an unhandled MailboxMessage" + networkEnvelop.toString());
}

View File

@ -229,7 +229,7 @@ public class ProcessModel implements Model, PersistablePayload {
public void removeMailboxMessageAfterProcessing(Trade trade) {
if (tradeMessage instanceof MailboxMessage &&
decryptedMessageWithPubKey != null &&
decryptedMessageWithPubKey.getWireEnvelope().equals(tradeMessage)) {
decryptedMessageWithPubKey.getNetworkEnvelope().equals(tradeMessage)) {
log.debug("Remove decryptedMsgWithPubKey from P2P network. decryptedMsgWithPubKey = " + decryptedMessageWithPubKey);
p2PService.removeEntryFromMailbox(decryptedMessageWithPubKey);
trade.removeDecryptedMessageWithPubKey(decryptedMessageWithPubKey);

View File

@ -71,16 +71,16 @@ public class SellerAsMakerProtocol extends TradeProtocol implements SellerProtoc
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void doApplyMailboxMessage(NetworkEnvelope wireEnvelope, Trade trade) {
public void doApplyMailboxMessage(NetworkEnvelope networkEnvelop, Trade trade) {
this.trade = trade;
NodeAddress peerNodeAddress = ((MailboxMessage) wireEnvelope).getSenderNodeAddress();
if (wireEnvelope instanceof DepositTxPublishedMessage)
handle((DepositTxPublishedMessage) wireEnvelope, peerNodeAddress);
else if (wireEnvelope instanceof FiatTransferStartedMessage)
handle((FiatTransferStartedMessage) wireEnvelope, peerNodeAddress);
NodeAddress peerNodeAddress = ((MailboxMessage) networkEnvelop).getSenderNodeAddress();
if (networkEnvelop instanceof DepositTxPublishedMessage)
handle((DepositTxPublishedMessage) networkEnvelop, peerNodeAddress);
else if (networkEnvelop instanceof FiatTransferStartedMessage)
handle((FiatTransferStartedMessage) networkEnvelop, peerNodeAddress);
else
log.error("We received an unhandled MailboxMessage" + wireEnvelope.toString());
log.error("We received an unhandled MailboxMessage" + networkEnvelop.toString());
}

View File

@ -60,17 +60,17 @@ public class SellerAsTakerProtocol extends TradeProtocol implements SellerProtoc
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void doApplyMailboxMessage(NetworkEnvelope wireEnvelope, Trade trade) {
public void doApplyMailboxMessage(NetworkEnvelope networkEnvelop, Trade trade) {
this.trade = trade;
if (wireEnvelope instanceof MailboxMessage) {
NodeAddress peerNodeAddress = ((MailboxMessage) wireEnvelope).getSenderNodeAddress();
if (wireEnvelope instanceof PublishDepositTxRequest)
handle((PublishDepositTxRequest) wireEnvelope, peerNodeAddress);
else if (wireEnvelope instanceof FiatTransferStartedMessage)
handle((FiatTransferStartedMessage) wireEnvelope, peerNodeAddress);
if (networkEnvelop instanceof MailboxMessage) {
NodeAddress peerNodeAddress = ((MailboxMessage) networkEnvelop).getSenderNodeAddress();
if (networkEnvelop instanceof PublishDepositTxRequest)
handle((PublishDepositTxRequest) networkEnvelop, peerNodeAddress);
else if (networkEnvelop instanceof FiatTransferStartedMessage)
handle((FiatTransferStartedMessage) networkEnvelop, peerNodeAddress);
else
log.error("We received an unhandled MailboxMessage" + wireEnvelope.toString());
log.error("We received an unhandled MailboxMessage" + networkEnvelop.toString());
}
}

View File

@ -54,10 +54,10 @@ public abstract class TradeProtocol {
PubKeyRing tradingPeerPubKeyRing = processModel.getTradingPeer().getPubKeyRing();
PublicKey signaturePubKey = decryptedMessageWithPubKey.getSignaturePubKey();
if (tradingPeerPubKeyRing != null && signaturePubKey.equals(tradingPeerPubKeyRing.getSignaturePubKey())) {
NetworkEnvelope wireEnvelope = decryptedMessageWithPubKey.getWireEnvelope();
log.trace("handleNewMessage: message = " + wireEnvelope.getClass().getSimpleName() + " from " + peersNodeAddress);
if (wireEnvelope instanceof TradeMessage) {
TradeMessage tradeMessage = (TradeMessage) wireEnvelope;
NetworkEnvelope networkEnvelop = decryptedMessageWithPubKey.getNetworkEnvelope();
log.trace("handleNewMessage: message = " + networkEnvelop.getClass().getSimpleName() + " from " + peersNodeAddress);
if (networkEnvelop instanceof TradeMessage) {
TradeMessage tradeMessage = (TradeMessage) networkEnvelop;
nonEmptyStringOf(tradeMessage.getTradeId());
if (tradeMessage.getTradeId().equals(processModel.getOfferId()))
@ -92,17 +92,17 @@ public abstract class TradeProtocol {
}
public void applyMailboxMessage(DecryptedMessageWithPubKey decryptedMessageWithPubKey, Trade trade) {
log.debug("applyMailboxMessage " + decryptedMessageWithPubKey.getWireEnvelope());
log.debug("applyMailboxMessage " + decryptedMessageWithPubKey.getNetworkEnvelope());
if (processModel.getTradingPeer().getPubKeyRing() != null &&
decryptedMessageWithPubKey.getSignaturePubKey().equals(processModel.getTradingPeer().getPubKeyRing().getSignaturePubKey())) {
processModel.setDecryptedMessageWithPubKey(decryptedMessageWithPubKey);
doApplyMailboxMessage(decryptedMessageWithPubKey.getWireEnvelope(), trade);
doApplyMailboxMessage(decryptedMessageWithPubKey.getNetworkEnvelope(), trade);
} else {
log.error("SignaturePubKey in message does not match the SignaturePubKey we have stored to that trading peer.");
}
}
protected abstract void doApplyMailboxMessage(NetworkEnvelope wireEnvelope, Trade trade);
protected abstract void doApplyMailboxMessage(NetworkEnvelope networkEnvelop, Trade trade);
protected abstract void doHandleDecryptedMessage(TradeMessage tradeMessage, NodeAddress peerNodeAddress);

View File

@ -17,6 +17,7 @@
package io.bisq.core.trade.protocol.tasks.taker;
import io.bisq.common.app.Version;
import io.bisq.common.taskrunner.TaskRunner;
import io.bisq.core.btc.AddressEntry;
import io.bisq.core.btc.wallet.BtcWalletService;
@ -85,7 +86,8 @@ public class TakerSendPayDepositRequest extends TradeTask {
new ArrayList<>(acceptedMediatorAddresses),
trade.getArbitratorNodeAddress(),
trade.getMediatorNodeAddress(),
UUID.randomUUID().toString());
UUID.randomUUID().toString(),
Version.getP2PMessageVersion());
processModel.setMyMultiSigPubKey(takerMultiSigPubKey);
processModel.getP2PService().sendEncryptedDirectMessage(

View File

@ -93,7 +93,64 @@ Output is in target/generated-sources which avoids the temptation of checking in
In order to support this, we need to use .writeDelimitedTo(outputstream) and parseDelimitedFrom(inputstream).
The writeDelimited writes a length varint before the object, allowing the parseDelimited to know the extent of the message.
## Checklist and conventions
### Code style
* Use line breaks after each param in constructor and PB methods
* Use line breaks at PB builders for best readability
* Use after the constructor a comment separator with the PB stuff and after the PB stuff a comment separator with API
* Use same order of fields as in main constructor and follow that order in the PB methods to make it easier to spot missing fields
### Conventions
* Try to use value objects for data which gets serialized with PB
* Use toProto and a static fromProto in the class which gets serialized
* Use proto as name for the PB param in the fromProto method
* If a constructor is used only for PB make it private and put it to the PB section, so its clear it is used only in that context
* Use same name for classes and fields in PB definition as in the java code base
* Use final
* Use Lombok Annotations
* Annotate all nullable fields with @Nullable
* If nullable fields must not be null at time of serialisation use checkNotNull with comment inside
* Use ProtoUtil convenience methods (e.g. stringOrNullFromProto, byteArrayOrNullFromProto, collectionToProto, enumFromProto,..)
* Use ProtoUtil.enumFromProto for all enums
* Enum in PB definition file needs an additional first entry with PB_ERROR in case of multiple enums in one message add postfix of enum (PB_ERROR_REASON = 0;)
* When serializing a custom type use the toProto and fromProto methods in the class of that type.
* Use the ProtoResolver classes for switching between different message cases. Pass the reference to the resolver if needed in fromProto
* For abstract super classes use a getBuilder method for handling the fields in that super class (e.g. PaymentAccountPayload)
* Use Payload as postfix for objects which are used in Envelopes or other Payloads if it helps to distinguish between the domain object and the value object (e.g. UserPayload)
* Separate network and persistable domains if possible
### Architecture
* Envelope is the base interface for all objects carrying PB data (messages, persisted objects)
* Payload is used inside Envelopes or other Payloads
* Interface structure:
Proto: base has Message toProtoMessage();
Envelope extends Proto: Marker interface for objects carrying PB data
NetworkEnvelope extends Envelope: Marker interface, has getDefaultBuilder for P2PMessageVersion
PersistableEnvelope extends Envelope: Marker interface
Payload extends Proto: Marker interface for objects used inside other Payload or Envelope objects
NetworkPayload extends Payload: Marker interface
PersistablePayload extends Payload: Marker interface
ProtoResolver: Base for resolver (switch message cases)
NetworkProtoResolver extends ProtoResolver: Marker interface
CoreNetworkProtoResolver implements NetworkProtoResolver: Implements switches for network messages
PersistableProtoResolver extends ProtoResolver: Marker interface
CorePersistableProtoResolver implements NetworkProtoResolver: Implements switches for persistable messages
### Check list
* Treat nullable fields correctly in the toProto and fromProto methods.
PB does not support null values but use default implementation for not set fields.
Depending on the type there is: isEmpty (string, collections) or has[Propertyname]
* If using @EqualsAndHashCode or @Data/@Value make sure to use callSuper=true if the class is extending another class
* If collections are modifiable take care to wrap the result of PB to a modifiable collection. PB delivers unmodifiable collections
* For network envelopes use NetworkEnvelope.getDefaultBuilder() which includes the P2PMessageVersion.
Store the messageVersion in all NetworkEnvelope instances
// TODO update, outdated...
## Actually transformed subtypes of Message
```

View File

@ -305,7 +305,7 @@ public class BisqApp extends Application {
// Used only for migrating old trade statistic to new data structure
// injector.getInstance(TradeStatisticsMigrationTool.class);
if (!Utilities.isCorrectOSArchitecture()) {
String osArchitecture = Utilities.getOSArchitecture();
// We don't force a shutdown as the osArchitecture might in strange cases return a wrong value.

View File

@ -626,9 +626,9 @@ public class MainViewModel implements ViewModel {
SealedAndSigned sealedAndSigned = EncryptionService.encryptHybridWithSignature(payload,
keyRing.getSignatureKeyPair(), keyRing.getPubKeyRing().getEncryptionPubKey());
DecryptedDataTuple tuple = encryptionService.decryptHybridWithSignature(sealedAndSigned, keyRing.getEncryptionKeyPair().getPrivate());
if (tuple.payload instanceof Ping &&
((Ping) tuple.payload).getNonce() == payload.getNonce() &&
((Ping) tuple.payload).getLastRoundTripTime() == payload.getLastRoundTripTime()) {
if (tuple.getNetworkEnvelope() instanceof Ping &&
((Ping) tuple.getNetworkEnvelope()).getNonce() == payload.getNonce() &&
((Ping) tuple.getNetworkEnvelope()).getLastRoundTripTime() == payload.getLastRoundTripTime()) {
log.debug("Crypto test succeeded");
if (Security.getProvider("BC") != null) {

View File

@ -33,7 +33,13 @@ import java.io.IOException;
import java.util.Scanner;
public class OsData {
public enum OsType {Windows, Linux32, Linux64, Mac, Android}
public enum OsType {
Windows,
Linux32,
Linux64,
Mac,
Android
}
private static OsType detectedType = null;

View File

@ -33,7 +33,7 @@ public abstract class TorNode<M extends OnionProxyManager, C extends OnionProxyC
log.debug("TorSocks running on port " + proxyPort);
this.proxy = setupSocksProxy(proxyPort);
}
public Socks5Proxy getSocksProxy() {
return proxy;
}

View File

@ -20,24 +20,18 @@ package io.bisq.network.crypto;
import io.bisq.common.proto.network.NetworkEnvelope;
import lombok.EqualsAndHashCode;
import lombok.Value;
import java.security.PublicKey;
@EqualsAndHashCode
@Value
public final class DecryptedDataTuple {
public final NetworkEnvelope payload;
public final PublicKey sigPublicKey;
private final NetworkEnvelope networkEnvelope;
private final PublicKey sigPublicKey;
public DecryptedDataTuple(NetworkEnvelope payload, PublicKey sigPublicKey) {
this.payload = payload;
public DecryptedDataTuple(NetworkEnvelope networkEnvelope, PublicKey sigPublicKey) {
this.networkEnvelope = networkEnvelope;
this.sigPublicKey = sigPublicKey;
}
@Override
public String toString() {
return "DecryptedPayloadWithPubKey{" +
"payload=" + payload +
", sigPublicKey.hashCode()=" + sigPublicKey.hashCode() +
'}';
}
}

View File

@ -45,8 +45,8 @@ public class EncryptionService {
this.networkProtoResolver = networkProtoResolver;
}
public SealedAndSigned encryptAndSign(PubKeyRing pubKeyRing, NetworkEnvelope wireEnvelope) throws CryptoException {
return encryptHybridWithSignature(wireEnvelope, keyRing.getSignatureKeyPair(), pubKeyRing.getEncryptionPubKey());
public SealedAndSigned encryptAndSign(PubKeyRing pubKeyRing, NetworkEnvelope networkEnvelop) throws CryptoException {
return encryptHybridWithSignature(networkEnvelop, keyRing.getSignatureKeyPair(), pubKeyRing.getEncryptionPubKey());
}
/**
@ -77,12 +77,12 @@ public class EncryptionService {
public DecryptedMessageWithPubKey decryptAndVerify(SealedAndSigned sealedAndSigned) throws CryptoException {
DecryptedDataTuple decryptedDataTuple = decryptHybridWithSignature(sealedAndSigned,
keyRing.getEncryptionKeyPair().getPrivate());
return new DecryptedMessageWithPubKey(decryptedDataTuple.payload,
decryptedDataTuple.sigPublicKey);
return new DecryptedMessageWithPubKey(decryptedDataTuple.getNetworkEnvelope(),
decryptedDataTuple.getSigPublicKey());
}
private static byte[] encryptPayloadWithHmac(NetworkEnvelope wireEnvelope, SecretKey secretKey) throws CryptoException {
return Encryption.encryptPayloadWithHmac(wireEnvelope.toProtoNetworkEnvelope().toByteArray(), secretKey);
private static byte[] encryptPayloadWithHmac(NetworkEnvelope networkEnvelop, SecretKey secretKey) throws CryptoException {
return Encryption.encryptPayloadWithHmac(networkEnvelop.toProtoNetworkEnvelope().toByteArray(), secretKey);
}
/**

View File

@ -1,6 +1,4 @@
package io.bisq.network.p2p;
import io.bisq.common.proto.network.NetworkEnvelope;
public interface AnonymousMessage extends NetworkEnvelope {
public interface AnonymousMessage {
}

View File

@ -1,26 +1,40 @@
package io.bisq.network.p2p;
import io.bisq.common.app.Version;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.generated.protobuffer.PB;
import lombok.EqualsAndHashCode;
import lombok.Value;
@EqualsAndHashCode(callSuper = true)
@Value
public final class CloseConnectionMessage implements NetworkEnvelope {
public final class CloseConnectionMessage extends NetworkEnvelope {
private final String reason;
public CloseConnectionMessage(String reason) {
this(reason, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private CloseConnectionMessage(String reason, int messageVersion) {
super(messageVersion);
this.reason = reason;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setCloseConnectionMessage(PB.CloseConnectionMessage.newBuilder()
.setReason(reason))
.build();
}
public static CloseConnectionMessage fromProto(PB.CloseConnectionMessage proto) {
return new CloseConnectionMessage(proto.getReason());
public static CloseConnectionMessage fromProto(PB.CloseConnectionMessage proto, int messageVersion) {
return new CloseConnectionMessage(proto.getReason(), messageVersion);
}
}

View File

@ -24,11 +24,11 @@ import java.security.PublicKey;
@Value
public final class DecryptedMessageWithPubKey {
private final NetworkEnvelope wireEnvelope;
private final NetworkEnvelope networkEnvelope;
private final PublicKey signaturePubKey;
public DecryptedMessageWithPubKey(NetworkEnvelope wireEnvelope, PublicKey signaturePubKey) {
this.wireEnvelope = wireEnvelope;
public DecryptedMessageWithPubKey(NetworkEnvelope networkEnvelope, PublicKey signaturePubKey) {
this.networkEnvelope = networkEnvelope;
this.signaturePubKey = signaturePubKey;
}
}

View File

@ -17,7 +17,5 @@
package io.bisq.network.p2p;
import io.bisq.common.proto.network.NetworkEnvelope;
public interface DirectMessage extends NetworkEnvelope {
public interface DirectMessage {
}

View File

@ -443,13 +443,13 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void onMessage(NetworkEnvelope wireEnvelope, Connection connection) {
if (wireEnvelope instanceof PrefixedSealedAndSignedMessage) {
Log.traceCall("\n\t" + wireEnvelope.toString() + "\n\tconnection=" + connection);
public void onMessage(NetworkEnvelope networkEnvelop, Connection connection) {
if (networkEnvelop instanceof PrefixedSealedAndSignedMessage) {
Log.traceCall("\n\t" + networkEnvelop.toString() + "\n\tconnection=" + connection);
// Seed nodes don't have set the encryptionService
if (optionalEncryptionService.isPresent()) {
try {
PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage = (PrefixedSealedAndSignedMessage) wireEnvelope;
PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage = (PrefixedSealedAndSignedMessage) networkEnvelop;
if (verifyAddressPrefixHash(prefixedSealedAndSignedMessage)) {
// We set connectionType to that connection to avoid that is get closed when
// we get too many connection attempts.
@ -471,7 +471,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
log.debug("Wrong receiverAddressMaskHash. The message is not intended for us.");
}
} catch (CryptoException e) {
log.debug(wireEnvelope.toString());
log.debug(networkEnvelop.toString());
log.debug(e.toString());
log.debug("Decryption of prefixedSealedAndSignedMessage.sealedAndSigned failed. " +
"That is expected if the message is not intended for us.");
@ -500,7 +500,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
// DirectMessages
///////////////////////////////////////////////////////////////////////////////////////////
public void sendEncryptedDirectMessage(NodeAddress peerNodeAddress, PubKeyRing pubKeyRing, DirectMessage message,
public void sendEncryptedDirectMessage(NodeAddress peerNodeAddress, PubKeyRing pubKeyRing, NetworkEnvelope message,
SendDirectMessageListener sendDirectMessageListener) {
Log.traceCall();
checkNotNull(peerNodeAddress, "PeerAddress must not be null (sendEncryptedDirectMessage)");
@ -511,7 +511,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
}
}
private void doSendEncryptedDirectMessage(@NotNull NodeAddress peersNodeAddress, PubKeyRing pubKeyRing, DirectMessage message,
private void doSendEncryptedDirectMessage(@NotNull NodeAddress peersNodeAddress, PubKeyRing pubKeyRing, NetworkEnvelope message,
SendDirectMessageListener sendDirectMessageListener) {
Log.traceCall();
checkNotNull(peersNodeAddress, "Peer node address must not be null at doSendEncryptedDirectMessage");
@ -564,8 +564,8 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
try {
DecryptedMessageWithPubKey decryptedMessageWithPubKey = optionalEncryptionService.get().decryptAndVerify(
prefixedSealedAndSignedMessage.getSealedAndSigned());
if (decryptedMessageWithPubKey.getWireEnvelope() instanceof MailboxMessage) {
MailboxMessage mailboxMessage = (MailboxMessage) decryptedMessageWithPubKey.getWireEnvelope();
if (decryptedMessageWithPubKey.getNetworkEnvelope() instanceof MailboxMessage) {
MailboxMessage mailboxMessage = (MailboxMessage) decryptedMessageWithPubKey.getNetworkEnvelope();
NodeAddress senderNodeAddress = mailboxMessage.getSenderNodeAddress();
checkNotNull(senderNodeAddress, "senderAddress must not be null for mailbox network_messages");
@ -576,7 +576,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
e -> e.onMailboxMessageAdded(decryptedMessageWithPubKey, senderNodeAddress));
} else {
log.warn("tryDecryptMailboxData: Expected MailboxMessage but got other type. " +
"decryptedMsgWithPubKey.message=", decryptedMessageWithPubKey.getWireEnvelope());
"decryptedMsgWithPubKey.message=", decryptedMessageWithPubKey.getNetworkEnvelope());
}
} catch (CryptoException e) {
log.debug(e.toString());
@ -590,7 +590,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
}
public void sendEncryptedMailboxMessage(NodeAddress peersNodeAddress, PubKeyRing peersPubKeyRing,
MailboxMessage message,
NetworkEnvelope message,
SendMailboxMessageListener sendMailboxMessageListener) {
Log.traceCall("message " + message);
checkNotNull(peersNodeAddress,
@ -740,7 +740,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
Log.traceCall();
checkArgument(optionalKeyRing.isPresent(), "keyRing not set. Seems that is called on a seed node which must not happen.");
if (isBootstrapped()) {
MailboxMessage mailboxMessage = (MailboxMessage) decryptedMessageWithPubKey.getWireEnvelope();
MailboxMessage mailboxMessage = (MailboxMessage) decryptedMessageWithPubKey.getNetworkEnvelope();
String uid = mailboxMessage.getUid();
if (mailboxMap.containsKey(uid)) {
ProtectedMailboxStorageEntry mailboxData = mailboxMap.get(uid);

View File

@ -1,15 +1,18 @@
package io.bisq.network.p2p;
import com.google.protobuf.ByteString;
import io.bisq.common.app.Version;
import io.bisq.common.crypto.SealedAndSigned;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.generated.protobuffer.PB;
import lombok.EqualsAndHashCode;
import lombok.Value;
import static com.google.common.base.Preconditions.checkNotNull;
@EqualsAndHashCode(callSuper = true)
@Value
public final class PrefixedSealedAndSignedMessage implements MailboxMessage, SendersNodeAddressMessage {
public final class PrefixedSealedAndSignedMessage extends NetworkEnvelope implements MailboxMessage, SendersNodeAddressMessage {
private final NodeAddress senderNodeAddress;
private final SealedAndSigned sealedAndSigned;
private final byte[] addressPrefixHash;
@ -19,6 +22,20 @@ public final class PrefixedSealedAndSignedMessage implements MailboxMessage, Sen
SealedAndSigned sealedAndSigned,
byte[] addressPrefixHash,
String uid) {
this(senderNodeAddress, sealedAndSigned, addressPrefixHash, uid, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private PrefixedSealedAndSignedMessage(NodeAddress senderNodeAddress,
SealedAndSigned sealedAndSigned,
byte[] addressPrefixHash,
String uid,
int messageVersion) {
super(messageVersion);
this.senderNodeAddress = checkNotNull(senderNodeAddress, "senderNodeAddress must not be null");
this.sealedAndSigned = sealedAndSigned;
this.addressPrefixHash = addressPrefixHash;
@ -27,7 +44,7 @@ public final class PrefixedSealedAndSignedMessage implements MailboxMessage, Sen
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setPrefixedSealedAndSignedMessage(PB.PrefixedSealedAndSignedMessage.newBuilder()
.setNodeAddress(senderNodeAddress.toProtoMessage())
.setSealedAndSigned(sealedAndSigned.toProtoMessage())
@ -36,11 +53,23 @@ public final class PrefixedSealedAndSignedMessage implements MailboxMessage, Sen
.build();
}
public static PrefixedSealedAndSignedMessage fromProto(PB.PrefixedSealedAndSignedMessage proto) {
public static PrefixedSealedAndSignedMessage fromProto(PB.PrefixedSealedAndSignedMessage proto, int messageVersion) {
return new PrefixedSealedAndSignedMessage(NodeAddress.fromProto(proto.getNodeAddress()),
SealedAndSigned.fromProto(proto.getSealedAndSigned()),
proto.getAddressPrefixHash().toByteArray(),
proto.getUid());
proto.getUid(),
messageVersion);
}
public static PrefixedSealedAndSignedMessage fromPayloadProto(PB.PrefixedSealedAndSignedMessage proto) {
// We have the case that an envelope got wrapped into a payload.
// We don't check the message version here as it was checked in the carrier envelope already (in connection class)
// Payloads dont have a message version and are also used for persistence
// We set the value to -1 to indicate it is set but irrelevant
return new PrefixedSealedAndSignedMessage(NodeAddress.fromProto(proto.getNodeAddress()),
SealedAndSigned.fromProto(proto.getSealedAndSigned()),
proto.getAddressPrefixHash().toByteArray(),
proto.getUid(),
-1);
}
}

View File

@ -1,8 +1,6 @@
package io.bisq.network.p2p;
import io.bisq.common.proto.network.NetworkEnvelope;
public interface SendersNodeAddressMessage extends NetworkEnvelope {
public interface SendersNodeAddressMessage {
NodeAddress getSenderNodeAddress();
}

View File

@ -1,11 +1,9 @@
package io.bisq.network.p2p;
import io.bisq.common.proto.network.NetworkEnvelope;
import javax.annotation.Nullable;
import java.util.ArrayList;
public interface SupportedCapabilitiesMessage extends NetworkEnvelope {
public interface SupportedCapabilitiesMessage {
@Nullable
ArrayList<Integer> getSupportedCapabilities();
}

View File

@ -247,9 +247,9 @@ public class Connection implements MessageListener {
}
}
public boolean isCapabilitySupported(NetworkEnvelope wireEnvelope) {
if (wireEnvelope instanceof AddDataMessage) {
final StoragePayload storagePayload = (((AddDataMessage) wireEnvelope).getProtectedStorageEntry()).getStoragePayload();
public boolean isCapabilitySupported(NetworkEnvelope networkEnvelop) {
if (networkEnvelop instanceof AddDataMessage) {
final StoragePayload storagePayload = (((AddDataMessage) networkEnvelop).getProtectedStorageEntry()).getStoragePayload();
if (storagePayload instanceof CapabilityRequiringPayload) {
final List<Integer> requiredCapabilities = ((CapabilityRequiringPayload) storagePayload).getRequiredCapabilities();
final List<Integer> supportedCapabilities = sharedModel.getSupportedCapabilities();
@ -282,8 +282,8 @@ public class Connection implements MessageListener {
}
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public boolean isCapabilityRequired(NetworkEnvelope wireEnvelope) {
return wireEnvelope instanceof AddDataMessage && (((AddDataMessage) wireEnvelope).getProtectedStorageEntry()).getStoragePayload() instanceof CapabilityRequiringPayload;
public boolean isCapabilityRequired(NetworkEnvelope networkEnvelop) {
return networkEnvelop instanceof AddDataMessage && (((AddDataMessage) networkEnvelop).getProtectedStorageEntry()).getStoragePayload() instanceof CapabilityRequiringPayload;
}
public List<Integer> getSupportedCapabilities() {
@ -309,7 +309,7 @@ public class Connection implements MessageListener {
}
// TODO either use the argument or delete it
private boolean violatesThrottleLimit(NetworkEnvelope wireEnvelope) {
private boolean violatesThrottleLimit(NetworkEnvelope networkEnvelop) {
long now = System.currentTimeMillis();
boolean violated = false;
//TODO remove message storage after network is tested stable
@ -346,7 +346,7 @@ public class Connection implements MessageListener {
messageTimeStamps.remove(0);
}
messageTimeStamps.add(new Tuple2<>(now, wireEnvelope));
messageTimeStamps.add(new Tuple2<>(now, networkEnvelop));
return violated;
}
@ -356,9 +356,9 @@ public class Connection implements MessageListener {
// Only receive non - CloseConnectionMessage network_messages
@Override
public void onMessage(NetworkEnvelope wireEnvelope, Connection connection) {
public void onMessage(NetworkEnvelope networkEnvelop, Connection connection) {
checkArgument(connection.equals(this));
UserThread.execute(() -> messageListeners.stream().forEach(e -> e.onMessage(wireEnvelope, connection)));
UserThread.execute(() -> messageListeners.stream().forEach(e -> e.onMessage(networkEnvelop, connection)));
}

View File

@ -3,5 +3,5 @@ package io.bisq.network.p2p.network;
import io.bisq.common.proto.network.NetworkEnvelope;
public interface MessageListener {
void onMessage(NetworkEnvelope wireEnvelope, Connection connection);
void onMessage(NetworkEnvelope networkEnvelop, Connection connection);
}

View File

@ -67,8 +67,8 @@ public abstract class NetworkNode implements MessageListener {
// when the events happen.
abstract public void start(@Nullable SetupListener setupListener);
public SettableFuture<Connection> sendMessage(@NotNull NodeAddress peersNodeAddress, NetworkEnvelope wireEnvelope) {
Log.traceCall("peersNodeAddress=" + peersNodeAddress + "\n\tmessage=" + Utilities.toTruncatedString(wireEnvelope));
public SettableFuture<Connection> sendMessage(@NotNull NodeAddress peersNodeAddress, NetworkEnvelope networkEnvelop) {
Log.traceCall("peersNodeAddress=" + peersNodeAddress + "\n\tmessage=" + Utilities.toTruncatedString(networkEnvelop));
checkNotNull(peersNodeAddress, "peerAddress must not be null");
Connection connection = getOutboundConnection(peersNodeAddress);
@ -76,7 +76,7 @@ public abstract class NetworkNode implements MessageListener {
connection = getInboundConnection(peersNodeAddress);
if (connection != null) {
return sendMessage(connection, wireEnvelope);
return sendMessage(connection, networkEnvelop);
} else {
log.debug("We have not found any connection for peerAddress {}.\n\t" +
"We will create a new outbound connection.", peersNodeAddress);
@ -114,7 +114,7 @@ public abstract class NetworkNode implements MessageListener {
} catch (Throwable throwable) {
log.error("Error at closing socket " + throwable);
}
existingConnection.sendMessage(wireEnvelope);
existingConnection.sendMessage(networkEnvelop);
return existingConnection;
} else {
final ConnectionListener connectionListener = new ConnectionListener() {
@ -153,11 +153,11 @@ public abstract class NetworkNode implements MessageListener {
+ "\nmyNodeAddress=" + getNodeAddress()
+ "\npeersNodeAddress=" + peersNodeAddress
+ "\nuid=" + outboundConnection.getUid()
+ "\nmessage=" + wireEnvelope
+ "\nmessage=" + networkEnvelop
+ "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
// can take a while when using tor
outboundConnection.sendMessage(wireEnvelope);
outboundConnection.sendMessage(networkEnvelop);
return outboundConnection;
}
} catch (Throwable throwable) {
@ -226,12 +226,12 @@ public abstract class NetworkNode implements MessageListener {
}
public SettableFuture<Connection> sendMessage(Connection connection, NetworkEnvelope wireEnvelope) {
Log.traceCall("\n\tmessage=" + Utilities.toTruncatedString(wireEnvelope) + "\n\tconnection=" + connection);
public SettableFuture<Connection> sendMessage(Connection connection, NetworkEnvelope networkEnvelop) {
Log.traceCall("\n\tmessage=" + Utilities.toTruncatedString(networkEnvelop) + "\n\tconnection=" + connection);
// connection.sendMessage might take a bit (compression, write to stream), so we use a thread to not block
ListenableFuture<Connection> future = executorService.submit(() -> {
Thread.currentThread().setName("NetworkNode:SendMessage-to-" + connection.getUid());
connection.sendMessage(wireEnvelope);
connection.sendMessage(networkEnvelop);
return connection;
});
final SettableFuture<Connection> resultFuture = SettableFuture.create();
@ -307,8 +307,8 @@ public abstract class NetworkNode implements MessageListener {
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void onMessage(NetworkEnvelope wireEnvelope, Connection connection) {
messageListeners.stream().forEach(e -> e.onMessage(wireEnvelope, connection));
public void onMessage(NetworkEnvelope networkEnvelop, Connection connection) {
messageListeners.stream().forEach(e -> e.onMessage(networkEnvelop, connection));
}

View File

@ -85,8 +85,8 @@ public class Statistic {
}
// TODO would need msg inspection to get useful information...
public void addReceivedMessage(NetworkEnvelope wireEnvelope) {
String messageClassName = wireEnvelope.getClass().getSimpleName();
public void addReceivedMessage(NetworkEnvelope networkEnvelop) {
String messageClassName = networkEnvelop.getClass().getSimpleName();
int counter = 1;
if (receivedMessages.containsKey(messageClassName))
counter = receivedMessages.get(messageClassName) + 1;
@ -94,8 +94,8 @@ public class Statistic {
receivedMessages.put(messageClassName, counter);
}
public void addSentMessage(NetworkEnvelope wireEnvelope) {
String messageClassName = wireEnvelope.getClass().getSimpleName();
public void addSentMessage(NetworkEnvelope networkEnvelop) {
String messageClassName = networkEnvelop.getClass().getSimpleName();
int counter = 1;
if (sentMessages.containsKey(messageClassName))
counter = sentMessages.get(messageClassName) + 1;

View File

@ -163,18 +163,18 @@ public class RequestDataHandler implements MessageListener {
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void onMessage(NetworkEnvelope wireEnvelope, Connection connection) {
public void onMessage(NetworkEnvelope networkEnvelop, Connection connection) {
if (connection.getPeersNodeAddressOptional().isPresent() && connection.getPeersNodeAddressOptional().get().equals(peersNodeAddress)) {
if (wireEnvelope instanceof GetDataResponse) {
Log.traceCall(wireEnvelope.toString() + "\n\tconnection=" + connection);
if (networkEnvelop instanceof GetDataResponse) {
Log.traceCall(networkEnvelop.toString() + "\n\tconnection=" + connection);
if (!stopped) {
GetDataResponse getDataResponse = (GetDataResponse) wireEnvelope;
GetDataResponse getDataResponse = (GetDataResponse) networkEnvelop;
Map<String, Set<StoragePayload>> payloadByClassName = new HashMap<>();
final HashSet<ProtectedStorageEntry> dataSet = getDataResponse.getDataSet();
dataSet.stream().forEach(e -> {
final StoragePayload storagePayload = e.getStoragePayload();
if (storagePayload == null) {
log.warn("StoragePayload was null: {}", wireEnvelope.toString());
log.warn("StoragePayload was null: {}", networkEnvelop.toString());
return;
}

View File

@ -188,9 +188,9 @@ public class RequestDataManager implements MessageListener, ConnectionListener,
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void onMessage(NetworkEnvelope wireEnvelope, Connection connection) {
if (wireEnvelope instanceof GetDataRequest) {
Log.traceCall(wireEnvelope.toString() + "\n\tconnection=" + connection);
public void onMessage(NetworkEnvelope networkEnvelop, Connection connection) {
if (networkEnvelop instanceof GetDataRequest) {
Log.traceCall(networkEnvelop.toString() + "\n\tconnection=" + connection);
if (!stopped) {
if (peerManager.isSeedNode(connection))
connection.setPeerType(Connection.PeerType.SEED_NODE);
@ -218,7 +218,7 @@ public class RequestDataManager implements MessageListener, ConnectionListener,
}
});
getDataRequestHandlers.put(uid, getDataRequestHandler);
getDataRequestHandler.handle((GetDataRequest) wireEnvelope, connection);
getDataRequestHandler.handle((GetDataRequest) networkEnvelop, connection);
} else {
log.warn("We have already a GetDataRequestHandler for that connection started. " +
"We start a cleanup timer if the handler has not closed by itself in between 2 minutes.");

View File

@ -2,11 +2,22 @@ package io.bisq.network.p2p.peers.getdata.messages;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.network.p2p.ExtendedDataSizePermission;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import java.util.Set;
public interface GetDataRequest extends NetworkEnvelope, ExtendedDataSizePermission {
int getNonce();
@EqualsAndHashCode(callSuper = true)
@Getter
@ToString
public abstract class GetDataRequest extends NetworkEnvelope implements ExtendedDataSizePermission {
protected final int nonce;
protected final Set<byte[]> excludedKeys;
Set<byte[]> getExcludedKeys();
public GetDataRequest(int messageVersion, int nonce, Set<byte[]> excludedKeys) {
super(messageVersion);
this.nonce = nonce;
this.excludedKeys = excludedKeys;
}
}

View File

@ -1,6 +1,7 @@
package io.bisq.network.p2p.peers.getdata.messages;
import io.bisq.common.app.Capabilities;
import io.bisq.common.app.Version;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.common.proto.network.NetworkProtoResolver;
import io.bisq.generated.protobuffer.PB;
@ -8,6 +9,7 @@ import io.bisq.network.p2p.ExtendedDataSizePermission;
import io.bisq.network.p2p.SupportedCapabilitiesMessage;
import io.bisq.network.p2p.storage.payload.ProtectedMailboxStorageEntry;
import io.bisq.network.p2p.storage.payload.ProtectedStorageEntry;
import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
@ -16,14 +18,24 @@ import java.util.HashSet;
import java.util.stream.Collectors;
@Slf4j
@EqualsAndHashCode(callSuper = true)
@Value
public final class GetDataResponse implements SupportedCapabilitiesMessage, ExtendedDataSizePermission {
public final class GetDataResponse extends NetworkEnvelope implements SupportedCapabilitiesMessage, ExtendedDataSizePermission {
private final HashSet<ProtectedStorageEntry> dataSet;
private final int requestNonce;
private final boolean isGetUpdatedDataResponse;
private final ArrayList<Integer> supportedCapabilities = Capabilities.getCapabilities();
public GetDataResponse(HashSet<ProtectedStorageEntry> dataSet, int requestNonce, boolean isGetUpdatedDataResponse) {
this(dataSet, requestNonce, isGetUpdatedDataResponse, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private GetDataResponse(HashSet<ProtectedStorageEntry> dataSet, int requestNonce, boolean isGetUpdatedDataResponse, int messageVersion) {
super(messageVersion);
this.dataSet = dataSet;
this.requestNonce = requestNonce;
this.isGetUpdatedDataResponse = isGetUpdatedDataResponse;
@ -31,7 +43,7 @@ public final class GetDataResponse implements SupportedCapabilitiesMessage, Exte
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setGetDataResponse(PB.GetDataResponse.newBuilder()
.addAllDataSet(dataSet.stream()
.map(protectedStorageEntry -> protectedStorageEntry instanceof ProtectedMailboxStorageEntry ?
@ -49,13 +61,14 @@ public final class GetDataResponse implements SupportedCapabilitiesMessage, Exte
.build();
}
public static GetDataResponse fromProto(PB.GetDataResponse proto, NetworkProtoResolver resolver) {
public static GetDataResponse fromProto(PB.GetDataResponse proto, NetworkProtoResolver resolver, int messageVersion) {
HashSet<ProtectedStorageEntry> dataSet = new HashSet<>(
proto.getDataSetList().stream()
.map(entry -> (ProtectedStorageEntry) resolver.fromProto(entry))
.collect(Collectors.toSet()));
return new GetDataResponse(dataSet,
proto.getRequestNonce(),
proto.getIsGetUpdatedDataResponse());
proto.getIsGetUpdatedDataResponse(),
messageVersion);
}
}

View File

@ -1,11 +1,12 @@
package io.bisq.network.p2p.peers.getdata.messages;
import com.google.protobuf.ByteString;
import io.bisq.common.app.Version;
import io.bisq.common.proto.ProtoUtil;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.NodeAddress;
import io.bisq.network.p2p.SendersNodeAddressMessage;
import lombok.EqualsAndHashCode;
import lombok.Value;
import java.util.Set;
@ -13,22 +14,39 @@ import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
@EqualsAndHashCode(callSuper = true)
@Value
public final class GetUpdatedDataRequest implements SendersNodeAddressMessage, GetDataRequest {
public final class GetUpdatedDataRequest extends GetDataRequest implements SendersNodeAddressMessage {
private final NodeAddress senderNodeAddress;
private final int nonce;
private final Set<byte[]> excludedKeys;
public GetUpdatedDataRequest(NodeAddress senderNodeAddress, int nonce, Set<byte[]> excludedKeys) {
public GetUpdatedDataRequest(NodeAddress senderNodeAddress,
int nonce,
Set<byte[]> excludedKeys) {
this(senderNodeAddress,
nonce,
excludedKeys,
Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private GetUpdatedDataRequest(NodeAddress senderNodeAddress,
int nonce,
Set<byte[]> excludedKeys,
int messageVersion) {
super(messageVersion,
nonce,
excludedKeys);
checkNotNull(senderNodeAddress, "senderNodeAddress must not be null at GetUpdatedDataRequest");
this.senderNodeAddress = senderNodeAddress;
this.nonce = nonce;
this.excludedKeys = excludedKeys;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setGetUpdatedDataRequest(PB.GetUpdatedDataRequest.newBuilder()
.setSenderNodeAddress(senderNodeAddress.toProtoMessage())
.setNonce(nonce)
@ -38,9 +56,10 @@ public final class GetUpdatedDataRequest implements SendersNodeAddressMessage, G
.build();
}
public static GetUpdatedDataRequest fromProto(PB.GetUpdatedDataRequest proto) {
public static GetUpdatedDataRequest fromProto(PB.GetUpdatedDataRequest proto, int messageVersion) {
return new GetUpdatedDataRequest(NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getNonce(),
ProtoUtil.byteSetFromProtoByteStringList(proto.getExcludedKeysList()));
ProtoUtil.byteSetFromProtoByteStringList(proto.getExcludedKeysList()),
messageVersion);
}
}

View File

@ -2,32 +2,40 @@ package io.bisq.network.p2p.peers.getdata.messages;
import com.google.protobuf.ByteString;
import io.bisq.common.app.Capabilities;
import io.bisq.common.app.Version;
import io.bisq.common.proto.ProtoUtil;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.AnonymousMessage;
import io.bisq.network.p2p.SupportedCapabilitiesMessage;
import lombok.EqualsAndHashCode;
import lombok.Value;
import java.util.ArrayList;
import java.util.Set;
import java.util.stream.Collectors;
@EqualsAndHashCode(callSuper = true)
@Value
public final class PreliminaryGetDataRequest implements AnonymousMessage, GetDataRequest, SupportedCapabilitiesMessage {
private final int nonce;
private final Set<byte[]> excludedKeys;
public final class PreliminaryGetDataRequest extends GetDataRequest implements AnonymousMessage, SupportedCapabilitiesMessage {
// ordinals of enum
private final ArrayList<Integer> supportedCapabilities = Capabilities.getCapabilities();
public PreliminaryGetDataRequest(int nonce, Set<byte[]> excludedKeys) {
this.nonce = nonce;
this.excludedKeys = excludedKeys;
this(nonce, excludedKeys, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private PreliminaryGetDataRequest(int nonce, Set<byte[]> excludedKeys, int messageVersion) {
super(messageVersion, nonce, excludedKeys);
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setPreliminaryGetDataRequest(PB.PreliminaryGetDataRequest.newBuilder()
.setNonce(nonce)
.addAllExcludedKeys(excludedKeys.stream()
@ -37,8 +45,9 @@ public final class PreliminaryGetDataRequest implements AnonymousMessage, GetDat
.build();
}
public static PreliminaryGetDataRequest fromProto(PB.PreliminaryGetDataRequest proto) {
public static PreliminaryGetDataRequest fromProto(PB.PreliminaryGetDataRequest proto, int messageVersion) {
return new PreliminaryGetDataRequest(proto.getNonce(),
ProtoUtil.byteSetFromProtoByteStringList(proto.getExcludedKeysList()));
ProtoUtil.byteSetFromProtoByteStringList(proto.getExcludedKeysList()),
messageVersion);
}
}

View File

@ -122,11 +122,11 @@ class KeepAliveHandler implements MessageListener {
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void onMessage(NetworkEnvelope wireEnvelope, Connection connection) {
if (wireEnvelope instanceof Pong) {
Log.traceCall(wireEnvelope.toString() + "\n\tconnection=" + connection);
public void onMessage(NetworkEnvelope networkEnvelop, Connection connection) {
if (networkEnvelop instanceof Pong) {
Log.traceCall(networkEnvelop.toString() + "\n\tconnection=" + connection);
if (!stopped) {
Pong pong = (Pong) wireEnvelope;
Pong pong = (Pong) networkEnvelop;
if (pong.getRequestNonce() == nonce) {
int roundTripTime = (int) (System.currentTimeMillis() - sendTs);
log.trace("roundTripTime=" + roundTripTime + "\n\tconnection=" + connection);

View File

@ -70,11 +70,11 @@ public class KeepAliveManager implements MessageListener, ConnectionListener, Pe
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void onMessage(NetworkEnvelope wireEnvelope, Connection connection) {
if (wireEnvelope instanceof Ping) {
Log.traceCall(wireEnvelope.toString() + "\n\tconnection=" + connection);
public void onMessage(NetworkEnvelope networkEnvelop, Connection connection) {
if (networkEnvelop instanceof Ping) {
Log.traceCall(networkEnvelop.toString() + "\n\tconnection=" + connection);
if (!stopped) {
Ping ping = (Ping) wireEnvelope;
Ping ping = (Ping) networkEnvelop;
// We get from peer last measured rrt
connection.getStatistic().setRoundTripTime(ping.getLastRoundTripTime());

View File

@ -1,6 +1,4 @@
package io.bisq.network.p2p.peers.keepalive.messages;
import io.bisq.common.proto.network.NetworkEnvelope;
public interface KeepAliveMessage extends NetworkEnvelope {
public interface KeepAliveMessage {
}

View File

@ -1,29 +1,42 @@
package io.bisq.network.p2p.peers.keepalive.messages;
import io.bisq.common.app.Version;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.generated.protobuffer.PB;
import lombok.EqualsAndHashCode;
import lombok.Value;
@EqualsAndHashCode(callSuper = true)
@Value
public final class Ping implements KeepAliveMessage {
public final class Ping extends NetworkEnvelope implements KeepAliveMessage {
private final int nonce;
private final int lastRoundTripTime;
public Ping(int nonce, int lastRoundTripTime) {
this(nonce, lastRoundTripTime, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private Ping(int nonce, int lastRoundTripTime, int messageVersion) {
super(messageVersion);
this.nonce = nonce;
this.lastRoundTripTime = lastRoundTripTime;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setPing(PB.Ping.newBuilder()
.setNonce(nonce)
.setLastRoundTripTime(lastRoundTripTime))
.build();
}
public static Ping fromProto(PB.Ping proto) {
return new Ping(proto.getNonce(), proto.getLastRoundTripTime());
public static Ping fromProto(PB.Ping proto, int messageVersion) {
return new Ping(proto.getNonce(), proto.getLastRoundTripTime(), messageVersion);
}
}

View File

@ -1,26 +1,39 @@
package io.bisq.network.p2p.peers.keepalive.messages;
import io.bisq.common.app.Version;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.generated.protobuffer.PB;
import lombok.EqualsAndHashCode;
import lombok.Value;
@EqualsAndHashCode(callSuper = true)
@Value
public final class Pong implements KeepAliveMessage {
public final class Pong extends NetworkEnvelope implements KeepAliveMessage {
private final int requestNonce;
public Pong(int requestNonce) {
this(requestNonce, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private Pong(int requestNonce, int messageVersion) {
super(messageVersion);
this.requestNonce = requestNonce;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setPong(PB.Pong.newBuilder()
.setRequestNonce(requestNonce))
.build();
}
public static Pong fromProto(PB.Pong proto) {
return new Pong(proto.getRequestNonce());
public static Pong fromProto(PB.Pong proto, int messageVersion) {
return new Pong(proto.getRequestNonce(), messageVersion);
}
}

View File

@ -146,11 +146,11 @@ class PeerExchangeHandler implements MessageListener {
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void onMessage(NetworkEnvelope wireEnvelope, Connection connection) {
if (wireEnvelope instanceof GetPeersResponse) {
public void onMessage(NetworkEnvelope networkEnvelop, Connection connection) {
if (networkEnvelop instanceof GetPeersResponse) {
if (!stopped) {
Log.traceCall(wireEnvelope.toString() + "\n\tconnection=" + connection);
GetPeersResponse getPeersResponse = (GetPeersResponse) wireEnvelope;
Log.traceCall(networkEnvelop.toString() + "\n\tconnection=" + connection);
GetPeersResponse getPeersResponse = (GetPeersResponse) networkEnvelop;
if (peerManager.isSeedNode(connection))
connection.setPeerType(Connection.PeerType.SEED_NODE);

View File

@ -144,9 +144,9 @@ public class PeerExchangeManager implements MessageListener, ConnectionListener,
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void onMessage(NetworkEnvelope wireEnvelope, Connection connection) {
if (wireEnvelope instanceof GetPeersRequest) {
Log.traceCall(wireEnvelope.toString() + "\n\tconnection=" + connection);
public void onMessage(NetworkEnvelope networkEnvelop, Connection connection) {
if (networkEnvelop instanceof GetPeersRequest) {
Log.traceCall(networkEnvelop.toString() + "\n\tconnection=" + connection);
if (!stopped) {
if (peerManager.isSeedNode(connection))
connection.setPeerType(Connection.PeerType.SEED_NODE);
@ -166,7 +166,7 @@ public class PeerExchangeManager implements MessageListener, ConnectionListener,
peerManager.handleConnectionFault(connection);
}
});
getPeersRequestHandler.handle((GetPeersRequest) wireEnvelope, connection);
getPeersRequestHandler.handle((GetPeersRequest) networkEnvelop, connection);
} else {
log.warn("We have stopped already. We ignore that onMessage call.");
}

View File

@ -1,12 +1,14 @@
package io.bisq.network.p2p.peers.peerexchange.messages;
import io.bisq.common.app.Capabilities;
import io.bisq.common.app.Version;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.NodeAddress;
import io.bisq.network.p2p.SendersNodeAddressMessage;
import io.bisq.network.p2p.SupportedCapabilitiesMessage;
import io.bisq.network.p2p.peers.peerexchange.Peer;
import lombok.EqualsAndHashCode;
import lombok.Value;
import java.util.ArrayList;
@ -15,14 +17,25 @@ import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
@EqualsAndHashCode(callSuper = true)
@Value
public final class GetPeersRequest implements PeerExchangeMessage, SendersNodeAddressMessage, SupportedCapabilitiesMessage {
public final class GetPeersRequest extends NetworkEnvelope implements PeerExchangeMessage, SendersNodeAddressMessage, SupportedCapabilitiesMessage {
private final NodeAddress senderNodeAddress;
private final int nonce;
private final HashSet<Peer> reportedPeers;
private final ArrayList<Integer> supportedCapabilities = Capabilities.getCapabilities();
public GetPeersRequest(NodeAddress senderNodeAddress, int nonce, HashSet<Peer> reportedPeers) {
this(senderNodeAddress, nonce, reportedPeers, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private GetPeersRequest(NodeAddress senderNodeAddress, int nonce, HashSet<Peer> reportedPeers, int messageVersion) {
super(messageVersion);
checkNotNull(senderNodeAddress, "senderNodeAddress must not be null at GetPeersRequest");
this.senderNodeAddress = senderNodeAddress;
this.nonce = nonce;
@ -31,7 +44,7 @@ public final class GetPeersRequest implements PeerExchangeMessage, SendersNodeAd
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setGetPeersRequest(PB.GetPeersRequest.newBuilder()
.setSenderNodeAddress(senderNodeAddress.toProtoMessage())
.setNonce(nonce)
@ -42,11 +55,12 @@ public final class GetPeersRequest implements PeerExchangeMessage, SendersNodeAd
.build();
}
public static GetPeersRequest fromProto(PB.GetPeersRequest proto) {
public static GetPeersRequest fromProto(PB.GetPeersRequest proto, int messageVersion) {
return new GetPeersRequest(NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getNonce(),
new HashSet<>(proto.getReportedPeersList().stream()
.map(Peer::fromProto)
.collect(Collectors.toSet())));
.collect(Collectors.toSet())),
messageVersion);
}
}

View File

@ -1,31 +1,44 @@
package io.bisq.network.p2p.peers.peerexchange.messages;
import io.bisq.common.app.Capabilities;
import io.bisq.common.app.Version;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.NodeAddress;
import io.bisq.network.p2p.SupportedCapabilitiesMessage;
import io.bisq.network.p2p.peers.peerexchange.Peer;
import lombok.EqualsAndHashCode;
import lombok.Value;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.stream.Collectors;
@EqualsAndHashCode(callSuper = true)
@Value
public final class GetPeersResponse implements PeerExchangeMessage, SupportedCapabilitiesMessage {
public final class GetPeersResponse extends NetworkEnvelope implements PeerExchangeMessage, SupportedCapabilitiesMessage {
private final int requestNonce;
private final HashSet<Peer> reportedPeers;
private final ArrayList<Integer> supportedCapabilities = Capabilities.getCapabilities();
public GetPeersResponse(int requestNonce, HashSet<Peer> reportedPeers) {
this(requestNonce, reportedPeers, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private GetPeersResponse(int requestNonce, HashSet<Peer> reportedPeers, int messageVersion) {
super(messageVersion);
this.requestNonce = requestNonce;
this.reportedPeers = reportedPeers;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setGetPeersResponse(PB.GetPeersResponse.newBuilder()
.setRequestNonce(requestNonce)
.addAllReportedPeers(reportedPeers.stream()
@ -35,13 +48,13 @@ public final class GetPeersResponse implements PeerExchangeMessage, SupportedCap
.build();
}
public static GetPeersResponse fromProto(PB.GetPeersResponse getPeersResponse) {
public static GetPeersResponse fromProto(PB.GetPeersResponse getPeersResponse, int messageVersion) {
HashSet<Peer> reportedPeers = new HashSet<>(
getPeersResponse.getReportedPeersList()
.stream()
.map(peer -> new Peer(new NodeAddress(peer.getNodeAddress().getHostName(),
peer.getNodeAddress().getPort())))
.collect(Collectors.toList()));
return new GetPeersResponse(getPeersResponse.getRequestNonce(), reportedPeers);
return new GetPeersResponse(getPeersResponse.getRequestNonce(), reportedPeers, messageVersion);
}
}

View File

@ -1,6 +1,4 @@
package io.bisq.network.p2p.peers.peerexchange.messages;
import io.bisq.common.proto.network.NetworkEnvelope;
public interface PeerExchangeMessage extends NetworkEnvelope {
public interface PeerExchangeMessage {
}

View File

@ -173,18 +173,18 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void onMessage(NetworkEnvelope wireEnvelope, Connection connection) {
if (wireEnvelope instanceof BroadcastMessage) {
Log.traceCall(Utilities.toTruncatedString(wireEnvelope) + "\n\tconnection=" + connection);
public void onMessage(NetworkEnvelope networkEnvelop, Connection connection) {
if (networkEnvelop instanceof BroadcastMessage) {
Log.traceCall(Utilities.toTruncatedString(networkEnvelop) + "\n\tconnection=" + connection);
connection.getPeersNodeAddressOptional().ifPresent(peersNodeAddress -> {
if (wireEnvelope instanceof AddDataMessage) {
add(((AddDataMessage) wireEnvelope).getProtectedStorageEntry(), peersNodeAddress, null, false);
} else if (wireEnvelope instanceof RemoveDataMessage) {
remove(((RemoveDataMessage) wireEnvelope).getProtectedStorageEntry(), peersNodeAddress, false);
} else if (wireEnvelope instanceof RemoveMailboxDataMessage) {
removeMailboxData(((RemoveMailboxDataMessage) wireEnvelope).getProtectedMailboxStorageEntry(), peersNodeAddress, false);
} else if (wireEnvelope instanceof RefreshOfferMessage) {
refreshTTL((RefreshOfferMessage) wireEnvelope, peersNodeAddress, false);
if (networkEnvelop instanceof AddDataMessage) {
add(((AddDataMessage) networkEnvelop).getProtectedStorageEntry(), peersNodeAddress, null, false);
} else if (networkEnvelop instanceof RemoveDataMessage) {
remove(((RemoveDataMessage) networkEnvelop).getProtectedStorageEntry(), peersNodeAddress, false);
} else if (networkEnvelop instanceof RemoveMailboxDataMessage) {
removeMailboxData(((RemoveMailboxDataMessage) networkEnvelop).getProtectedMailboxStorageEntry(), peersNodeAddress, false);
} else if (networkEnvelop instanceof RefreshOfferMessage) {
refreshTTL((RefreshOfferMessage) networkEnvelop, peersNodeAddress, false);
}
});
}

View File

@ -1,7 +1,7 @@
package io.bisq.network.p2p.storage.messages;
import com.google.protobuf.Message;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.common.app.Version;
import io.bisq.common.proto.network.NetworkProtoResolver;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.storage.payload.ProtectedMailboxStorageEntry;
@ -15,6 +15,16 @@ public final class AddDataMessage extends BroadcastMessage {
private final ProtectedStorageEntry protectedStorageEntry;
public AddDataMessage(ProtectedStorageEntry protectedStorageEntry) {
this(protectedStorageEntry, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private AddDataMessage(ProtectedStorageEntry protectedStorageEntry, int messageVersion) {
super(messageVersion);
this.protectedStorageEntry = protectedStorageEntry;
}
@ -27,13 +37,13 @@ public final class AddDataMessage extends BroadcastMessage {
else
builder.setProtectedStorageEntry((PB.ProtectedStorageEntry) message);
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setAddDataMessage(PB.AddDataMessage.newBuilder()
.setEntry(builder))
.build();
}
public static AddDataMessage fromProto(PB.AddDataMessage proto, NetworkProtoResolver resolver) {
return new AddDataMessage((ProtectedStorageEntry) resolver.fromProto(proto.getEntry()));
public static AddDataMessage fromProto(PB.AddDataMessage proto, NetworkProtoResolver resolver, int messageVersion) {
return new AddDataMessage((ProtectedStorageEntry) resolver.fromProto(proto.getEntry()), messageVersion);
}
}

View File

@ -1,6 +1,11 @@
package io.bisq.network.p2p.storage.messages;
import io.bisq.common.proto.network.NetworkEnvelope;
import lombok.EqualsAndHashCode;
public abstract class BroadcastMessage implements NetworkEnvelope {
@EqualsAndHashCode(callSuper = true)
public abstract class BroadcastMessage extends NetworkEnvelope {
protected BroadcastMessage(int messageVersion) {
super(messageVersion);
}
}

View File

@ -1,7 +1,7 @@
package io.bisq.network.p2p.storage.messages;
import com.google.protobuf.ByteString;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.common.app.Version;
import io.bisq.generated.protobuffer.PB;
import lombok.EqualsAndHashCode;
import lombok.Value;
@ -18,6 +18,20 @@ public final class RefreshOfferMessage extends BroadcastMessage {
byte[] signature,
byte[] hashOfPayload,
int sequenceNumber) {
this(hashOfDataAndSeqNr, signature, hashOfPayload, sequenceNumber, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private RefreshOfferMessage(byte[] hashOfDataAndSeqNr,
byte[] signature,
byte[] hashOfPayload,
int sequenceNumber,
int messageVersion) {
super(messageVersion);
this.hashOfDataAndSeqNr = hashOfDataAndSeqNr;
this.signature = signature;
this.hashOfPayload = hashOfPayload;
@ -26,7 +40,7 @@ public final class RefreshOfferMessage extends BroadcastMessage {
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setRefreshOfferMessage(PB.RefreshOfferMessage.newBuilder()
.setHashOfDataAndSeqNr(ByteString.copyFrom(hashOfDataAndSeqNr))
.setSignature(ByteString.copyFrom(signature))
@ -35,10 +49,11 @@ public final class RefreshOfferMessage extends BroadcastMessage {
.build();
}
public static RefreshOfferMessage fromProto(PB.RefreshOfferMessage proto) {
public static RefreshOfferMessage fromProto(PB.RefreshOfferMessage proto, int messageVersion) {
return new RefreshOfferMessage(proto.getHashOfDataAndSeqNr().toByteArray(),
proto.getSignature().toByteArray(),
proto.getHashOfPayload().toByteArray(),
proto.getSequenceNumber());
proto.getSequenceNumber(),
messageVersion);
}
}

View File

@ -1,6 +1,6 @@
package io.bisq.network.p2p.storage.messages;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.common.app.Version;
import io.bisq.common.proto.network.NetworkProtoResolver;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.storage.payload.ProtectedStorageEntry;
@ -13,18 +13,29 @@ public final class RemoveDataMessage extends BroadcastMessage {
private final ProtectedStorageEntry protectedStorageEntry;
public RemoveDataMessage(ProtectedStorageEntry protectedStorageEntry) {
this(protectedStorageEntry, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private RemoveDataMessage(ProtectedStorageEntry protectedStorageEntry,
int messageVersion) {
super(messageVersion);
this.protectedStorageEntry = protectedStorageEntry;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setRemoveDataMessage(PB.RemoveDataMessage.newBuilder()
.setProtectedStorageEntry((PB.ProtectedStorageEntry) protectedStorageEntry.toProtoMessage()))
.build();
}
public static RemoveDataMessage fromProto(PB.RemoveDataMessage proto, NetworkProtoResolver resolver) {
return new RemoveDataMessage(ProtectedStorageEntry.fromProto(proto.getProtectedStorageEntry(), resolver));
public static RemoveDataMessage fromProto(PB.RemoveDataMessage proto, NetworkProtoResolver resolver, int messageVersion) {
return new RemoveDataMessage(ProtectedStorageEntry.fromProto(proto.getProtectedStorageEntry(), resolver), messageVersion);
}
}

View File

@ -1,6 +1,6 @@
package io.bisq.network.p2p.storage.messages;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.common.app.Version;
import io.bisq.common.proto.network.NetworkProtoResolver;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.storage.payload.ProtectedMailboxStorageEntry;
@ -13,18 +13,29 @@ public final class RemoveMailboxDataMessage extends BroadcastMessage {
private final ProtectedMailboxStorageEntry protectedMailboxStorageEntry;
public RemoveMailboxDataMessage(ProtectedMailboxStorageEntry protectedMailboxStorageEntry) {
this(protectedMailboxStorageEntry, Version.getP2PMessageVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private RemoveMailboxDataMessage(ProtectedMailboxStorageEntry protectedMailboxStorageEntry,
int messageVersion) {
super(messageVersion);
this.protectedMailboxStorageEntry = protectedMailboxStorageEntry;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
return getNetworkEnvelopeBuilder()
.setRemoveMailboxDataMessage(PB.RemoveMailboxDataMessage.newBuilder()
.setProtectedStorageEntry(protectedMailboxStorageEntry.toProtoMessage()))
.build();
}
public static RemoveMailboxDataMessage fromProto(PB.RemoveMailboxDataMessage proto, NetworkProtoResolver resolver) {
return new RemoveMailboxDataMessage(ProtectedMailboxStorageEntry.fromProto(proto.getProtectedStorageEntry(), resolver));
public static RemoveMailboxDataMessage fromProto(PB.RemoveMailboxDataMessage proto, NetworkProtoResolver resolver, int messageVersion) {
return new RemoveMailboxDataMessage(ProtectedMailboxStorageEntry.fromProto(proto.getProtectedStorageEntry(), resolver), messageVersion);
}
}

View File

@ -79,7 +79,7 @@ public final class MailboxStoragePayload implements StoragePayload {
public static MailboxStoragePayload fromProto(PB.MailboxStoragePayload proto) {
return new MailboxStoragePayload(
PrefixedSealedAndSignedMessage.fromProto(proto.getPrefixedSealedAndSignedMessage()),
PrefixedSealedAndSignedMessage.fromPayloadProto(proto.getPrefixedSealedAndSignedMessage()),
proto.getSenderPubKeyForAddOperationBytes().toByteArray(),
proto.getOwnerPubKeyBytes().toByteArray(),
CollectionUtils.isEmpty(proto.getExtraDataMap()) ? null : proto.getExtraDataMap());

Binary file not shown.

View File

@ -119,10 +119,11 @@ public class EncryptionServiceTests {
log.trace("took " + (System.currentTimeMillis() - ts) + " ms.");
}*/
private static class MockMessage implements NetworkEnvelope {
private static class MockMessage extends NetworkEnvelope {
public final int nonce;
public MockMessage(int nonce) {
super(0);
this.nonce = nonce;
}

View File

@ -154,7 +154,7 @@ public class TestUtils {
}
@Override
public NetworkPayload fromProto(PB.StoragePayload storagePayload) {
public NetworkPayload fromProto(PB.StoragePayload proto) {
return null;
}

View File

@ -1,17 +1,20 @@
package io.bisq.network.p2p.mocks;
import io.bisq.common.app.Version;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.MailboxMessage;
import io.bisq.network.p2p.NodeAddress;
import io.bisq.network.p2p.storage.payload.ExpirablePayload;
import lombok.EqualsAndHashCode;
import lombok.Value;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import java.util.UUID;
@EqualsAndHashCode(callSuper = true)
@Value
public final class MockMailboxPayload implements MailboxMessage, ExpirablePayload {
public final class MockMailboxPayload extends NetworkEnvelope implements MailboxMessage, ExpirablePayload {
private final int messageVersion = Version.getP2PMessageVersion();
public final String msg;
public final NodeAddress senderNodeAddress;
@ -19,6 +22,7 @@ public final class MockMailboxPayload implements MailboxMessage, ExpirablePayloa
private final String uid;
public MockMailboxPayload(String msg, NodeAddress senderNodeAddress) {
super(0);
this.msg = msg;
this.senderNodeAddress = senderNodeAddress;
uid = UUID.randomUUID().toString();

View File

@ -7,12 +7,13 @@ import io.bisq.network.p2p.storage.payload.ExpirablePayload;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
@SuppressWarnings("ALL")
public final class MockPayload implements NetworkEnvelope, ExpirablePayload {
public final class MockPayload extends NetworkEnvelope implements ExpirablePayload {
public final String msg;
public long ttl;
private final int messageVersion = Version.getP2PMessageVersion();
public MockPayload(String msg) {
super(0);
this.msg = msg;
}

View File

@ -6,14 +6,15 @@ import io.bisq.common.app.Version;
import io.bisq.common.crypto.KeyRing;
import io.bisq.common.crypto.KeyStorage;
import io.bisq.common.crypto.PubKeyRing;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.common.util.Tuple3;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.crypto.EncryptionService;
import io.bisq.network.p2p.*;
import io.bisq.network.p2p.messaging.DecryptedMailboxListener;
import io.bisq.network.p2p.seed.SeedNodesRepository;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import lombok.EqualsAndHashCode;
import lombok.Value;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.jetbrains.annotations.NotNull;
@ -25,7 +26,6 @@ import org.junit.runner.JUnitCore;
import org.junit.runner.Request;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import java.io.File;
import java.io.IOException;
@ -558,9 +558,9 @@ public class NetworkStressTest {
// Make the peer ready for receiving direct network_messages.
srcPeer.addDecryptedDirectMessageListener((decryptedDirectMessageListener, peerNodeAddress) -> {
if (!(decryptedDirectMessageListener.getWireEnvelope() instanceof StressTestDirectMessage))
if (!(decryptedDirectMessageListener.getNetworkEnvelope() instanceof StressTestDirectMessage))
return;
StressTestDirectMessage directMessage = (StressTestDirectMessage) (decryptedDirectMessageListener.getWireEnvelope());
StressTestDirectMessage directMessage = (StressTestDirectMessage) (decryptedDirectMessageListener.getNetworkEnvelope());
if ((directMessage.getData().equals("test/" + srcPeerAddress)))
receivedDirectLatch.countDown();
});
@ -742,9 +742,9 @@ public class NetworkStressTest {
private void addMailboxListeners(P2PService peer, CountDownLatch receivedMailboxLatch) {
class MailboxMessageListener implements DecryptedDirectMessageListener, DecryptedMailboxListener {
private void handle(DecryptedMessageWithPubKey decryptedMessageWithPubKey) {
if (!(decryptedMessageWithPubKey.getWireEnvelope() instanceof StressTestMailboxMessage))
if (!(decryptedMessageWithPubKey.getNetworkEnvelope() instanceof StressTestMailboxMessage))
return;
StressTestMailboxMessage msg = (StressTestMailboxMessage) (decryptedMessageWithPubKey.getWireEnvelope());
StressTestMailboxMessage msg = (StressTestMailboxMessage) (decryptedMessageWithPubKey.getNetworkEnvelope());
if ((msg.getData().equals("test/" + peer.getAddress())))
countDownAndPrint(receivedMailboxLatch, 'm');
}
@ -808,44 +808,32 @@ public class NetworkStressTest {
// # MESSAGE CLASSES
final class StressTestDirectMessage implements DirectMessage {
final class StressTestDirectMessage extends NetworkEnvelope implements DirectMessage {
private final int messageVersion = Version.getP2PMessageVersion();
private final String data;
StressTestDirectMessage(String data) {
super(0);
this.data = data;
}
@Override
public int getMessageVersion() {
return messageVersion;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
throw new NotImplementedException();
}
String getData() {
return data;
}
}
@EqualsAndHashCode(callSuper = true)
@Value
final class StressTestMailboxMessage implements MailboxMessage {
final class StressTestMailboxMessage extends NetworkEnvelope implements MailboxMessage {
private final int messageVersion = Version.getP2PMessageVersion();
private final String uid = UUID.randomUUID().toString();
private final NodeAddress senderNodeAddress;
private final String data;
StressTestMailboxMessage(NodeAddress sender, String data) {
super(0);
this.senderNodeAddress = sender;
this.data = data;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
throw new NotImplementedException();
}
}