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

Networking & Other Refactoring #115

Merged
merged 4 commits into from
Jan 8, 2024

Conversation

dimitrovmaksim
Copy link
Contributor

What this PR does:

  • Replacing manually parsing localhost ip with LOCALHOST constant
  • array::from_fn to avoid duplication when generating random IDs
  • Make functions which have paramaters for ip: IpAddr, port: u16 instead have SocketAddr
  • Having Message::tracked_subnets accept any slice instead of just Vecs (overly strict type for what is needed)
  • Change TLS server/client config error to be consistently io::error::ErrorKind::Other

Copy link
Collaborator

@richardpringle richardpringle left a comment

Choose a reason for hiding this comment

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

This is a lot nicer! Only two of my comments are actual change requests. Feel free to resolve the others.

core/network/src/peer/mod.rs Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

let peer_node_id = node::Id::from_cert_der_bytes(&peer_certificate.0)?;
info!(
"successfully connected to {} (total {} certificates, first cert {}-byte)",
peer_node_id,
peer_certs.len(),
other_certificates.len() + 1,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't use other_certificates. It would probably be better to do the following:

        let (peer_certificate, total_certificates) = conn
            .peer_certificates()
            .and_then(|certs| {
                let total_certs = certs.len();
                certs.split_first().map(|(first, _)| (first, total_certs))
            })
            .ok_or(Error::new(
                ErrorKind::NotConnected,
                "no peer certificate found",
            ))?;

        let peer_node_id = node::Id::from_cert_der_bytes(&peer_certificate.0)?;
        info!(
            "successfully connected to {} (total {} certificates, first cert {}-byte)",
            peer_node_id,
            total_certificates,
            peer_certificate.0.len(),
        );

@@ -153,7 +138,7 @@ fn test_connector() {
/// Represents a connection to a peer.
/// ref. <https://github.com/rustls/rustls/commit/b8024301747fb0328c9493d7cf7268e0de17ffb3>
pub struct Stream {
pub addr: String,
pub addr: SocketAddr,
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

.iter()
.map(|id| id.to_vec())
.map(prost::bytes::Bytes::from)
.collect();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Much nicer, 🥇

@richardpringle
Copy link
Collaborator

@dimitrovmaksim, @Angel-Petrov has an unsigned commit on this branch. If one of you can sign that commit, we can merge.

Angel-Petrov and others added 2 commits December 20, 2023 09:49
Signed-off-by: Maksim Dimitrov <dimitrov.maksim@gmail.com>
Signed-off-by: Maksim Dimitrov <dimitrov.maksim@gmail.com>
@dimitrovmaksim dimitrovmaksim force-pushed the networking-refactor branch 2 times, most recently from a878b7a to 4891b06 Compare December 20, 2023 07:51
@dimitrovmaksim
Copy link
Contributor Author

@dimitrovmaksim, @Angel-Petrov has an unsigned commit on this branch. If one of you can sign that commit, we can merge.

I signed it, hopefully I did not break something else 😅

@richardpringle richardpringle merged commit 7f1be4a into ava-labs:main Jan 8, 2024
7 checks passed
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.

3 participants