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

Generalize TPeerId into TConnInfo #1045

Merged
merged 3 commits into from
Apr 5, 2019

Conversation

tomaka
Copy link
Member

@tomaka tomaka commented Apr 4, 2019

This is the first part of #1030

At the moment, the structs in the nodes module have a TPeerId parameter that notably requires Eq + Hash.

This PR turns TPeerId into TConnInfo, and introduces a new trait that TConnInfo must implement:

/// Information about a connection.
pub trait ConnectionInfo {
    /// Identity of the node we are connected to.
    type PeerId: Eq + Hash;

    /// Returns the identity of the node we are connected to on this connection.
    fn peer_id(&self) -> &Self::PeerId;
}

impl ConnectionInfo for PeerId {
    type PeerId = PeerId;

    fn peer_id(&self) -> &PeerId {
        self
    }
}

By default, a TConnInfo is a PeerId. But after this PR, it can consist of anything that contains a PeerId.

@ghost ghost assigned tomaka Apr 4, 2019
@ghost ghost added the in progress label Apr 4, 2019
}

/// Returns the identity of the node we connected to.
pub fn peer_id(&self) -> &TPeerId
Copy link
Contributor

Choose a reason for hiding this comment

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

How about removing peer_id()?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is there for convenience and is used a lot in raw_swarm. Can I keep it? 🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

Of course you can keep it 😄. It was just a thought.

@tomaka tomaka merged commit b176032 into libp2p:master Apr 5, 2019
@tomaka tomaka deleted the generalize-connec-info branch April 5, 2019 16:37
@ghost ghost removed the in progress label Apr 5, 2019
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