Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
fix: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
ppodolsky committed Feb 23, 2023
1 parent 430f3dd commit 1daf452
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 42 deletions.
4 changes: 2 additions & 2 deletions iroh-api/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ impl Api {
) -> Result<BoxStream<'static, Result<(Cid, u64)>>> {
let blocks = match entry {
UnixfsEntry::File(f) => f.encode().await?.boxed(),
UnixfsEntry::Directory(d) => d.encode(&DEFAULT_CODE),
UnixfsEntry::Directory(d) => d.encode(DEFAULT_CODE),
UnixfsEntry::Symlink(s) => Box::pin(async_stream::try_stream! {
yield s.encode(&DEFAULT_CODE)?
yield s.encode(DEFAULT_CODE)?
}),
UnixfsEntry::RawBlock(r) => Box::pin(async_stream::try_stream! {
yield r.encode()?
Expand Down
14 changes: 3 additions & 11 deletions iroh-bitswap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,16 @@ pub struct Bitswap<S: Store> {
_workers: Arc<Vec<JoinHandle<()>>>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
enum PeerState {
Connected(ConnectionId),
Responsive(ConnectionId, ProtocolId),
Unresponsive,
#[default]
Disconnected,
DialFailure(Instant),
}

impl Default for PeerState {
fn default() -> Self {
PeerState::Disconnected
}
}

impl PeerState {
fn is_connected(self) -> bool {
matches!(self, PeerState::Connected(_) | PeerState::Responsive(_, _))
Expand Down Expand Up @@ -496,10 +491,7 @@ impl<S: Store> NetworkBehaviour for Bitswap<S> {
}
}
}
HandlerEvent::Message {
mut message,
protocol,
} => {
HandlerEvent::Message { message, protocol } => {
self.set_peer_state(&peer_id, PeerState::Responsive(connection, protocol));
self.receive_message(peer_id, message);
}
Expand Down
5 changes: 2 additions & 3 deletions iroh-gateway/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,10 @@ impl<T: ContentLoader + std::marker::Unpin> Client<T> {
) -> Result<Out, String> {
info!("retrieve path metadata {}", path);
if raw_format {
return self
.resolver
self.resolver
.resolve_raw(path)
.await
.map_err(|e| e.to_string());
.map_err(|e| e.to_string())
} else {
self.resolver.resolve(path).await.map_err(|e| e.to_string())
}
Expand Down
2 changes: 1 addition & 1 deletion iroh-share/src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Sender {
let p2p_rpc = p2p.rpc().try_p2p()?;
let store = p2p.rpc().try_store()?;
let (root, num_parts) = {
let parts = root_dir.encode(&DEFAULT_CODE);
let parts = root_dir.encode(DEFAULT_CODE);
tokio::pin!(parts);
let mut num_parts = 0;
let mut root_cid = None;
Expand Down
16 changes: 7 additions & 9 deletions iroh-unixfs/src/balanced_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ impl TreeBuilder {
chunks: impl Stream<Item = std::io::Result<Bytes>> + Send,
) -> impl Stream<Item = Result<Block>> {
match self {
TreeBuilder::Balanced { degree, code } => {
stream_balanced_tree(chunks, *degree, code.clone())
}
TreeBuilder::Balanced { degree, code } => stream_balanced_tree(chunks, *degree, *code),
}
}
}
Expand All @@ -54,10 +52,10 @@ pub struct LinkInfo {
}

impl LinkInfo {
pub fn new(raw_data_len: u64, encoded_len: u64) -> LinkInfo{
pub fn new(raw_data_len: u64, encoded_len: u64) -> LinkInfo {
LinkInfo {
raw_data_len,
encoded_len
encoded_len,
}
}
}
Expand Down Expand Up @@ -98,7 +96,7 @@ fn stream_balanced_tree(
let in_stream = in_stream.err_into::<anyhow::Error>().map(|chunk| {
let code = code.clone();
tokio::task::spawn_blocking(move || {
chunk.and_then(|chunk| TreeNode::Leaf(chunk).encode(&code))
chunk.and_then(|chunk| TreeNode::Leaf(chunk).encode(code))
}).err_into::<anyhow::Error>()
}).buffered(hash_par).map(|x| x.and_then(|x| x));

Expand All @@ -125,7 +123,7 @@ fn stream_balanced_tree(

// create node, keeping the cid
let links = std::mem::replace(&mut tree[i], Vec::with_capacity(degree));
let (block, link_info) = TreeNode::Stem(links).encode(&code)?;
let (block, link_info) = TreeNode::Stem(links).encode(code)?;
let cid = *block.cid();
yield block;

Expand Down Expand Up @@ -154,7 +152,7 @@ fn stream_balanced_tree(
// since all the stem nodes are able to receive links
// we don't have to worry about "overflow"
while let Some(links) = tree.pop_front() {
let (block, link_info) = TreeNode::Stem(links).encode(&code)?;
let (block, link_info) = TreeNode::Stem(links).encode(code)?;
let cid = *block.cid();
yield block;

Expand Down Expand Up @@ -215,7 +213,7 @@ pub enum TreeNode {
}

impl TreeNode {
pub fn encode(self, code: &multihash::Code) -> Result<(Block, LinkInfo)> {
pub fn encode(self, code: multihash::Code) -> Result<(Block, LinkInfo)> {
match self {
TreeNode::Leaf(bytes) => {
let len = bytes.len();
Expand Down
28 changes: 13 additions & 15 deletions iroh-unixfs/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Directory {
Directory::single("".into(), Entry::Directory(self))
}

pub async fn encode_root(self, code: &multihash::Code) -> Result<Block> {
pub async fn encode_root(self, code: multihash::Code) -> Result<Block> {
let mut current = None;
let parts = self.encode(code);
tokio::pin!(parts);
Expand All @@ -105,7 +105,7 @@ impl Directory {
current.expect("must not be empty")
}

pub fn encode<'a>(self, code: &multihash::Code) -> BoxStream<'a, Result<Block>> {
pub fn encode<'a>(self, code: multihash::Code) -> BoxStream<'a, Result<Block>> {
match self {
Directory::Basic(basic) => basic.encode(code),
Directory::Hamt(hamt) => hamt.encode(code),
Expand All @@ -114,13 +114,12 @@ impl Directory {
}

impl BasicDirectory {
pub fn encode<'a>(self, code: &multihash::Code) -> BoxStream<'a, Result<Block>> {
let code = code.clone();
pub fn encode<'a>(self, code: multihash::Code) -> BoxStream<'a, Result<Block>> {
async_stream::try_stream! {
let mut links = Vec::new();
for entry in self.entries {
let name = entry.name().to_string();
let parts = entry.encode(&code).await?;
let parts = entry.encode(code).await?;
tokio::pin!(parts);
let mut root = None;
let mut size = 0u64;
Expand All @@ -145,14 +144,14 @@ impl BasicDirectory {
};
let outer = encode_unixfs_pb(&inner, links)?;
let node = UnixfsNode::Directory(Node { outer, inner });
yield node.encode(&code)?;
yield node.encode(code)?;
}
.boxed()
}
}

impl HamtDirectory {
pub fn encode<'a>(self, code: &multihash::Code) -> BoxStream<'a, Result<Block>> {
pub fn encode<'a>(self, code: multihash::Code) -> BoxStream<'a, Result<Block>> {
self.hamt.encode(code)
}
}
Expand Down Expand Up @@ -264,7 +263,7 @@ impl Symlink {
&self.name
}

pub fn encode(self, code: &multihash::Code) -> Result<Block> {
pub fn encode(self, code: multihash::Code) -> Result<Block> {
let target = self
.target
.to_str()
Expand Down Expand Up @@ -463,7 +462,7 @@ impl Entry {
}
}

pub async fn encode(self, code: &multihash::Code) -> Result<BoxStream<'static, Result<Block>>> {
pub async fn encode(self, code: multihash::Code) -> Result<BoxStream<'static, Result<Block>>> {
Ok(match self {
Entry::File(f) => f.encode().await?.boxed(),
Entry::Directory(d) => d.encode(code),
Expand Down Expand Up @@ -595,7 +594,7 @@ impl DirectoryBuilder {

pub async fn add_path(self, path: impl Into<PathBuf>) -> Result<Self> {
let chunker = self.chunker.clone();
let degree = self.degree.clone();
let degree = self.degree;
Ok(self.add_entries(
make_entries_from_path(path, chunker, degree)
.await?
Expand Down Expand Up @@ -680,8 +679,7 @@ impl HamtNode {
}
}

pub fn encode<'a>(self, code: &multihash::Code) -> BoxStream<'a, Result<Block>> {
let code = code.clone();
pub fn encode<'a>(self, code: multihash::Code) -> BoxStream<'a, Result<Block>> {
match self {
Self::Branch(tree) => {
async_stream::try_stream! {
Expand All @@ -690,7 +688,7 @@ impl HamtNode {
for (prefix, node) in tree {
let name = format!("{:02X}{}", prefix, node.name());
bitfield.set_bit(prefix);
let blocks = node.encode(&code);
let blocks = node.encode(code);
let mut root = None;
tokio::pin!(blocks);
while let Some(block) = blocks.next().await {
Expand All @@ -715,11 +713,11 @@ impl HamtNode {
// it does not really matter what enum variant we choose here as long as
// it is not raw. The type of the node will be HamtShard from above.
let node = UnixfsNode::Directory(crate::unixfs::Node { outer, inner });
yield node.encode(&code)?;
yield node.encode(code)?;
}
.boxed()
}
Self::Leaf(HamtLeaf(_hash, entry)) => async move { entry.encode(&code).await }
Self::Leaf(HamtLeaf(_hash, entry)) => async move { entry.encode(code).await }
.try_flatten_stream()
.boxed(),
}
Expand Down
2 changes: 1 addition & 1 deletion iroh-unixfs/src/unixfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl UnixfsNode {
}
}

pub fn encode(&self, code: &multihash::Code) -> Result<Block> {
pub fn encode(&self, code: multihash::Code) -> Result<Block> {
let res = match self {
UnixfsNode::Raw(data) => {
let out = data.clone();
Expand Down

0 comments on commit 1daf452

Please sign in to comment.