GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ChannelOption to identify peer cert server name for quiche::connect (… · chrisvest/netty@9dbd41a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/main/java/io/netty/incubator/codec/quic
    • DefaultQuicChannelConfig.java
    • QuicChannel.java
    • QuicChannelConfig.java
    • QuicChannelOption.java
    • QuicheQuicChannel.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/main/java/io/netty/incubator/codec/quic/DefaultQuicChannelConfig.java‎

Copy file name to clipboard
+148Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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.incubator.codec.quic;
17+
18+
import java.util.Map;
19+
20+
import io.netty.buffer.ByteBufAllocator;
21+
import io.netty.channel.Channel;
22+
import io.netty.channel.ChannelOption;
23+
import io.netty.channel.DefaultChannelConfig;
24+
import io.netty.channel.MessageSizeEstimator;
25+
import io.netty.channel.RecvByteBufAllocator;
26+
import io.netty.channel.WriteBufferWaterMark;
27+
28+
/**
29+
* A QUIC {@link ChannelConfig}.
30+
*/
31+
final class DefaultQuicChannelConfig extends DefaultChannelConfig implements QuicChannelConfig {
32+
33+
/**
34+
* Optional parameter to verify peer's certificate.
35+
* See <a href="https://docs.rs/quiche/0.6.0/quiche/fn.connect.html">server_name</a>.
36+
*/
37+
private String peerCertServerName;
38+
39+
DefaultQuicChannelConfig(Channel channel) {
40+
super(channel);
41+
}
42+
43+
@Override
44+
public Map<ChannelOption<?>, Object> getOptions() {
45+
return getOptions(super.getOptions(), QuicChannelOption.PEER_CERT_SERVER_NAME);
46+
}
47+
48+
@SuppressWarnings("unchecked")
49+
@Override
50+
public <T> T getOption(ChannelOption<T> option) {
51+
if (option == QuicChannelOption.PEER_CERT_SERVER_NAME) {
52+
return (T) String.valueOf(getPeerCertServerName());
53+
}
54+
55+
return super.getOption(option);
56+
}
57+
58+
@Override
59+
public <T> boolean setOption(ChannelOption<T> option, T value) {
60+
validate(option, value);
61+
62+
if (option == QuicChannelOption.PEER_CERT_SERVER_NAME) {
63+
setPeerCertServerName((String) value);
64+
} else {
65+
return super.setOption(option, value);
66+
}
67+
68+
return true;
69+
}
70+
71+
@Override
72+
public DefaultQuicChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis) {
73+
super.setConnectTimeoutMillis(connectTimeoutMillis);
74+
return this;
75+
}
76+
77+
@Override
78+
@Deprecated
79+
public DefaultQuicChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead) {
80+
super.setMaxMessagesPerRead(maxMessagesPerRead);
81+
return this;
82+
}
83+
84+
@Override
85+
public DefaultQuicChannelConfig setWriteSpinCount(int writeSpinCount) {
86+
super.setWriteSpinCount(writeSpinCount);
87+
return this;
88+
}
89+
90+
@Override
91+
public DefaultQuicChannelConfig setAllocator(ByteBufAllocator allocator) {
92+
super.setAllocator(allocator);
93+
return this;
94+
}
95+
96+
@Override
97+
public DefaultQuicChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) {
98+
super.setRecvByteBufAllocator(allocator);
99+
return this;
100+
}
101+
102+
@Override
103+
public DefaultQuicChannelConfig setAutoRead(boolean autoRead) {
104+
super.setAutoRead(autoRead);
105+
return this;
106+
}
107+
108+
@Override
109+
public DefaultQuicChannelConfig setAutoClose(boolean autoClose) {
110+
super.setAutoClose(autoClose);
111+
return this;
112+
}
113+
114+
@Override
115+
public DefaultQuicChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark) {
116+
super.setWriteBufferHighWaterMark(writeBufferHighWaterMark);
117+
return this;
118+
}
119+
120+
@Override
121+
public DefaultQuicChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark) {
122+
super.setWriteBufferLowWaterMark(writeBufferLowWaterMark);
123+
return this;
124+
}
125+
126+
@Override
127+
public DefaultQuicChannelConfig setWriteBufferWaterMark(WriteBufferWaterMark writeBufferWaterMark) {
128+
super.setWriteBufferWaterMark(writeBufferWaterMark);
129+
return this;
130+
}
131+
132+
@Override
133+
public DefaultQuicChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator) {
134+
super.setMessageSizeEstimator(estimator);
135+
return this;
136+
}
137+
138+
@Override
139+
public String getPeerCertServerName() {
140+
return peerCertServerName;
141+
}
142+
143+
@Override
144+
public DefaultQuicChannelConfig setPeerCertServerName(String peerCertServerName) {
145+
this.peerCertServerName = peerCertServerName;
146+
return this;
147+
}
148+
}
Collapse file

‎src/main/java/io/netty/incubator/codec/quic/QuicChannel.java‎

