-
Notifications
You must be signed in to change notification settings - Fork 900
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
Redesign upgrade::{write_one, write_with_len_prefix, read_one}
#2111
Conversation
Even though the docs state it, I've ran into a bug multiple times where I used `write_one` several times on the same socket, which obviously doesn't work because it is closed after the first one.
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.
Would you mind including an entry in core/CHANGELOG.md
as well?
While we are at it with breaking the interface, I've always found it a bit annoying that |
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.
While we are at it with breaking the interface, I've always found it a bit annoying that read_length_prefixed returns a dedicated error and not just an io::Error. Do you think we could represent the TooLarge variant as one of the representations of io::Error?
How about ErrorKind::InvalidData
? If you decide to apply this change, can you document the ErrorKind::InvalidData
return value?
write_one
to write_one_and_close
upgrade::{write_one, write_with_len_prefix, read_one}
@mxinden While writing migration docs, I thought it would actually be much better to just not break the API right away and instead deprecate the old functions. So I did just that! The deprecation note should hopefully guide people towards the new functions. I removed |
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.
Looks good to me. Thanks for thorough patch.
I don't quite understand the benefit of deprecating the 3 methods, given that users will have to update at some point anyways and updating should be very low friction. That said, I am fine either way.
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.
@mxinden Noticed another thing, please hold on with merging.
Includes replacing `upgrade::{write_one, read_one}` with `upgrade::{write_length_prefixed, read_length_prefixed}` respectively, which is a direct consequence of [PR2110](libp2p/rust-libp2p#2111).
Includes replacing `upgrade::{write_one, read_one}` with `upgrade::{write_length_prefixed, read_length_prefixed}` respectively, which is a direct consequence of [PR2111](libp2p/rust-libp2p#2111).
This PR re-designs the above three functions to:
We achieve this by:
write_one
functionSemantically, this function is a composition of
write_with_len_prefix
andio.close()
. This represents a footgun because theclose
functionality is not obvious and only mentioned in the docs. Using this function multiple times on a single substream will produces hard to debug behaviour.Deprecating
read_one
andwrite_with_len_prefix
functionsIntroducing
write_length_prefixed
andread_length_prefixed
io::Error
)