Skip to content

Commit

Permalink
core/src: tweak key ownership in PeerRecord constructor (#2510)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsenta committed Feb 15, 2022
1 parent feaa121 commit b4a4ba5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions core/src/peer_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl PeerRecord {
/// Construct a new [`PeerRecord`] by authenticating the provided addresses with the given key.
///
/// This is the same key that is used for authenticating every libp2p connection of your application, i.e. what you use when setting up your [`crate::transport::Transport`].
pub fn new(key: Keypair, addresses: Vec<Multiaddr>) -> Result<Self, SigningError> {
pub fn new(key: &Keypair, addresses: Vec<Multiaddr>) -> Result<Self, SigningError> {
use prost::Message;

let seq = SystemTime::now()
Expand Down Expand Up @@ -200,8 +200,9 @@ mod tests {

#[test]
fn roundtrip_envelope() {
let record =
PeerRecord::new(Keypair::generate_ed25519(), vec![HOME.parse().unwrap()]).unwrap();
let key = Keypair::generate_ed25519();

let record = PeerRecord::new(&key, vec![HOME.parse().unwrap()]).unwrap();

let envelope = record.to_signed_envelope();
let reconstructed = PeerRecord::from_signed_envelope(envelope).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion protocols/rendezvous/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl NetworkBehaviour for Behaviour {
));
}

let action = match PeerRecord::new(self.keypair.clone(), external_addresses) {
let action = match PeerRecord::new(&self.keypair, external_addresses) {
Ok(peer_record) => NetworkBehaviourAction::NotifyHandler {
peer_id: rendezvous_node,
event: handler::OutboundInEvent::NewSubstream {
Expand Down
2 changes: 1 addition & 1 deletion protocols/rendezvous/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ mod tests {
) -> NewRegistration {
NewRegistration::new(
Namespace::from_static(namespace),
PeerRecord::new(identity, vec!["/ip4/127.0.0.1/tcp/1234".parse().unwrap()]).unwrap(),
PeerRecord::new(&identity, vec!["/ip4/127.0.0.1/tcp/1234".parse().unwrap()]).unwrap(),
ttl,
)
}
Expand Down

0 comments on commit b4a4ba5

Please sign in to comment.