-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
ipfs backend support #7297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
ipfs backend support #7297
Conversation
Signed-off-by: ale <[email protected]>
Signed-off-by: ale <[email protected]>
Signed-off-by: ale <[email protected]>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
IPFS Storage Backend Implementation for PeerTube
This document provides a comprehensive overview of the IPFS (InterPlanetary File System) storage backend implementation for PeerTube using Helia.
Summary of Changes
This implementation adds IPFS as an alternative decentralized storage backend for PeerTube, allowing video files and other resources to be stored on IPFS instead of traditional filesystem or S3-compatible object storage.
Modified Files
1. Dependencies (
package.json)Added Dependencies:
helia@^5.2.1- Core IPFS implementation@helia/unixfs@^4.2.1- UnixFS file system support for IPFS@helia/strings@^4.2.1- String content support@chainsafe/libp2p-noise@^16.0.0- Noise protocol for connection encryption@chainsafe/libp2p-yamux@^7.0.1- Yamux stream multiplexer@libp2p/tcp@^10.2.2- TCP transport for libp2p@libp2p/bootstrap@^11.1.5- Bootstrap peer discoveryblockstore-fs@^2.1.2- Filesystem-based blockstoredatastore-fs@^10.1.2- Filesystem-based datastore2. Configuration (
config/default.yaml)Added Section:
Purpose: Configures IPFS storage backend settings, including node configuration, gateway URL, network settings, and storage buckets for different resource types.
3. Configuration Initializer (
server/core/initializers/config.ts)Added Configuration Object:
Purpose: Parses and loads IPFS configuration from YAML files into the application's CONFIG object.
New Files Created
4. IPFS Client (
server/core/lib/object-storage/shared/ipfs-client.ts)Key Functions:
getHeliaClient()- Returns singleton Helia IPFS node instanceinitializeHelia()- Initializes Helia with libp2p, blockstore, and datastorestopHeliaClient()- Gracefully stops the IPFS nodeisHeliaInitialized()- Check if IPFS node is runningPurpose: Manages the lifecycle of the Helia IPFS node, providing a singleton instance for the application.
Features:
5. IPFS Storage Helpers (
server/core/lib/object-storage/ipfs-storage-helpers.ts)Key Functions:
storeObjectInIPFS()- Upload file from local path to IPFSstoreContentInIPFS()- Upload string content to IPFSstoreStreamInIPFS()- Upload readable stream to IPFSmakeAvailableFromIPFS()- Download file from IPFS to local pathcreateIPFSReadStream()- Create readable stream from IPFS CIDremoveObjectFromIPFS()- Unpin content from IPFSgetIPFSFileSize()- Get file size from IPFS metadatabuildIPFSUrl()- Generate URL for IPFS content (gateway or ipfs://)Purpose: Provides IPFS-specific storage operations compatible with PeerTube's storage abstraction layer.
Features:
6. Unified Storage Service (
server/core/lib/object-storage/unified-storage.ts)Key Functions:
getStorageBackend()- Determines active storage backend (S3 or IPFS)storeObjectUnified()- Upload file using active backendstoreContentUnified()- Upload content using active backendstoreStreamUnified()- Upload stream using active backendmakeAvailableUnified()- Download file using active backendcreateObjectReadStreamUnified()- Create read stream using active backendremoveObjectUnified()- Remove file using active backendgetObjectStorageFileSizeUnified()- Get file size using active backendPurpose: Provides a unified interface for storage operations that automatically routes to either S3 or IPFS based on configuration.
Features:
7. Database Migration (
server/core/initializers/migrations/0950-ipfs-storage.ts)Database Changes:
ipfsCidcolumn tovideoFiletableipfsCidcolumn tovideoStreamingPlaylisttableipfsCidcolumn tovideoCaptiontableipfsCidcolumn tovideoSourcetableColumn Specification:
VARCHAR(255)(Sequelize.STRING)truenullPurpose: Stores IPFS Content Identifiers (CIDs) alongside existing file URLs, enabling IPFS storage while maintaining backward compatibility.
8. Video File Model Update (
server/core/models/video/video-file.ts)Added Field:
Purpose: Adds IPFS CID field to the VideoFile model, allowing storage and retrieval of IPFS content identifiers.
9. Documentation (
support/doc/ipfs-storage.md)Sections:
Purpose: Comprehensive guide for administrators to configure and use IPFS storage backend.
Architecture
Storage Backend Selection
Priority: IPFS > S3 > Error
IPFS Upload Flow
IPFS Download Flow
Integration Points
Storage Layer
The unified storage service integrates with:
server/core/lib/object-storage/videos.ts- Video file storageserver/core/lib/job-queue/handlers/move-to-object-storage.ts- Storage migration jobsserver/core/lib/paths.ts- File path managementserver/core/controllers/api/videos/upload.ts- Video upload handlingDatabase Layer
IPFS CIDs are stored in:
videoFile.ipfsCid- Individual video file CIDsvideoStreamingPlaylist.ipfsCid- HLS playlist CIDsvideoCaption.ipfsCid- Caption file CIDsvideoSource.ipfsCid- Original video source CIDsConfiguration Layer
IPFS settings are loaded from:
config/default.yaml- Default configurationconfig/production.yaml- Production overridesserver/core/initializers/config.ts- Configuration parserUsage Example
Enable IPFS Storage
Install Dependencies
cd /var/www/peertube pnpm install --frozen-lockfile npm run build:serverRestart PeerTube
Upload Video
Videos uploaded after enabling IPFS will:
Testing
Manual Testing
Enable IPFS:
Upload a test video:
npm run dev:server # Upload via web interfaceVerify CID in database:
Test gateway access:
Automated Testing
Integration tests should be added to:
packages/tests/src/api/object-storage/videos.ts- Video storage testspackages/tests/src/api/ipfs-storage/directory for IPFS-specific testsSecurity Considerations
Public IPFS Network
Warning: Content added to public IPFS network is:
Recommendations for Production
Performance Considerations
Network Bandwidth
Storage Efficiency
Caching
Migration Path
Existing PeerTube Instances
To migrate from S3/filesystem to IPFS:
Migration Script: Use
npm run migrate-to-ipfswith various options (see support/doc/ipfs-storage.md for details).Migration Script Features
The
server/scripts/migrate-to-ipfs.tsscript provides:Migration Script Options
Known Limitations
Future Enhancements
Planned Features
Community Contributions
Contributions welcome for:
Dependencies Version Matrix
References
Support
For issues related to this implementation:
License
This implementation is part of PeerTube and licensed under AGPL-3.0.
Changelog
Version 1.0.0 (Initial Implementation)
Added:
Modified:
ipfsCidfieldKnown Issues:
Implementation Date: November 29, 2025
Authors: GitHub Copilot
Status: Ready for Testing