-
Notifications
You must be signed in to change notification settings - Fork 68
[HIGH] Bound peer-created stream state #201
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -90,7 +90,9 @@ def initialize(settings = {}) | |||||||||||||
| @last_stream_id = 0 | ||||||||||||||
| @streams = {} | ||||||||||||||
| @streams_recently_closed = {} | ||||||||||||||
| @idle_stream_priorities = {} | ||||||||||||||
| @oldest_stream_recently_closed = nil | ||||||||||||||
| @last_promised_stream_id = 0 | ||||||||||||||
| @pending_settings = [] | ||||||||||||||
|
|
||||||||||||||
| @framer = Framer.new(@local_settings[:settings_max_frame_size]) | ||||||||||||||
|
|
@@ -316,11 +318,19 @@ def receive(data) | |||||||||||||
| verify_pseudo_headers(frame) | ||||||||||||||
|
|
||||||||||||||
| verify_stream_order(stream_id) | ||||||||||||||
| priority = @idle_stream_priorities.delete(stream_id) || {} | ||||||||||||||
| if frame[:flags].anybits?(PRIORITY) | ||||||||||||||
| priority = { | ||||||||||||||
| weight: frame[:weight], | ||||||||||||||
| dependency: frame[:dependency], | ||||||||||||||
| exclusive: frame[:exclusive] | ||||||||||||||
| } | ||||||||||||||
| end | ||||||||||||||
| stream = activate_stream( | ||||||||||||||
| id: stream_id, | ||||||||||||||
| weight: frame[:weight] || DEFAULT_WEIGHT, | ||||||||||||||
| dependency: frame[:dependency] || 0, | ||||||||||||||
| exclusive: frame[:exclusive] || false | ||||||||||||||
| weight: priority.fetch(:weight, DEFAULT_WEIGHT), | ||||||||||||||
| dependency: priority.fetch(:dependency, 0), | ||||||||||||||
| exclusive: priority.fetch(:exclusive, false) | ||||||||||||||
|
Comment on lines
+331
to
+333
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| ) | ||||||||||||||
| emit(:stream, stream) | ||||||||||||||
| end | ||||||||||||||
|
|
@@ -352,6 +362,8 @@ def receive(data) | |||||||||||||
| parent = @streams[stream_id] | ||||||||||||||
| pid = frame[:promise_stream] | ||||||||||||||
|
|
||||||||||||||
| validate_push_promise(pid) | ||||||||||||||
|
|
||||||||||||||
| # if PUSH parent is recently closed, RST_STREAM the push | ||||||||||||||
| if @streams_recently_closed[stream_id] | ||||||||||||||
| send(type: :rst_stream, stream: pid, error: :refused_stream) | ||||||||||||||
|
|
@@ -377,6 +389,13 @@ def receive(data) | |||||||||||||
|
|
||||||||||||||
| _verify_pseudo_headers(frame, REQUEST_MANDATORY_HEADERS) | ||||||||||||||
| verify_stream_order(pid) | ||||||||||||||
|
|
||||||||||||||
| promised_stream_count = @streams.each_value.count(&:parent) | ||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of counting on the fly and in order to avoid a O(n), bookkeep this in an ivar instead. |
||||||||||||||
| if promised_stream_count >= @local_settings[:settings_max_concurrent_streams] | ||||||||||||||
| send(type: :rst_stream, stream: pid, error: :refused_stream) | ||||||||||||||
| next | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| stream = activate_stream(id: pid, parent: parent) | ||||||||||||||
| emit(:promise, stream) | ||||||||||||||
| stream << frame | ||||||||||||||
|
|
@@ -399,12 +418,17 @@ def receive(data) | |||||||||||||
| # the draining connection open. | ||||||||||||||
| next if closed? && stream_id <= @last_stream_id | ||||||||||||||
|
|
||||||||||||||
| stream = activate_stream( | ||||||||||||||
| id: stream_id, | ||||||||||||||
| unless @idle_stream_priorities.key?(stream_id) | ||||||||||||||
| next if @idle_stream_priorities.size >= @local_settings[:settings_max_concurrent_streams] | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| priority = { | ||||||||||||||
| weight: frame[:weight] || DEFAULT_WEIGHT, | ||||||||||||||
| dependency: frame[:dependency] || 0, | ||||||||||||||
| exclusive: frame[:exclusive] || false | ||||||||||||||
| ) | ||||||||||||||
| } | ||||||||||||||
| @idle_stream_priorities[stream_id] = priority | ||||||||||||||
| stream = Stream.new(connection: self, id: stream_id, **priority) | ||||||||||||||
|
|
||||||||||||||
| emit(:stream, stream) | ||||||||||||||
| stream << frame | ||||||||||||||
|
|
@@ -577,6 +601,18 @@ def ping_management(frame) | |||||||||||||
| end | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| def validate_push_promise(stream_id) | ||||||||||||||
| connection_error(:protocol_error, msg: "clients cannot send PUSH_PROMISE") if @local_role == :server | ||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this clause is easier to read with |
||||||||||||||
| if @local_settings[:settings_enable_push].zero? | ||||||||||||||
| connection_error(:protocol_error, msg: "received PUSH_PROMISE while push is disabled") | ||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| end | ||||||||||||||
| unless stream_id.positive? && stream_id.even? && stream_id > @last_promised_stream_id | ||||||||||||||
| connection_error(:protocol_error, msg: "invalid promised stream ID") | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| @last_promised_stream_id = stream_id | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| # Validate settings parameters. See sepc Section 6.5.2. | ||||||||||||||
| # | ||||||||||||||
| # @param role [Symbol] The sender's role: :client or :server | ||||||||||||||
|
|
||||||||||||||
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.