|
11 | 11 | import tianxiu2b2t.anyio.streams.proxy as streams_proxy |
12 | 12 | from tianxiu2b2t.anyio import concurrency |
13 | 13 | from tianxiu2b2t.utils import runtime |
14 | | -from tianxiu2b2t.http.asgi import ASGIApplicationBridge, ASGIConfig |
| 14 | +from tianxiu2b2t.http.asgi import ASGIApplicationBridge, ASGIConfig, ASGIListener |
15 | 15 |
|
16 | 16 | from . import utils, abc |
17 | 17 | from .logger import logger |
@@ -130,16 +130,18 @@ async def pub_listener( |
130 | 130 | async def serve( |
131 | 131 | listener: anyio.abc.Listener, |
132 | 132 | ): |
133 | | - async with listener: |
134 | | - logger.tinfo("web.forward.pub_port", port=pub_port) |
135 | | - if not cfg.bridge_web_application: |
136 | | - await listener.serve(pub_handler) |
137 | | - async with ASGIApplicationBridge( |
| 133 | + logger.tinfo("web.forward.pub_port", port=pub_port) |
| 134 | + if cfg.bridge_web_application: |
| 135 | + asgi_listener = ASGIListener( |
138 | 136 | ASGIConfig( |
139 | 137 | app, |
140 | | - ) |
141 | | - ) as bridge: |
142 | | - await bridge.serve(listener) |
| 138 | + ), |
| 139 | + listener |
| 140 | + ) |
| 141 | + await asgi_listener.serve() |
| 142 | + return |
| 143 | + async with listener: |
| 144 | + await listener.serve(pub_handler) |
143 | 145 |
|
144 | 146 | async def pub_handler( |
145 | 147 | sock: streams.BufferedByteStream, |
@@ -241,29 +243,22 @@ async def setup( |
241 | 243 | cfg.get("cert.cert"), |
242 | 244 | cfg.get("cert.key") |
243 | 245 | )) |
244 | | - elif cert_type == abc.CertificateType.CLUSTER: |
245 | | - for cert in await concurrency.gather(*( |
246 | | - cluster.request_cert() for cluster in clusters.clusters |
247 | | - )): |
248 | | - if cert is None: |
249 | | - continue |
250 | | - certificates.append(cert) |
251 | 246 |
|
252 | | - if len(certificates) == 0: |
253 | | - raise RuntimeError(t("error.web.certificates")) |
| 247 | + update_certificates(certificates) |
254 | 248 |
|
255 | | - if tls_listener is None: |
256 | | - raise RuntimeError(t("error.web.tls_listener")) |
257 | | - |
258 | | - for cert in certificates: |
| 249 | +def update_certificates( |
| 250 | + certicates: list[abc.Certificate] |
| 251 | +): |
| 252 | + assert tls_listener is not None |
| 253 | + for cert in certicates: |
259 | 254 | context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) |
260 | 255 | context.load_cert_chain(cert.cert, cert.key) |
261 | 256 | context.check_hostname = False |
262 | 257 | context.hostname_checks_common_name = False |
263 | 258 | context.verify_mode = ssl.CERT_NONE |
264 | 259 | if cfg.bridge_web_application: |
265 | 260 | context.set_alpn_protocols(["h2", "http/1.1"]) |
266 | | - |
| 261 | + |
267 | 262 | for domain in cert.domains: |
268 | 263 | tls_listener.add_context( |
269 | 264 | domain, |
|
0 commit comments