-
Notifications
You must be signed in to change notification settings - Fork 964
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(swarm): enforce creation of Swarm
via SwarmBuilder
#3588
Conversation
Swarm
in favour of SwormBuilder
.Swarm
in favour of SwarmBuilder
.
Swarm
in favour of SwarmBuilder
.Swarm
via SwarmBuilder
.
537d608
to
e170ac0
Compare
Swarm
via SwarmBuilder
.Swarm
via SwarmBuilder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this! Left some comments.
swarm/src/lib.rs
Outdated
impl<TBehaviour> Swarm<TBehaviour> | ||
where | ||
TBehaviour: NetworkBehaviour, | ||
{ | ||
/// Builds a new `Swarm` with a provided executor. | ||
#[deprecated( | ||
note = "Use a builder chain `SwarmBuilder::with_executor(transport, behaviour, local_peer_id, executor).build()` instead." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can shorten this to:
note = "Use a builder chain `SwarmBuilder::with_executor(transport, behaviour, local_peer_id, executor).build()` instead." | |
note = "Use `SwarmBuilder::with_executor` instead." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will replace it, however, the message I propose could be used as a direct replacement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will replace it, however, the message I propose could be used as a direct replacement.
That only works if users use these exact variable names. The only thing we can say for sure is the name of the function so that is what I'd like to point to.
The story would be different if Rust had support for codemods :)
This pull request has merge conflicts. Could you please resolve them @vnermolaev? 🙏 |
e170ac0
to
90bed40
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thank you for that!
Can you add a changelog entry to libp2p-swarm
please?
swarm/src/lib.rs
Outdated
/// Sets executor to a threadpool executor. | ||
pub fn with_threadpool_executor( | ||
transport: transport::Boxed<(PeerId, StreamMuxerBox)>, | ||
behaviour: TBehaviour, | ||
local_peer_id: PeerId, | ||
) -> Self { | ||
match ThreadPoolBuilder::new() | ||
.name_prefix("libp2p-swarm-task-") | ||
.create() | ||
{ | ||
Ok(tp) => Self::with_executor(transport, behaviour, local_peer_id, tp), | ||
Err(err) => { | ||
log::warn!("Failed to create executor thread pool: {:?}", err); | ||
Self::without_executor(transport, behaviour, local_peer_id) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not introduce this one. See #3107.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I cannot simply not introduce it.
error[E0599]: no function or associated item named `with_threadpool_executor` found for struct `SwarmBuilder` in the current scope
--> examples/file-sharing/src/network.rs:50:31
|
50 | let swarm = SwarmBuilder::with_threadpool_executor(
| ^^^^^^^^^^^^^^^^^^^^^^^^
| |
| function or associated item not found in `SwarmBuilder<_>`
| help: there is an associated function with a similar name: `with_executor`
So I keep it for now and then it will be removed as part of #3107?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to not introduce code only to deprecate it later again. Would you mind porting the file-sharing example to a different executor?
swarm/src/lib.rs
Outdated
@@ -401,6 +405,7 @@ where | |||
} | |||
|
|||
/// Builds a new `Swarm` with a threadpool executor. | |||
#[deprecated(note = "Use `SwarmBuilder::with_threadpool_executor` instead.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[deprecated(note = "Use `SwarmBuilder::with_threadpool_executor` instead.")] | |
#[deprecated(note = "The `futures::executor::ThreadPool` executor is deprecated. See https://github.com/libp2p/rust-libp2p/issues/3107.")] |
2595802
to
3015e93
Compare
3015e93
to
53959a5
Compare
53959a5
to
291542b
Compare
Swarm
via SwarmBuilder
Swarm
via SwarmBuilder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, thank you!
Mark constructors `Swarm::with_X_executor` as deprecated. Move the deprecated functionality to `SwarmBuilder::with_X_executor` Use `SwarmBuilder` throughout. Resolves libp2p#3186. Resolves libp2p#3107. Pull-Request: libp2p#3588.
Description
Mark constructors
Swarm::with_X_executor
as deprecated.Move the deprecated functionality to
SwarmBuilder::with_X_executor
Use
SwarmBuilder
throughout.Resolves #3186.
Resolves #3107.
Notes
The main file to audit is https://github.com/libp2p/rust-libp2p/pull/3588/files#diff-7d75430c06d5d5aeba4229b6535d2b56f4e67809ffdac99d2dec8eb8a81b3c5c.
The rest contain changes related to the API change.
Change checklist
Changelog is to be updated after the tech side is settled.