Class ProtocolNegotiator
When two nodes connect, they perform a handshake to: 1. Exchange LoomVersion information (major.minor.patch) 2. Exchange protocol version integers 3. Determine compatibility 4. Confirm both peers use the single wire version supported by this build
This build does not include versioned codecs. Rolling upgrades are supported
only when both peers advertise MessageCodec.PROTOCOL_VERSION. Feature
flags may still disable optional behavior within that exact wire version.
Thread-safe: Each connection has one negotiator instance (used during handshake only).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classException thrown when version negotiation fails. -
Constructor Summary
ConstructorsConstructorDescriptionProtocolNegotiator(LoomVersion localVersion, int localProtocolVersion) Create a protocol negotiator. -
Method Summary
Modifier and TypeMethodDescriptionstatic ProtocolNegotiatorCreate a negotiator with current version.voidperformHandshake(LoomVersion remoteVersion, int remoteProtocolVersion) Perform version handshake with a remote peer.voidperformHandshake(LoomVersion remoteVersion, LoomVersion remoteMinCompatibleVersion, int remoteProtocolVersion) Perform version handshake with a remote peer using the peer's advertised minimum compatible version.
-
Constructor Details
-
ProtocolNegotiator
Create a protocol negotiator.- Parameters:
localVersion- the local LoomVersion (must not be null)localProtocolVersion- the local protocol version (must be > 0)- Throws:
IllegalArgumentException- if localVersion is null or localProtocolVersion is invalid input: '<'= 0
-
-
Method Details
-
forCurrentVersion
Create a negotiator with current version.- Returns:
- a new ProtocolNegotiator with current version
-
performHandshake
Perform version handshake with a remote peer.When the remote peer's advertised minimum-compatible version is unavailable, this overload conservatively assumes the peer only accepts its current version.
- Parameters:
remoteVersion- the remote node's LoomVersion (must not be null)remoteProtocolVersion- the remote node's protocol version (must be > 0)- Throws:
ProtocolNegotiator.IncompatibleVersionException- if versions are incompatibleIllegalArgumentException- if parameters are invalid
-
performHandshake
public void performHandshake(LoomVersion remoteVersion, LoomVersion remoteMinCompatibleVersion, int remoteProtocolVersion) Perform version handshake with a remote peer using the peer's advertised minimum compatible version.Validates that: 1. The remote version satisfies the local minimum-compatible floor 2. The local version satisfies the remote minimum-compatible floor 3. Both sides agree on minimum protocol version 4. Negotiated protocol version is set for serialization
Rejects the handshake if versions are incompatible.
- Parameters:
remoteVersion- the remote node's LoomVersion (must not be null)remoteMinCompatibleVersion- the remote node's minimum compatible LoomVersion (must not be null)remoteProtocolVersion- the remote node's protocol version (must be > 0)- Throws:
ProtocolNegotiator.IncompatibleVersionException- if versions are incompatibleIllegalArgumentException- if parameters are invalid
-