diff --git a/MobileGL/MG_Remote/Protocol/generated/protocol_generated.h b/MobileGL/MG_Remote/Protocol/generated/protocol_generated.h index 3dd6897a..2a2fc473 100644 --- a/MobileGL/MG_Remote/Protocol/generated/protocol_generated.h +++ b/MobileGL/MG_Remote/Protocol/generated/protocol_generated.h @@ -50,6 +50,9 @@ struct WelcomeBuilder; struct DataBind; struct DataBindBuilder; +struct PairBind; +struct PairBindBuilder; + struct CapsSnapshot; struct CapsSnapshotBuilder; @@ -552,11 +555,12 @@ enum class CtrlMsg : uint8_t { LogFlush = 12, DataBind = 13, SurfaceProgress = 14, + PairBind = 15, MIN = NONE, - MAX = SurfaceProgress + MAX = PairBind }; -inline const CtrlMsg (&EnumValuesCtrlMsg())[15] { +inline const CtrlMsg (&EnumValuesCtrlMsg())[16] { static const CtrlMsg values[] = { CtrlMsg::NONE, CtrlMsg::Hello, @@ -572,13 +576,14 @@ inline const CtrlMsg (&EnumValuesCtrlMsg())[15] { CtrlMsg::Refuse, CtrlMsg::LogFlush, CtrlMsg::DataBind, - CtrlMsg::SurfaceProgress + CtrlMsg::SurfaceProgress, + CtrlMsg::PairBind }; return values; } inline const char * const *EnumNamesCtrlMsg() { - static const char * const names[16] = { + static const char * const names[17] = { "NONE", "Hello", "Welcome", @@ -594,13 +599,14 @@ inline const char * const *EnumNamesCtrlMsg() { "LogFlush", "DataBind", "SurfaceProgress", + "PairBind", nullptr }; return names; } inline const char *EnumNameCtrlMsg(CtrlMsg e) { - if (::flatbuffers::IsOutRange(e, CtrlMsg::NONE, CtrlMsg::SurfaceProgress)) return ""; + if (::flatbuffers::IsOutRange(e, CtrlMsg::NONE, CtrlMsg::PairBind)) return ""; const size_t index = static_cast(e); return EnumNamesCtrlMsg()[index]; } @@ -665,6 +671,10 @@ template<> struct CtrlMsgTraits { static const CtrlMsg enum_value = CtrlMsg::SurfaceProgress; }; +template<> struct CtrlMsgTraits { + static const CtrlMsg enum_value = CtrlMsg::PairBind; +}; + template bool VerifyCtrlMsg(::flatbuffers::VerifierTemplate &verifier, const void *obj, CtrlMsg type); template @@ -1478,6 +1488,76 @@ inline ::flatbuffers::Offset CreateDataBindDirect( nonce__); } +struct PairBind FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { + typedef PairBindBuilder Builder; + struct Traits; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_NONCE = 4, + VT_AUX = 6 + }; + const ::flatbuffers::Vector *nonce() const { + return GetPointer *>(VT_NONCE); + } + bool aux() const { + return GetField(VT_AUX, 0) != 0; + } + template + bool Verify(::flatbuffers::VerifierTemplate &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_NONCE) && + verifier.VerifyVector(nonce()) && + VerifyField(verifier, VT_AUX, 1) && + verifier.EndTable(); + } +}; + +struct PairBindBuilder { + typedef PairBind Table; + ::flatbuffers::FlatBufferBuilder &fbb_; + ::flatbuffers::uoffset_t start_; + void add_nonce(::flatbuffers::Offset<::flatbuffers::Vector> nonce) { + fbb_.AddOffset(PairBind::VT_NONCE, nonce); + } + void add_aux(bool aux) { + fbb_.AddElement(PairBind::VT_AUX, static_cast(aux), 0); + } + explicit PairBindBuilder(::flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + ::flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = ::flatbuffers::Offset(end); + return o; + } +}; + +inline ::flatbuffers::Offset CreatePairBind( + ::flatbuffers::FlatBufferBuilder &_fbb, + ::flatbuffers::Offset<::flatbuffers::Vector> nonce = 0, + bool aux = false) { + PairBindBuilder builder_(_fbb); + builder_.add_nonce(nonce); + builder_.add_aux(aux); + return builder_.Finish(); +} + +struct PairBind::Traits { + using type = PairBind; + static auto constexpr Create = CreatePairBind; +}; + +inline ::flatbuffers::Offset CreatePairBindDirect( + ::flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *nonce = nullptr, + bool aux = false) { + auto nonce__ = nonce ? _fbb.CreateVector(*nonce) : 0; + return MobileGL::Wire::CreatePairBind( + _fbb, + nonce__, + aux); +} + struct CapsSnapshot FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { typedef CapsSnapshotBuilder Builder; struct Traits; @@ -2416,6 +2496,9 @@ struct CtrlEnvelope FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { const MobileGL::Wire::SurfaceProgress *msg_as_SurfaceProgress() const { return msg_type() == MobileGL::Wire::CtrlMsg::SurfaceProgress ? static_cast(msg()) : nullptr; } + const MobileGL::Wire::PairBind *msg_as_PairBind() const { + return msg_type() == MobileGL::Wire::CtrlMsg::PairBind ? static_cast(msg()) : nullptr; + } template bool Verify(::flatbuffers::VerifierTemplate &verifier) const { return VerifyTableStart(verifier) && @@ -2482,6 +2565,10 @@ template<> inline const MobileGL::Wire::SurfaceProgress *CtrlEnvelope::msg_as inline const MobileGL::Wire::PairBind *CtrlEnvelope::msg_as() const { + return msg_as_PairBind(); +} + struct CtrlEnvelopeBuilder { typedef CtrlEnvelope Table; ::flatbuffers::FlatBufferBuilder &fbb_; @@ -2580,6 +2667,10 @@ inline bool VerifyCtrlMsg(::flatbuffers::VerifierTemplate &verifier, const vo auto ptr = reinterpret_cast(obj); return verifier.VerifyTable(ptr); } + case CtrlMsg::PairBind: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } default: return true; } } diff --git a/MobileGL/MG_Remote/Protocol/mg_protocol_base.h b/MobileGL/MG_Remote/Protocol/mg_protocol_base.h index edf4e928..cacd67e2 100644 --- a/MobileGL/MG_Remote/Protocol/mg_protocol_base.h +++ b/MobileGL/MG_Remote/Protocol/mg_protocol_base.h @@ -67,7 +67,9 @@ extern "C" { // 2 P7 (p7/spawnhang): the SurfaceProgress message. // 3 P12 (on-screen server window): WindowKind.ServerOwned, the SurfaceRefusal enum and // SurfaceReply.width/height/refusal. -#define MOBILEGL_PROTOCOL_CONTROL_REVISION 3 +// 4 P11 PAIR: the PairBind message - a socket client's control and aux connections pair by +// the nonce each presents first, not by arrival order. +#define MOBILEGL_PROTOCOL_CONTROL_REVISION 4 #define MOBILEGL_ABI_VERSION(major, minor) (((uint32_t)(major) << 16) | (uint32_t)(minor)) #define MOBILEGL_ABI_MAJOR_OF(version) ((uint32_t)(version) >> 16) diff --git a/MobileGL/MG_Remote/Protocol/protocol.fbs b/MobileGL/MG_Remote/Protocol/protocol.fbs index db1f9487..b0f05e5a 100644 --- a/MobileGL/MG_Remote/Protocol/protocol.fbs +++ b/MobileGL/MG_Remote/Protocol/protocol.fbs @@ -142,6 +142,19 @@ table DataBind { nonce: [ubyte]; } +// P11 PAIR. The FIRST frame on each of the two connections a socket client opens with +// SocketTransport::ConnectTo - control, then aux (the SCM_RIGHTS socket; the data connection on a +// tcp:// ConnectTo) - and on control the only frame before the Hello. `nonce` is 128 bits from the +// client's CSPRNG, the same on both; `aux` says which of the two this connection is. The server +// holds every accepted connection until it has presented this and pairs the two halves by the +// nonce, never by arrival order (Server/PairAcceptor.h): a stray connection, or a second client +// connecting at the same moment, cannot become half of this client's session. A control connection +// whose first frame is a Hello is a peer from before this message and is refused by name. +table PairBind { + nonce: [ubyte]; + aux: bool; +} + // --------------------------------------------------------------------------- // Capabilities // --------------------------------------------------------------------------- @@ -401,6 +414,7 @@ union CtrlMsg { LogFlush, DataBind, SurfaceProgress, + PairBind, } table CtrlEnvelope { diff --git a/scripts/ci/protocol_revision_pins.json b/scripts/ci/protocol_revision_pins.json index b8443b0e..579fe842 100644 --- a/scripts/ci/protocol_revision_pins.json +++ b/scripts/ci/protocol_revision_pins.json @@ -1,5 +1,6 @@ { "1": "7fc859f7fa756818401f4162e7d49a25d430b91e44d89c297321e3cb36c69638", "2": "b30928e6fc93ddc015fd86f634a6820f775a6f2f6de5a848d273981e706b2597", - "3": "da09f0acb48cf245703f28556ef5a38bc9e25241ebbf7b6baa9ab1765b7ddd50" + "3": "da09f0acb48cf245703f28556ef5a38bc9e25241ebbf7b6baa9ab1765b7ddd50", + "4": "6357c3a07ae258d2825dc42bfd610712b15a38a3beb7a96b5f56ea2988705e7f" }