feat: add routing policy commands - #67
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new shared DAG-JSON helpers allow unbounded object/array sizes (missing the generators’ 8192-entry limit), creating an avoidable input-parsing DoS risk and inconsistent decoding behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR introduces a new commands/routing package that defines UCAN commands for routing policies (/routing/put and /routing/use), including types, codecs, and generated CBOR/DAG-JSON encoders/decoders. It also refactors existing hand-written codecs to use a new shared internal codec helper package.
Changes:
- Add
/routing/putand/routing/usecommand bindings plus routing policy argument types. - Add a hand-written codec for DID-keyed
CandidateSet, along with generated*_gen.gofiles and round-trip tests. - Introduce
commands/internal/codecto share CBOR/DAG-JSON helper primitives and update the S3 hand-written codec to use it.
File summaries
| File | Description |
|---|---|
| commands/s3/codec.go | Refactors hand-written codecs to use shared internal codec helpers. |
| commands/routing/use.go | Adds /routing/use command binding and stable error-name constants. |
| commands/routing/types.go | Defines routing policy types and command argument structs. |
| commands/routing/put.go | Adds /routing/put command binding and stable error-name constant. |
| commands/routing/json_gen.go | Generated DAG-JSON codec for routing types/arguments. |
| commands/routing/gen/main.go | Code generator entrypoint for routing CBOR/DAG-JSON files. |
| commands/routing/codec.go | Hand-written codec for DID-keyed CandidateSet. |
| commands/routing/codec_test.go | Round-trip tests for routing codecs and wire format. |
| commands/routing/cbor_gen.go | Generated CBOR codec for routing types/arguments. |
| commands/internal/codec/codec.go | New shared CBOR/DAG-JSON helper primitives for hand-written codecs. |
Review details
Files not reviewed (2)
- commands/routing/cbor_gen.go: Generated file
- commands/routing/json_gen.go: Generated file
Suppressed comments (1)
commands/internal/codec/codec.go:194
- ReadJSONArray has no maximum element count, unlike dag-json-gen generated decoders which reject arrays larger than 8192 elements. Adding a limit here avoids unbounded allocation/CPU on malicious inputs and keeps behavior consistent with generator defaults.
for {
v, err := read()
if err != nil {
return nil, err
}
out = append(out, v)
close, err := jr.ReadArrayCloseOrComma()
if err != nil {
return nil, err
}
if close {
return out, nil
}
}
- Files reviewed: 8/10 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Adds:
/routing/put- add/update a routing policy/routing/use- instruct a space to use an existing routing policyrefs https://github.com/fil-one/RFC/blob/main/rfcs/2026-08-routing-policies.md