127 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
30 lines
1.4 KiB
C++
30 lines
1.4 KiB
C++
#pragma once
|
|
#include "gateway/protocol.hpp"
|
|
#include <optional>
|
|
namespace gateway {
|
|
struct LegacyPacket { uint32_t opcode; Bytes body; };
|
|
// Transport-independent, single-owner Turtle world framing. Account/SRP/world
|
|
// authentication remains with the caller; this class cannot establish it.
|
|
class LegacyPacketStream {
|
|
friend class WorldAuthentication;
|
|
Cipher outbound_,inbound_;
|
|
std::array<uint8_t,4> header_{};
|
|
size_t header_bytes_=0,body_bytes_=0;
|
|
std::optional<LegacyPacket> packet_;
|
|
bool failed_=false,allow_plain_auth_failure_=false;
|
|
void authentication_complete(){allow_plain_auth_failure_=false;}
|
|
public:
|
|
explicit LegacyPacketStream(const Bytes& key,bool allow_plain_auth_failure=false):outbound_(key,HeaderKeyWidth::SourceBigNumber),inbound_(key,HeaderKeyWidth::SourceBigNumber),allow_plain_auth_failure_(allow_plain_auth_failure){}
|
|
LegacyPacketStream(const LegacyPacketStream&)=delete;
|
|
LegacyPacketStream& operator=(const LegacyPacketStream&)=delete;
|
|
// Bounded destination demand; a transport may supply arbitrary chunks.
|
|
size_t needed() const;
|
|
// Consumes at most one header/body segment. Unconsumed coalesced input stays
|
|
// with the caller. Returns0 while a complete packet awaits take().
|
|
size_t feed(std::span<const uint8_t>);
|
|
bool ready() const;
|
|
LegacyPacket take();
|
|
Bytes encode(uint32_t opcode,std::span<const uint8_t>);
|
|
};
|
|
}
|