forked from QORT/qortal
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from szisti/networking
Code formatting, connection age, and logging changes for networking
- Loading branch information
Showing
4 changed files
with
2,033 additions
and
1,885 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,74 @@ | ||
package org.qortal.api.model; | ||
|
||
import javax.xml.bind.annotation.XmlAccessType; | ||
import javax.xml.bind.annotation.XmlAccessorType; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import org.qortal.data.network.PeerChainTipData; | ||
import org.qortal.data.network.PeerData; | ||
import org.qortal.network.Handshake; | ||
import org.qortal.network.Peer; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import javax.xml.bind.annotation.XmlAccessType; | ||
import javax.xml.bind.annotation.XmlAccessorType; | ||
import java.util.UUID; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@XmlAccessorType(XmlAccessType.FIELD) | ||
public class ConnectedPeer { | ||
|
||
public enum Direction { | ||
INBOUND, | ||
OUTBOUND; | ||
} | ||
public Direction direction; | ||
public Handshake handshakeStatus; | ||
public Long lastPing; | ||
public Long connectedWhen; | ||
public Long peersConnectedWhen; | ||
|
||
public String address; | ||
public String version; | ||
|
||
public String nodeId; | ||
|
||
public Integer lastHeight; | ||
@Schema(example = "base58") | ||
public byte[] lastBlockSignature; | ||
public Long lastBlockTimestamp; | ||
|
||
protected ConnectedPeer() { | ||
} | ||
|
||
public ConnectedPeer(Peer peer) { | ||
this.direction = peer.isOutbound() ? Direction.OUTBOUND : Direction.INBOUND; | ||
this.handshakeStatus = peer.getHandshakeStatus(); | ||
this.lastPing = peer.getLastPing(); | ||
|
||
PeerData peerData = peer.getPeerData(); | ||
this.connectedWhen = peer.getConnectionTimestamp(); | ||
this.peersConnectedWhen = peer.getPeersConnectionTimestamp(); | ||
|
||
this.address = peerData.getAddress().toString(); | ||
|
||
this.version = peer.getPeersVersionString(); | ||
this.nodeId = peer.getPeersNodeId(); | ||
|
||
PeerChainTipData peerChainTipData = peer.getChainTipData(); | ||
if (peerChainTipData != null) { | ||
this.lastHeight = peerChainTipData.getLastHeight(); | ||
this.lastBlockSignature = peerChainTipData.getLastBlockSignature(); | ||
this.lastBlockTimestamp = peerChainTipData.getLastBlockTimestamp(); | ||
} | ||
} | ||
public enum Direction { | ||
INBOUND, | ||
OUTBOUND; | ||
} | ||
|
||
public Direction direction; | ||
public Handshake handshakeStatus; | ||
public Long lastPing; | ||
public Long connectedWhen; | ||
public Long peersConnectedWhen; | ||
|
||
public String address; | ||
public String version; | ||
|
||
public String nodeId; | ||
|
||
public Integer lastHeight; | ||
@Schema(example = "base58") | ||
public byte[] lastBlockSignature; | ||
public Long lastBlockTimestamp; | ||
public UUID connectionId; | ||
public String age; | ||
|
||
protected ConnectedPeer() { | ||
} | ||
|
||
public ConnectedPeer(Peer peer) { | ||
this.direction = peer.isOutbound() ? Direction.OUTBOUND : Direction.INBOUND; | ||
this.handshakeStatus = peer.getHandshakeStatus(); | ||
this.lastPing = peer.getLastPing(); | ||
|
||
PeerData peerData = peer.getPeerData(); | ||
this.connectedWhen = peer.getConnectionTimestamp(); | ||
this.peersConnectedWhen = peer.getPeersConnectionTimestamp(); | ||
|
||
this.address = peerData.getAddress().toString(); | ||
|
||
this.version = peer.getPeersVersionString(); | ||
this.nodeId = peer.getPeersNodeId(); | ||
this.connectionId = peer.getPeerConnectionId(); | ||
if (peer.getConnectionEstablishedTime() > 0) { | ||
long age = (System.currentTimeMillis() - peer.getConnectionEstablishedTime()); | ||
long minutes = TimeUnit.MILLISECONDS.toMinutes(age); | ||
long seconds = TimeUnit.MILLISECONDS.toSeconds(age) - TimeUnit.MINUTES.toSeconds(minutes); | ||
this.age = String.format("%dm %ds", minutes, seconds); | ||
} else { | ||
this.age = "connecting..."; | ||
} | ||
|
||
PeerChainTipData peerChainTipData = peer.getChainTipData(); | ||
if (peerChainTipData != null) { | ||
this.lastHeight = peerChainTipData.getLastHeight(); | ||
this.lastBlockSignature = peerChainTipData.getLastBlockSignature(); | ||
this.lastBlockTimestamp = peerChainTipData.getLastBlockTimestamp(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.