-
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
base: main
Are you sure you want to change the base?
Conversation
- 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
|
It doesn't appear that the tests here are being run in CI. If you look in only files in When I do run the tests directly, I'm getting a number of them failing - at least one in |
… requests; add BlockUnavailableError for missing blocks; update message creation for block data handling.
|
@pacrob Thanks for pointing out the test files issue, |
|
@sumanjeet0012 : Thanks Sumanjeet. Appreciate your efforts. Please create a discussion page reflecting the details on the implementation of the PR. Also, please add the nice screencasts that you had recorded on bitswap implementation. We should also add an example for this PR in the examples section. This would enable other developers to start using bitswap in your projects. I'll ask @lla-dane and @Hany-Almnaem to use bitswap in their projects too - |
|
@sumanjeet0012 : Thank you for resolving the issue shared by @pacrob. This PR is indeed ready for final review + merge. Reviewing it and will share feedback soon. |
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.bitswappackage: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
.pyand.pyifiles 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
BlockStoreinterface, 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
Makefilewith 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