Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ libp2p-ping = { version = "0.47.0", path = "protocols/ping" }
libp2p-plaintext = { version = "0.43.0", path = "transports/plaintext" }
libp2p-pnet = { version = "0.26.0", path = "transports/pnet" }
libp2p-quic = { version = "0.13.0", path = "transports/quic" }
libp2p-relay = { version = "0.21.0", path = "protocols/relay" }
libp2p-relay = { version = "0.21.1", path = "protocols/relay" }
libp2p-rendezvous = { version = "0.17.0", path = "protocols/rendezvous" }
libp2p-request-response = { version = "0.29.0", path = "protocols/request-response" }
libp2p-server = { version = "0.12.7", path = "misc/server" }
Expand All @@ -109,7 +109,7 @@ libp2p-tcp = { version = "0.44.0", path = "transports/tcp" }
libp2p-tls = { version = "0.6.2", path = "transports/tls" }
libp2p-uds = { version = "0.43.0", path = "transports/uds" }
libp2p-upnp = { version = "0.5.0", path = "protocols/upnp" }
libp2p-webrtc = { version = "0.9.0-alpha.1", path = "transports/webrtc" }
libp2p-webrtc = { version = "0.9.1-alpha", path = "transports/webrtc" }
libp2p-webrtc-utils = { version = "0.4.0", path = "misc/webrtc-utils" }
libp2p-webrtc-websys = { version = "0.4.0", path = "transports/webrtc-websys" }
libp2p-websocket = { version = "0.45.2", path = "transports/websocket" }
Expand Down
2 changes: 1 addition & 1 deletion misc/peer-store/src/memory_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<T> MemoryStore<T> {
let record = self
.records
.entry(*peer)
.or_insert(PeerRecord::new(self.config.record_capacity));
.or_insert_with(|| PeerRecord::new(self.config.record_capacity));
let is_new = record.add_address(address, is_permanent);
if is_new {
self.push_event_and_wake(Event::PeerAddressAdded {
Expand Down
3 changes: 3 additions & 0 deletions protocols/gossipsub/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
- Remove `Rpc` from the public API.
See [PR 6091](https://github.com/libp2p/rust-libp2p/pull/6091)

- reduce allocations by replacing `or_insert` with `or_insert_with`
See [PR 6136](https://github.com/libp2p/rust-libp2p/pull/6136)

## 0.49.2

- Relax `Behaviour::with_metrics` requirements, do not require DataTransform and TopicSubscriptionFilter to also impl Default
Expand Down
42 changes: 24 additions & 18 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3125,14 +3125,17 @@ where
// The protocol negotiation occurs once a message is sent/received. Once this happens we
// update the type of peer that this is in order to determine which kind of routing should
// occur.
let connected_peer = self.connected_peers.entry(peer_id).or_insert(PeerDetails {
kind: PeerKind::Floodsub,
connections: vec![],
outbound: false,
sender: Sender::new(self.config.connection_handler_queue_len()),
topics: Default::default(),
dont_send: LinkedHashMap::new(),
});
let connected_peer = self
.connected_peers
.entry(peer_id)
.or_insert_with(|| PeerDetails {
kind: PeerKind::Floodsub,
connections: vec![],
outbound: false,
sender: Sender::new(self.config.connection_handler_queue_len()),
topics: Default::default(),
dont_send: LinkedHashMap::new(),
});
// Add the new connection
connected_peer.connections.push(connection_id);

Expand All @@ -3150,16 +3153,19 @@ where
_: Endpoint,
_: PortUse,
) -> Result<THandler<Self>, ConnectionDenied> {
let connected_peer = self.connected_peers.entry(peer_id).or_insert(PeerDetails {
kind: PeerKind::Floodsub,
connections: vec![],
// Diverging from the go implementation we only want to consider a peer as outbound peer
// if its first connection is outbound.
outbound: !self.px_peers.contains(&peer_id),
sender: Sender::new(self.config.connection_handler_queue_len()),
topics: Default::default(),
dont_send: LinkedHashMap::new(),
});
let connected_peer = self
.connected_peers
.entry(peer_id)
.or_insert_with(|| PeerDetails {
kind: PeerKind::Floodsub,
connections: vec![],
// Diverging from the go implementation we only want to consider a peer as outbound
// peer if its first connection is outbound.
outbound: !self.px_peers.contains(&peer_id),
sender: Sender::new(self.config.connection_handler_queue_len()),
topics: Default::default(),
dont_send: LinkedHashMap::new(),
});
// Add the new connection
connected_peer.connections.push(connection_id);

Expand Down
5 changes: 5 additions & 0 deletions protocols/relay/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.21.1

- reduce allocations by replacing `get_or_insert` with `get_or_insert_with`
See [PR 6136](https://github.com/libp2p/rust-libp2p/pull/6136)

## 0.21.0

<!-- Update to libp2p-swarm v0.47.0 -->
Expand Down
2 changes: 1 addition & 1 deletion protocols/relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-relay"
edition.workspace = true
rust-version = { workspace = true }
description = "Communications relaying for libp2p"
version = "0.21.0"
version = "0.21.1"
authors = ["Parity Technologies <admin@parity.io>", "Max Inden <mail@max-inden.de>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
4 changes: 2 additions & 2 deletions protocols/relay/src/priv_client/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,12 @@ fn parse_relayed_multiaddr(addr: Multiaddr) -> Result<RelayedMultiaddr, Transpor
if before_circuit {
relayed_multiaddr
.relay_addr
.get_or_insert(Multiaddr::empty())
.get_or_insert_with(Multiaddr::empty)
.push(p);
} else {
relayed_multiaddr
.dst_addr
.get_or_insert(Multiaddr::empty())
.get_or_insert_with(Multiaddr::empty)
.push(p);
}
}
Expand Down
5 changes: 5 additions & 0 deletions transports/webrtc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.9.1-alpha

- reduce allocations by replacing `get_or_insert` with `get_or_insert_with`
See [PR 6136](https://github.com/libp2p/rust-libp2p/pull/6136)

## 0.9.0-alpha.1

- Bump `webrtc` dependency to `0.12.0`.
Expand Down
2 changes: 1 addition & 1 deletion transports/webrtc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libp2p-webrtc"
version = "0.9.0-alpha.1"
version = "0.9.1-alpha"
Comment thread
elenaf9 marked this conversation as resolved.
Outdated
authors = ["Parity Technologies <admin@parity.io>"]
description = "WebRTC transport for libp2p"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
44 changes: 24 additions & 20 deletions transports/webrtc/src/tokio/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,27 +203,29 @@ impl StreamMuxer for Connection {
cx: &mut Context<'_>,
) -> Poll<Result<Self::Substream, Self::Error>> {
let peer_conn = self.peer_conn.clone();
let fut = self.outbound_fut.get_or_insert(Box::pin(async move {
let peer_conn = peer_conn.lock().await;
let fut = self.outbound_fut.get_or_insert_with(|| {
Box::pin(async move {
let peer_conn = peer_conn.lock().await;

let data_channel = peer_conn.create_data_channel("", None).await?;
let data_channel = peer_conn.create_data_channel("", None).await?;

// No need to hold the lock during the DTLS handshake.
drop(peer_conn);
// No need to hold the lock during the DTLS handshake.
drop(peer_conn);

tracing::trace!(channel=%data_channel.id(), "Opening data channel");
tracing::trace!(channel=%data_channel.id(), "Opening data channel");

let (tx, rx) = oneshot::channel::<Arc<DetachedDataChannel>>();
let (tx, rx) = oneshot::channel::<Arc<DetachedDataChannel>>();

// Wait until the data channel is opened and detach it.
register_data_channel_open_handler(data_channel, tx).await;
// Wait until the data channel is opened and detach it.
register_data_channel_open_handler(data_channel, tx).await;

// Wait until data channel is opened and ready to use
match rx.await {
Ok(detached) => Ok(detached),
Err(e) => Err(Error::Internal(e.to_string())),
}
}));
// Wait until data channel is opened and ready to use
match rx.await {
Ok(detached) => Ok(detached),
Err(e) => Err(Error::Internal(e.to_string())),
}
})
});

match ready!(fut.as_mut().poll(cx)) {
Ok(detached) => {
Expand All @@ -250,12 +252,14 @@ impl StreamMuxer for Connection {
tracing::debug!("Closing connection");

let peer_conn = self.peer_conn.clone();
let fut = self.close_fut.get_or_insert(Box::pin(async move {
let peer_conn = peer_conn.lock().await;
peer_conn.close().await?;
let fut = self.close_fut.get_or_insert_with(|| {
Box::pin(async move {
let peer_conn = peer_conn.lock().await;
peer_conn.close().await?;

Ok(())
}));
Ok(())
})
});

match ready!(fut.as_mut().poll(cx)) {
Ok(()) => {
Expand Down
Loading