HPPR Replication and Streams
Tags: repo, command, streaming
© R.A.Sol
Repository replication and live streams are repository commands with streaming result modes from 031.
🖧EXCHANGEuses negotiated raw packet exchange🖧STREAM_PUBuses relay mode after response🖧STREAM_SUBuses relay mode without response
🖧EXCHANGE
🖧EXCHANGE synchronizes packets while preserving
repository policy decisions. It has three phases:
- announce
- transfer
- finalize
Phase 1: Announce
Requester sends up to 1024 LF-separated lines:
NEED <versioned-coordinate>
HAVE <versioned-coordinate>
Responder returns FIN or PENDING
followed by status lines:
SEND <coord>
DENY <coord>
RECV <coord>
HAVE <coord>
Status meanings:
SEND: responder will send this packetDENY: denied by repository policyRECV: responder wants this packet from requesterHAVE: responder already has this packet
Phase 2: Transfer
Both peers stream raw packets concurrently in both directions.
Implementations MUST perform bidirectional I/O concurrently. Unidirectional blocking can deadlock the exchange.
Packet boundaries are parsed using Data-Length.
Phase 3: Finalize
When Phase 1 returned PENDING, the responder reports
final results for the coordinates that entered Phase 2 transfer
(SEND and RECV items):
FIN
OK <coord>
FAIL <coord> <type> <msg>
Phase 1 HAVE and DENY items are already
terminal negotiation results and do not appear in Phase 3.
OK means the Phase 2 action for that coordinate
completed: for SEND, the responder wrote the packet
bytes; for RECV, the responder received, validated, and
stored the matching packet. FAIL is only used for
receive/store failures after a RECV, for example
invalid received packet, coordinate mismatch, hash mismatch, storage
failure, or stream EOF before the expected packet arrived.
A responder MUST NOT skip a packet promised by Phase 1
SEND and report that missing packet as Phase 3
FAIL. Clients count exact raw Phase 2 packets after
SEND; a missing raw packet would make the Phase 3
response packet ambiguous. If a responder cannot write a promised
SEND packet, it MUST fail the exchange at the
connection level, for example with a FATAL error or close.
Repository Authorization in Phase 1
Authorization for NEED and HAVE is
repository-service behavior.
The HPPR Repository Service applies the following ACL rules in Phase 1.
For NEED <coord>:
- check
read - if readable and exists:
SEND - else:
DENY
For HAVE <coord>:
- check
read - if denied:
DENY - if allowed and exists:
HAVE - if missing, check
write - if writable:
RECV - else:
DENY
Blob-Addressed
🖧EXCHANGE
🖧EXCHANGE also accepts blob hash addressing:
NEED ////B.<hash>.H3
HAVE ////B.<hash>.H3
Rules:
- only
B.hashes are valid P.andS.in blob-addressed mode are FATAL invalid requests- additional authorization rules are service-specific
- the HPPR Repository Service applies no ACL checks in this mode
- the HPPR Repository Service allows any authenticated session to request blob hash sync
Decision rules:
NEED: blob exists =>SEND, elseDENYHAVE: blob exists =>HAVE, elseRECV
Transfer still uses full raw blob packets.
🖧STREAM_PUB
🖧STREAM_PUB ingests live trailer-format Seal
segments.
Request:
API: 🖧STREAM_PUB- data:
<coordinate-prefix>
Response:
- sealed
OK
After OK, connection enters relay mode and accepts
trailer segments.
Per segment:
- relay bytes to matching
🖧STREAM_SUBsubscribers - detect segment close marker
- verify hash and signature
- store packet
- emit
🖧WATCHevent
Authorization is repository-service behavior. The HPPR Repository
Service checks write per segment at store time.
Disconnect behavior:
- publisher disconnect ends stream
- no explicit end marker required
- partial in-flight segment is discarded
- subscriber sockets are closed
No FATAL is injected into relay stream. Subscribers detect truncation via trailer parsing.
Size rule:
- each segment must respect 32 MiB blob limit
Continuity recommendation:
- include
Previous-Segment: <hash>after first segment
🖧STREAM_SUB
🖧STREAM_SUB subscribes to live trailer bytes by
prefix.
Request:
API: 🖧STREAM_SUB- data:
<coordinate-prefix>
Behavior:
- enters dedicated relay mode immediately
- no
OKresponse packet - when no active publisher exists for the prefix, subscriber waits for one
- wait uses a fixed server timeout
- on wait timeout, repo writes
FATAL NOT_FOUND wait timeoutand closes - forwards bytes from matching active publishers
Late joiners receive bytes buffered from current in-flight segment and then continue live.
Authorization is repository-service behavior. The HPPR Repository
Service checks read at subscription time.
On publisher disconnect, repo closes subscriber sockets. Mid-segment disconnect yields partial trailer data followed by EOF.
Completed segments remain available via 🖧GET and
🖧EXCHANGE.
Relay Chaining
A downstream repo can relay a live stream by:
- subscribing upstream with
🖧STREAM_SUB - publishing downstream with
🖧STREAM_PUB