View Javadoc
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.channel.ChannelFuture;
19  import io.netty.channel.ChannelFutureListener;
20  import io.netty.channel.ChannelProgressivePromise;
21  import io.netty.channel.ChannelPromise;
22  import io.netty.channel.socket.DuplexChannel;
23  import org.jetbrains.annotations.Nullable;
24  
25  import java.net.SocketAddress;
26  
27  /**
28   * A QUIC stream.
29   */
30  public interface QuicStreamChannel extends DuplexChannel {
31  
32      /**
33       * Should be added to a {@link ChannelFuture} when the output should be cleanly shutdown via a {@code FIN}. No more
34       * writes will be allowed after this point.
35       */
36      ChannelFutureListener SHUTDOWN_OUTPUT = f -> ((QuicStreamChannel) f.channel()).shutdownOutput();
37  
38      @Override
39      default ChannelFuture bind(SocketAddress socketAddress) {
40          return pipeline().bind(socketAddress);
41      }
42  
43      @Override
44      default ChannelFuture connect(SocketAddress remoteAddress) {
45          return pipeline().connect(remoteAddress);
46      }
47  
48      @Override
49      default ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress) {
50          return pipeline().connect(remoteAddress, localAddress);
51      }
52  
53      @Override
54      default ChannelFuture disconnect() {
55          return pipeline().disconnect();
56      }
57  
58      @Override
59      default ChannelFuture close() {
60          return pipeline().close();
61      }
62  
63      @Override
64      default ChannelFuture deregister() {
65          return pipeline().deregister();
66      }
67  
68      @Override
69      default ChannelFuture bind(SocketAddress localAddress, ChannelPromise channelPromise) {
70          return pipeline().bind(localAddress, channelPromise);
71      }
72  
73      @Override
74      default ChannelFuture connect(SocketAddress remoteAddress, ChannelPromise channelPromise) {
75          return pipeline().connect(remoteAddress, channelPromise);
76      }
77  
78      @Override
79      default ChannelFuture connect(
80              SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise channelPromise) {
81          return pipeline().connect(remoteAddress, localAddress, channelPromise);
82      }
83  
84      @Override
85      default ChannelFuture disconnect(ChannelPromise channelPromise) {
86          return pipeline().disconnect(channelPromise);
87      }
88  
89      @Override
90      default ChannelFuture close(ChannelPromise channelPromise) {
91          return pipeline().close(channelPromise);
92      }
93  
94      @Override
95      default ChannelFuture deregister(ChannelPromise channelPromise) {
96          return pipeline().deregister(channelPromise);
97      }
98  
99      @Override
100     default ChannelFuture write(Object msg) {
101         return pipeline().write(msg);
102     }
103 
104     @Override
105     default ChannelFuture write(Object msg, ChannelPromise channelPromise) {
106         return pipeline().write(msg, channelPromise);
107     }
108 
109     @Override
110     default ChannelFuture writeAndFlush(Object msg, ChannelPromise channelPromise) {
111         return pipeline().writeAndFlush(msg, channelPromise);
112     }
113 
114     @Override
115     default ChannelFuture writeAndFlush(Object msg) {
116         return pipeline().writeAndFlush(msg);
117     }
118 
119     @Override
120     default ChannelPromise newPromise() {
121         return pipeline().newPromise();
122     }
123 
124     @Override
125     default ChannelProgressivePromise newProgressivePromise() {
126         return pipeline().newProgressivePromise();
127     }
128 
129     @Override
130     default ChannelFuture newSucceededFuture() {
131         return pipeline().newSucceededFuture();
132     }
133 
134     @Override
135     default ChannelFuture newFailedFuture(Throwable cause) {
136         return pipeline().newFailedFuture(cause);
137     }
138 
139     @Override
140     default ChannelPromise voidPromise() {
141         return pipeline().voidPromise();
142     }
143 
144     @Override
145     default ChannelFuture shutdownInput() {
146         return shutdownInput(newPromise());
147     }
148 
149     @Override
150     default ChannelFuture shutdownInput(ChannelPromise promise) {
151         return shutdownInput(0, promise);
152     }
153 
154     @Override
155     default ChannelFuture shutdownOutput() {
156         return shutdownOutput(newPromise());
157     }
158 
159     @Override
160     default ChannelFuture shutdown() {
161         return shutdown(newPromise());
162     }
163 
164     /**
165      * Shortcut for calling {@link #shutdownInput(int)} and {@link #shutdownInput(int)}.
166      *
167      * @param error the error to send.
168      * @return the future that is notified on completion.
169      */
170     default ChannelFuture shutdown(int error) {
171         return shutdown(error, newPromise());
172     }
173 
174     /**
175      * Shortcut for calling {@link #shutdownInput(int, ChannelPromise)} and {@link #shutdownInput(int, ChannelPromise)}.
176      *
177      * @param error the error to send.
178      * @param promise will be notified on completion.
179      * @return the future that is notified on completion.
180      */
181     ChannelFuture shutdown(int error, ChannelPromise promise);
182 
183     /**
184      * Shutdown the input of the stream with the given error code. This means a {@code STOP_SENDING} frame will
185      * be send to the remote peer and all data received will be discarded.
186      *
187      * @param error the error to send as part of the {@code STOP_SENDING} frame.
188      * @return the future that is notified on completion.
189      */
190     default ChannelFuture shutdownInput(int error) {
191         return shutdownInput(error, newPromise());
192     }
193 
194     /**
195      * Shutdown the input of the stream with the given error code. This means a {@code STOP_SENDING} frame will
196      * be send to the remote peer and all data received will be discarded.
197      *
198      * @param error the error to send as part of the {@code STOP_SENDING} frame.
199      * @param promise will be notified on completion.
200      * @return the future that is notified on completion.
201      */
202     ChannelFuture shutdownInput(int error, ChannelPromise promise);
203 
204     /**
205      * Shutdown the output of the stream with the given error code. This means a {@code RESET_STREAM} frame will
206      * be send to the remote peer and all data that is not sent yet will be discarded.
207      *
208      * <strong>Important:</strong>If you want to shutdown the output without sending a {@code RESET_STREAM} frame you
209      * should use {@link #shutdownOutput()} which will shutdown the output by sending a {@code FIN} and so signal
210      * a clean shutdown.
211      *
212      * @param error the error to send as part of the {@code RESET_STREAM} frame.
213      * @return the future that is notified on completion.
214      */
215     default ChannelFuture shutdownOutput(int error) {
216         return shutdownOutput(error, newPromise());
217     }
218 
219     /**
220      * Shutdown the output of the stream with the given error code. This means a {@code RESET_STREAM} frame will
221      * be send to the remote peer and all data that is not sent yet will be discarded.
222      *
223      * <strong>Important:</strong>If you want to shutdown the output without sending a {@code RESET_STREAM} frame you
224      * should use {@link #shutdownOutput(ChannelPromise)} which will shutdown the output by sending a {@code FIN}
225      * and so signal a clean shutdown.
226      *
227      * @param error the error to send as part of the {@code RESET_STREAM} frame.
228      * @param promise will be notified on completion.
229      * @return the future that is notified on completion.
230      */
231     ChannelFuture shutdownOutput(int error, ChannelPromise promise);
232 
233     @Override
234     QuicStreamAddress localAddress();
235 
236     @Override
237     QuicStreamAddress remoteAddress();
238 
239     /**
240      * Returns {@code true} if the stream was created locally.
241      *
242      * @return {@code true} if created locally, {@code false} otherwise.
243      */
244     boolean isLocalCreated();
245 
246     /**
247      * Returns the {@link QuicStreamType} of the stream.
248      *
249      * @return {@link QuicStreamType} of this stream.
250      */
251     QuicStreamType type();
252 
253     /**
254      * The id of the stream.
255      *
256      * @return the stream id of this {@link QuicStreamChannel}.
257      */
258     long streamId();
259 
260     /**
261      * The {@link QuicStreamPriority} if explicit set for the stream via {@link #updatePriority(QuicStreamPriority)} or
262      * {@link #updatePriority(QuicStreamPriority, ChannelPromise)}. Otherwise {@code null}.
263      *
264      * @return the priority if any was set.
265      */
266     @Nullable
267     QuicStreamPriority priority();
268 
269     /**
270      * Update the priority of the stream. A stream's priority determines the order in which stream data is sent
271      * on the wire (streams with lower priority are sent first).
272      *
273      * @param priority  the priority.
274      * @return          future that is notified once the operation completes.
275      */
276     default ChannelFuture updatePriority(QuicStreamPriority priority) {
277         return updatePriority(priority, newPromise());
278     }
279 
280     /**
281      * Update the priority of the stream. A stream's priority determines the order in which stream data is sent
282      * on the wire (streams with lower priority are sent first).
283      *
284      * @param priority  the priority.
285      * @param promise   notified once operations completes.
286      * @return          future that is notified once the operation completes.
287      */
288     ChannelFuture updatePriority(QuicStreamPriority priority, ChannelPromise promise);
289 
290     @Override
291     QuicChannel parent();
292 
293     @Override
294     QuicStreamChannel read();
295 
296     @Override
297     QuicStreamChannel flush();
298 
299     @Override
300     QuicStreamChannelConfig config();
301 }