22#include <flow/error/error.hpp>
29 flow::log::Log_context(logger_ptr,
Log_component::S_TRANSPORT),
31 m_local_max_proto_ver(local_max_proto_ver),
32 m_local_min_proto_ver(local_min_proto_ver),
33 m_local_max_proto_ver_sent(false),
34 m_negotiated_proto_ver(S_VER_UNKNOWN)
39 FLOW_LOG_INFO(
"Protocol_negotiator [" <<
m_nickname <<
"]: We speak protocol version range "
76 opposing_max_proto_ver, _1);
81 FLOW_LOG_TRACE(
"Protocol_negotiator [" <<
m_nickname <<
"]: We were asked to compute negotiated protocol version "
82 "based on opposing max-version [" << opposing_max_proto_ver <<
"]; but we have already done so "
84 "Tip: Check for negotiated_proto_ver()=UNKNOWN before calling us.");
89 if (opposing_max_proto_ver <= 0)
91 FLOW_LOG_WARNING(
"Protocol_negotiator [" <<
m_nickname <<
"]: Negotiation computation: "
93 "they speak at most [" << opposing_max_proto_ver <<
"]. The latter value is in and of itself "
94 "invalid -- we cannot trust the other side at all; or there may be a bug in user code here. "
95 "Presumably we will abruptly close this comm pathway shorly.");
103 FLOW_LOG_INFO(
"Protocol_negotiator [" <<
m_nickname <<
"]: Negotiation computation: "
105 "they speak at most [" << opposing_max_proto_ver <<
"]; therefore we shall speak "
107 "in which case it will abruptly close this comm pathway shortly.");
112 FLOW_LOG_INFO(
"Protocol_negotiator [" <<
m_nickname <<
"]: Negotiation computation: "
114 "they speak at most [" << opposing_max_proto_ver <<
"]; therefore we shall speak "
115 "[" << opposing_max_proto_ver <<
"], as we are backwards-compatible with that version.");
120 FLOW_LOG_WARNING(
"Protocol_negotiator [" <<
m_nickname <<
"]: Negotiation computation: "
122 "they speak at most [" << opposing_max_proto_ver <<
"]; therefore we lack backwards-compatibility "
123 "with that older version. Presumably we will abruptly close this comm pathway shorly.");
138 FLOW_LOG_INFO(
"Protocol_negotiator [" <<
m_nickname <<
"]: About to send our preferred (highest) version "
A simple state machine that, assuming the opposide side of a comm pathway uses an equivalent state ma...
static constexpr proto_ver_t S_VER_UNSUPPORTED
A proto_ver_t value, namely zero, which is a reserved value indicating "unsupported version"; it is n...
void reset()
Resets the negotiation state, meaning back to the state as-if just after ctor invoked.
std::string m_nickname
The nickname from ctor. Not const so as to support copyability.
int16_t proto_ver_t
Type sufficient to store a protocol version; positive values identify newer versions of a protocol; w...
Protocol_negotiator(flow::log::Logger *logger_ptr, util::String_view nickname, proto_ver_t local_max_proto_ver, proto_ver_t local_min_proto_ver)
Constructs a comm pathway's negotiator object in initial state wherein: (1) negotiated_proto_ver() re...
proto_ver_t local_max_proto_ver_for_sending()
To be called at most once, this returns local_max_proto_ver from ctor the first time and S_VER_UNKNOW...
bool compute_negotiated_proto_ver(proto_ver_t opposing_max_proto_ver, Error_code *err_code=0)
Based on the presumably-just-received-from-opposing-side value of their local_max_proto_ver,...
proto_ver_t m_local_max_proto_ver
local_max_proto_ver from ctor. Not const so as to support copyability.
proto_ver_t negotiated_proto_ver() const
Returns S_VER_UNKNOWN before compute_negotiated_proto_ver(); then either the positive version of the ...
static constexpr proto_ver_t S_VER_UNKNOWN
A proto_ver_t value, namely a negative one, which is a reserved value indicating "unknown version"; i...
proto_ver_t m_negotiated_proto_ver
See negotiated_proto_ver().
proto_ver_t m_local_min_proto_ver
local_min_proto_ver from ctor. Not const so as to support copyability.
bool m_local_max_proto_ver_sent
Init value false indicating has local_max_proto_ver_for_sending() has not been called; subsequently t...
Protocol_negotiator & operator=(const Protocol_negotiator &src)
Copy-assigns *this to be equal to src.
@ S_PROTOCOL_NEGOTIATION_OPPOSING_VER_INVALID
In protocol negotiation, opposing side sent invalid version value (not positive, not a number,...
@ S_PROTOCOL_NEGOTIATION_OPPOSING_VER_TOO_OLD
In protocol negotiation, opposing side reported its newest protocol version is even older than the mo...
Flow-IPC module providing transmission of structured messages and/or low-level blobs (and more) betwe...
flow::util::String_view String_view
Short-hand for Flow's String_view.
Log_component
The flow::log::Component payload enumeration containing various log components used by Flow-IPC inter...
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.