Skip to content

Add ShortIDFromContext so handlers can attribute a stream to its short ID - #20

Merged
myleshorton merged 1 commit into
mainfrom
fisk/shortid-from-context
Oct 31, 2026
Merged

myleshorton merged 1 commit into
mainfrom
fisk/shortid-from-context

Conversation

@myleshorton

@myleshorton myleshorton commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Adds ShortIDFromContext(ctx) ([8]byte, bool), so a handler can tell which short ID its session authenticated with.

Why

Lantern's personal proxies give each helper-invite pairing its own samizdat short ID on the volunteer's peer proxy. To show "Adam connected right now" on the volunteer's device, lantern-box's samizdat inbound has to attribute each stream to a pairing. The server already verifies and tracks the short ID per session, but handlers could only reach the session's connection (SessionConnFromContext).

Changes

  • handleAuthenticated passes the short ID it verified to serveH2, which stores it in the ServeConn context next to sessionConnKey. Every stream's handler context inherits it.
  • ShortIDFromContext sits next to SessionConnFromContext. The repo's short ID type is [shortIDLen]byte with shortIDLen = 8, which the public API already spells [8]byte.
  • Additive only: no behavior change, and nothing logs the short ID.

Testing

  • TestIntegrationShortIDInContext: two clients, one per allowed short ID, two streams each. Each handler sees its own session's ID.
  • TestShortIDFromContextMissing: a context without the ID returns the zero value and false.
  • go build ./..., go vet ./... and go test -race -count=1 ./... pass.
  • golangci-lint run --new-from-rev=origin/main reports 0 issues.

Risk

Very low. The ID is fixed for a session's lifetime, which is fine because revoking an ID with SetShortIDs already closes the session.

How to revert

Revert the merge commit.

Rollout

lantern-box will bump samizdat and add the short ID to peerconn.Event (the next step).

Pre-PR review (local Codex gate)

  • Rounds: 1. Final: CODEX GATE: verdict=approve critical=0 important=0 minor=0 preexisting=0 reviewed=6
  • Reviewed at: ee59657
  • Exit: approve
  • Step back: not needed
  • Fixed: none
  • Dismissed: none
  • Pre-existing (not introduced here, worth filing): gofmt -l lists connpool.go, fragmenter.go, integration_test.go, samizdat.go and server.go on main.
  • Proposed AGENTS.md additions: none

🤖 Generated with Claude Code

https://claude.ai/code/session_01KqE58aYaai3u8CFZe5nXdE

Summary by CodeRabbit

  • New Features
    • Authenticated HTTP/2 handlers can now access the short ID associated with the active session.
  • Tests
    • Added coverage verifying that handlers receive the correct session ID across multiple clients and streams.
    • Added checks confirming that a session ID is not reported when the relevant session context is missing.

Add ShortIDFromContext alongside SessionConnFromContext so a Handler can
tell which of the server's accepted short IDs its session authenticated
with. handleAuthenticated already has it from VerifySessionID; serveH2
now carries it into the per-connection context every stream inherits.
Additive only: no behavior change, and the ID is never logged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KqE58aYaai3u8CFZe5nXdE
Copilot AI balanced review requested due to automatic review settings October 30, 2026 22:02
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ee0b107f-7a0d-46b5-9075-c2d94bdde8e9
Commits

Reviewing files that changed from the base of the PR and between 50f4385 and ee59657.

Files selected for processing: 2
  • integration_test.go
  • server.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The server now exposes the authenticated session’s short ID through ShortIDFromContext. HTTP/2 handler contexts carry both the accepted connection and short ID. Integration tests check retrieval across clients and streams, and check contexts without a session connection.

Changes: Handler context access

Layer / File(s) Summary
Expose short ID to handlers
server.go, integration_test.go
serveH2 receives the authenticated short ID and adds it to HTTP/2 request contexts. ShortIDFromContext reports whether the ID is present. Integration tests check IDs across clients and streams, plus missing-context cases.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Possibly related PRs

  • getlantern/samizdat#17: Adds the session connection to the handler context, which PR #20 retains while adding the short ID.
  • getlantern/samizdat#18: Passes the verified short ID through authentication, which PR #20 uses when creating the handler context.
Merge Risk: Minimal · up to ee596

No merge-blocking issue is apparent from the supplied review evidence.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: adding ShortIDFromContext so handlers can identify a stream's authenticated short ID.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the change adding session short-ID attribution to handler contexts.

No open issues 🎉

What changed in this PR

Adds ShortIDFromContext so handlers can attribute each stream to its session’s authenticated short ID, supporting per-pairing connection reporting.

Changes:

  • Passes the verified short ID into the HTTP/2 session context alongside the session connection.
  • Exposes an additive accessor returning the short ID and whether it is present.
  • Adds tests for attribution across two clients with two streams each, plus missing-value behavior.
File Description
server.go Propagates the authenticated short ID to handler contexts and adds its public accessor.
integration_test.go Tests per-session short ID attribution and contexts without a short ID.

Review effort: Balanced

@myleshorton
myleshorton merged commit 1248df9 into main Oct 31, 2026
4 checks passed
@myleshorton
myleshorton deleted the fisk/shortid-from-context branch October 31, 2026 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants