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

Commit 070abe5

Browse files
bors[bot]ljedrz
andauthored
Merge #373
373: Tidy up some dependencies and tests r=ljedrz a=ljedrz No functional changes, just quality of life / developer experience ones plus a small dependency update. As always, the commits describe the specific changes. Co-authored-by: ljedrz <ljedrz@gmail.com>
2 parents 6011812 + 922dede commit 070abe5

File tree

7 files changed

+124
-127
lines changed

7 files changed

+124
-127
lines changed

Cargo.lock

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

src/lib.rs

Lines changed: 67 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,6 @@
33
#![cfg_attr(feature = "nightly", feature(external_doc))]
44
#![cfg_attr(feature = "nightly", doc(include = "../README.md"))]
55

6-
#[macro_use]
7-
extern crate tracing;
8-
9-
pub use crate::ipld::Ipld;
10-
use anyhow::{anyhow, format_err};
11-
pub use bitswap::{BitswapEvent, Block, Stats};
12-
pub use cid::Cid;
13-
use cid::Codec;
14-
use either::Either;
15-
use futures::channel::mpsc::{channel, Receiver, Sender};
16-
use futures::channel::oneshot::{channel as oneshot_channel, Sender as OneshotSender};
17-
use futures::sink::SinkExt;
18-
use futures::stream::{Fuse, Stream};
19-
pub use libp2p::core::{
20-
connection::ListenerId, multiaddr::Protocol, ConnectedPoint, Multiaddr, PeerId, PublicKey,
21-
};
22-
use libp2p::swarm::NetworkBehaviour;
23-
pub use libp2p::{
24-
identity::Keypair,
25-
kad::{record::Key, Quorum},
26-
};
27-
use std::path::PathBuf;
28-
use tracing::Span;
29-
use tracing_futures::Instrument;
30-
31-
use std::borrow::Borrow;
32-
use std::collections::{HashMap, HashSet};
33-
use std::fmt;
34-
use std::future::Future;
35-
use std::ops::Range;
36-
use std::pin::Pin;
37-
use std::sync::{atomic::Ordering, Arc};
38-
use std::task::{Context, Poll};
39-
406
mod config;
417
pub mod dag;
428
pub mod error;
@@ -50,17 +16,66 @@ pub mod repo;
5016
mod subscription;
5117
pub mod unixfs;
5218

53-
use self::dag::IpldDag;
54-
pub use self::error::Error;
55-
use self::ipns::Ipns;
56-
use self::p2p::addr::{could_be_bound_from_ephemeral, starts_unspecified};
57-
pub use self::p2p::pubsub::{PubsubMessage, SubscriptionStream};
58-
use self::p2p::{create_swarm, SwarmOptions, TSwarm};
59-
pub use self::p2p::{Connection, KadResult, MultiaddrWithPeerId, MultiaddrWithoutPeerId};
60-
pub use self::path::IpfsPath;
61-
use self::repo::{create_repo, Repo, RepoEvent, RepoOptions};
62-
pub use self::repo::{PinKind, PinMode, RepoTypes};
63-
use self::subscription::SubscriptionFuture;
19+
#[macro_use]
20+
extern crate tracing;
21+
22+
use anyhow::{anyhow, format_err};
23+
use cid::Codec;
24+
use either::Either;
25+
use futures::{
26+
channel::{
27+
mpsc::{channel, Receiver, Sender},
28+
oneshot::{channel as oneshot_channel, Sender as OneshotSender},
29+
},
30+
sink::SinkExt,
31+
stream::{Fuse, Stream},
32+
};
33+
use libp2p::swarm::NetworkBehaviour;
34+
use tracing::Span;
35+
use tracing_futures::Instrument;
36+
37+
use std::{
38+
borrow::Borrow,
39+
collections::{HashMap, HashSet},
40+
env, fmt,
41+
future::Future,
42+
ops::{Deref, DerefMut, Range},
43+
path::PathBuf,
44+
pin::Pin,
45+
sync::{atomic::Ordering, Arc},
46+
task::{Context, Poll},
47+
};
48+
49+
use self::{
50+
dag::IpldDag,
51+
ipns::Ipns,
52+
p2p::{
53+
addr::{could_be_bound_from_ephemeral, starts_unspecified},
54+
create_swarm, SwarmOptions, TSwarm,
55+
},
56+
repo::{create_repo, Repo, RepoEvent, RepoOptions},
57+
subscription::SubscriptionFuture,
58+
};
59+
60+
pub use self::{
61+
error::Error,
62+
ipld::Ipld,
63+
p2p::{
64+
pubsub::{PubsubMessage, SubscriptionStream},
65+
Connection, KadResult, MultiaddrWithPeerId, MultiaddrWithoutPeerId,
66+
},
67+
path::IpfsPath,
68+
repo::{PinKind, PinMode, RepoTypes},
69+
};
70+
pub use bitswap::{BitswapEvent, Block, Stats};
71+
pub use cid::Cid;
72+
pub use libp2p::{
73+
core::{
74+
connection::ListenerId, multiaddr::Protocol, ConnectedPoint, Multiaddr, PeerId, PublicKey,
75+
},
76+
identity::Keypair,
77+
kad::{record::Key, Quorum},
78+
};
6479

