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 peerType = new SimpleStringProperty();
private final StringProperty connectionType = new SimpleStringProperty();
private final StringProperty roundTripTime = new SimpleStringProperty();
private final StringProperty onionAddress = new SimpleStringProperty();
private final Clock.Listener listener;
@ -63,7 +61,7 @@ public class P2pNetworkListItem {
onionAddressSubscription = EasyBind.subscribe(connection.peersNodeAddressProperty(),
nodeAddress -> onionAddress.set(nodeAddress != null ? nodeAddress.getFullAddress() : "Not known yet"));
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() {
@Override

View File

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

View File

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

View File

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