Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.net.http/share/classes/jdk/internal/net/http/AsyncSSLTunnelConnection.java
41171 views
1
/*
2
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package jdk.internal.net.http;
27
28
import java.net.InetSocketAddress;
29
import java.nio.channels.SocketChannel;
30
import java.util.concurrent.CompletableFuture;
31
import java.net.http.HttpHeaders;
32
import java.util.function.Function;
33
import jdk.internal.net.http.common.MinimalFuture;
34
import jdk.internal.net.http.common.SSLTube;
35
import jdk.internal.net.http.common.Utils;
36
import static jdk.internal.net.http.common.Utils.ProxyHeaders;
37
38
/**
39
* An SSL tunnel built on a Plain (CONNECT) TCP tunnel.
40
*/
41
class AsyncSSLTunnelConnection extends AbstractAsyncSSLConnection {
42
43
final PlainTunnelingConnection plainConnection;
44
final PlainHttpPublisher writePublisher;
45
volatile SSLTube flow;
46
47
AsyncSSLTunnelConnection(InetSocketAddress addr,
48
HttpClientImpl client,
49
String[] alpn,
50
InetSocketAddress proxy,
51
ProxyHeaders proxyHeaders)
52
{
53
super(addr, client, Utils.getServerName(addr), addr.getPort(), alpn);
54
this.plainConnection = new PlainTunnelingConnection(addr, proxy, client, proxyHeaders);
55
this.writePublisher = new PlainHttpPublisher();
56
}
57
58
@Override
59
public CompletableFuture<Void> connectAsync(Exchange<?> exchange) {
60
if (debug.on()) debug.log("Connecting plain tunnel connection");
61
// This will connect the PlainHttpConnection flow, so that
62
// its HttpSubscriber and HttpPublisher are subscribed to the
63
// SocketTube
64
return plainConnection
65
.connectAsync(exchange)
66
.thenApply( unused -> {
67
if (debug.on()) debug.log("creating SSLTube");
68
// create the SSLTube wrapping the SocketTube, with the given engine
69
flow = new SSLTube(engine,
70
client().theExecutor(),
71
client().getSSLBufferSupplier()::recycle,
72
plainConnection.getConnectionFlow());
73
return null;} );
74
}
75
76
@Override
77
public CompletableFuture<Void> finishConnect() {
78
// The actual ALPN value, which may be the empty string, is not
79
// interesting at this point, only that the handshake has completed.
80
return getALPN()
81
.handle((String unused, Throwable ex) -> {
82
if (ex == null) {
83
return plainConnection.finishConnect();
84
} else {
85
plainConnection.close();
86
return MinimalFuture.<Void>failedFuture(ex);
87
} })
88
.thenCompose(Function.identity());
89
}
90
91
@Override
92
boolean isTunnel() { return true; }
93
94
@Override
95
boolean connected() {
96
return plainConnection.connected(); // && sslDelegate.connected();
97
}
98
99
@Override
100
HttpPublisher publisher() { return writePublisher; }
101
102
@Override
103
public String toString() {
104
return "AsyncSSLTunnelConnection: " + super.toString();
105
}
106
107
@Override
108
ConnectionPool.CacheKey cacheKey() {
109
return ConnectionPool.cacheKey(address, plainConnection.proxyAddr);
110
}
111
112
@Override
113
public void close() {
114
plainConnection.close();
115
}
116
117
@Override
118
SocketChannel channel() {
119
return plainConnection.channel();
120
}
121
122
@Override
123
boolean isProxied() {
124
return true;
125
}
126
127
@Override
128
InetSocketAddress proxy() {
129
return plainConnection.proxyAddr;
130
}
131
132
@Override
133
SSLTube getConnectionFlow() {
134
return flow;
135
}
136
}
137
138