1 /*
2 * Copyright 2020 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 package io.netty.handler.codec.quic;
17
18 import io.netty.buffer.ByteBuf;
19
20 import java.net.InetSocketAddress;
21
22 /**
23 * Handle token related operations.
24 */
25 public interface QuicTokenHandler {
26
27 /**
28 * Generate a new token for the given destination connection id and address. This token is written to {@code out}.
29 * If no token should be generated and so no token validation should take place at all this method should return
30 * {@code false}.
31 *
32 * @param out {@link ByteBuf} into which the token will be written.
33 * @param dcid the destination connection id. The {@link ByteBuf#readableBytes()} will be at most
34 * {@link Quic#MAX_CONN_ID_LEN}.
35 * @param address the {@link InetSocketAddress} of the sender.
36 * @return {@code true} if a token was written and so validation should happen, {@code false} otherwise.
37 */
38 boolean writeToken(ByteBuf out, ByteBuf dcid, InetSocketAddress address);
39
40 /**
41 * Validate the token and return the offset, {@code -1} is returned if the token is not valid.
42 *
43 * @param token the {@link ByteBuf} that contains the token. The ownership is not transferred.
44 * @param address the {@link InetSocketAddress} of the sender.
45 * @return the start index after the token or {@code -1} if the token was not valid.
46 */
47 int validateToken(ByteBuf token, InetSocketAddress address);
48
49 /**
50 * Return the maximal token length.
51 *
52 * @return the maximal supported token length.
53 */
54 int maxTokenLength();
55 }