Skip to content

Commit d85b0af

Browse files
committed
Add Bitswap client
1 parent 08311db commit d85b0af

File tree

5 files changed

+297
-62
lines changed

5 files changed

+297
-62
lines changed

Cargo.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ indexmap = { version = "2.9.0", features = ["std"] }
2525
libc = "0.2.158"
2626
mockall = "0.13.1"
2727
multiaddr = "0.17.0"
28-
multihash = { version = "0.17.0", default-features = false, features = ["std", "multihash-impl", "identity", "sha2", "blake2b"] }
28+
multihash = { version = "0.17.0", default-features = false, features = ["std", "multihash-impl", "identity", "sha2", "sha3", "blake2b"] }
2929
network-interface = "2.0.1"
3030
parking_lot = "0.12.3"
3131
pin-project = "1.1.10"

src/protocol/libp2p/bitswap/handle.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ pub enum BitswapEvent {
4444
/// Requested CIDs.
4545
cids: Vec<(Cid, WantType)>,
4646
},
47+
48+
/// Bitswap response.
49+
Response {
50+
/// Peer ID.
51+
peer: PeerId,
52+
53+
/// Response entries: vector of CIDs with either block data or block presence.
54+
responses: Vec<ResponseType>,
55+
},
4756
}
4857

4958
/// Response type for received bitswap request.
@@ -73,6 +82,15 @@ pub enum ResponseType {
7382
#[derive(Debug)]
7483
#[cfg_attr(feature = "fuzz", derive(serde::Serialize, serde::Deserialize))]
7584
pub enum BitswapCommand {
85+
/// Send bitswap request.
86+
SendRequest {
87+
/// Peer ID.
88+
peer: PeerId,
89+
90+
/// Requested CIDs.
91+
cids: Vec<(Cid, WantType)>,
92+
},
93+
7694
/// Send bitswap response.
7795
SendResponse {
7896
/// Peer ID.
@@ -99,10 +117,8 @@ impl BitswapHandle {
99117
}
100118

101119
/// Send `request` to `peer`.
102-
///
103-
/// Not supported by the current implementation.
104-
pub async fn send_request(&self, _peer: PeerId, _request: Vec<u8>) {
105-
unimplemented!("bitswap requests are not supported");
120+
pub async fn send_request(&self, peer: PeerId, cids: Vec<(Cid, WantType)>) {
121+
let _ = self.cmd_tx.send(BitswapCommand::SendRequest { peer, cids }).await;
106122
}
107123

108124
/// Send `response` to `peer`.

0 commit comments

Comments
 (0)