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

feat(id): keep a track of connections using a connection ID within qp2p #295

Merged
merged 3 commits into from
Aug 3, 2021

Conversation

lionel-faber
Copy link
Contributor

No description provided.

@lionel-faber lionel-faber requested a review from a team as a code owner July 27, 2021 10:43
@@ -476,8 +478,8 @@ impl Endpoint {
}

/// Get an existing connection for the peer address.
pub(crate) async fn get_connection(&self, peer_addr: &SocketAddr) -> Option<Connection> {
if let Some((conn, guard)) = self.connection_pool.get(peer_addr).await {
pub(crate) async fn get_connection(&self, peer_addr: &SocketAddr) -> Option<Connection<I>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

we probably need get_connection_by_id too no?

In Safe we'd want to avoid any referencing via SockerAddr

Copy link
Contributor

@connec connec left a comment

Choose a reason for hiding this comment

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

I've left some non-functional nitpicks.

Another thing I wondered would be whether we should give I a default type? Perhaps impl Id for u64 and I = u64 (maybe we could even remove Key?).

May not be worth it though, since this would already be a breaking change with the method renames.

.range(Key::min(*addr)..=Key::max(*addr))
.next()
.is_some()
}

#[allow(unused)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: This should be unnecessary for a pub fn.

@@ -14,69 +14,90 @@ use tokio::sync::RwLock;
// Pool for keeping open connections. Pooled connections are associated with a `ConnectionRemover`
// which can be used to remove them from the pool.
#[derive(Clone)]
pub(crate) struct ConnectionPool {
store: Arc<RwLock<Store>>,
pub(crate) struct ConnectionPool<T: Id> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: we probably should be consistent with the type parameter name. We're mostly using I: Id, which I think is a bit better naming.

.range(Key::min(*addr)..=Key::max(*addr))
.next()
.is_some()
}

#[allow(unused)]
pub async fn has_id(&self, id: &T) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps we should rename it to has_conn_id ? and also perhaps have the methods like this one to expect an arg of type &dyn ConnId rather than having a generic on the whole structs?

id_gen: IdGen,
}

/// Unique key identifying a connection. Two connections will always have distict keys even if they
/// have the same socket address.
pub trait Id:
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 naming it ConnId since it's what it is?

BREAKING CHANGE: introduces generic type to Qp2p and Endpoint
- wraps the return type of the generate function in a Result
- updates tests and doc-tests
- implements ConnId for XorName
@joshuef joshuef merged commit 8b2ad02 into maidsafe:master Aug 3, 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.

4 participants