Skip to content

Commit

Permalink
refactor: store the identity::Keypair within Config
Browse files Browse the repository at this point in the history
Explicitly call `make_server_config` and `make_client_config` as part of the upgrade.
  • Loading branch information
denis2glez committed Nov 27, 2023
1 parent 3eb5f1f commit 2ede11c
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions transports/tls/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,15 @@ pub enum UpgradeError {
pub struct Config {
server: rustls::ServerConfig,
client: rustls::ClientConfig,
keypair: identity::Keypair,
}

impl Config {
pub fn new(identity: &identity::Keypair) -> Result<Self, certificate::GenError> {
Ok(Self {
server: crate::make_server_config(identity)?,
client: crate::make_client_config(identity, None)?,
})
}

pub(crate) fn with_expected_peer_id(
expected_peer_id: Option<PeerId>,
) -> Result<Self, certificate::GenError> {
let identity = libp2p_identity::Keypair::generate_ed25519();

Ok(Self {
server: crate::make_server_config(&identity)?,
client: crate::make_client_config(&identity, expected_peer_id)?,
keypair: identity.clone(),
})
}
}
Expand Down Expand Up @@ -152,7 +143,10 @@ where
) -> Self::Future {
async move {
// Create new ad-hoc client and server configuration by passing the expected PeerId
self = Self::with_expected_peer_id(expected_peer_id)?;
let keypair = libp2p_identity::Keypair::generate_ed25519();

Check failure on line 146 in transports/tls/src/upgrade.rs

View workflow job for this annotation

GitHub Actions / Test libp2p-quic

no function or associated item named `generate_ed25519` found for struct `libp2p_identity::Keypair` in the current scope
self.server = crate::make_server_config(&keypair)?;
self.client = crate::make_client_config(&keypair, expected_peer_id)?;
self.keypair = keypair;

// Spec: In order to keep this flexibility for future versions, clients that only support
// the version of the handshake defined in this document MUST NOT send any value in the
Expand Down

0 comments on commit 2ede11c

Please sign in to comment.