-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: retrieval server & client setup #654
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,32 @@ | ||||
[package] | ||||
authors.workspace = true | ||||
edition.workspace = true | ||||
homepage.workspace = true | ||||
license-file.workspace = true | ||||
name = "storage-retrieval" | ||||
repository.workspace = true | ||||
version = "0.1.0" | ||||
|
||||
[lints] | ||||
workspace = true | ||||
|
||||
[dependencies] | ||||
anyhow = { workspace = true } | ||||
beetswap = { workspace = true } | ||||
blockstore = { workspace = true } | ||||
cid = { workspace = true } | ||||
futures = { workspace = true } | ||||
libp2p = { workspace = true, features = ["macros", "noise", "tcp", "tokio", "yamux"] } | ||||
libp2p-core = { workspace = true } | ||||
libp2p-swarm = { workspace = true } | ||||
mater = { workspace = true } | ||||
polka-index = { workspace = true } | ||||
thiserror = { workspace = true } | ||||
tokio = { workspace = true, features = ["macros", "rt", "rt-multi-thread", "sync", "time"] } | ||||
tracing = { workspace = true } | ||||
|
||||
[dev-dependencies] | ||||
# multihash = "0.19.3" | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
multihash-codetable = { workspace = true, features = ["sha2"] } | ||||
tracing-appender = { workspace = true } | ||||
tracing-subscriber = { workspace = true, features = ["env-filter"] } |
Empty file.
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,97 @@ | ||
use std::{str::FromStr, sync::Arc, time::Duration}; | ||
|
||
use anyhow::Result; | ||
use blockstore::{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice, didn't know eiger had this library |
||
block::{Block, CidError}, | ||
InMemoryBlockstore, | ||
}; | ||
use cid::Cid; | ||
use libp2p::Multiaddr; | ||
use mater::{Blockstore, CarV2Reader, InMemory}; | ||
use multihash_codetable::{Code, MultihashDigest}; | ||
use storage_retrieval::{client::Client, server::Server}; | ||
use tokio::{fs::File, time::sleep}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
// Init tracing | ||
let _guard = init_tracing(); | ||
|
||
// Setup indexer | ||
// let indexer_path = temp_dir(); | ||
// let indexer = Arc::new(RocksDBLid::new(RocksDBStateStoreConfig { | ||
// path: indexer_path, | ||
// })?); | ||
|
||
// TODO: Blocks should not be hold in memory. Implement blockstore that can | ||
// source blocks directly from sectors on disk with the help of an index. | ||
let file = File::open("./examples/test-data-big.car").await?; | ||
let car_reader = CarV2Reader::new(file); | ||
let mut blockstore = Blockstore::new(); | ||
blockstore.read_car(car_reader).await?; | ||
|
||
let blockstore: InMemory = blockstore.into(); | ||
|
||
// let blockstore = Arc::new(InMemoryBlockstore::<64>::new()); | ||
// blockstore.put(StringBlock("12345".to_string())).await?; | ||
|
||
// Setup server | ||
let server = Server::new(Arc::new(blockstore))?; | ||
let address: Multiaddr = format!("/ip4/127.0.0.1/tcp/8989").parse()?; | ||
|
||
tokio::spawn({ | ||
let address = address.clone(); | ||
async move { | ||
let _ = server.run(vec![address]).await; | ||
} | ||
}); | ||
|
||
// TODO: Implement blockstore that persist blocks directly to disk as car file. | ||
let blockstore = Arc::new(InMemoryBlockstore::<64>::new()); | ||
let client = Client::new(blockstore, vec![address])?; | ||
|
||
// Payload cid of the car file we want to fetch | ||
let payload_cid = | ||
Cid::from_str("bafkreiechz74drg7tg5zswmxf4g2dnwhemlwdv7e3l5ypehdqdwaoyz3dy").unwrap(); | ||
// let payload_cid = | ||
// Cid::from_str("bafkreiczsrdrvoybcevpzqmblh3my5fu6ui3tgag3jm3hsxvvhaxhswpyu").unwrap(); | ||
client | ||
.download(payload_cid, sleep(Duration::from_secs(10))) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
struct StringBlock(pub String); | ||
|
||
impl Block<64> for StringBlock { | ||
fn cid(&self) -> Result<Cid, CidError> { | ||
const RAW_CODEC: u64 = 0x55; | ||
let hash = Code::Sha2_256.digest(self.0.as_ref()); | ||
Ok(Cid::new_v1(RAW_CODEC, hash)) | ||
} | ||
|
||
fn data(&self) -> &[u8] { | ||
self.0.as_ref() | ||
} | ||
} | ||
|
||
fn init_tracing() -> tracing_appender::non_blocking::WorkerGuard { | ||
let (non_blocking, guard) = tracing_appender::non_blocking(std::io::stdout()); | ||
|
||
let filter = tracing_subscriber::EnvFilter::builder() | ||
.with_default_directive(tracing_subscriber::filter::LevelFilter::INFO.into()) | ||
.from_env_lossy(); | ||
|
||
tracing_subscriber::fmt() | ||
.event_format( | ||
tracing_subscriber::fmt::format() | ||
.with_file(true) | ||
.with_line_number(true), | ||
) | ||
.with_env_filter(filter) | ||
.with_writer(non_blocking) | ||
.init(); | ||
|
||
guard | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is it?