fix: comment on prove_block and only provide new blocks
Signed-off-by: ljedrz <ljedrz@gmail.com>
This commit is contained in:
parent
c3bcadf5d3
commit
77d9a6cc0e
@ -433,6 +433,9 @@ impl<Types: IpfsTypes> Behaviour<Types> {
|
|||||||
) -> Result<SubscriptionFuture<(), String>, anyhow::Error> {
|
) -> Result<SubscriptionFuture<(), String>, anyhow::Error> {
|
||||||
let key = cid.to_bytes();
|
let key = cid.to_bytes();
|
||||||
match self.kademlia.start_providing(key.into()) {
|
match self.kademlia.start_providing(key.into()) {
|
||||||
|
// Kademlia queries are marked with QueryIds, which are most fitting to
|
||||||
|
// be used as kad Subscription keys - they are small and require no
|
||||||
|
// conversion for the applicable finish_subscription calls
|
||||||
Ok(id) => Ok(self.kad_subscriptions.create_subscription(id.into(), None)),
|
Ok(id) => Ok(self.kad_subscriptions.create_subscription(id.into(), None)),
|
||||||
Err(e) => Err(anyhow!("kad: can't provide block {}: {:?}", cid, e)),
|
Err(e) => Err(anyhow!("kad: can't provide block {}: {:?}", cid, e)),
|
||||||
}
|
}
|
||||||
|
@ -204,17 +204,20 @@ impl<TRepoTypes: RepoTypes> Repo<TRepoTypes> {
|
|||||||
let (_cid, res) = self.block_store.put(block.clone()).await?;
|
let (_cid, res) = self.block_store.put(block.clone()).await?;
|
||||||
self.subscriptions
|
self.subscriptions
|
||||||
.finish_subscription(cid.clone().into(), Ok(block));
|
.finish_subscription(cid.clone().into(), Ok(block));
|
||||||
// sending only fails if no one is listening anymore
|
|
||||||
// and that is okay with us.
|
|
||||||
let (tx, rx) = oneshot::channel();
|
|
||||||
|
|
||||||
self.events
|
if let BlockPut::NewBlock = res {
|
||||||
.clone()
|
// sending only fails if no one is listening anymore
|
||||||
.send(RepoEvent::ProvideBlock(cid.clone(), tx))
|
// and that is okay with us.
|
||||||
.await
|
let (tx, rx) = oneshot::channel();
|
||||||
.ok();
|
|
||||||
|
|
||||||
rx.await??.await?;
|
self.events
|
||||||
|
.clone()
|
||||||
|
.send(RepoEvent::ProvideBlock(cid.clone(), tx))
|
||||||
|
.await
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
rx.await??.await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok((cid, res))
|
Ok((cid, res))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user