Skip to content
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

Send/forward messages only to target peers. #2357

Closed
wants to merge 2 commits into from
Closed

Send/forward messages only to target peers. #2357

wants to merge 2 commits into from

Conversation

vnermolaev
Copy link
Contributor

@vnermolaev vnermolaev commented Nov 23, 2021

Problem:
Observe the definition of Floodsub:

pub struct Floodsub {
   ...
    /// List of peers to send messages to.
    target_peers: FnvHashSet<PeerId>,

    /// List of peers the network is connected to, and the topics that they're subscribed to.
    connected_peers: HashMap<PeerId, SmallVec<[Topic; 8]>>,
    ...
}

Say, you have added a peer to your communication list as such

floodsub.add_node_to_partial_view(peer_id)

and then publish a message as such

floodsub.publish(topic, bytes)

You will find that the message will be propagated across all connected peers, rather than target peers.
Problem is that target_peers seems to not be used as intended, and thus the call add_node_to_partial_view has no influence on whether messages are going to be sent to that peer_id.

This behaviour is easy to abuse by establishing an unauthorized connection to a network and sniffing on the internal communication, even if the unauthorized node did was not added to the partial view.

PS: Corrected loops are very much imperative and can be written in a more functional style. I did not want to introduce larger changes before you either confirm or deny my claim on the anticipated behaviour.

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks sane to me. Would you mind adding a changelog entry and bumping the crate version? See https://github.com/libp2p/rust-libp2p/blob/master/docs/release.md.

May I ask why you are using floodsub over gossipsub?

@vnermolaev
Copy link
Contributor Author

vnermolaev commented Nov 26, 2021

May I ask why you are using floodsub over gossipsub?

haha, I am just starting to learn libp2p, I did what the documentation told me :)

@vnermolaev
Copy link
Contributor Author

I had to open a copycat PR due to a personal git branching mess-up. Sorry.
See #2360

@vnermolaev vnermolaev closed this Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants