|
Fray Engine
|
Tracks neighbor liveness and health from what the router hears, and reports state transitions. Not thread safe: all calls and callbacks run on the router (engine message) thread. Never blocks or waits on a neighbor; the clock is injected so time-based rules (3s suspect/degraded, 10s down/unreachable) can be tested. It holds no readiness table itself; the owning router is the source of truth, read through the State callback. More...
#include <neighbor_monitor.hpp>
Classes | |
| struct | QueueHealth |
| struct | HealthReport |
| struct | Neighbor |
Public Types | |
| using | Clock = std::chrono::steady_clock |
| using | Now = std::function<Clock::time_point()> |
| using | Send = std::function<void(Key, MonitorCommand)> |
| using | State = std::function<NeighborState(Key)> |
| using | Changed = std::function<void(Key, NeighborState)> |
Public Member Functions | |
| NeighborMonitor (Send send, State state, Changed changed, Now now=[] { return Clock::now();}) | |
| Creates a monitor with no neighbors. | |
| void | start (Key neighbor) |
| Begins monitoring a neighbor (restarting if already tracked) and requests the probing state. | |
| void | observe (Key neighbor, bool ready) |
| Records that a message was heard from the neighbor and may move it to ready or degraded. Ignored for neighbors not started. A degraded neighbor stays degraded here; tick() recovers it. | |
| void | report (Key neighbor, HealthReport health) |
| Stores a health report received from a neighbor and updates heartbeat and queue-progress timestamps. Ignored for neighbors not started. | |
| void | tick () |
| Periodic check (the owner calls it about once a second): applies the timing rules and sends probes/pings. Probing neighbors get a probe, or become unreachable after 10 seconds. Ready, suspect, degraded and down neighbors become down after 10 seconds of silence, suspect after 3, degraded if health looks bad, or ready again if a degraded one recovered, and each gets a ping. State changes are requested through the Changed callback. | |
Private Member Functions | |
| void | setState (Key neighbor, NeighborState state) |
| Calls the Changed callback only if the router's current state differs from the requested one. | |
Static Private Member Functions | |
| static bool | hasQueue (const HealthReport &health) |
| True if any queue in the report has a nonzero depth. | |
| static bool | isDegraded (const Neighbor &entry, Clock::time_point now) |
| Decides whether a neighbor's health is bad at the given time. | |
Private Attributes | |
| Send | _send |
| State | _state |
| Changed | _changed |
| Now | _now |
| std::map< Key, Neighbor > | _neighbors |
Tracks neighbor liveness and health from what the router hears, and reports state transitions. Not thread safe: all calls and callbacks run on the router (engine message) thread. Never blocks or waits on a neighbor; the clock is injected so time-based rules (3s suspect/degraded, 10s down/unreachable) can be tested. It holds no readiness table itself; the owning router is the source of truth, read through the State callback.
| Key | Identifies a neighbor (ordered; for example ProcessKind). |
Definition at line 26 of file neighbor_monitor.hpp.
| using fray::routing::NeighborMonitor< Key >::Changed = std::function<void(Key, NeighborState)> |
Callback invoked when the monitor decides a neighbor should be in a different state.
Definition at line 38 of file neighbor_monitor.hpp.
| using fray::routing::NeighborMonitor< Key >::Clock = std::chrono::steady_clock |
Monotonic clock.
Definition at line 30 of file neighbor_monitor.hpp.
| using fray::routing::NeighborMonitor< Key >::Now = std::function<Clock::time_point()> |
Callback returning the current time.
Definition at line 32 of file neighbor_monitor.hpp.
| using fray::routing::NeighborMonitor< Key >::Send = std::function<void(Key, MonitorCommand)> |
Callback that transmits a probe or ping to a neighbor.
Definition at line 34 of file neighbor_monitor.hpp.
| using fray::routing::NeighborMonitor< Key >::State = std::function<NeighborState(Key)> |
Callback returning the router's current state for a neighbor.
Definition at line 36 of file neighbor_monitor.hpp.
|
inline |
Creates a monitor with no neighbors.
| send | Transmits a probe or ping to a neighbor. |
| state | Reads the router's current state for a neighbor. |
| changed | Called when the monitor wants a neighbor moved to a new state; the owner applies it. |
| now | Time source; defaults to the steady clock. |
Definition at line 61 of file neighbor_monitor.hpp.
|
inlinestaticprivate |
True if any queue in the report has a nonzero depth.
Definition at line 176 of file neighbor_monitor.hpp.
|
inlinestaticprivate |
Decides whether a neighbor's health is bad at the given time.
| entry | Neighbor bookkeeping. |
| now | Time to evaluate at. |
Definition at line 188 of file neighbor_monitor.hpp.
|
inline |
Records that a message was heard from the neighbor and may move it to ready or degraded. Ignored for neighbors not started. A degraded neighbor stays degraded here; tick() recovers it.
| neighbor | Neighbor heard from. |
| ready | True if the message announced readiness (a READY), which also starts the expectation of health reports. |
Definition at line 86 of file neighbor_monitor.hpp.
|
inline |
Stores a health report received from a neighbor and updates heartbeat and queue-progress timestamps. Ignored for neighbors not started.
| neighbor | Neighbor that reported. |
| health | The report, moved into the monitor. |
Definition at line 107 of file neighbor_monitor.hpp.
|
inlineprivate |
Calls the Changed callback only if the router's current state differs from the requested one.
| neighbor | Neighbor to update. |
| state | Desired state. |
Definition at line 203 of file neighbor_monitor.hpp.
|
inline |
Begins monitoring a neighbor (restarting if already tracked) and requests the probing state.
| neighbor | Neighbor to watch; the next tick() sends probes until it answers or 10 seconds pass. |
Definition at line 72 of file neighbor_monitor.hpp.
|
inline |
Periodic check (the owner calls it about once a second): applies the timing rules and sends probes/pings. Probing neighbors get a probe, or become unreachable after 10 seconds. Ready, suspect, degraded and down neighbors become down after 10 seconds of silence, suspect after 3, degraded if health looks bad, or ready again if a degraded one recovered, and each gets a ping. State changes are requested through the Changed callback.
Definition at line 130 of file neighbor_monitor.hpp.
|
private |
Requests state changes.
Definition at line 214 of file neighbor_monitor.hpp.
|
private |
Watched neighbors.
Definition at line 218 of file neighbor_monitor.hpp.
|
private |
Time source.
Definition at line 216 of file neighbor_monitor.hpp.
|
private |
Transmits probes and pings.
Definition at line 210 of file neighbor_monitor.hpp.
|
private |
Reads the router's state for a neighbor.
Definition at line 212 of file neighbor_monitor.hpp.