mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-19 07:15:54 -04:00
Add support for btc network version for p2p network messages
This commit is contained in:
parent
7c4bf8680b
commit
09321c89b3
@ -42,4 +42,7 @@ public class Version {
|
||||
// compatible.
|
||||
public static final long PROTOCOL_VERSION = 1;
|
||||
|
||||
// The version for the bitcoin network (Mainnet = 0, TestNet = 1, Regtest = 2)
|
||||
public static int NETWORK_ID;
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class DisputeMailMessage implements DisputeMessage {
|
||||
public class DisputeMailMessage extends DisputeMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
transient private static final Logger log = LoggerFactory.getLogger(DisputeMailMessage.class);
|
||||
|
@ -17,7 +17,12 @@
|
||||
|
||||
package io.bitsquare.arbitration.messages;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.p2p.messaging.MailboxMessage;
|
||||
|
||||
public interface DisputeMessage extends MailboxMessage {
|
||||
public abstract class DisputeMessage implements MailboxMessage {
|
||||
@Override
|
||||
public int networkId() {
|
||||
return Version.NETWORK_ID;
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import io.bitsquare.app.Version;
|
||||
import io.bitsquare.arbitration.DisputeResult;
|
||||
import io.bitsquare.p2p.Address;
|
||||
|
||||
public class DisputeResultMessage implements DisputeMessage {
|
||||
public class DisputeResultMessage extends DisputeMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
@ -21,7 +21,7 @@ import io.bitsquare.app.Version;
|
||||
import io.bitsquare.arbitration.Dispute;
|
||||
import io.bitsquare.p2p.Address;
|
||||
|
||||
public class OpenNewDisputeMessage implements DisputeMessage {
|
||||
public class OpenNewDisputeMessage extends DisputeMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
@ -21,7 +21,7 @@ import io.bitsquare.app.Version;
|
||||
import io.bitsquare.arbitration.Dispute;
|
||||
import io.bitsquare.p2p.Address;
|
||||
|
||||
public class PeerOpenedDisputeMessage implements DisputeMessage {
|
||||
public class PeerOpenedDisputeMessage extends DisputeMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
public final Dispute dispute;
|
||||
|
@ -22,7 +22,7 @@ import io.bitsquare.p2p.Address;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class PeerPublishedPayoutTxMessage implements DisputeMessage {
|
||||
public class PeerPublishedPayoutTxMessage extends DisputeMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
@ -32,4 +32,9 @@ public abstract class OfferMessage implements MailMessage {
|
||||
protected OfferMessage(String offerId) {
|
||||
this.offerId = offerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int networkId() {
|
||||
return Version.NETWORK_ID;
|
||||
}
|
||||
}
|
||||
|
@ -48,4 +48,9 @@ public abstract class TradeMessage implements MailMessage {
|
||||
protected TradeMessage(String tradeId) {
|
||||
this.tradeId = tradeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int networkId() {
|
||||
return Version.NETWORK_ID;
|
||||
}
|
||||
}
|
||||
|
@ -132,6 +132,8 @@ public class BitsquareApp extends Application {
|
||||
injector = Guice.createInjector(bitsquareAppModule);
|
||||
injector.getInstance(InjectorViewFactory.class).setInjector(injector);
|
||||
|
||||
Version.NETWORK_ID = injector.getInstance(BitsquareEnvironment.class).getBitcoinNetwork().ordinal();
|
||||
|
||||
// load the main view and create the main scene
|
||||
CachingViewLoader viewLoader = injector.getInstance(CachingViewLoader.class);
|
||||
mainView = (MainView) viewLoader.load(MainView.class);
|
||||
|
@ -9,15 +9,8 @@
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<description>Cloned from http://sourceforge.net/projects/jsocks/</description>
|
||||
|
||||
<artifactId>jsocks</artifactId>
|
||||
|
||||
|
||||
<!-- <properties>
|
||||
<project.build.sourceEncoding>ASCII</project.build.sourceEncoding>
|
||||
</properties>-->
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
@ -25,36 +18,5 @@
|
||||
<version>1.5.11</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<!-- <build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src</directory>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-pmd-plugin</artifactId>
|
||||
<version>2.7.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>2.9.1</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>-->
|
||||
|
||||
</project>
|
@ -11,21 +11,4 @@
|
||||
|
||||
<artifactId>jtorctl</artifactId>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -19,4 +19,9 @@ public final class SealedAndSignedMessage implements MailboxMessage {
|
||||
public Address getSenderAddress() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int networkId() {
|
||||
return Version.NETWORK_ID;
|
||||
}
|
||||
}
|
||||
|
@ -3,5 +3,5 @@ package io.bitsquare.p2p;
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface Message extends Serializable {
|
||||
|
||||
int networkId();
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
||||
|
||||
// peer group
|
||||
peerGroup = new PeerGroup(networkNode, seedNodeAddresses);
|
||||
if (useLocalhost) PeerGroup.setSimulateAuthTorNode(2 * 1000);
|
||||
if (useLocalhost) PeerGroup.setSimulateAuthTorNode(2 * 100);
|
||||
|
||||
// storage
|
||||
dataStorage = new ProtectedExpirableDataStorage(peerGroup, storageDir);
|
||||
|
@ -34,6 +34,11 @@ public final class DecryptedMsgWithPubKey implements MailMessage {
|
||||
this.signaturePubKey = signaturePubKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int networkId() {
|
||||
return Version.NETWORK_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -3,6 +3,7 @@ package io.bitsquare.p2p.network;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import com.google.common.util.concurrent.Uninterruptibles;
|
||||
import io.bitsquare.app.Log;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.ByteArrayUtils;
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.p2p.Address;
|
||||
@ -488,45 +489,52 @@ public class Connection implements MessageListener {
|
||||
+ " rawInputObject " + rawInputObject);
|
||||
|
||||
int size = ByteArrayUtils.objectToByteArray(rawInputObject).length;
|
||||
if (size <= getMaxMsgSize()) {
|
||||
Serializable serializable = null;
|
||||
if (useCompression) {
|
||||
if (rawInputObject instanceof byte[]) {
|
||||
byte[] compressedObjectAsBytes = (byte[]) rawInputObject;
|
||||
size = compressedObjectAsBytes.length;
|
||||
//log.trace("Read object compressed data size: " + size);
|
||||
serializable = Utils.decompress(compressedObjectAsBytes);
|
||||
} else {
|
||||
sharedSpace.reportIllegalRequest(IllegalRequest.InvalidDataType);
|
||||
}
|
||||
} else {
|
||||
if (rawInputObject instanceof Serializable) {
|
||||
serializable = (Serializable) rawInputObject;
|
||||
} else {
|
||||
sharedSpace.reportIllegalRequest(IllegalRequest.InvalidDataType);
|
||||
}
|
||||
}
|
||||
//log.trace("Read object decompressed data size: " + ByteArrayUtils.objectToByteArray(serializable).length);
|
||||
if (size > getMaxMsgSize()) {
|
||||
sharedSpace.reportIllegalRequest(IllegalRequest.MaxSizeExceeded);
|
||||
return;
|
||||
}
|
||||
|
||||
// compressed size might be bigger theoretically so we check again after decompression
|
||||
if (size <= getMaxMsgSize()) {
|
||||
if (serializable instanceof Message) {
|
||||
sharedSpace.updateLastActivityDate();
|
||||
Message message = (Message) serializable;
|
||||
if (message instanceof CloseConnectionMessage) {
|
||||
stopped = true;
|
||||
sharedSpace.shutDown(false);
|
||||
} else if (!stopped) {
|
||||
messageListener.onMessage(message, null);
|
||||
}
|
||||
} else {
|
||||
sharedSpace.reportIllegalRequest(IllegalRequest.InvalidDataType);
|
||||
}
|
||||
Serializable serializable = null;
|
||||
if (useCompression) {
|
||||
if (rawInputObject instanceof byte[]) {
|
||||
byte[] compressedObjectAsBytes = (byte[]) rawInputObject;
|
||||
size = compressedObjectAsBytes.length;
|
||||
//log.trace("Read object compressed data size: " + size);
|
||||
serializable = Utils.decompress(compressedObjectAsBytes);
|
||||
} else {
|
||||
sharedSpace.reportIllegalRequest(IllegalRequest.MaxSizeExceeded);
|
||||
sharedSpace.reportIllegalRequest(IllegalRequest.InvalidDataType);
|
||||
}
|
||||
} else {
|
||||
if (rawInputObject instanceof Serializable) {
|
||||
serializable = (Serializable) rawInputObject;
|
||||
} else {
|
||||
sharedSpace.reportIllegalRequest(IllegalRequest.InvalidDataType);
|
||||
}
|
||||
}
|
||||
//log.trace("Read object decompressed data size: " + ByteArrayUtils.objectToByteArray(serializable).length);
|
||||
|
||||
// compressed size might be bigger theoretically so we check again after decompression
|
||||
if (size > getMaxMsgSize()) {
|
||||
sharedSpace.reportIllegalRequest(IllegalRequest.MaxSizeExceeded);
|
||||
return;
|
||||
}
|
||||
if (!(serializable instanceof Message)) {
|
||||
sharedSpace.reportIllegalRequest(IllegalRequest.InvalidDataType);
|
||||
return;
|
||||
}
|
||||
|
||||
Message message = (Message) serializable;
|
||||
if (message.networkId() != Version.NETWORK_ID) {
|
||||
sharedSpace.reportIllegalRequest(IllegalRequest.WrongNetworkId);
|
||||
return;
|
||||
}
|
||||
|
||||
sharedSpace.updateLastActivityDate();
|
||||
if (message instanceof CloseConnectionMessage) {
|
||||
stopped = true;
|
||||
sharedSpace.shutDown(false);
|
||||
} else if (!stopped) {
|
||||
messageListener.onMessage(message, null);
|
||||
}
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
stopped = true;
|
||||
|
@ -3,7 +3,8 @@ package io.bitsquare.p2p.network;
|
||||
public enum IllegalRequest {
|
||||
MaxSizeExceeded(1),
|
||||
NotAuthenticated(2),
|
||||
InvalidDataType(2);
|
||||
InvalidDataType(2),
|
||||
WrongNetworkId(2);
|
||||
|
||||
public final int maxTolerance;
|
||||
|
||||
|
@ -27,8 +27,8 @@ import java.util.function.Consumer;
|
||||
public class LocalhostNetworkNode extends NetworkNode {
|
||||
private static final Logger log = LoggerFactory.getLogger(LocalhostNetworkNode.class);
|
||||
|
||||
private static volatile int simulateTorDelayTorNode = 2 * 1000;
|
||||
private static volatile int simulateTorDelayHiddenService = 2 * 1000;
|
||||
private static volatile int simulateTorDelayTorNode = 2 * 100;
|
||||
private static volatile int simulateTorDelayHiddenService = 2 * 100;
|
||||
private Address address;
|
||||
|
||||
public static void setSimulateTorDelayTorNode(int simulateTorDelayTorNode) {
|
||||
|
@ -7,4 +7,8 @@ public final class CloseConnectionMessage implements Message {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
@Override
|
||||
public int networkId() {
|
||||
return Version.NETWORK_ID;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,9 @@
|
||||
package io.bitsquare.p2p.peers;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
import io.bitsquare.app.Log;
|
||||
import io.bitsquare.common.util.Tuple2;
|
||||
import io.bitsquare.p2p.Address;
|
||||
import io.bitsquare.p2p.Message;
|
||||
import io.bitsquare.p2p.network.Connection;
|
||||
@ -17,7 +15,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
// authentication example:
|
||||
@ -194,8 +194,6 @@ public class AuthenticationHandshake implements MessageListener {
|
||||
"\nThat is expected if seed nodes are offline." +
|
||||
"\nException:" + throwable.getMessage());
|
||||
onFault(throwable);
|
||||
// log.trace("We try to authenticate to another random seed nodes of that list: " + remainingAddresses);
|
||||
// authenticateToNextRandomPeer(remainingAddresses);
|
||||
}
|
||||
});
|
||||
|
||||
@ -268,30 +266,6 @@ public class AuthenticationHandshake implements MessageListener {
|
||||
// Private
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* private void authenticateToNextRandomPeer(Set<Address> remainingAddresses) {
|
||||
Log.traceCall();
|
||||
Optional<Tuple2<Address, Set<Address>>> tupleOptional = getRandomAddressAndRemainingSet(remainingAddresses);
|
||||
if (tupleOptional.isPresent()) {
|
||||
Tuple2<Address, Set<Address>> tuple = tupleOptional.get();
|
||||
requestAuthentication(tuple.second, tuple.first);
|
||||
} else {
|
||||
log.info("No other seed node found. That is expected for the first seed node.");
|
||||
onSuccess(null);
|
||||
}
|
||||
}*/
|
||||
|
||||
private Optional<Tuple2<Address, Set<Address>>> getRandomAddressAndRemainingSet(Set<Address> addresses) {
|
||||
Log.traceCall();
|
||||
if (!addresses.isEmpty()) {
|
||||
List<Address> list = new ArrayList<>(addresses);
|
||||
Collections.shuffle(list);
|
||||
Address address = list.remove(0);
|
||||
return Optional.of(new Tuple2<>(address, Sets.newHashSet(list)));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private long getAndSetNonce() {
|
||||
Log.traceCall();
|
||||
nonce = new Random().nextLong();
|
||||
|
@ -15,7 +15,7 @@ import io.bitsquare.p2p.network.MessageListener;
|
||||
import io.bitsquare.p2p.network.NetworkNode;
|
||||
import io.bitsquare.p2p.peers.messages.auth.AuthenticationRequest;
|
||||
import io.bitsquare.p2p.peers.messages.maintenance.*;
|
||||
import io.bitsquare.p2p.storage.messages.BroadcastMessage;
|
||||
import io.bitsquare.p2p.storage.messages.DataBroadcastMessage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
@ -127,7 +127,7 @@ public class PeerGroup implements MessageListener, ConnectionListener {
|
||||
seedNodeAddresses.remove(mySeedNodeAddress);
|
||||
}
|
||||
|
||||
public void broadcast(BroadcastMessage message, @Nullable Address sender) {
|
||||
public void broadcast(DataBroadcastMessage message, @Nullable Address sender) {
|
||||
Log.traceCall("Sender " + sender + ". Message " + message.toString());
|
||||
if (authenticatedPeers.values().size() > 0) {
|
||||
log.info("Broadcast message to {} peers. Message:", authenticatedPeers.values().size(), message);
|
||||
@ -201,7 +201,7 @@ public class PeerGroup implements MessageListener, ConnectionListener {
|
||||
// After connection is authenticated, we try to connect to any reported peer as long we have not
|
||||
// reached our max connection size.
|
||||
private void authenticateToSeedNode(Set<Address> remainingAddresses, Address peerAddress, boolean continueOnSuccess) {
|
||||
Log.traceCall();
|
||||
Log.traceCall(peerAddress.getFullAddress());
|
||||
checkArgument(!authenticatedPeers.containsKey(peerAddress),
|
||||
"We have that peer already authenticated. That must never happen.");
|
||||
|
||||
@ -229,20 +229,27 @@ public class PeerGroup implements MessageListener, ConnectionListener {
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Throwable throwable) {
|
||||
log.error("AuthenticationHandshake failed. " + throwable.getMessage());
|
||||
throwable.printStackTrace();
|
||||
log.info("Send RequestAuthenticationMessage to " + peerAddress + " failed." +
|
||||
"\nThat is expected if seed nodes are offline." +
|
||||
"\nException:" + throwable.getMessage());
|
||||
removePeer(peerAddress);
|
||||
|
||||
// If we fail we try again with the remaining set
|
||||
remainingAddresses.remove(peerAddress);
|
||||
|
||||
log.trace("We try to authenticate to another random seed nodes of that list: " + remainingAddresses);
|
||||
|
||||
Optional<Tuple2<Address, Set<Address>>> tupleOptional = getRandomItemAndRemainingSet(remainingAddresses);
|
||||
if (tupleOptional.isPresent()) {
|
||||
log.info("We try to authenticate to a seed node. " + tupleOptional.get().first);
|
||||
authenticateToSeedNode(tupleOptional.get().second, tupleOptional.get().first, true);
|
||||
} else {
|
||||
} else if (reportedPeerAddresses.size() > 0) {
|
||||
log.info("We don't have any more seed nodes for connecting. Lets try the reported peers.");
|
||||
authenticateToRemainingReportedPeers();
|
||||
} else {
|
||||
log.info("We don't have any more seed nodes or reported nodes for connecting. " +
|
||||
"We stop bootstrapping now, but will repeat after an while.");
|
||||
UserThread.runAfter(() -> authenticateToRemainingReportedPeers(), 60);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -263,7 +270,7 @@ public class PeerGroup implements MessageListener, ConnectionListener {
|
||||
// We try to connect to a reported peer. If we fail we repeat after the failed peer has been removed.
|
||||
// If we succeed we repeat until we are ut of addresses.
|
||||
private void authenticateToReportedPeer(Set<Address> remainingAddresses, Address peerAddress) {
|
||||
Log.traceCall();
|
||||
Log.traceCall(peerAddress.getFullAddress());
|
||||
checkArgument(!authenticatedPeers.containsKey(peerAddress),
|
||||
"We have that peer already authenticated. That must never happen.");
|
||||
|
||||
@ -320,7 +327,7 @@ public class PeerGroup implements MessageListener, ConnectionListener {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void authenticateToPeer(Address peerAddress, @Nullable Runnable authenticationCompleteHandler, @Nullable Runnable faultHandler) {
|
||||
Log.traceCall();
|
||||
Log.traceCall(peerAddress.getFullAddress());
|
||||
checkArgument(!authenticatedPeers.containsKey(peerAddress),
|
||||
"We have that seed node already authenticated. That must never happen.");
|
||||
|
||||
@ -348,7 +355,7 @@ public class PeerGroup implements MessageListener, ConnectionListener {
|
||||
}
|
||||
|
||||
private void setAuthenticated(Connection connection, Address peerAddress) {
|
||||
Log.traceCall();
|
||||
Log.traceCall(peerAddress.getFullAddress());
|
||||
log.info("\n\n############################################################\n" +
|
||||
"We are authenticated to:" +
|
||||
"\nconnection=" + connection.getUid()
|
||||
@ -364,7 +371,7 @@ public class PeerGroup implements MessageListener, ConnectionListener {
|
||||
}
|
||||
|
||||
private void addAuthenticatedPeer(Peer peer) {
|
||||
Log.traceCall();
|
||||
Log.traceCall(peer.toString());
|
||||
authenticatedPeers.put(peer.address, peer);
|
||||
reportedPeerAddresses.remove(peer.address);
|
||||
firstPeerAdded = !firstPeerAdded && authenticatedPeers.size() == 1;
|
||||
|
@ -1,6 +1,11 @@
|
||||
package io.bitsquare.p2p.peers.messages.auth;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.p2p.Message;
|
||||
|
||||
public interface AuthenticationMessage extends Message {
|
||||
public abstract class AuthenticationMessage implements Message {
|
||||
@Override
|
||||
public int networkId() {
|
||||
return Version.NETWORK_ID;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package io.bitsquare.p2p.peers.messages.auth;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.p2p.Address;
|
||||
|
||||
public final class AuthenticationRequest implements AuthenticationMessage {
|
||||
public final class AuthenticationRequest extends AuthenticationMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
@ -3,7 +3,7 @@ package io.bitsquare.p2p.peers.messages.auth;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.p2p.Address;
|
||||
|
||||
public final class AuthenticationResponse implements AuthenticationMessage {
|
||||
public final class AuthenticationResponse extends AuthenticationMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
@ -5,7 +5,7 @@ import io.bitsquare.p2p.Address;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public final class GetPeersAuthRequest implements AuthenticationMessage {
|
||||
public final class GetPeersAuthRequest extends AuthenticationMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
@ -5,7 +5,7 @@ import io.bitsquare.p2p.Address;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public final class GetPeersAuthResponse implements AuthenticationMessage {
|
||||
public final class GetPeersAuthResponse extends AuthenticationMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
@ -5,7 +5,7 @@ import io.bitsquare.p2p.Address;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public final class GetPeersRequest implements MaintenanceMessage {
|
||||
public final class GetPeersRequest extends MaintenanceMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
@ -5,7 +5,7 @@ import io.bitsquare.p2p.Address;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public final class GetPeersResponse implements MaintenanceMessage {
|
||||
public final class GetPeersResponse extends MaintenanceMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
@ -1,6 +1,11 @@
|
||||
package io.bitsquare.p2p.peers.messages.maintenance;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.p2p.Message;
|
||||
|
||||
public interface MaintenanceMessage extends Message {
|
||||
public abstract class MaintenanceMessage implements Message {
|
||||
@Override
|
||||
public int networkId() {
|
||||
return Version.NETWORK_ID;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package io.bitsquare.p2p.peers.messages.maintenance;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
|
||||
public final class PingMessage implements MaintenanceMessage {
|
||||
public final class PingMessage extends MaintenanceMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
@ -2,7 +2,7 @@ package io.bitsquare.p2p.peers.messages.maintenance;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
|
||||
public final class PongMessage implements MaintenanceMessage {
|
||||
public final class PongMessage extends MaintenanceMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.bitsquare.p2p.seed;
|
||||
|
||||
import io.bitsquare.app.Log;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.crypto.KeyRing;
|
||||
import io.bitsquare.crypto.EncryptionService;
|
||||
@ -38,10 +39,11 @@ public class SeedNode {
|
||||
// API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// args: myAddress (incl. port) maxConnections useLocalhost seedNodes (separated with |)
|
||||
// args: myAddress (incl. port) BitcoinNetworkId maxConnections useLocalhost seedNodes (separated with |)
|
||||
// 2. and 3. args are optional
|
||||
// eg. lmvdenjkyvx2ovga.onion:8001 20 false eo5ay2lyzrfvx2nr.onion:8002|si3uu56adkyqkldl.onion:8003
|
||||
// or when using localhost: localhost:8001 20 true localhost:8002|localhost:8003
|
||||
// eg. lmvdenjkyvx2ovga.onion:8001 0 20 false eo5ay2lyzrfvx2nr.onion:8002|si3uu56adkyqkldl.onion:8003
|
||||
// or when using localhost: localhost:8001 2 20 true localhost:8002|localhost:8003
|
||||
// BitcoinNetworkId: The id for the bitcoin network (Mainnet = 0, TestNet = 1, Regtest = 2)
|
||||
public void processArgs(String[] args) {
|
||||
Log.traceCall();
|
||||
if (args.length > 0) {
|
||||
@ -50,27 +52,36 @@ public class SeedNode {
|
||||
mySeedNodeAddress = new Address(arg0);
|
||||
if (args.length > 1) {
|
||||
String arg1 = args[1];
|
||||
int maxConnections = Integer.parseInt(arg1);
|
||||
checkArgument(maxConnections < 1000, "maxConnections seems to be a bit too high...");
|
||||
PeerGroup.setMaxConnections(maxConnections);
|
||||
int networkId = Integer.parseInt(arg1);
|
||||
checkArgument(networkId > -1 && networkId < 3, "networkId out of scope (Mainnet = 0, TestNet = 1, Regtest = 2)");
|
||||
Version.NETWORK_ID = networkId;
|
||||
if (args.length > 2) {
|
||||
String arg2 = args[2];
|
||||
checkArgument(arg2.equals("true") || arg2.equals("false"));
|
||||
useLocalhost = ("true").equals(arg2);
|
||||
int maxConnections = Integer.parseInt(arg2);
|
||||
checkArgument(maxConnections < 1000, "maxConnections seems to be a bit too high...");
|
||||
PeerGroup.setMaxConnections(maxConnections);
|
||||
} else {
|
||||
// we keep default a higher connection size for seed nodes
|
||||
PeerGroup.setMaxConnections(50);
|
||||
}
|
||||
if (args.length > 3) {
|
||||
String arg3 = args[3];
|
||||
checkArgument(arg3.contains(":") && arg3.split(":").length > 1 && arg3.split(":")[1].length() > 3, "Wrong program argument");
|
||||
List<String> list = Arrays.asList(arg3.split("|"));
|
||||
checkArgument(arg3.equals("true") || arg3.equals("false"));
|
||||
useLocalhost = ("true").equals(arg3);
|
||||
}
|
||||
if (args.length > 4) {
|
||||
String arg4 = args[4];
|
||||
checkArgument(arg4.contains(":") && arg4.split(":").length > 1 && arg4.split(":")[1].length() > 3, "Wrong program argument");
|
||||
List<String> list = Arrays.asList(arg4.split("|"));
|
||||
seedNodes = new HashSet<>();
|
||||
list.forEach(e -> {
|
||||
checkArgument(e.contains(":") && e.split(":").length == 2 && e.split(":")[1].length() == 4, "Wrong program argument");
|
||||
seedNodes.add(new Address(e));
|
||||
});
|
||||
seedNodes.remove(mySeedNodeAddress);
|
||||
} else if (args.length > 4) {
|
||||
} else if (args.length > 5) {
|
||||
log.error("Too many program arguments." +
|
||||
"\nProgram arguments: myAddress useLocalhost seedNodes");
|
||||
"\nProgram arguments: myAddress (incl. port) BitcoinNetworkId maxConnections useLocalhost seedNodes (separated with |)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,10 @@ import io.bitsquare.p2p.network.MessageListener;
|
||||
import io.bitsquare.p2p.network.NetworkNode;
|
||||
import io.bitsquare.p2p.peers.PeerGroup;
|
||||
import io.bitsquare.p2p.storage.data.*;
|
||||
import io.bitsquare.p2p.storage.messages.*;
|
||||
import io.bitsquare.p2p.storage.messages.AddDataMessage;
|
||||
import io.bitsquare.p2p.storage.messages.DataBroadcastMessage;
|
||||
import io.bitsquare.p2p.storage.messages.RemoveDataMessage;
|
||||
import io.bitsquare.p2p.storage.messages.RemoveMailboxDataMessage;
|
||||
import io.bitsquare.storage.Storage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -99,7 +102,7 @@ public class ProtectedExpirableDataStorage implements MessageListener {
|
||||
@Override
|
||||
public void onMessage(Message message, Connection connection) {
|
||||
Log.traceCall("Message=" + message);
|
||||
if (message instanceof DataMessage) {
|
||||
if (message instanceof DataBroadcastMessage) {
|
||||
if (connection.isAuthenticated()) {
|
||||
log.trace("ProtectedExpirableDataMessage received " + message + " on connection " + connection);
|
||||
if (message instanceof AddDataMessage) {
|
||||
@ -350,7 +353,7 @@ public class ProtectedExpirableDataStorage implements MessageListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void broadcast(BroadcastMessage message, @Nullable Address sender) {
|
||||
private void broadcast(DataBroadcastMessage message, @Nullable Address sender) {
|
||||
Log.traceCall(message.toString());
|
||||
peerGroup.broadcast(message, sender);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package io.bitsquare.p2p.storage.messages;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.p2p.storage.data.ProtectedData;
|
||||
|
||||
public final class AddDataMessage implements DataMessage {
|
||||
public final class AddDataMessage extends DataBroadcastMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
@ -1,6 +0,0 @@
|
||||
package io.bitsquare.p2p.storage.messages;
|
||||
|
||||
import io.bitsquare.p2p.Message;
|
||||
|
||||
public interface BroadcastMessage extends Message {
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package io.bitsquare.p2p.storage.messages;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.p2p.Message;
|
||||
|
||||
public abstract class DataBroadcastMessage implements Message {
|
||||
@Override
|
||||
public int networkId() {
|
||||
return Version.NETWORK_ID;
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package io.bitsquare.p2p.storage.messages;
|
||||
|
||||
// market interface for messages which manipulate data (add, remove)
|
||||
public interface DataMessage extends BroadcastMessage {
|
||||
}
|
@ -9,4 +9,9 @@ public final class GetDataRequest implements Message {
|
||||
|
||||
public GetDataRequest() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int networkId() {
|
||||
return Version.NETWORK_ID;
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,11 @@ public final class GetDataResponse implements Message {
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int networkId() {
|
||||
return Version.NETWORK_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -3,7 +3,7 @@ package io.bitsquare.p2p.storage.messages;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.p2p.storage.data.ProtectedData;
|
||||
|
||||
public final class RemoveDataMessage implements DataMessage {
|
||||
public final class RemoveDataMessage extends DataBroadcastMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
@ -3,7 +3,7 @@ package io.bitsquare.p2p.storage.messages;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.p2p.storage.data.ProtectedMailboxData;
|
||||
|
||||
public final class RemoveMailboxDataMessage implements DataMessage {
|
||||
public final class RemoveMailboxDataMessage extends DataBroadcastMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
package io.bitsquare.crypto;
|
||||
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.crypto.CryptoException;
|
||||
import io.bitsquare.common.crypto.KeyRing;
|
||||
import io.bitsquare.common.crypto.KeyStorage;
|
||||
@ -92,4 +93,9 @@ class TestMessage implements MailboxMessage {
|
||||
public Address getSenderAddress() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int networkId() {
|
||||
return Version.NETWORK_ID;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.bitsquare.p2p.mocks;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.p2p.Address;
|
||||
import io.bitsquare.p2p.messaging.MailboxMessage;
|
||||
import io.bitsquare.p2p.storage.data.ExpirablePayload;
|
||||
@ -14,6 +15,11 @@ public class MockMailboxMessage implements MailboxMessage, ExpirablePayload {
|
||||
this.senderAddress = senderAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int networkId() {
|
||||
return Version.NETWORK_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.bitsquare.p2p.mocks;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.p2p.Message;
|
||||
import io.bitsquare.p2p.storage.data.ExpirablePayload;
|
||||
|
||||
@ -11,6 +12,11 @@ public class MockMessage implements Message, ExpirablePayload {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int networkId() {
|
||||
return Version.NETWORK_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user