This commit is contained in:
Manfred Karrer 2015-11-16 17:52:27 +01:00
parent 6f523e02dd
commit a35b7250df
5 changed files with 11 additions and 19 deletions

View File

@ -186,7 +186,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
// We set connectionType to that connection to avoid that is get closed when // We set connectionType to that connection to avoid that is get closed when
// we get too many connection attempts. // we get too many connection attempts.
// That is used as protection against eclipse attacks. // That is used as protection against eclipse attacks.
connection.setConnectionType(ConnectionMode.DIRECT_MSG); connection.setConnectionType(ConnectionType.DIRECT_MSG);
log.info("Received SealedAndSignedMessage and decrypted it: " + decryptedMsgWithPubKey); log.info("Received SealedAndSignedMessage and decrypted it: " + decryptedMsgWithPubKey);
decryptedMailListeners.stream().forEach( decryptedMailListeners.stream().forEach(

View File

@ -31,7 +31,7 @@ public class Connection implements MessageListener {
private static final Logger log = LoggerFactory.getLogger(Connection.class); private static final Logger log = LoggerFactory.getLogger(Connection.class);
private static final int MAX_MSG_SIZE = 5 * 1024 * 1024; // 5 MB of compressed data private static final int MAX_MSG_SIZE = 5 * 1024 * 1024; // 5 MB of compressed data
private static final int SOCKET_TIMEOUT = 30 * 60 * 1000; // 30 min. private static final int SOCKET_TIMEOUT = 30 * 60 * 1000; // 30 min.
private ConnectionMode connectionType; private ConnectionType connectionType;
public static int getMaxMsgSize() { public static int getMaxMsgSize() {
return MAX_MSG_SIZE; return MAX_MSG_SIZE;
@ -123,7 +123,7 @@ public class Connection implements MessageListener {
connectionListener.onPeerAddressAuthenticated(peerAddress, connection); connectionListener.onPeerAddressAuthenticated(peerAddress, connection);
} }
public void setConnectionType(ConnectionMode connectionType) { public void setConnectionType(ConnectionType connectionType) {
this.connectionType = connectionType; this.connectionType = connectionType;
} }
@ -210,7 +210,7 @@ public class Connection implements MessageListener {
return stopped; return stopped;
} }
public ConnectionMode getConnectionType() { public ConnectionType getConnectionType() {
return connectionType; return connectionType;
} }

View File

@ -1,8 +0,0 @@
package io.bitsquare.p2p.network;
public enum ConnectionMode {
PASSIVE, // for connections initiated by other peer
ACTIVE, // for connections initiated by us
DIRECT_MSG, // for connections used for direct messaging
AUTH_REQUEST // for connections used for starting the authentication
}

View File

@ -8,7 +8,7 @@ import io.bitsquare.common.UserThread;
import io.bitsquare.p2p.Address; import io.bitsquare.p2p.Address;
import io.bitsquare.p2p.Message; import io.bitsquare.p2p.Message;
import io.bitsquare.p2p.network.Connection; import io.bitsquare.p2p.network.Connection;
import io.bitsquare.p2p.network.ConnectionMode; import io.bitsquare.p2p.network.ConnectionType;
import io.bitsquare.p2p.network.MessageListener; import io.bitsquare.p2p.network.MessageListener;
import io.bitsquare.p2p.network.NetworkNode; import io.bitsquare.p2p.network.NetworkNode;
import io.bitsquare.p2p.peers.messages.auth.*; import io.bitsquare.p2p.peers.messages.auth.*;
@ -72,7 +72,7 @@ public class AuthenticationHandshake implements MessageListener {
// We use the active connectionType if we started the authentication request to another peer // We use the active connectionType if we started the authentication request to another peer
// That is used for protecting eclipse attacks // That is used for protecting eclipse attacks
connection.setConnectionType(ConnectionMode.ACTIVE); connection.setConnectionType(ConnectionType.ACTIVE);
AuthenticationResponse authenticationResponse = (AuthenticationResponse) message; AuthenticationResponse authenticationResponse = (AuthenticationResponse) message;
Address peerAddress = authenticationResponse.address; Address peerAddress = authenticationResponse.address;
@ -180,7 +180,7 @@ public class AuthenticationHandshake implements MessageListener {
log.trace("send AuthenticationRequest to " + peerAddress + " succeeded."); log.trace("send AuthenticationRequest to " + peerAddress + " succeeded.");
connection.setPeerAddress(peerAddress); connection.setPeerAddress(peerAddress);
// We protect that connection from getting closed by maintenance cleanup... // We protect that connection from getting closed by maintenance cleanup...
connection.setConnectionType(ConnectionMode.AUTH_REQUEST); connection.setConnectionType(ConnectionType.AUTH_REQUEST);
} }
@Override @Override
@ -228,7 +228,7 @@ public class AuthenticationHandshake implements MessageListener {
connection.setPeerAddress(peerAddress); connection.setPeerAddress(peerAddress);
// We use passive connectionType for connections created from received authentication requests from other peers // We use passive connectionType for connections created from received authentication requests from other peers
// That is used for protecting eclipse attacks // That is used for protecting eclipse attacks
connection.setConnectionType(ConnectionMode.PASSIVE); connection.setConnectionType(ConnectionType.PASSIVE);
} }
@Override @Override

View File

@ -168,7 +168,7 @@ public class PeerGroup implements MessageListener, ConnectionListener {
Address peerAddress = message.address; Address peerAddress = message.address;
if (!authenticationHandshakes.containsKey(peerAddress)) { if (!authenticationHandshakes.containsKey(peerAddress)) {
// We protect that connection from getting closed by maintenance cleanup... // We protect that connection from getting closed by maintenance cleanup...
connection.setConnectionType(ConnectionMode.AUTH_REQUEST); connection.setConnectionType(ConnectionType.AUTH_REQUEST);
AuthenticationHandshake authenticationHandshake = new AuthenticationHandshake(networkNode, PeerGroup.this, getMyAddress()); AuthenticationHandshake authenticationHandshake = new AuthenticationHandshake(networkNode, PeerGroup.this, getMyAddress());
authenticationHandshakes.put(peerAddress, authenticationHandshake); authenticationHandshakes.put(peerAddress, authenticationHandshake);
SettableFuture<Connection> future = authenticationHandshake.respondToAuthenticationRequest(message, connection); SettableFuture<Connection> future = authenticationHandshake.respondToAuthenticationRequest(message, connection);
@ -467,7 +467,7 @@ public class PeerGroup implements MessageListener, ConnectionListener {
List<Connection> authenticatedConnections = allConnections.stream() List<Connection> authenticatedConnections = allConnections.stream()
.filter(e -> e.isAuthenticated()) .filter(e -> e.isAuthenticated())
.filter(e -> e.getConnectionType() == ConnectionMode.PASSIVE) .filter(e -> e.getConnectionType() == ConnectionType.PASSIVE)
.collect(Collectors.toList()); .collect(Collectors.toList());
if (authenticatedConnections.size() == 0) { if (authenticatedConnections.size() == 0) {
@ -476,7 +476,7 @@ public class PeerGroup implements MessageListener, ConnectionListener {
if (size > MAX_CONNECTIONS_NORMAL_PRIO) { if (size > MAX_CONNECTIONS_NORMAL_PRIO) {
authenticatedConnections = allConnections.stream() authenticatedConnections = allConnections.stream()
.filter(e -> e.isAuthenticated()) .filter(e -> e.isAuthenticated())
.filter(e -> e.getConnectionType() == ConnectionMode.PASSIVE || e.getConnectionType() == ConnectionMode.ACTIVE) .filter(e -> e.getConnectionType() == ConnectionType.PASSIVE || e.getConnectionType() == ConnectionType.ACTIVE)
.collect(Collectors.toList()); .collect(Collectors.toList());
if (authenticatedConnections.size() == 0) { if (authenticatedConnections.size() == 0) {