Add supportedCapabilities

This commit is contained in:
Manfred Karrer 2016-07-23 15:00:38 +02:00
parent 4d39364772
commit 8e34eea62f
16 changed files with 181 additions and 2 deletions

View File

@ -6,6 +6,8 @@ import io.bitsquare.p2p.messaging.MailboxMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.UUID;
public class PrivateNotificationMessage implements MailboxMessage {
@ -16,6 +18,14 @@ public class PrivateNotificationMessage implements MailboxMessage {
public PrivateNotification privateNotification;
private final String uid = UUID.randomUUID().toString();
private final int messageVersion = Version.getP2PMessageVersion();
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
return supportedCapabilities;
}
public PrivateNotificationMessage(PrivateNotification privateNotification, NodeAddress myNodeAddress) {
this.myNodeAddress = myNodeAddress;

View File

@ -20,10 +20,21 @@ package io.bitsquare.arbitration.messages;
import io.bitsquare.app.Version;
import io.bitsquare.p2p.messaging.MailboxMessage;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.UUID;
public abstract class DisputeMessage implements MailboxMessage {
private final int messageVersion = Version.getP2PMessageVersion();
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
return supportedCapabilities;
}
private final String uid = UUID.randomUUID().toString();
@Override

View File

@ -20,7 +20,9 @@ package io.bitsquare.trade.protocol.availability.messages;
import io.bitsquare.app.Version;
import io.bitsquare.p2p.messaging.DirectMessage;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import java.util.ArrayList;
@Immutable
public abstract class OfferMessage implements DirectMessage {
@ -28,6 +30,15 @@ public abstract class OfferMessage implements DirectMessage {
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
private final int messageVersion = Version.getP2PMessageVersion();
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
return supportedCapabilities;
}
public final String offerId;
OfferMessage(String offerId) {

View File

@ -20,7 +20,9 @@ package io.bitsquare.trade.protocol.trade.messages;
import io.bitsquare.app.Version;
import io.bitsquare.p2p.messaging.DirectMessage;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import java.util.ArrayList;
@Immutable
public abstract class TradeMessage implements DirectMessage {
@ -28,6 +30,15 @@ public abstract class TradeMessage implements DirectMessage {
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
private final int messageVersion = Version.getP2PMessageVersion();
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
return supportedCapabilities;
}
public final String tradeId;
@Override

View File

@ -1,7 +1,12 @@
package io.bitsquare.p2p;
import javax.annotation.Nullable;
import java.io.Serializable;
import java.util.ArrayList;
public interface Message extends Serializable {
int getMessageVersion();
@Nullable
ArrayList<Integer> getSupportedCapabilities();
}

View File

@ -5,6 +5,8 @@ import io.bitsquare.common.crypto.SealedAndSigned;
import io.bitsquare.p2p.NodeAddress;
import io.bitsquare.p2p.network.messages.SendersNodeAddressMessage;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.UUID;
@ -15,6 +17,15 @@ public final class PrefixedSealedAndSignedMessage implements MailboxMessage, Sen
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
private final int messageVersion = Version.getP2PMessageVersion();
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
return supportedCapabilities;
}
private final NodeAddress senderNodeAddress;
public final SealedAndSigned sealedAndSigned;
public final byte[] addressPrefixHash;

View File

@ -3,13 +3,26 @@ package io.bitsquare.p2p.network.messages;
import io.bitsquare.app.Version;
import io.bitsquare.p2p.Message;
import javax.annotation.Nullable;
import java.util.ArrayList;
public final class CloseConnectionMessage implements Message {
// That object is sent over the wire, so we need to take care of version compatibility.
// We dont use the Version.NETWORK_PROTOCOL_VERSION here as we report also compatibility issues and
// a changed version would render that message invalid as well, so the peer cannot get notified about the problem.
private static final long serialVersionUID = 0;
private final int messageVersion = Version.getP2PMessageVersion();
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
return supportedCapabilities;
}
public final String reason;
public CloseConnectionMessage(String reason) {

View File

@ -4,12 +4,22 @@ import io.bitsquare.app.Version;
import io.bitsquare.p2p.Message;
import io.bitsquare.p2p.storage.storageentry.ProtectedStorageEntry;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashSet;
public final class GetDataResponse implements Message {
// That object is sent over the wire, so we need to take care of version compatibility.
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
private final int messageVersion = Version.getP2PMessageVersion();
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
return supportedCapabilities;
}
public final HashSet<ProtectedStorageEntry> dataSet;
public final int requestNonce;

View File

@ -3,11 +3,23 @@ package io.bitsquare.p2p.peers.getdata.messages;
import io.bitsquare.app.Version;
import io.bitsquare.p2p.network.messages.AnonymousMessage;
import javax.annotation.Nullable;
import java.util.ArrayList;
public final class PreliminaryGetDataRequest implements AnonymousMessage, GetDataRequest {
// That object is sent over the wire, so we need to take care of version compatibility.
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
private final int messageVersion = Version.getP2PMessageVersion();
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
return supportedCapabilities;
}
private final int nonce;
public PreliminaryGetDataRequest(int nonce) {

View File

@ -3,10 +3,24 @@ package io.bitsquare.p2p.peers.keepalive.messages;
import io.bitsquare.app.Version;
import io.bitsquare.p2p.Message;
import javax.annotation.Nullable;
import java.util.ArrayList;
public abstract class KeepAliveMessage implements Message {
private final int messageVersion = Version.getP2PMessageVersion();
@Override
public int getMessageVersion() {
return Version.getP2PMessageVersion();
return messageVersion;
}
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
return supportedCapabilities;
}
@Override

View File

@ -3,8 +3,19 @@ package io.bitsquare.p2p.peers.peerexchange.messages;
import io.bitsquare.app.Version;
import io.bitsquare.p2p.Message;
import javax.annotation.Nullable;
import java.util.ArrayList;
abstract class PeerExchangeMessage implements Message {
private final int messageVersion = Version.getP2PMessageVersion();
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
return supportedCapabilities;
}
@Override
public int getMessageVersion() {

View File

@ -3,8 +3,19 @@ package io.bitsquare.p2p.storage.messages;
import io.bitsquare.app.Version;
import io.bitsquare.p2p.Message;
import javax.annotation.Nullable;
import java.util.ArrayList;
public abstract class BroadcastMessage implements Message {
private final int messageVersion = Version.getP2PMessageVersion();
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
return supportedCapabilities;
}
@Override
public int getMessageVersion() {

View File

@ -17,7 +17,6 @@
package io.bitsquare.crypto;
import io.bitsquare.app.Version;
import io.bitsquare.common.crypto.*;
import io.bitsquare.p2p.NodeAddress;
@ -33,12 +32,14 @@ import org.junit.rules.ExpectedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.Security;
import java.security.cert.CertificateException;
import java.util.ArrayList;
import java.util.UUID;
import static org.junit.Assert.assertEquals;
@ -85,6 +86,15 @@ public class EncryptionServiceTests {
final class TestMessage implements MailboxMessage {
public String data = "test";
private final int messageVersion = Version.getP2PMessageVersion();
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
return supportedCapabilities;
}
private String uid;
public TestMessage(String data) {

View File

@ -5,10 +5,21 @@ import io.bitsquare.p2p.NodeAddress;
import io.bitsquare.p2p.messaging.MailboxMessage;
import io.bitsquare.p2p.storage.payload.ExpirablePayload;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.UUID;
public final class MockMailboxPayload implements MailboxMessage, ExpirablePayload {
private final int messageVersion = Version.getP2PMessageVersion();
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
return supportedCapabilities;
}
public final String msg;
public final NodeAddress senderNodeAddress;
public long ttl;

View File

@ -4,10 +4,21 @@ import io.bitsquare.app.Version;
import io.bitsquare.p2p.Message;
import io.bitsquare.p2p.storage.payload.ExpirablePayload;
import javax.annotation.Nullable;
import java.util.ArrayList;
public final class MockPayload implements Message, ExpirablePayload {
public final String msg;
public long ttl;
private final int messageVersion = Version.getP2PMessageVersion();
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
return supportedCapabilities;
}
public MockPayload(String msg) {
this.msg = msg;

View File

@ -24,6 +24,7 @@ import org.junit.runner.Request;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.nio.file.*;
@ -827,6 +828,14 @@ public class NetworkStressTest {
final class StressTestDirectMessage implements DirectMessage {
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
private final int messageVersion = Version.getP2PMessageVersion();
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
return supportedCapabilities;
}
private String data;
@ -847,6 +856,14 @@ final class StressTestDirectMessage implements DirectMessage {
final class StressTestMailboxMessage implements MailboxMessage {
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
private final int messageVersion = Version.getP2PMessageVersion();
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
return supportedCapabilities;
}
private final String uid = UUID.randomUUID().toString();
private NodeAddress senderNodeAddress;