mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-05-02 22:55:09 -04:00
Add UI info for P2P network
This commit is contained in:
parent
b81e263c24
commit
d666c6cd3b
30 changed files with 232 additions and 625 deletions
|
@ -1,14 +0,0 @@
|
|||
package io.bitsquare.p2p;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class NetworkStatistics {
|
||||
private static final Logger log = LoggerFactory.getLogger(NetworkStatistics.class);
|
||||
|
||||
@Inject
|
||||
public NetworkStatistics() {
|
||||
|
||||
}
|
||||
}
|
|
@ -28,7 +28,9 @@ import io.bitsquare.p2p.storage.data.ProtectedMailboxData;
|
|||
import io.bitsquare.p2p.storage.messages.GetDataRequest;
|
||||
import io.bitsquare.p2p.storage.messages.GetDataResponse;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
import org.fxmisc.easybind.monadic.MonadicBinding;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -60,7 +62,6 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||
private final EncryptionService encryptionService;
|
||||
private final KeyRing keyRing;
|
||||
private final File storageDir;
|
||||
private final NetworkStatistics networkStatistics;
|
||||
|
||||
private NetworkNode networkNode;
|
||||
private PeerGroup peerGroup;
|
||||
|
@ -78,6 +79,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||
private final BooleanProperty requestingDataCompleted = new SimpleBooleanProperty();
|
||||
private final BooleanProperty authenticated = new SimpleBooleanProperty();
|
||||
private MonadicBinding<Boolean> readyForAuthentication;
|
||||
public final IntegerProperty numAuthenticatedPeers = new SimpleIntegerProperty(0);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -101,8 +103,6 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||
this.keyRing = keyRing;
|
||||
this.storageDir = storageDir;
|
||||
|
||||
networkStatistics = new NetworkStatistics();
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||
|
||||
// peer group
|
||||
peerGroup = new PeerGroup(networkNode, seedNodeAddresses);
|
||||
if (useLocalhost) PeerGroup.setSimulateAuthTorNode(1 * 1000);
|
||||
if (useLocalhost) PeerGroup.setSimulateAuthTorNode(2 * 1000);
|
||||
|
||||
// storage
|
||||
dataStorage = new ProtectedExpirableDataStorage(peerGroup, storageDir);
|
||||
|
@ -216,6 +216,8 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||
authenticated.set(true);
|
||||
|
||||
p2pServiceListeners.stream().forEach(e -> e.onFirstPeerAuthenticated());
|
||||
|
||||
numAuthenticatedPeers.set(authenticatedPeerAddresses.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -223,6 +225,8 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||
Log.traceCall();
|
||||
if (connection.isAuthenticated())
|
||||
authenticatedPeerAddresses.remove(connection.getPeerAddress());
|
||||
|
||||
numAuthenticatedPeers.set(authenticatedPeerAddresses.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -506,8 +510,8 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||
}
|
||||
});
|
||||
} catch (CryptoException e) {
|
||||
e.printStackTrace();
|
||||
log.error("sendEncryptedMessage failed");
|
||||
e.printStackTrace();
|
||||
sendMailboxMessageListener.onFault();
|
||||
}
|
||||
}
|
||||
|
@ -652,9 +656,8 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||
return networkNode.getAddress();
|
||||
}
|
||||
|
||||
public NetworkStatistics getNetworkStatistics() {
|
||||
Log.traceCall();
|
||||
return networkStatistics;
|
||||
public Set<Address> getAuthenticatedPeerAddresses() {
|
||||
return authenticatedPeerAddresses;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.google.common.util.concurrent.Uninterruptibles;
|
|||
import io.bitsquare.app.Log;
|
||||
import io.bitsquare.common.ByteArrayUtils;
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.util.Utilities;
|
||||
import io.bitsquare.p2p.Address;
|
||||
import io.bitsquare.p2p.Message;
|
||||
import io.bitsquare.p2p.Utils;
|
||||
|
@ -19,13 +18,8 @@ import java.net.Socket;
|
|||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.Date;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* Connection is created by the server thread or by sendMessage from NetworkNode.
|
||||
|
@ -137,16 +131,6 @@ public class Connection implements MessageListener {
|
|||
Log.traceCall();
|
||||
if (!stopped) {
|
||||
try {
|
||||
Timer timeoutTimer = new Timer();
|
||||
timeoutTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
Utilities.setThreadName("SendMessageTimerTask");
|
||||
throw new RuntimeException("Timeout occurred: Send message " + message
|
||||
+ " on connection with port " + portInfo + " failed.");
|
||||
}
|
||||
}, SEND_MESSAGE_TIMEOUT);
|
||||
|
||||
log.info("writeObject " + message + " on connection with port " + portInfo);
|
||||
Object objectToWrite;
|
||||
if (useCompression) {
|
||||
|
@ -166,7 +150,6 @@ public class Connection implements MessageListener {
|
|||
}
|
||||
sharedSpace.updateLastActivityDate();
|
||||
}
|
||||
timeoutTimer.cancel();
|
||||
} catch (IOException e) {
|
||||
// an exception lead to a shutdown
|
||||
sharedSpace.handleConnectionException(e);
|
||||
|
@ -271,8 +254,8 @@ public class Connection implements MessageListener {
|
|||
// TODO increase delay
|
||||
Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
log.error(t.getMessage());
|
||||
t.printStackTrace();
|
||||
} finally {
|
||||
UserThread.execute(() -> continueShutDown(shutDownCompleteHandler));
|
||||
}
|
||||
|
@ -302,8 +285,8 @@ public class Connection implements MessageListener {
|
|||
} catch (SocketException e) {
|
||||
log.trace("SocketException at shutdown might be expected " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("Exception at shutdown. " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
MoreExecutors.shutdownAndAwaitTermination(singleThreadExecutor, 500, TimeUnit.MILLISECONDS);
|
||||
|
||||
|
@ -412,7 +395,7 @@ public class Connection implements MessageListener {
|
|||
shutDownReason = ConnectionListener.Reason.SOCKET_CLOSED;
|
||||
else
|
||||
shutDownReason = ConnectionListener.Reason.RESET;
|
||||
} else if (e instanceof SocketTimeoutException) {
|
||||
} else if (e instanceof SocketTimeoutException || e instanceof TimeoutException) {
|
||||
shutDownReason = ConnectionListener.Reason.TIMEOUT;
|
||||
} else if (e instanceof EOFException) {
|
||||
shutDownReason = ConnectionListener.Reason.PEER_DISCONNECTED;
|
||||
|
|
|
@ -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 = 1 * 100;
|
||||
private static volatile int simulateTorDelayHiddenService = 1 * 100;
|
||||
private static volatile int simulateTorDelayTorNode = 2 * 1000;
|
||||
private static volatile int simulateTorDelayHiddenService = 2 * 1000;
|
||||
private Address address;
|
||||
|
||||
public static void setSimulateTorDelayTorNode(int simulateTorDelayTorNode) {
|
||||
|
@ -144,7 +144,7 @@ public class LocalhostNetworkNode extends NetworkNode {
|
|||
Uninterruptibles.sleepUninterruptibly(simulateTorDelayHiddenService, TimeUnit.MILLISECONDS);
|
||||
|
||||
log.info("\n\n############################################################\n" +
|
||||
"Hidden service created [simulation]:" +
|
||||
"Hidden service published [simulation]:" +
|
||||
"\nTook " + (System.currentTimeMillis() - ts) + " ms"
|
||||
+ "\n############################################################\n");
|
||||
// as we are simulating we return null
|
||||
|
|
|
@ -26,6 +26,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
public abstract class NetworkNode implements MessageListener, ConnectionListener {
|
||||
private static final Logger log = LoggerFactory.getLogger(NetworkNode.class);
|
||||
|
||||
private static final int CREATE_SOCKET_TIMEOUT = 1 * 1000; // 10 sec.
|
||||
|
||||
protected final int servicePort;
|
||||
|
||||
private final CopyOnWriteArraySet<Connection> inBoundConnections = new CopyOnWriteArraySet<>();
|
||||
|
|
|
@ -61,8 +61,8 @@ class Server implements Runnable {
|
|||
e.printStackTrace();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
log.error("Executing task failed. " + t.getMessage());
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,8 +78,8 @@ class Server implements Runnable {
|
|||
} catch (SocketException e) {
|
||||
log.warn("SocketException at shutdown might be expected " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("Exception at shutdown. " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
log.info("Server shutdown complete");
|
||||
}
|
||||
|
|
|
@ -149,8 +149,8 @@ public class TorNetworkNode extends NetworkNode {
|
|||
});
|
||||
} catch (Throwable e) {
|
||||
UserThread.execute(() -> {
|
||||
e.printStackTrace();
|
||||
log.error("Shutdown torNode failed with exception: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
// We want to switch to UserThread
|
||||
shutDownExecutorService();
|
||||
});
|
||||
|
@ -175,8 +175,8 @@ public class TorNetworkNode extends NetworkNode {
|
|||
log.info("Shutdown completed");
|
||||
shutDownCompleteHandler.run();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
log.error("Shutdown executorService failed with exception: " + t.getMessage());
|
||||
t.printStackTrace();
|
||||
shutDownCompleteHandler.run();
|
||||
}
|
||||
}).start();
|
||||
|
|
|
@ -185,8 +185,8 @@ public class PeerGroup implements MessageListener, ConnectionListener {
|
|||
|
||||
@Override
|
||||
public void onFailure(@NotNull Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
log.error("AuthenticationHandshake failed. " + throwable.getMessage());
|
||||
throwable.printStackTrace();
|
||||
removePeer(connection.getPeerAddress());
|
||||
}
|
||||
});
|
||||
|
@ -229,8 +229,8 @@ public class PeerGroup implements MessageListener, ConnectionListener {
|
|||
|
||||
@Override
|
||||
public void onFailure(@NotNull Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
log.error("AuthenticationHandshake failed. " + throwable.getMessage());
|
||||
throwable.printStackTrace();
|
||||
removePeer(peerAddress);
|
||||
|
||||
// If we fail we try again with the remaining set
|
||||
|
@ -291,8 +291,8 @@ public class PeerGroup implements MessageListener, ConnectionListener {
|
|||
|
||||
@Override
|
||||
public void onFailure(@NotNull Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
log.error("AuthenticationHandshake failed. " + throwable.getMessage());
|
||||
throwable.printStackTrace();
|
||||
removePeer(peerAddress);
|
||||
|
||||
log.info("Authentication failed. Lets try again with the remaining reported peer addresses.");
|
||||
|
@ -338,8 +338,8 @@ public class PeerGroup implements MessageListener, ConnectionListener {
|
|||
|
||||
@Override
|
||||
public void onFailure(@NotNull Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
log.error("AuthenticationHandshake failed. " + throwable.getMessage());
|
||||
throwable.printStackTrace();
|
||||
removePeer(peerAddress);
|
||||
if (faultHandler != null)
|
||||
faultHandler.run();
|
||||
|
@ -394,8 +394,8 @@ public class PeerGroup implements MessageListener, ConnectionListener {
|
|||
pingPeers();
|
||||
});
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
log.error("Executing task failed. " + t.getMessage());
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, SEND_PING_INTERVAL, SEND_PING_INTERVAL);
|
||||
|
@ -407,8 +407,8 @@ public class PeerGroup implements MessageListener, ConnectionListener {
|
|||
try {
|
||||
UserThread.execute(() -> trySendGetPeersRequest());
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
log.error("Executing task failed. " + t.getMessage());
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, GET_PEERS_INTERVAL, GET_PEERS_INTERVAL);
|
||||
|
|
|
@ -77,8 +77,8 @@ public class ProtectedExpirableDataStorage implements MessageListener {
|
|||
Utilities.setThreadName("RemoveExpiredEntriesTimer");
|
||||
UserThread.execute(() -> removeExpiredEntries());
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
log.error("Executing task failed. " + t.getMessage());
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -37,6 +37,7 @@ public class ProtectedData implements Serializable {
|
|||
date = new Date();
|
||||
|
||||
} catch (Throwable t) {
|
||||
log.error("Exception at readObject: " + t.getMessage());
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ public class ProtectedMailboxData extends ProtectedData {
|
|||
date = new Date();
|
||||
|
||||
} catch (Throwable t) {
|
||||
log.error("Exception at readObject: " + t.getMessage());
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue