1 /* 2 * Copyright 2021 The Netty Project 3 * 4 * The Netty Project licenses this file to you under the Apache License, 5 * version 2.0 (the "License"); you may not use this file except in compliance 6 * with the License. You may obtain a copy of the License at: 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 17 package io.netty.handler.codec.http3; 18 19 /** 20 * A strategy that determines when to send <a 21 * href="https://www.rfc-editor.org/rfc/rfc9204.html#name-section-acknowledgment">acknowledgment</a> of new table 22 * entries on the QPACK decoder stream. 23 */ 24 public interface QpackDecoderStateSyncStrategy { 25 26 /** 27 * Callback when an <a 28 * href="https://www.rfc-editor.org/rfc/rfc9204.html#name-encoded-field-section-prefi"> 29 * encoded header field section</a> is decoded successfully by the decoder. 30 * 31 * @param requiredInsertCount for the encoded field section. 32 */ 33 void sectionAcknowledged(int requiredInsertCount); 34 35 /** 36 * When a header field entry is added to the decoder dynamic table. 37 * 38 * @param insertCount for the entry. 39 * @return {@code true} if an <a 40 * href="https://www.rfc-editor.org/rfc/rfc9204.html#name-insert-count-increment">insert count 41 * increment decoder instruction</a> should be sent. 42 */ 43 boolean entryAdded(int insertCount); 44 45 /** 46 * Returns a {@link QpackDecoderStateSyncStrategy} that will acknowledge each entry added via 47 * {@link #entryAdded(int)} unless a prior {@link #sectionAcknowledged(int)} call has implicitly acknowledged the 48 * addition. 49 * 50 * @return A {@link QpackDecoderStateSyncStrategy} that will acknowledge each entry added via 51 * {@link #entryAdded(int)} unless a prior {@link #sectionAcknowledged(int)} call has implicitly acknowledged the 52 * addition. 53 */ 54 static QpackDecoderStateSyncStrategy ackEachInsert() { 55 return new QpackDecoderStateSyncStrategy() { 56 private int lastCountAcknowledged; 57 58 @Override 59 public void sectionAcknowledged(int requiredInsertCount) { 60 if (lastCountAcknowledged < requiredInsertCount) { 61 lastCountAcknowledged = requiredInsertCount; 62 } 63 } 64 65 @Override 66 public boolean entryAdded(int insertCount) { 67 if (lastCountAcknowledged < insertCount) { 68 lastCountAcknowledged = insertCount; 69 return true; 70 } 71 return false; 72 } 73 }; 74 } 75 }