arturobernalg commented on code in PR #742:
URL: 
https://github.com/apache/httpcomponents-core/pull/742#discussion_r4546601305


##########
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/FrameLimitController.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http2.impl.nio;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.hc.core5.util.Args;
+
+/**
+ * Per-connection resource policy for unsolicited HTTP/2 control frames. 
Non-ACK PING and
+ * SETTINGS frames share one token bucket, exactly as before this class 
existed; rapid
+ * cancellation (RST_STREAM) of peer-initiated streams is charged against its 
own,
+ * independent bucket.
+ *
+ * <p>ACK frames, DATA and WINDOW_UPDATE are not charged, as they can 
represent legitimate
+ * high-throughput or highly concurrent exchanges. A stream reset is only 
charged against the
+ * RST_STREAM bucket when it arrives shortly after the stream was activated; 
resets of
+ * long-lived streams are not charged.</p>
+ *
+ * <p>Parameters are hardwired for now; they may become user configurable in 
the future, at
+ * which point this is the single place that would need a public constructor 
or setters.</p>
+ *
+ * <p>This is a resource safeguard, not an RFC 9113 protocol-validity rule.</p>
+ */
+final class FrameLimitController {
+
+    static final int CONTROL_FRAME_CAPACITY = 256;
+    static final int CONTROL_FRAME_REFILL_PER_SECOND = 128;
+
+    static final int RST_STREAM_CAPACITY = 128;
+    static final int RST_STREAM_REFILL_PER_SECOND = 64;
+    static final long RST_STREAM_MAX_AGE_NANOS = TimeUnit.SECONDS.toNanos(1);
+
+    private final TokenBucket controlFrameBucket;
+    private final TokenBucket rstStreamBucket;
+    private final long rstStreamMaxAgeNanos;
+
+    FrameLimitController() {
+        this(CONTROL_FRAME_CAPACITY, CONTROL_FRAME_REFILL_PER_SECOND,
+                RST_STREAM_CAPACITY, RST_STREAM_REFILL_PER_SECOND,
+                RST_STREAM_MAX_AGE_NANOS);
+    }
+
+    FrameLimitController(
+            final int controlFrameCapacity,
+            final int controlFrameRefillPerSecond,
+            final int rstStreamCapacity,
+            final int rstStreamRefillPerSecond,
+            final long rstStreamMaxAgeNanos) {
+        this.controlFrameBucket = new TokenBucket(controlFrameCapacity, 
controlFrameRefillPerSecond);
+        this.rstStreamBucket = new TokenBucket(rstStreamCapacity, 
rstStreamRefillPerSecond);
+        this.rstStreamMaxAgeNanos = Args.positive(rstStreamMaxAgeNanos, 
"Maximum reset age");
+    }
+
+    boolean acceptControlFrame(final long nowNanos) {

Review Comment:
   Exactly. activatedAtNanos is used to identify early resets (within the first 
second of a stream's lifetime). Those count against the RST_STREAM budget; 
resets of older streams do not.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to