namespace NATS.Server.Raft; /// /// Tracks replication and health state for a single RAFT peer. /// Go reference: raft.go peer tracking fields (nextIndex, matchIndex, last contact). /// public sealed class RaftPeerState { /// /// The peer's unique node identifier. /// public required string PeerId { get; init; } /// /// The next log index to send to this peer (leader use only). /// public long NextIndex { get; set; } = 1; /// /// The highest log index known to be replicated on this peer. /// public long MatchIndex { get; set; } /// /// Timestamp of the last successful communication with this peer. /// public DateTime LastContact { get; set; } = DateTime.UtcNow; /// /// Whether this peer is considered active in the cluster. /// public bool Active { get; set; } = true; /// /// Returns true if this peer has been contacted within the election timeout window. /// Go reference: raft.go isCurrent check. /// public bool IsCurrent(TimeSpan electionTimeout) => DateTime.UtcNow - LastContact < electionTimeout; /// /// Returns true if this peer is both active and has been contacted within the health threshold. /// public bool IsHealthy(TimeSpan healthThreshold) => Active && DateTime.UtcNow - LastContact < healthThreshold; }