-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
185 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::{path::Path, sync::Arc}; | ||
|
||
use blockstore::Error; | ||
use polka_index::local_index_directory::Service; | ||
|
||
/// The blockstore that reads blocks directly from unsealed sectors | ||
pub struct ProviderBlockstore<I> { | ||
indexer: Arc<I>, | ||
} | ||
|
||
impl<I> ProviderBlockstore<I> { | ||
pub fn new<P>(unsealed_sectors_path: P, indexer: Arc<I>) -> Self | ||
where | ||
I: Service, | ||
P: AsRef<Path>, | ||
{ | ||
Self { indexer } | ||
} | ||
} | ||
|
||
impl<I> blockstore::Blockstore for ProviderBlockstore<I> | ||
where | ||
I: Send + Sync + 'static, | ||
{ | ||
async fn get<const S: usize>( | ||
&self, | ||
_cid: &cid::CidGeneric<S>, | ||
) -> blockstore::Result<Option<Vec<u8>>> { | ||
// TODO: Find the sector that holds the requested cid | ||
// TODO: open a file handler to the sector file. | ||
// TODO: Read the blocks from the sector | ||
todo!() | ||
} | ||
|
||
async fn put_keyed<const S: usize>( | ||
&self, | ||
_cid: &cid::CidGeneric<S>, | ||
_data: &[u8], | ||
) -> blockstore::Result<()> { | ||
Err(Error::FatalDatabaseError( | ||
"put operation not supported".to_string(), | ||
)) | ||
} | ||
|
||
async fn remove<const S: usize>(&self, _cid: &cid::CidGeneric<S>) -> blockstore::Result<()> { | ||
Err(Error::FatalDatabaseError( | ||
"remove operation not supported".to_string(), | ||
)) | ||
} | ||
|
||
async fn close(self) -> blockstore::Result<()> { | ||
Ok(()) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::{path::PathBuf, sync::Arc}; | ||
|
||
use blockstore::ProviderBlockstore; | ||
use libp2p::Multiaddr; | ||
use polka_index::local_index_directory::Service; | ||
use polka_storage_retrieval::Server; | ||
use tokio_util::sync::CancellationToken; | ||
|
||
use crate::ServerError; | ||
|
||
mod blockstore; | ||
|
||
pub struct RetrievalServerConfig<I> { | ||
pub listen_address: Multiaddr, | ||
pub unsealed_sectors_dir: PathBuf, | ||
pub indexer: Arc<I>, | ||
} | ||
|
||
#[tracing::instrument(skip_all)] | ||
pub async fn start_retrieval<I>( | ||
config: RetrievalServerConfig<I>, | ||
token: CancellationToken, | ||
) -> Result<(), ServerError> | ||
where | ||
I: Service + Send + Sync + 'static, | ||
{ | ||
// Blockstore used by the retrieval server provider | ||
let blockstore = Arc::new(ProviderBlockstore::new( | ||
config.unsealed_sectors_dir, | ||
config.indexer, | ||
)); | ||
|
||
// Setup & run the retrieval server | ||
let server = Server::new(blockstore)?; | ||
server | ||
.run(vec![config.listen_address], async move { | ||
token.cancelled_owned().await; | ||
tracing::trace!("shutting down the retrieval server"); | ||
}) | ||
.await?; | ||
|
||
Ok(()) | ||
} |
This file contains 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
This file contains 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