requestBlock method
- String cid,
- Peer peer
Requests a specific block from a peer via Bitswap.
Implementation
Future<void> requestBlock(String cid, Peer peer) async {
try {
// Validate CID format
if (!_container.get<DHTHandler>().isValidCID(cid)) {
throw ArgumentError('Invalid CID format: $cid');
}
// Use bitswap to request the block
final block = await _container.get<BitswapHandler>().wantBlock(cid);
if (block == null) {
throw Exception('Failed to retrieve block from peer');
}
// Store the block in our datastore
await _container.get<DatastoreHandler>().putBlock(block);
} catch (e) {
// print('Error requesting block $cid from peer ${peer.toString()}: $e');
rethrow;
}
}