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
Add stream_id
accessors to public API types
#292
Conversation
This will be necessary to add similar accessors to the public API types that wrap these. Signed-off-by: Eliza Weisman <eliza@buoyant.io>
The types `SendStream`, `RecvStream`, `ReleaseCapacity`, `client::ResponseFuture`, and `server::SendResponse` now all have `stream_id` methods which return the stream ID of the corresponding stream. Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
pub const ZERO: StreamId = StreamId(0); | ||
|
||
/// The maximum allowed stream ID. | ||
pub const MAX: StreamId = StreamId(u32::MAX >> 1); | ||
|
||
/// Parse the stream 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.
I'm not sure if this function should be publicly exposed or not (perhaps it should be pub(crate)
instead?)
pub fn is_zero(&self) -> bool { | ||
self.0 == 0 | ||
} | ||
|
||
/// Returns the next stream ID initiated by the same peer as this stream | ||
/// ID, or an error if incrementing this stream ID would overflow the | ||
/// maximum. | ||
pub fn next_id(&self) -> Result<StreamId, StreamIdOverflow> { |
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.
Again, I'm not sure whether or not we want users of the library to be able to construct their own StreamId
s. It seems harmless but I'm not sure if there's any use-case for it. Perhaps this should be pub(crate)
?
|
||
pub fn stream_id(&self) -> StreamId { | ||
self.inner.lock() | ||
.unwrap() |
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 thought unwrap
ping this was probably reasonable, rather than returning a Result
, since if the mutex on the stream store is poisoned, we're in a pretty bad state (and the other functions on StreamRef
also unwrap
).
Yea, I'm also a little uncertain about exposing the |
I'm unsure...I think the newtype better expresses intent, and the |
@seanmonstar Exposing a new type would be more conservative than |
True, a public |
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@seanmonstar WDYT of 557435c? |
Looks good to me, if we also put |
Will do. Note that making
...and so on. |
Actually, nevermind; the fact that a lot of these types are publically-exposed if the |
Hmph. I'm not even particularly sure what the |
I believe it's mainly used so that the test support crate can access things that would otherwise not be public. |
Yes, it is for the test stuff. That being said, with the introduction of tests in a sub crate, there is most likely a way to get rid of that feature flag. |
Okay. That seems out of scope for this branch, though? |
yes |
To comment on this issue, I'm OK exposing the stream ID where appropriate, but it should be a new type |
That's what this branch does as of commit 557435c --- that commit adds a separate The conversation @seanmonstar and I were having was about the fact that the |
src/share.rs
Outdated
/// new stream. | ||
/// | ||
/// [Section 5.1.1]: https://tools.ietf.org/html/rfc7540#section-5.1.1 | ||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] |
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 would recommend removing Copy
. I'd also remove Ord
and PartialOrd
unless there is a case to keep them.
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.
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.
Clone
would make more sense. Copy
is pretty strong and adds a forwards compat hazard.
Build failure for 2d63ed4 was due to a connection issue downloading |
This branch adds an accessor for the stream ID to `RecvBody`. It also updates the h2 dependency to v0.1.11, as it requires hyperium/h2#292. Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Problem:
Applications may want to access the underlying h2 stream ID for
diagnostics, etc. Stream IDs were not previously exposed in public APIs.
Solution:
The
frame::StreamId
type is now publically exported and has RustDoccomments. The public API types
SendStream
,RecvStream
,ReleaseCapacity
,client::ResponseFuture
, andserver::SendResponse
now all have
stream_id
methods which return the stream ID of thecorresponding stream.
Closes #289.
Signed-off-by: Eliza Weisman eliza@buoyant.io