Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Refactor muts away, enhance ci builds #155

Merged
merged 4 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,16 @@ jobs:

- name: Build
if: matrix.platform.cross == false
run: cargo build --workspace
run: cargo build --locked --workspace --tests --examples

- name: Build android
if: contains(matrix.platform.target, 'android')
run: cargo ndk --android-platform 29 --target ${{ matrix.platform.target }} build --workspace --exclude ipfs-http
run: cargo ndk --android-platform 29 --target ${{ matrix.platform.target }} build --locked --workspace --exclude ipfs-http
# exclude http on android because openssl

- name: Build other cross compilations
if: contains(matrix.platform.target, 'android') == false && matrix.platform.cross == true
run: cargo build --workspace --exclude ipfs-http --target ${{ matrix.platform.target }}
run: cargo build --locked --workspace --exclude ipfs-http --target ${{ matrix.platform.target }}
# exclude http on other cross compilation targets because openssl

- name: Rust tests
Expand Down
4 changes: 3 additions & 1 deletion examples/examples/ipfs_bitswap_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ fn main() {
env_logger::init();
let options = IpfsOptions::<TestTypes>::default();

// Note: this test is now at rust-ipfs/tests/exchange_block.rs

task::block_on(async move {
// Start daemon and initialize repo
let (mut ipfs, fut) = UninitializedIpfs::new(options).await.start().await.unwrap();
let (ipfs, fut) = UninitializedIpfs::new(options).await.start().await.unwrap();
task::spawn(fut);

// Create a Block
Expand Down
14 changes: 4 additions & 10 deletions http/src/v0/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ pub struct GetQuery {
arg: String,
}

async fn get_query<T: IpfsTypes>(
mut ipfs: Ipfs<T>,
query: GetQuery,
) -> Result<impl Reply, Rejection> {
async fn get_query<T: IpfsTypes>(ipfs: Ipfs<T>, query: GetQuery) -> Result<impl Reply, Rejection> {
let cid: Cid = query.arg.parse().map_err(StringError::from)?;
let data = ipfs
.get_block(&cid)
Expand Down Expand Up @@ -49,7 +46,7 @@ pub struct PutResponse {
}

async fn put_query<T: IpfsTypes>(
mut ipfs: Ipfs<T>,
ipfs: Ipfs<T>,
query: PutQuery,
mut form: multipart::FormData,
) -> Result<impl Reply, Rejection> {
Expand Down Expand Up @@ -120,10 +117,7 @@ pub struct RmQuery {
#[serde(rename_all = "PascalCase")]
pub struct RmResponse {}

async fn rm_query<T: IpfsTypes>(
mut ipfs: Ipfs<T>,
query: RmQuery,
) -> Result<impl Reply, Rejection> {
async fn rm_query<T: IpfsTypes>(ipfs: Ipfs<T>, query: RmQuery) -> Result<impl Reply, Rejection> {
let cid: Cid = query.arg.parse().map_err(StringError::from)?;
ipfs.remove_block(&cid).await.map_err(StringError::from)?;
let response = RmResponse {};
Expand Down Expand Up @@ -152,7 +146,7 @@ pub struct StatResponse {
}

async fn stat_query<T: IpfsTypes>(
mut ipfs: Ipfs<T>,
ipfs: Ipfs<T>,
query: StatQuery,
) -> Result<impl Reply, Rejection> {
let cid: Cid = query.arg.parse().map_err(StringError::from)?;
Expand Down
2 changes: 1 addition & 1 deletion http/src/v0/dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct PutQuery {
}

async fn put_query<T: IpfsTypes>(
mut ipfs: Ipfs<T>,
ipfs: Ipfs<T>,
query: PutQuery,
mut form: multipart::FormData,
) -> Result<impl Reply, Rejection> {
Expand Down
12 changes: 7 additions & 5 deletions http/src/v0/refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ async fn inner_local<T: IpfsTypes>(ipfs: Ipfs<T>) -> Result<impl Reply, Rejectio
err: "".to_string(),
})
.map(|response| {
serde_json::to_string(&response).map_err(|e| {
eprintln!("error from serde_json: {}", e);
HandledErr
}).unwrap()
serde_json::to_string(&response)
.map_err(|e| {
eprintln!("error from serde_json: {}", e);
HandledErr
})
.unwrap()
})
.map(|ref_json| Ok(format!("{}{}", ref_json, "\n")))
.collect();
Expand Down Expand Up @@ -76,7 +78,7 @@ mod tests {

let options = IpfsOptions::inmemory_with_generated_keys(false);

let (mut ipfs, fut) = UninitializedIpfs::new(options).await.start().await.unwrap();
let (ipfs, fut) = UninitializedIpfs::new(options).await.start().await.unwrap();
drop(fut);

for data in &[b"1", b"2", b"3"] {
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,17 +323,17 @@ impl<Types: IpfsTypes> UninitializedIpfs<Types> {

impl<Types: IpfsTypes> Ipfs<Types> {
/// Puts a block into the ipfs repo.
pub async fn put_block(&mut self, block: Block) -> Result<Cid, Error> {
pub async fn put_block(&self, block: Block) -> Result<Cid, Error> {
Ok(self.repo.put_block(block).await?.0)
}

/// Retrives a block from the ipfs repo.
pub async fn get_block(&mut self, cid: &Cid) -> Result<Block, Error> {
pub async fn get_block(&self, cid: &Cid) -> Result<Block, Error> {
Ok(self.repo.get_block(cid).await?)
}

/// Remove block from the ipfs repo.
pub async fn remove_block(&mut self, cid: &Cid) -> Result<(), Error> {
pub async fn remove_block(&self, cid: &Cid) -> Result<(), Error> {
Ok(self.repo.remove_block(cid).await?)
}

Expand Down Expand Up @@ -793,7 +793,7 @@ mod tests {
let cid = Cid::new_v1(Codec::Raw, Sha2_256::digest(&data));
let block = Block::new(data, cid);
let ipfs = UninitializedIpfs::new(options).await;
let (mut ipfs, fut) = ipfs.start().await.unwrap();
let (ipfs, fut) = ipfs.start().await.unwrap();
task::spawn(fut);

let cid: Cid = ipfs.put_block(block.clone()).await.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions tests/exchange_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ async fn exchange_block() {
let data = b"hello block\n".to_vec().into_boxed_slice();
let cid = Cid::new_v1(Codec::Raw, Sha2_256::digest(&data));

let mut a = Node::new(mdns).await;
let mut b = Node::new(mdns).await;
let a = Node::new(mdns).await;
let b = Node::new(mdns).await;

let (_, mut addrs) = b.identity().await.unwrap();

Expand Down