|
47 | 47 | from twisted.logger import LoggingFile, LogLevel |
48 | 48 | from twisted.protocols.tls import TLSMemoryBIOFactory |
49 | 49 | from twisted.python.threadpool import ThreadPool |
| 50 | +from twisted.web.resource import Resource |
50 | 51 |
|
51 | 52 | import synapse.util.caches |
52 | 53 | from synapse.api.constants import MAX_PDU_SIZE |
|
55 | 56 | from synapse.config import ConfigError |
56 | 57 | from synapse.config._base import format_config_error |
57 | 58 | from synapse.config.homeserver import HomeServerConfig |
58 | | -from synapse.config.server import ManholeConfig |
| 59 | +from synapse.config.server import ListenerConfig, ManholeConfig |
59 | 60 | from synapse.crypto import context_factory |
60 | 61 | from synapse.events.presence_router import load_legacy_presence_router |
61 | 62 | from synapse.events.spamcheck import load_legacy_spam_checkers |
62 | 63 | from synapse.events.third_party_rules import load_legacy_third_party_event_rules |
63 | 64 | from synapse.handlers.auth import load_legacy_password_auth_providers |
| 65 | +from synapse.http.site import SynapseSite |
64 | 66 | from synapse.logging.context import PreserveLoggingContext |
65 | 67 | from synapse.logging.opentracing import init_tracer |
66 | 68 | from synapse.metrics import install_gc_manager, register_threadpool |
@@ -357,6 +359,55 @@ def listen_tcp( |
357 | 359 | return r # type: ignore[return-value] |
358 | 360 |
|
359 | 361 |
|
| 362 | +def listen_http( |
| 363 | + listener_config: ListenerConfig, |
| 364 | + root_resource: Resource, |
| 365 | + version_string: str, |
| 366 | + max_request_body_size: int, |
| 367 | + context_factory: IOpenSSLContextFactory, |
| 368 | + reactor: IReactorSSL = reactor, |
| 369 | +) -> List[Port]: |
| 370 | + port = listener_config.port |
| 371 | + bind_addresses = listener_config.bind_addresses |
| 372 | + tls = listener_config.tls |
| 373 | + |
| 374 | + assert listener_config.http_options is not None |
| 375 | + |
| 376 | + site_tag = listener_config.http_options.tag |
| 377 | + if site_tag is None: |
| 378 | + site_tag = str(port) |
| 379 | + |
| 380 | + site = SynapseSite( |
| 381 | + "synapse.access.%s.%s" % ("https" if tls else "http", site_tag), |
| 382 | + site_tag, |
| 383 | + listener_config, |
| 384 | + root_resource, |
| 385 | + version_string, |
| 386 | + max_request_body_size=max_request_body_size, |
| 387 | + reactor=reactor, |
| 388 | + ) |
| 389 | + if tls: |
| 390 | + # refresh_certificate should have been called before this. |
| 391 | + assert context_factory is not None |
| 392 | + ports = listen_ssl( |
| 393 | + bind_addresses, |
| 394 | + port, |
| 395 | + site, |
| 396 | + context_factory, |
| 397 | + reactor=reactor, |
| 398 | + ) |
| 399 | + logger.info("Synapse now listening on TCP port %d (TLS)", port) |
| 400 | + else: |
| 401 | + ports = listen_tcp( |
| 402 | + bind_addresses, |
| 403 | + port, |
| 404 | + site, |
| 405 | + reactor=reactor, |
| 406 | + ) |
| 407 | + logger.info("Synapse now listening on TCP port %d", port) |
| 408 | + return ports |
| 409 | + |
| 410 | + |
360 | 411 | def listen_ssl( |
361 | 412 | bind_addresses: Collection[str], |
362 | 413 | port: int, |
|
0 commit comments