-
Notifications
You must be signed in to change notification settings - Fork 189
Implement Bitswap in py-libp2p #980
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
Open
sumanjeet0012
wants to merge
24
commits into
libp2p:main
Choose a base branch
from
sumanjeet0012:feature/file_sharing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Created `test_dag.py` to test the MerkleDag class, including methods for adding bytes and files, fetching files, and verifying file information. - Implemented tests for handling small and large data, progress tracking, and error handling. - Added `test_dag_pb.py` to test the encoding and decoding of DAG-PB structures, including file and directory nodes. - Introduced a verification script `verify_bitswap.py` to ensure the Bitswap implementation's structure and functionality, including imports, configuration, block store operations, message creation, and file structure validation.
…12/py-libp2p into feature/file_sharing
0bc2f22
to
3400608
Compare
… logging; update chunking logic and enhance file handling with directory wrapping.
…d available interfaces
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What was wrong?
• py-libp2p lacked Bitswap protocol support for IPFS block exchange
• Could not participate in decentralized file sharing networks
• Missing feature parity with Go, Rust, and JavaScript implementations
• Limited use cases for distributed storage and content delivery
How was it fixed?
Core Module Implementation
Added new
libp2p.bitswap
package:Protocol Layer:
•
client.py
- Bitswap protocol client with block request/response•
block_store.py
- Abstract storage interface + in-memory implementation•
bitswap_message.py
- Message serialization/deserialization•
exceptions.py
- Custom exception typesMerkle DAG:
•
dag.py
- File chunking and DAG construction•
dag_pb.py
- DAG-PB encoding/decoding•
unixfs.py
- UnixFS metadata support•
utils.py
- CID computation utilitiesProtocol Buffers:
•
pb/bitswap.proto
,dag_pb.proto
,unixfs.proto
- Wire format definitions• Generated
.py
and.pyi
files with mypy stubsKey Features
• Bitswap Protocol: Bidirectional block exchange, want-list management, priority requests, block deduplication, multistream negotiation
• Merkle DAG: File chunking, DAG construction/traversal, CID computation, raw + DAG-PB encoding
• UnixFS: File metadata, directory structure, IPFS UnixFS v1 compatible
• Block Storage: Pluggable
BlockStore
interface, in-memory implementation, async/await, type-safe CIDs• CLI Tool: Provider/client modes for file sharing with examples
Protocol Compliance
• Bitswap: Compatible with go-ipfs and js-ipfs
• DAG-PB: IPLD Merkle DAG encoding
• UnixFS v1: IPFS file system abstraction
• Multicodec/Multihash: Standard content addressing
• Protobuf definitions integrated in
Makefile
with mypy stubsExamples
CLI Usage:
Benefits
• Feature Parity: Matches Go/Rust/JavaScript implementations, enables IPFS network participation
• Developer Experience: Type-safe API, async/await, documented examples, modular design
• Performance: Efficient chunking, minimal memory footprint, proper async cleanup
• Interoperability: Compatible with go-ipfs/js-ipfs, standard multiaddr/CID addressing
To-Do
Cute Animal Picture