6580
/// All types can be changed at compile time by implementing
6681
/// `IpfsTypes`.
@@ -119,7 +134,7 @@ impl IpfsOptions {
119134
/// Creates an inmemory store backed node for tests
120135
pub fn inmemory_with_generated_keys() -> Self {
121136
Self {
122-
ipfs_path: std::env::temp_dir(),
137+
ipfs_path: env::temp_dir(),
123138
keypair: Keypair::generate_ed25519(),
124139
mdns: Default::default(),
125140
bootstrap: Default::default(),
@@ -194,13 +209,13 @@ impl Default for IpfsOptions {
194209
);
195210
}
196211

197-
let ipfs_path = if let Ok(path) = std::env::var("IPFS_PATH") {
212+
let ipfs_path = if let Ok(path) = env::var("IPFS_PATH") {
198213
PathBuf::from(path)
199214
} else {
200215
let root = if let Some(home) = dirs::home_dir() {
201216
home
202217
} else {
203-
std::env::current_dir().unwrap()
218+
env::current_dir().unwrap()
204219
};
205220
root.join(".rust-ipfs")
206221
};
@@ -383,7 +398,7 @@ impl<Types: IpfsTypes> UninitializedIpfs<Types> {
383398
}
384399
}
385400

386-
impl<Types: IpfsTypes> std::ops::Deref for Ipfs<Types> {
401+
impl<Types: IpfsTypes> Deref for Ipfs<Types> {
387402
type Target = IpfsInner<Types>;
388403

389404
fn deref(&self) -> &Self::Target {
@@ -1676,16 +1691,16 @@ mod node {
16761691
}
16771692
}
16781693

1679-
impl std::ops::Deref for Node {
1694+
impl Deref for Node {
16801695
type Target = Ipfs<TestTypes>;
16811696

16821697
fn deref(&self) -> &Self::Target {
16831698
&self.ipfs
16841699
}
16851700
}
16861701

1687-
impl std::ops::DerefMut for Node {
1688-
fn deref_mut(&mut self) -> &mut <Self as std::ops::Deref>::Target {
1702+
impl DerefMut for Node {
1703+
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
16891704
&mut self.ipfs
16901705
}
16911706
}

tests/bitswap.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ use std::time::Duration;
55
use tokio::time;
66

77
mod common;
8-
use common::{spawn_connected_nodes, Topology};
8+
use common::{spawn_nodes, Topology};
99

1010
// Ensure that the Bitswap object doesn't leak.
1111
#[tokio::test(max_threads = 1)]
1212
async fn check_bitswap_cleanups() {
1313
// create a few nodes and connect the first one to others
14-
let mut nodes = spawn_connected_nodes(3, Topology::Star).await;
14+
let mut nodes = spawn_nodes(3, Topology::Star).await;
1515

1616
let bitswap_peers = nodes[0].get_bitswap_peers().await.unwrap();
1717
assert_eq!(bitswap_peers.len(), 2);
@@ -52,7 +52,7 @@ async fn bitswap_stress_test() {
5252
let data = b"hello block\n".to_vec().into_boxed_slice();
5353
let cid = Cid::new_v1(Codec::Raw, Sha2_256::digest(&data));
5454

55-
let nodes = spawn_connected_nodes(5, Topology::Mesh).await;
55+
let nodes = spawn_nodes(5, Topology::Mesh).await;
5656

5757
for (i, node) in nodes.iter().enumerate() {
5858
if filter(i) {

tests/common/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ pub mod interop;
22

33
use ipfs::Node;
44

5-
/// The way in which nodes are connected to each other; to be used with spawn_connected_nodes.
5+
/// The way in which nodes are connected to each other; to be used with spawn_nodes.
66
#[allow(dead_code)]
77
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
88
pub enum Topology {
9+
/// no connections
10+
None,
911
/// a > b > c
1012
Line,
1113
/// a > b > c > a
@@ -17,7 +19,7 @@ pub enum Topology {
1719
}
1820

1921
#[allow(dead_code)]
20-
pub async fn spawn_connected_nodes(count: usize, topology: Topology) -> Vec<Node> {
22+
pub async fn spawn_nodes(count: usize, topology: Topology) -> Vec<Node> {
2123
let mut nodes = Vec::with_capacity(count);
2224

2325
for i in 0..count {
@@ -54,6 +56,7 @@ pub async fn spawn_connected_nodes(count: usize, topology: Topology) -> Vec<Node
5456
nodes[0].connect(node.addrs[0].clone()).await.unwrap();
5557
}
5658
}
59+
Topology::None => {}
5760
}
5861

5962
nodes

tests/exchange_block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::time::Duration;
55
use tokio::time::timeout;
66

77
mod common;
8-
use common::{spawn_connected_nodes, Topology};
8+
use common::{spawn_nodes, Topology};
99

1010
#[tokio::test(max_threads = 1)]
1111
async fn exchange_block() {
@@ -14,7 +14,7 @@ async fn exchange_block() {
1414
let data = b"hello block\n".to_vec().into_boxed_slice();
1515
let cid = Cid::new_v1(Codec::Raw, Sha2_256::digest(&data));
1616

17-
let nodes = spawn_connected_nodes(2, Topology::Line).await;
17+
let nodes = spawn_nodes(2, Topology::Line).await;
1818

1919
nodes[0]
2020
.put_block(Block {

0 commit comments

Comments
 (0)