Files
praxisandClaude Fable 5.2 c2194c59d4 Protocol core: packet translation between source and native
127 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:47 +02:00

65 lines
3.5 KiB
C++

#pragma once
#include "gateway/protocol.hpp"
#include "gateway/taxi_profile.hpp"
#include "gateway/taxi_paths_profile.hpp"
#include <limits>
#include <queue>
#include <algorithm>
namespace gateway {
// Tortoise TaxiHandler::SendTaxiMenu and TaxiMaskSize=8 uint32 words.
// IDs and discovery bits stay authoritative; client data compatibility is a
// separate requirement. No newer-expansion destinations are invented here.
struct TaxiMenu {uint64_t vendor=0;uint32_t current=0;Bytes known;};
inline TaxiMenu turtle_taxi_menu(std::span<const uint8_t> body){
Reader r(body);if(r.le(4)!=1)throw Error("unsupported taxi window mode");
TaxiMenu menu;menu.vendor=r.le(8);menu.current=r.le(4);menu.known=r.take(32);r.end();
if((menu.vendor>>48)!=0xf130 || !menu.current || menu.current>256)throw Error("invalid source taxi window");
return menu;
}
// Original70334 TaxiPackets::ShowTaxiNodes::Write: optional WindowInfo,
// mask lengths in uint64 blocks, packed vendor, node, then both byte masks.
inline Bytes forever_taxi_menu(const TaxiMenu& menu,const Guid128& vendor){
if(!menu.current || menu.current>256 || menu.known.size()!=32)throw Error("invalid source taxi menu");
auto visible=menu.known;for(unsigned i=0;i<32;++i)visible[i]&=taxi_profile::SupportedMask[i];
Bytes out{0x80};le(out,4,4);le(out,4,4);append(out,pack_guid(vendor));le(out,menu.current,4);
append(out,visible);append(out,visible);return out;
}
inline Bytes forever_taxi_status(const Guid128& vendor,uint8_t source){
if(source>1)throw Error("unsupported source taxi status");
auto out=pack_guid(vendor);le(out,(source?1:2)<<6,1);return out;
}
inline Bytes forever_taxi_reply(std::span<const uint8_t> body){
Reader r(body);auto result=r.le(4);r.end();
// Shared source/target enum0..9 verified; newer-only result codes are not
// accepted as source semantics. Server rejection is never changed to OK.
if(result>9)throw Error("unreviewed source taxi reply");
return Bytes{uint8_t(result<<4)};
}
inline Bytes turtle_taxi_activation(const TaxiMenu& menu,uint32_t destination){
auto known=[&](uint32_t id){return id>=1 && id<=256 && menu.known.size()==32 &&
(menu.known[(id-1)/8]&taxi_profile::SupportedMask[(id-1)/8]&(1u<<((id-1)%8)));};
if(destination==menu.current || !known(menu.current) || !known(destination))throw Error("taxi endpoints outside actual discovery/native mapping");
std::array<uint64_t,257> costs;costs.fill(std::numeric_limits<uint64_t>::max());
std::array<uint32_t,257> parent{};costs[menu.current]=0;
using Step=std::pair<uint64_t,uint32_t>;
std::priority_queue<Step,std::vector<Step>,std::greater<Step>> queue;queue.push({0,menu.current});
while(!queue.empty()){
auto [cost,node]=queue.top();queue.pop();if(cost!=costs[node])continue;
if(node==destination)break;
for(const auto& edge:taxi_profile::Paths)if(edge.from==node && known(edge.to) && cost+edge.cost<costs[edge.to]){
costs[edge.to]=cost+edge.cost;parent[edge.to]=node;queue.push({costs[edge.to],edge.to});
}
}
if(costs[destination]>0xffffffffu)throw Error("no bounded discovered source taxi route");
std::vector<uint32_t> route{destination};
while(route.back()!=menu.current){
if(route.size()>=256 || !parent[route.back()])throw Error("invalid source taxi route reconstruction");
route.push_back(parent[route.back()]);
}
std::reverse(route.begin(),route.end());Bytes out;le(out,menu.vendor,8);le(out,costs[destination],4);le(out,route.size(),4);
for(auto node:route)le(out,node,4);
return out;
}
}