Improve API output for GET /peers

This commit is contained in:
catbref 2019-06-04 16:15:50 +01:00
parent 3a3cc5a81b
commit b7f53afe68

View File

@ -3,33 +3,48 @@ package org.qora.api.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import org.qora.data.network.PeerData;
import org.qora.network.Handshake;
import org.qora.network.Peer;
@XmlAccessorType(XmlAccessType.FIELD)
public class ConnectedPeer {
public String address;
public Long lastPing;
public Integer lastHeight;
public enum Direction {
INBOUND,
OUTBOUND;
}
public Direction direction;
public Handshake handshakeStatus;
public Long lastPing;
public String address;
public String version;
public Long buildTimestamp;
public Integer lastHeight;
public byte[] lastBlockSignature;
public Long lastBlockTimestamp;
protected ConnectedPeer() {
}
public ConnectedPeer(Peer peer) {
this.address = peer.getPeerData().getAddress().toString();
this.lastPing = peer.getLastPing();
this.direction = peer.isOutbound() ? Direction.OUTBOUND : Direction.INBOUND;
this.lastHeight = peer.getPeerData() == null ? null : peer.getPeerData().getLastHeight();
this.handshakeStatus = peer.getHandshakeStatus();
this.lastPing = peer.getLastPing();
PeerData peerData = peer.getPeerData();
this.address = peerData.getAddress().toString();
if (peer.getVersionMessage() != null) {
this.version = peer.getVersionMessage().getVersionString();
this.buildTimestamp = peer.getVersionMessage().getBuildTimestamp();
}
this.lastHeight = peerData.getLastHeight();
this.lastBlockSignature = peerData.getLastBlockSignature();
this.lastBlockTimestamp = peerData.getLastBlockTimestamp();
}
}