fastn
fastn copied to clipboard
feat: complete fastn-p2p streaming API and remote shell functionality
Summary
Main Tracking PR - Complete implementation plan for fastn-p2p streaming API and remote shell functionality (rshell/rexec). This PR tracks the complete plan originally outlined in PR #2202, building on the fastn-context foundation from PR #2203.
This feature will be built incrementally through focused, reviewable PRs for better development and review process.
๐ฏ Complete Implementation Plan
Phase 1: Basic fastn-context (Minimal) โ Completed
- [x] Create fastn-context crate with basic Context struct
- [x] Implement simple context tree (parent/child relationships)
- [x] Add basic cancellation tokens per context
- [x] Move #[fastn_p2p::main] to #[fastn_context::main]
- [x] Basic spawn() with context inheritance
- Status: PR #2203 โ (merged to main)
Phase 2: fastn-p2p Streaming API ๐ง API Stubs Only
- [x] Add client module with connect() function signature
- [x] Implement client::Session struct definition
- [x] Add basic open_uni()/accept_uni() function signatures
- [x] Add server::Session struct definition with context integration
- [x] Add Session -> Request conversion signature (into_request())
- [x] Preserve existing Request methods (get_input, handle)
- [x] Basic context integration structure
- Status: PR #2208 ๐ง (API stubs with TODOs, needs actual implementation)
Phase 2a: Implement Core Streaming โณ Next - Must Do
- [ ] Implement client::connect() - actual iroh connection establishment
- [ ] Implement Session stream creation and management
- [ ] Add real context integration to Session structs
- [ ] Implement Session::into_request() conversion
- Scope: Make the API actually work, not just compile
Phase 3: Implement Multi-Stream Support โณ After 2a
- [ ] Implement accept_uni()/open_uni() for stderr streams
- [ ] Implement accept_bi()/open_bi() for bidirectional streams
- [ ] Test multiple concurrent streams
- [ ] Validate stream lifecycle management
Phase 4: Test and Validate โณ After 3
- [ ] Update fastn-p2p-test sender/receiver to use new API
- [ ] Test both RPC (Session->Request) and streaming patterns
- [ ] Validate iroh connection reuse works correctly
- Scope: End-to-end P2P streaming validation
Phase 5: Remote Shell Integration โณ After 4
- [ ] Update fastn-remote to use fastn-p2p streaming API
- [ ] Implement rshell using client::connect() -> Session
- [ ] Implement server-side rshell using Session streams
- [ ] Add stderr handling via open_uni()/accept_uni()
- [ ] Test fastn rshell and fastn rexec commands work
- Scope: Working remote shell over P2P
Phase 6: Codebase Migration โณ Critical
- [ ] Migrate existing fastn-p2p usage across main workspace
- [ ] Update fastn-daemon to use new fastn-context main macro
- [ ] Migrate existing fastn-p2p call() usage to ensure compatibility
- [ ] Update all existing tests to pass with new APIs
- [ ] Ensure v0.5 workspace tests continue to pass
- [ ] Verify main workspace tests pass with fastn-context integration
- [ ] Fix any regressions in existing functionality
- Scope: Zero breaking changes for existing code
๐ Related PRs
- PR #2203 โ - fastn-context foundation (merged to main)
- PR #2208 ๐ง - fastn-p2p streaming API stubs (needs actual implementation)
- Future PRs - Will be created against this feature branch for Phases 2a-6
๐ฏ Success Criteria
- โ fastn-context integrated - Hierarchical contexts for debugging (PR #2203)
- ๐ง Streaming API stubs - Type definitions exist (PR #2208)
- โณ Streaming API works - Functions actually implemented (Phase 2a)
- โณ Multi-stream support - Uni/bi streams work (Phase 3)
- โณ fastn-p2p-test passes - New streaming API validated (Phase 4)
- โณ fastn rshell works - Interactive shell over P2P (Phase 5)
- โณ fastn rexec works - Command execution with separate stderr (Phase 5)
- โณ All existing tests pass - Main and v0.5 workspaces (Phase 6)
๐จ Current Reality
PR #2208 Status: API stubs with 7 TODOs
client::connect()-todo!()client::Sessioncontext - commented outSession::accept_uni/bi()-todo!()Session::into_request()-todo!()Session::open_uni/bi()-todo!()
Next: Implement Phase 2a to make these functions actually work.
๐ง Development Strategy
This feature branch approach provides:
- ๐ Incremental development through focused, reviewable PRs
- ๐ Better review process with smaller, targeted changes
- ๐ Continuous integration on the feature branch
- ๐ Clear progress tracking through this main PR
- ๐งช Isolated testing of the complete feature before main merge
- ๐ Migration safety through comprehensive testing in Phase 6
Goal: Working remote shell over P2P with minimal API surface, built through reviewable increments, with zero breaking changes to existing code.
๐ค Generated with Claude Code