Class Peer
A Peer encapsulates all the addressing and identity information needed to
establish and maintain a TCP connection to another network participant. It is used by
PeerManager to track the set of known nodes and by NodeClient
to open outbound connections (design.md ยง3, FR-NET-01).
Identity vs address
The nodeId is a stable logical identifier (e.g., a hex-encoded public key hash)
that persists across reconnections. The host/port pair is the current
physical location of the peer, which may change if the peer restarts on a different address.
Usage
Peer peer = Peer.builder()
.nodeId("ab12cd34ef56...")
.host("192.168.1.10")
.port(8545)
.publicKeyHex("04aabb...")
.build();
// Record a heartbeat
Peer refreshed = peer.withLastSeen(Instant.now());
- Since:
- 1.0.0
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic Peer.Builderbuilder()Returns a newPeer.Builderfor constructing aPeer.booleanTwo peers are equal if and only if theirnodeIds are equal.Returns the network address inhost:portnotation.getHost()Returns the hostname or IP address of this peer.Returns the UTC instant of the most recent heartbeat or message exchange.Returns the stable logical identifier of this peer.intgetPort()Returns the TCP port on which this peer's node server listens.Returns the hex-encoded secp256k1 public key of this peer.inthashCode()Hash code based solely onnodeIdfor consistency withequals(java.lang.Object).toString()Returns a human-readable summary of this peer (safe for logging).withLastSeen(Instant lastSeen) Returns a newPeerwith thelastSeenfield updated to the given instant.withPublicKey(String publicKeyHex) Returns a newPeerwith the public key filled in after handshake.
-
Method Details
-
builder
Returns a newPeer.Builderfor constructing aPeer.- Returns:
- a fresh, empty builder
-
getNodeId
Returns the stable logical identifier of this peer.- Returns:
- non-null, non-blank node ID
-
getHost
Returns the hostname or IP address of this peer.- Returns:
- non-null, non-blank host string
-
getPort
public int getPort()Returns the TCP port on which this peer's node server listens.- Returns:
- port in range [1024, 65535]
-
getPublicKeyHex
Returns the hex-encoded secp256k1 public key of this peer.May return
nullif the key exchange handshake has not yet completed (e.g., for a freshly discovered peer).- Returns:
- hex-encoded public key, or
nullbefore handshake
-
getLastSeen
Returns the UTC instant of the most recent heartbeat or message exchange.Returns
nullfor peers that have been added to the peer list but have not yet been contacted.- Returns:
- last-seen timestamp, or
null
-
getAddress
Returns the network address inhost:portnotation.- Returns:
- formatted address string (e.g.
"192.168.1.10:8545")
-
withLastSeen
Returns a newPeerwith thelastSeenfield updated to the given instant.All other fields are carried over unchanged. This method is used by
PeerManageron every successful heartbeat or message exchange.- Parameters:
lastSeen- updated last-seen timestamp (non-null)- Returns:
- new
Peerinstance with updated timestamp - Throws:
NullPointerException- if lastSeen is null
-
withPublicKey
Returns a newPeerwith the public key filled in after handshake.- Parameters:
publicKeyHex- hex-encoded secp256k1 public key (non-null, non-blank)- Returns:
- new
Peerinstance with populated public key - Throws:
NullPointerException- if publicKeyHex is nullIllegalArgumentException- if publicKeyHex is blank
-
equals
Two peers are equal if and only if theirnodeIds are equal. -
hashCode
public int hashCode()Hash code based solely onnodeIdfor consistency withequals(java.lang.Object). -
toString
Returns a human-readable summary of this peer (safe for logging).
-