This commit is contained in:
Manfred Karrer 2016-02-26 18:48:11 +01:00
parent 6daf959f78
commit d6e6a52010
5 changed files with 13 additions and 11 deletions

View file

@ -44,8 +44,6 @@ public class P2pNetworkListItem {
private final StringProperty receivedBytes = new SimpleStringProperty(); private final StringProperty receivedBytes = new SimpleStringProperty();
private final StringProperty peerType = new SimpleStringProperty(); private final StringProperty peerType = new SimpleStringProperty();
private final StringProperty connectionType = new SimpleStringProperty(); private final StringProperty connectionType = new SimpleStringProperty();
private final StringProperty roundTripTime = new SimpleStringProperty(); private final StringProperty roundTripTime = new SimpleStringProperty();
private final StringProperty onionAddress = new SimpleStringProperty(); private final StringProperty onionAddress = new SimpleStringProperty();
private final Clock.Listener listener; private final Clock.Listener listener;
@ -63,7 +61,7 @@ public class P2pNetworkListItem {
onionAddressSubscription = EasyBind.subscribe(connection.peersNodeAddressProperty(), onionAddressSubscription = EasyBind.subscribe(connection.peersNodeAddressProperty(),
nodeAddress -> onionAddress.set(nodeAddress != null ? nodeAddress.getFullAddress() : "Not known yet")); nodeAddress -> onionAddress.set(nodeAddress != null ? nodeAddress.getFullAddress() : "Not known yet"));
roundTripTimeSubscription = EasyBind.subscribe(statistic.roundTripTimeProperty(), roundTripTimeSubscription = EasyBind.subscribe(statistic.roundTripTimeProperty(),
roundTripTime -> this.roundTripTime.set(DurationFormatUtils.formatDuration((long) roundTripTime, "ss.SSS"))); roundTripTime -> this.roundTripTime.set((int) roundTripTime == 0 ? "-" : roundTripTime + " ms"));
listener = new Clock.Listener() { listener = new Clock.Listener() {
@Override @Override

View file

@ -3,9 +3,7 @@ package io.bitsquare.p2p.network;
import io.bitsquare.common.UserThread; import io.bitsquare.common.UserThread;
import io.bitsquare.p2p.Message; import io.bitsquare.p2p.Message;
import javafx.beans.property.IntegerProperty; import javafx.beans.property.IntegerProperty;
import javafx.beans.property.LongProperty;
import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleLongProperty;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -51,7 +49,7 @@ public class Statistic {
private final IntegerProperty receivedBytes = new SimpleIntegerProperty(0); private final IntegerProperty receivedBytes = new SimpleIntegerProperty(0);
private final Map<String, Integer> receivedMessages = new ConcurrentHashMap<>(); private final Map<String, Integer> receivedMessages = new ConcurrentHashMap<>();
private final Map<String, Integer> sentMessages = new ConcurrentHashMap<>(); private final Map<String, Integer> sentMessages = new ConcurrentHashMap<>();
private final LongProperty roundTripTime = new SimpleLongProperty(0); private final IntegerProperty roundTripTime = new SimpleIntegerProperty(0);
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -103,7 +101,7 @@ public class Statistic {
sentMessages.put(messageClassName, counter); sentMessages.put(messageClassName, counter);
} }
public void setRoundTripTime(long roundTripTime) { public void setRoundTripTime(int roundTripTime) {
this.roundTripTime.set(roundTripTime); this.roundTripTime.set(roundTripTime);
} }
@ -139,7 +137,7 @@ public class Statistic {
return creationDate; return creationDate;
} }
public LongProperty roundTripTimeProperty() { public IntegerProperty roundTripTimeProperty() {
return roundTripTime; return roundTripTime;
} }

View file

@ -79,7 +79,7 @@ class KeepAliveHandler implements MessageListener {
private void sendPing(Connection connection) { private void sendPing(Connection connection) {
Log.traceCall("connection=" + connection + " / this=" + this); Log.traceCall("connection=" + connection + " / this=" + this);
if (!stopped) { if (!stopped) {
Ping ping = new Ping(nonce); Ping ping = new Ping(nonce, connection.getStatistic().roundTripTimeProperty().get());
sendTs = System.currentTimeMillis(); sendTs = System.currentTimeMillis();
SettableFuture<Connection> future = networkNode.sendMessage(connection, ping); SettableFuture<Connection> future = networkNode.sendMessage(connection, ping);
Futures.addCallback(future, new FutureCallback<Connection>() { Futures.addCallback(future, new FutureCallback<Connection>() {
@ -127,7 +127,7 @@ class KeepAliveHandler implements MessageListener {
if (!stopped) { if (!stopped) {
Pong pong = (Pong) message; Pong pong = (Pong) message;
if (pong.requestNonce == nonce) { if (pong.requestNonce == nonce) {
long roundTripTime = System.currentTimeMillis() - sendTs; int roundTripTime = (int) (System.currentTimeMillis() - sendTs);
log.trace("roundTripTime=" + roundTripTime + "\n\tconnection=" + connection); log.trace("roundTripTime=" + roundTripTime + "\n\tconnection=" + connection);
connection.getStatistic().setRoundTripTime(roundTripTime); connection.getStatistic().setRoundTripTime(roundTripTime);
cleanup(); cleanup();

View file

@ -79,6 +79,10 @@ public class KeepAliveManager implements MessageListener, ConnectionListener, Pe
Log.traceCall(message.toString() + "\n\tconnection=" + connection); Log.traceCall(message.toString() + "\n\tconnection=" + connection);
if (!stopped) { if (!stopped) {
Ping ping = (Ping) message; Ping ping = (Ping) message;
// We get from peer last measured rrt
connection.getStatistic().setRoundTripTime(ping.lastRoundTripTime);
Pong pong = new Pong(ping.nonce); Pong pong = new Pong(ping.nonce);
SettableFuture<Connection> future = networkNode.sendMessage(connection, pong); SettableFuture<Connection> future = networkNode.sendMessage(connection, pong);
Futures.addCallback(future, new FutureCallback<Connection>() { Futures.addCallback(future, new FutureCallback<Connection>() {

View file

@ -7,9 +7,11 @@ public final class Ping extends KeepAliveMessage {
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION; private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
public final int nonce; public final int nonce;
public final int lastRoundTripTime;
public Ping(int nonce) { public Ping(int nonce, int lastRoundTripTime) {
this.nonce = nonce; this.nonce = nonce;
this.lastRoundTripTime = lastRoundTripTime;
} }
@Override @Override