class Raft::Transport::TCP

Overview

TCP transport with TLV framing, HMAC-SHA256 authentication, and connection pooling.

Maintains one persistent TCP connection per peer, lazily established on the first #send. Failed connections are retried with exponential backoff (100ms initial, doubling up to 10s). Inbound connections are authenticated via Transport::Handshake before any messages are exchanged.

Defined in:

raft/transport/tcp.cr

Constructors

Instance Method Summary

Instance methods inherited from class Raft::Transport

send(peer_id : String, message : RPC::Message) : Nil send, start(inbox : Channel(RPC::Envelope)) : Nil start, stop : Nil stop

Constructor Detail

def self.new(bind_address : String, port : Int32, peer_addresses : Hash(String, Tuple(String, Int32)), cookie : String) #

[View source]

Instance Method Detail

def actual_port : Int32 #

Returns the actual port the server is listening on.

Useful when binding to port 0 (OS-assigned) in tests.


[View source]
def send(peer_id : String, message : RPC::Message) : Nil #
Description copied from class Raft::Transport

Sends an RPC message to the peer identified by peer_id.

Delivery is best-effort. If the peer is unreachable the message is silently dropped — Raft's protocol-level retries handle the loss.


[View source]
def start(inbox : Channel(RPC::Envelope)) : Nil #
Description copied from class Raft::Transport

Starts listening for incoming messages.

Received messages are wrapped in RPC::Envelope (tagged with sender ID) and pushed into the provided inbox channel.


[View source]
def stop : Nil #
Description copied from class Raft::Transport

Shuts down the transport, closing all connections and listeners.


[View source]