Copy file name to clipboardExpand all lines: src/main/java/io/netty/incubator/codec/quic/QuicChannel.java
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
*/
2929
public interface QuicChannel extends Channel {
3030

31+
/**
32+
* Returns the configuration of this channel.
33+
*/
34+
@Override
35+
QuicChannelConfig config();
36+
3137
/**
3238
* Creates a stream that is using this {@link QuicChannel} and notifies the {@link Future} once done.
3339
* The {@link ChannelHandler} (if not {@code null}) is added to the {@link io.netty.channel.ChannelPipeline} of the
Collapse file

‎src/main/java/io/netty/incubator/codec/quic/QuicChannelConfig.java‎

Copy file name to clipboard
+75Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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.incubator.codec.quic;
17+
18+
import io.netty.buffer.ByteBufAllocator;
19+
import io.netty.channel.ChannelConfig;
20+
import io.netty.channel.MessageSizeEstimator;
21+
import io.netty.channel.RecvByteBufAllocator;
22+
import io.netty.channel.WriteBufferWaterMark;
23+
24+
/**
25+
* A QUIC {@link ChannelConfig}.
26+
*/
27+
public interface QuicChannelConfig extends ChannelConfig {
28+
29+
@Override
30+
@Deprecated
31+
QuicChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead);
32+
33+
@Override
34+
QuicChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis);
35+
36+
@Override
37+
QuicChannelConfig setWriteSpinCount(int writeSpinCount);
38+
39+
@Override
40+
QuicChannelConfig setAllocator(ByteBufAllocator allocator);
41+
42+
@Override
43+
QuicChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
44+
45+
@Override
46+
QuicChannelConfig setAutoRead(boolean autoRead);
47+
48+
@Override
49+
QuicChannelConfig setAutoClose(boolean autoClose);
50+
51+
@Override
52+
QuicChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark);
53+
54+
@Override
55+
QuicChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark);
56+
57+
@Override
58+
QuicChannelConfig setWriteBufferWaterMark(WriteBufferWaterMark writeBufferWaterMark);
59+
60+
@Override
61+
QuicChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator);
62+
63+
/**
64+
* Return the server name parameter used to verify peer's certificate.
65+
*/
66+
String getPeerCertServerName();
67+
68+
/**
69+
* Set set server name for peer's certificate verification.
70+
*
71+
* <strong>Be aware this config setting can only be adjusted before the
72+
* connection is established.</strong>
73+
*/
74+
QuicChannelConfig setPeerCertServerName(String peerCertServerName);
75+
}
Collapse file

‎src/main/java/io/netty/incubator/codec/quic/QuicChannelOption.java‎

Copy file name to clipboard
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.incubator.codec.quic;
17+
18+
import io.netty.channel.ChannelOption;
19+
20+
public final class QuicChannelOption<T> extends ChannelOption<T> {
21+
22+
/**
23+
* Optional parameter to verify peer's certificate.
24+
* See <a href="https://docs.rs/quiche/0.6.0/quiche/fn.connect.html">server_name</a>.
25+
*/
26+
public static final ChannelOption<String> PEER_CERT_SERVER_NAME =
27+
valueOf(QuicChannelOption.class, "PEER_CERT_SERVER_NAME");
28+
29+
@SuppressWarnings({ "deprecation" })
30+
private QuicChannelOption() {
31+
super(null);
32+
}
33+
}
Collapse file

‎src/main/java/io/netty/incubator/codec/quic/QuicheQuicChannel.java‎

Copy file name to clipboardExpand all lines: src/main/java/io/netty/incubator/codec/quic/QuicheQuicChannel.java
+5-6Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import io.netty.buffer.Unpooled;
2121
import io.netty.channel.AbstractChannel;
2222
import io.netty.channel.Channel;
23-
import io.netty.channel.ChannelConfig;
2423
import io.netty.channel.ChannelFuture;
2524
import io.netty.channel.ChannelFutureListener;
2625
import io.netty.channel.ChannelHandler;
@@ -31,7 +30,6 @@
3130
import io.netty.channel.ChannelPipeline;
3231
import io.netty.channel.ChannelPromise;
3332
import io.netty.channel.ConnectTimeoutException;
34-
import io.netty.channel.DefaultChannelConfig;
3533
import io.netty.channel.DefaultChannelPipeline;
3634
import io.netty.channel.EventLoop;
3735
import io.netty.channel.socket.DatagramPacket;
@@ -98,7 +96,7 @@ public void operationComplete(ChannelFuture future) {
9896
// TODO: Consider using quiche_conn_stream_init_application_data(...) and quiche_conn_stream_application_data(...)
9997
private final LongObjectMap<QuicheQuicStreamChannel> streams = new LongObjectHashMap<>();
10098
private final Queue<Long> flushPendingQueue = new ArrayDeque<>();
101-
private final ChannelConfig config;
99+
private final QuicChannelConfig config;
102100
private final boolean server;
103101
private final QuicStreamIdGenerator idGenerator;
104102
private final ChannelHandler streamHandler;
@@ -171,7 +169,7 @@ private QuicheQuicChannel(Channel parent, boolean server, ByteBuffer key, long c
171169
Map.Entry<ChannelOption<?>, Object>[] streamOptionsArray,
172170
Map.Entry<AttributeKey<?>, Object>[] streamAttrsArray) {
173171
super(parent);
174-
config = new DefaultChannelConfig(this);
172+
config = new DefaultQuicChannelConfig(this);
175173
this.server = server;
176174
this.idGenerator = new QuicStreamIdGenerator(server);
177175
this.key = key;
@@ -207,8 +205,9 @@ private void connect(long configAddr) throws Exception {
207205
assert this.traceId == null;
208206
assert this.key == null;
209207
ByteBuf idBuffer = alloc().directBuffer(connectId.remaining()).writeBytes(connectId.duplicate());
208+
final String serverName = config().getPeerCertServerName();
210209
try {
211-
long connection = Quiche.quiche_connect(null, idBuffer.memoryAddress() + idBuffer.readerIndex(),
210+
long connection = Quiche.quiche_connect(serverName, idBuffer.memoryAddress() + idBuffer.readerIndex(),
212211
idBuffer.readableBytes(), configAddr);
213212
if (connection == -1) {
214213
ConnectException connectException = new ConnectException();
@@ -436,7 +435,7 @@ protected void doWrite(ChannelOutboundBuffer channelOutboundBuffer) {
436435
}
437436

438437
@Override
439-
public ChannelConfig config() {
438+
public QuicChannelConfig config() {
440439
return config;
441440
}
442441

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.